Skip to content

koansang/enertalk-api-client

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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';

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,
});

NOTE:

  1. The prameters refreshToken, clientId, clientSecret, domain are used to issue new access token.
  2. tokenUpdateFn will be called when 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,
});

Supported API Methods

name:[...parameters] description
getUser: Get user profile
listSites: List sites
listDevicesOfSite:siteIds List devices of multiple sites
getBills:siteId Get bill information
periodicUsagesBySite:siteId:params Get usage for a site
periodicUsagesByTag:siteId:tagId:params Get usage for a tag
periodicUsagesByDevice:deviceId:params Get usage for a device
periodicUsagesByDeviceWithChannels:devcieId:params Get usage for a device with channels
billingUsagesBySite:siteId:params Get usage and bill for a site
billingUsagesByTag:siteId:tagId:params Get usage and bill for a tag
billingUsagesByDevice:deviceId:params Get usage and bill for a device
billingUsagesByDeviceWithChannels:devcieId:params Get usage and bill for a device with channels
realtimeUsagesBySite:siteId Get real time usage for a site
realtimeUsagesByTag:siteId:tagId Get real time usage for a tag
realtimeUsagesByDevice:deviceId Get real time usage for a device
realtimeUsagesByDeviceWithChannels:devcieId Get real time usage for a device with channels

...

These will continue to be added.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%