enertalk-api-client

0.6.6 • Public • Published

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.

category method descriptions
[bills](https://developer.encoredtech.com/api2-bill/) getBills(siteId:String) Get billing information
updateBills(siteId:String, data:Object) Update bill information
getSuppliers() List suppliers
getRatePlanSchema(supplierId:String, ratePlanId:Number) Get rate plan schema
[devices](https://developer.encoredtech.com/api2-devices/) listDevicesOfSite(siteId:String) List devices of a site
createDevice(siteId:String, data:Object) Create device
getDevice(deviceId:String) Get device
updateDevice(deviceId:String, data:Object) Update device
replaceDevice(deviceId:String, data:Object) Replace device
deleteDevice(deviceId:String) Delete device
[push](https://developer.encoredtech.com/api2-push/) registerPushId(data:Object) Register push id
getPushInfo(params:Object) Get push information
updatePushStates(data:Object) Update push states
getPushStates() Get push states
resetPushToken(params: Object) Reset push token
[sites](https://developer.encoredtech.com/api2-sites/) createSite(data:Object) Create a site
listSites() Get information of all sites belonging to a user
getSite(siteId:String) Get a site information for a user
updateSite(siteId:String, data:Object) Update a site Information for a user
deleteSite(siteId:String) Delete a site and its devices
[tags](https://developer.encoredtech.com/api2-tags/) createTag(siteId:String, data:Object) Create a tag for the site
listTags(siteId:String) List all tags of the site
getTag(siteId:String, tagId:String)
updateTag(siteId:String, tagId:String, data:Object) Update tag information
deleteTag(siteId:String, tagId:String) Delete a tag and untag its devices and channels
tagDeviceOrChannel(tagId:String, deviceId:String, data:Object) Tag or untag a device or channels
[teams](https://developer.encoredtech.com/api2-teams/) createTeam(data:Object) Create a team
listTeams() List all teams where authenticated user is a member
getTeam(teamId:String) Retrieve a team information
updateTeam(teamId:String, data:Object) Update team information
deleteTeam(teamId:String) Delete a team
addTeamMemeber(teamId:Sring, data:Object) Add a user to a team
removeMember(teamId:String, data:Object) Remove a member from a team
[usages](https://developer.encoredtech.com/api2-usages/) periodicUsagesBySite(siteId:String, params:Object) Get usage from start to end time for a site, tag, or a device.
periodicUsagesByTag(siteId:String, tagId:String, params:Object)
periodicUsagesByDevice(deviceId:String, params:Object)
periodicUsagesByDeviceWithChannels(deviceId:String, params:Object)
billingUsagesBySite(siteId:String, params:Object) Get usage and bill for billing periods from start to end time.
billingUsagesByTag(siteId:String, tagId:String, params:Object)
billingUsagesByDevice(deviceId:String, params:Object)
billingUsagesByDeviceWithChannels(deviceId:String, params:Object)
realtimeUsagesBySite(siteId:String) Get realtime usage information for a site, tag, or a device.
realtimeUsagesByTag(siteId:String, tagId:String)
realtimeUsagesByDevice(deviceId:String)
realtimeUsagesByDeviceWithChannels(deviceId:String)
[users](https://developer.encoredtech.com/api2-users/) getUser() Get user information
updateUser(data:Object) Update user information
timelines timelines(registrationId:String, params:Object) Get timelines for a device
updateTimeline(registrationId:String, timelineId:Number, data:Object) Update timeline
timelinesBySite timelinesBySite(siteId:String, params:Object) Get timelines for a site
updateTimelineBySite(siteId:String, timelineId:Number, data:Object) Update timeline for a site
legacy legacy(options:Object) The bridge of old APIs

These will continue to be added.

Readme

Keywords

none

Package Sidebar

Install

npm i enertalk-api-client

Weekly Downloads

34

Version

0.6.6

License

MIT

Unpacked Size

174 kB

Total Files

56

Last publish

Collaborators

  • yongdamsh