3 Star 0 Fork 0

Gitee 极速下载 / shimo-js

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/shimohq/shimo.js.git
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

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:

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.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:

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.post('files', { body: { name: 'Untitled Document' } });

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.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;
});
The MIT License (MIT) Copyright (c) 2015 shimo Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

暂无描述 展开 收起
JavaScript
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/mirrors/shimo-js.git
git@gitee.com:mirrors/shimo-js.git
mirrors
shimo-js
shimo-js
master

搜索帮助