Kitsu
![David](https://img.shields.io/david/wopian/kitsu.svg?style=flat-square)
![CC Issues](https://img.shields.io/codeclimate/issues/github/wopian/kitsu.svg?style=flat-square)
Promise based NodeJS API wrapper for Kitsu.io
Features
- Supports OAuth2 authentication
- Supports the JSON API specification
- Serialises and deserialises requests for pain-free usage
- Supports the Promise API
- Retries on network failure
- Timeout handling
Install
yarn add kitsu
or
npm install kitsu --save
Usage
import Kitsu from 'kitsu'
const Kitsu = require('kitsu')
const kitsu = new Kitsu()
kitsu.get('anime').then(res => console.log(res))
More Examples
Docs
new Kitsu([options])
Creates a new instance with the required JSON API headers already
set
options
Type: object
Type: object
Add extra headers to be sent with all requests, or override the
default user-agent
header
(Kitsu/<version> (https://github.com/wopian/kitsu)
)
If you already have an accessToken
for authentication, you can
construct the authorization
header here with
authorization: 'Bearer <accessToken>'
retries
Type: number
Default: 2
Number of times to retry requests after network failures
timeout
Type: number
Default: 30000
Milliseconds to wait before aborting the request with an ETIMEDOUT
error
useElectronNet
Type: boolean
Default: true
When used in Electron, Kitsu will automatically use
electron.net instead of the NodeJS http
module
kitsu.auth([options])
Returns a Promised object containing an accessToken
on successful
authentication
The authorization
header is automatically applied and passed in
all subsequent DELETE
, GET
, PATCH
and POST
requests
options
Type: object
Inputs for the OAuth 2 Authorization Code grant type. See the
Kitsu API documentation for further details
clientId (required)
Type: string
clientSecret (required)
Type: string
username (required)
Type: string
password (required)
Type: string
kitsu.delete(model, data)
Not yet implemented!
kitsu.get(model, [options])
Returns a Promised response
object
model
Type: string
The resource model to request. Check out the Kitsu API documentation for
available models
options
Type: object
Any of the JSON API request parameters
include
Type: string
Include relationships. Multiple includes are comma seperated
fields
Type: object
Returns only the specified fields
sort
Type: string
Sort lists by an attribute. Append -
for descending order. Multiple sorts are comma seperated
page
Type: object
Limit number of returned resources (page: { limit: 2 }
).
Offset returned resources (page: { offset: 20 }
)
filter
Type: object
Filter returned resources by an attribute
kitsu.patch(model, data)
Not yet implemented!
kitsu.post(model, data)
Not yet implemented!
kitsu.whoAmI([options])
Returns a Promised object containing the user data if the
authorization
header is set
options
Type: object
compact
Type: boolean
Default: false
Returns just the user ID and name if true
Type: object
Returns the current headers
kitsu.isAuth
Type: boolean
Returns true
if the authorization
header is set
Contributing
Requirements
- git 2.0.0 or newer
- node.js 7.0.0 or newer
- yarn 0.21.0 or newer (optional)
Setup
-
Fork this repo
-
Clone your fork:
git clone https://github.com/your-username/kitsu.git
cd kitsu
-
Create a feature branch:
git checkout -b your-feature-name
-
Install dependencies:
yarn install
npm install
-
Commit changes:
git commit -am 'feat: add feature name'
-
Push changes:
git push origin your-feature-name
-
Open a pull request
Releases
See CHANGELOG
License
All code released under MIT