Shimo.js
Official Shimo client for Node.js. Supports Node.js >= 0.10.
Links
Install
npm install shimo
Usage
var Shimo = ;var shimo = version: 'v2' ;
Shimo
constructor accepts an option, where:
name | required | default | description |
---|---|---|---|
version | true | API version | |
protocol | false | https | API protocol |
host | false | api.shimo.im | API host |
clientId | false | null |
Client id, used for requesting tokens |
clientSecret | false | null |
Client secret, used for requesting tokens |
accessToken | false | null |
Access Token, used for access private resources |
refreshToken | false | null |
Refresh Token, used for exchanging access token |
API supports both Node-style callback and Bluebird Proimse:
shimo;shimo;
accessToken
is required in order to access private resources. If accessToken
is omitted or invalid (getting 401
error when accessing APIs), refreshToken
, if present, would be used to exchange a new access token and refresh token.
API
Shimo#:httpMethod
Invoking Shimo Open API. Accepts three arguments:
name | required | description |
---|---|---|
path | true | API endpoint, e.g. 'users/me' |
option | false | API options, e.g. { qs: { id: 12 }, body: { title: 'new' } } |
callback | false | Callback function. If omitted, a promise will be returned |
Example:
shimo;
Shimo#token
Requesting tokens. Accepts three arguments:
name | required | description |
---|---|---|
grant type | true | Grant type, e.g. 'refresh_token' , 'password' |
option | false | Token options, e.g. { scope: 'read' } |
callback | false | Callback function. If omitted, a promise will be returned |
Example:
shimo;
Shimo#authorization
Getting authorization endpoint url.
Example:
// redirect user to the authorization pageres;
Events
Shimo extends EventEmitter
and will emit the following events:
accesstoken_change
When access token changed, the first argument is the new access token.
Example:
shimo;
refreshtoken_change
When refresh token changed, the first argument is the new refresh token.
Example:
shimo;