# shimo

> Official Shimo client for Node.js

Latest version **1.7.0** (published 2018-05-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install shimo
pnpm add shimo
yarn add shimo
bun add shimo
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.7.0 |
| Published | 2018-05-15 |
| First published | 2015-10-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 6 |
| Unpacked size | 13.8 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 41 |
| Author | Zihua Li |
| Maintainers | luin, tomwan |
| Keywords | shimo |

## Links

- npm: https://www.npmjs.com/package/shimo
- Repository: https://github.com/shimohq/shimo.js
- Homepage: https://github.com/shimohq/shimo.js#readme
- Issues: https://github.com/shimohq/shimo.js/issues
- npm.io page: https://npm.io/package/shimo

## Dependencies (6)

- [qs](https://npm.io/package/qs.md) ^6.2.0
- [config](https://npm.io/package/config.md) ^1.16.0
- [lodash](https://npm.io/package/lodash.md) ^4.13.1
- [request](https://npm.io/package/request.md) ^2.72.0
- [bluebird](https://npm.io/package/bluebird.md) ^3.4.0
- [http-errors](https://npm.io/package/http-errors.md) ^1.5.0

## Recent versions

- 1.7.0 (latest) — 2018-05-15
- 1.6.1 — 2017-06-21
- 1.6.0 — 2017-06-21
- 1.5.4 — 2017-01-25
- 1.5.3 — 2016-11-11
- 1.5.2 — 2016-07-18
- 1.5.1 — 2016-07-11
- 1.5.0 — 2016-07-11
- 1.4.0 — 2016-05-25
- 1.3.8 — 2016-01-13
- 1.3.7 — 2016-01-13
- 1.3.6 — 2015-12-22
- 1.3.5 — 2015-12-17
- 1.3.4 — 2015-12-13
- 1.3.3 — 2015-12-13
- … 5 more at https://npm.io/package/shimo/versions

## README

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

[![Build Status](https://travis-ci.org/shimohq/shimo.js.svg?branch=master)](https://travis-ci.org/shimohq/shimo.js)
[![Dependency Status](https://david-dm.org/shimohq/shimo.js.svg)](https://david-dm.org/shimohq/shimo.js)

## Links

[Shimo Open API Documentation](http://shimohq.github.io/doc)

## Install

```shell
npm install shimo
```

## Usage

```javascript
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:

```javascript
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:

```javascript
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:

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

### Shimo#authorization

Getting authorization endpoint url.

Example:

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

### refreshtoken_change

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

Example:
```javascript
shimo.on('refreshtoken_change', function (refreshToken) {
  req.session.refreshToken = refreshToken;
});
```

---
_Source: https://npm.io/package/shimo · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
