weibo-js

0.1.0 • Public • Published

weibo.js

Matador compliant weib.com API SDK, supporting oAuth flow and general API calls

Usage

Install Matador and Initialize a matador based application

npm install -g matador
matador init matador-app
cd matador-app
npm install matador weibo-js

Register weibo middleware in ./server.js

app.use(matador.session({secret: 'key'}))
app.use(require('weibo-js').middleware({
  appId : 'appId',
  secret : 'appSecret',
  loginUrl: '/auth/login',
  logoutUrl: '/auth/logout',
  callbackUrl: '/auth/callback'
}))

Register a filter in base controller, ./app/controllers/ApplicationController.js

module.exports = require('matador').BaseController.extend(function() {
  this.viewFolder = '';
  this.addBeforeFilter(this.requireAuth)
}).methods({
  requireAuth : function(callback) {
    if(this.request.weibo)
      return callback(null)
    this.response.redirect('/auth/login?redirect=' + this.request.url);
  }
})

Call APIs in sub controller, e.g. ./app/controllers/HomeController.js

module.exports = require(app.set('controllers') + '/ApplicationController').extend(function() {
  this.addExcludeFilter(['index'], this.requireAuth)
}).methods({
  index : function() {
    this.render('index', {
      title : 'The Matador Framework'
    })
  },
  status : function() {
    var that = this;
    this.request.weibo.get('/statuses/friends_timeline.json', function(status) {
      that.json(status);
    }, function(error) {
      console.log(error);
      that.render('500');
    });
  }
})

Contributors

Readme

Keywords

none

Package Sidebar

Install

npm i weibo-js

Weekly Downloads

1

Version

0.1.0

License

none

Last publish

Collaborators

  • yonggao