0.6.6 • Published 6 years ago

enertalk-api-client v0.6.6

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

EnerTalk API Client

The EnerTalk API Wrapper for convenience

Requirements

Authentication must be perform by EnerTalk tokens based on OAuth2.
You can find a way to get tokens on our developer site.

Getting Started

Install Package

> npm install enertalk-api-client

Import Package

const EnerTalkAPI = require('enertalk-api-client');
or
import EnerTalkAPI from 'enertalk-api-client';

NOTE:
There's a compatibility issue.
If you're using webpack based project like create-react-app,
please use the build file as below:

const EnerTalkAPI = require('enertalk-api-client/build');
or
import EnerTalkAPI from 'enertalk-api-client/build';

Make an instance

const api = new EnerTalkAPI(authConfig, options);

Use methods with promise

api.getUser()
  .then(response => console.log(response.data))
  .catch(error => console.log(error.response.data));

Auth Config

Set the authConfig at the point of initialization.

const api = new EnerTalkAPI({
  accessToken: 'yourAccessToken',
  refreshToken: 'yourRefreshToken',
  clientId: 'yourClientId',
  clientSecret: 'yourClientSecret',
  domain: 'yourCustomAuthServerDomain', // Default domain will be override
  tokenUpdateFn: (tokenObject) => {
    // The logic that update your token storage
    // `tokenObject`has fields below:
    // - `accessToken`
    // - `refreshToken`
    // - `expiresIn` (unit: second)
  },
});

Or you can update the authConfig at any time.

api.updateAuthConfig({
  accessToken: 'yourAccessToken',
  refreshToken: 'yourRefreshToken',
  // ...otherFields,
});

NOTES:
1. The prameters refreshToken, clientId, clientSecret, domain are used to issue new access token.
2. tokenUpdateFn will be called when a new token issued. You can sync the token object with your token storage.

Request Options

This option follows axios request config.

For example,

const api = new EnerTalkAPI(authConfig, {
  baseURL: 'yourCustomResourceServerDomain',
  timeout: 10000,
});

Pick API Category

You can pick specific categories by second or third option when construct instance.

For example,

const api = new EnerTalkAPI(authConfig, {
  baseURL: 'yourCustomResourceServerDomain',
  timeout: 10000,
}, ['bills', 'devices', 'usages']);

or apiConfig options can be omitted.

const api = new EnerTalkAPI(authConfig, ['bills', 'devices', 'usages']);

It's possible to pass single API Category

const api = new EnerTalkAPI(authConfig, 'bills');

Supported API Methods

Clicking on a category takes you to the api document.

These will continue to be added.

0.6.6

6 years ago

0.6.5

6 years ago

0.6.4

6 years ago

0.6.3

6 years ago

0.6.2

7 years ago

0.6.1

7 years ago

0.6.0

7 years ago

0.5.0

7 years ago

0.4.9

7 years ago

0.4.8

7 years ago

0.4.7

7 years ago

0.4.6

7 years ago

0.4.5

7 years ago

0.4.4

7 years ago

0.4.3

7 years ago

0.4.2

7 years ago

0.4.1

7 years ago

0.4.0

7 years ago

0.3.7

7 years ago

0.3.6

7 years ago

0.3.5

7 years ago

0.3.4

7 years ago

0.3.3

7 years ago

0.3.2

7 years ago

0.3.1

7 years ago

0.3.0

7 years ago

0.2.4

7 years ago

0.2.3

7 years ago

0.2.2

7 years ago

0.2.1

7 years ago

0.2.0

7 years ago