yarn add @putdotio/api-client
npm install @putdotio/api-client
import PutioAPI from '@putdotio/api-client'
const PutioAPI = require('@putdotio/api-client').default
// you can pass the options in constructor
const putioAPI = new PutioAPI({ clientID: 'OAUTH_CLIENT_ID' })
// or use `configure` method
MyApp.bootstrap(config => {
putioAPI.configure({ clientID: config.OAUTH_CLIENT_ID })
})
// setToken will send the given auth token with every request, in Authorization header
MyApp.onLogin(token => {
putioAPI.setToken(token)
putioAPI.Account.Info()
.then(r => console.log('Fetched user info: ', r))
.catch(e => console.log('An error occurred while fetching user info: ', e))
})
// clearToken will perform a clean-up and stop sending the token in Authorization header
MyApp.onLogout(() => {
putioAPI.clearToken()
})
Prop | Type | Default Value | Description |
---|---|---|---|
clientID | number | 1 | OAuth app client ID, defaults to put.io web app |
baseURL | string | api.put.io/v2 | Base URL of the API |
webAppURL | string | app.put.io | Base URL of the Put.io web app, used in the authentication flow |
Name | Parameters | Return Value |
---|---|---|
configure | (options: IPutioAPIClientOptions) |
PutioAPIClient Instance |
setToken | (token: string) |
PutioAPIClient Instance |
clearToken | PutioAPIClient Instance |
Value | Payload | Description |
---|---|---|
ERROR | IPutioAPIClientError | Fired when an HTTP request fails |
CLIENT_IP_CHANGED | { IP: string, newIP: string } |
Fired when the IP of the client changes |