1.7.0 • Published 6 years ago

shimo v1.7.0

Weekly downloads
24
License
MIT
Repository
github
Last release
6 years ago

Shimo.js

Official Shimo client for Node.js. Supports Node.js >= 0.10.

Build Status Dependency Status

Links

Shimo Open API Documentation

Install

npm install shimo

Usage

var Shimo = require('shimo');
var shimo = new Shimo({ version: 'v2' });

Shimo constructor accepts an option, where:

namerequireddefaultdescription
versiontrueAPI version
protocolfalsehttpsAPI protocol
hostfalseapi.shimo.imAPI host
clientIdfalsenullClient id, used for requesting tokens
clientSecretfalsenullClient secret, used for requesting tokens
accessTokenfalsenullAccess Token, used for access private resources
refreshTokenfalsenullRefresh Token, used for exchanging access token

API supports both Node-style callback and Bluebird Proimse:

shimo.get('users/me', function (err, user) {});
shimo.get('users/me').then(function (user) {});

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:

namerequireddescription
pathtrueAPI endpoint, e.g. 'users/me'
optionfalseAPI options, e.g. { qs: { id: 12 }, body: { title: 'new' } }
callbackfalseCallback function. If omitted, a promise will be returned

Example:

shimo.post('files', { body: { name: 'Untitled Document' } });

Shimo#token

Requesting tokens. Accepts three arguments:

namerequireddescription
grant typetrueGrant type, e.g. 'refresh_token', 'password'
optionfalseToken options, e.g. { scope: 'read' }
callbackfalseCallback function. If omitted, a promise will be returned

Example:

shimo.token('authorization', {
  code: req.query.code,
  redirect_uri: 'https://yourapp.tld/oauth/callback'
});

Shimo#authorization

Getting authorization endpoint url.

Example:

// redirect user to the authorization page
res.redirect(shimo.authorization({
  redirect_uri: 'https://yourapp.tld/oauth/callback'
}));

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.on('accesstoken_change', function (accessToken) { });

refreshtoken_change

When refresh token changed, the first argument is the new refresh token.

Example:

shimo.on('refreshtoken_change', function (refreshToken) {
  req.session.refreshToken = refreshToken;
});
1.7.0

6 years ago

1.6.1

7 years ago

1.6.0

7 years ago

1.5.4

7 years ago

1.5.3

8 years ago

1.5.2

8 years ago

1.5.1

8 years ago

1.5.0

8 years ago

1.4.0

8 years ago

1.3.8

8 years ago

1.3.7

8 years ago

1.3.6

8 years ago

1.3.5

8 years ago

1.3.4

8 years ago

1.3.3

8 years ago

1.3.2

8 years ago

0.3.2

9 years ago

0.3.1

9 years ago

0.1.0

9 years ago

0.0.1

9 years ago