-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from septk/feature/new-setup-modules
Feature/new setup modules
- Loading branch information
Showing
14 changed files
with
301 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,4 @@ compiled | |
.awcache | ||
.rpt2_cache | ||
docs | ||
test/__snapshots__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,25 @@ | ||
#SigfoxJS | ||
# SigfoxJS | ||
|
||
![Sigfox Logo img](https://temp.iotdk.dk/wp-content/uploads/2018/01/Sigfox_Logo_RGB_R-300x175.png ) | ||
|
||
## [WIP] | ||
|
||
- Work in Progress | ||
```javascript | ||
const SigfoxApi = require('sigfox-js'); | ||
|
||
const apiConnection = new SigfoxApi({ | ||
username: 'username', | ||
password: 'password' | ||
}); | ||
|
||
const infoDevices = await connection.devices.getAllDevices(); | ||
``` | ||
|
||
#### To Do: | ||
|
||
- Users [x] | ||
- Coverages [ ] | ||
- Devices [ ] | ||
- Devices Types [ ] | ||
- Groups [ ] | ||
- Tiles [ ] |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
import axios, { AxiosInstance } from 'axios' | ||
|
||
import { RootObject, ModemCertificate } from '../types/devices/getAllDevices' | ||
import { API_CONFIG } from '../config/constants' | ||
|
||
export class Devices { | ||
rest: AxiosInstance | ||
config: object | ||
|
||
constructor(config: object) { | ||
this.rest = axios.create({ baseURL: API_CONFIG.baseURL }) | ||
this.config = config | ||
} | ||
|
||
/** | ||
* The endpoint to get Device Info. | ||
* HTTP GET /devices/${deviceId} | ||
* @returns {device} | ||
*/ | ||
public getDeviceInfo(deviceId: string): Promise<RootObject> { | ||
return this.rest | ||
.get<RootObject>(API_CONFIG.baseURL + `/devices/${deviceId}`, this.config) | ||
.then(response => response.data) | ||
.catch(error => error.response.statusText) | ||
} | ||
|
||
/** | ||
* The endpoint to get info from all devices. | ||
* HTTP GET /devices/?deep=false&sort=name&limit=100&offset=0 | ||
* To Do - query + params customizable | ||
* @returns [Devices] | ||
*/ | ||
public getAllDevices(): Promise<RootObject> { | ||
return this.rest | ||
.get<RootObject>( | ||
API_CONFIG.baseURL + `/devices/?deep=false&sort=name&limit=100&offset=0`, | ||
this.config | ||
) | ||
.then(response => response.data) | ||
.catch(error => error.response.statusText) | ||
} | ||
|
||
/** | ||
* Retrieve a list of undelivered callbacks and errors for a given device, in reverse chronological order (most recent message first). | ||
* HTTP GET /devices/${deviceId}/callbacks-not-delivered | ||
* @returns [Callbacks - Errors] | ||
*/ | ||
public getCallbacksNotDelivered(deviceId: string) { | ||
return this.rest | ||
.get(API_CONFIG.baseURL + `/devices/${deviceId}/callbacks-not-delivered`, this.config) | ||
.then(response => response.data) | ||
.catch(error => error.response.statusText) | ||
} | ||
|
||
/** | ||
* Retrieve the modem certificate associated with a device. | ||
* HTTP GET /devices/${deviceId}/certificate/modem | ||
* @returns {ModemCertificate} | ||
*/ | ||
public getModemCert(deviceId: string): Promise<ModemCertificate> { | ||
return this.rest | ||
.get<ModemCertificate>( | ||
API_CONFIG.baseURL + `/devices/${deviceId}/certificate/modem`, | ||
this.config | ||
) | ||
.then(response => response.data) | ||
.catch(error => error.response.statusText) | ||
} | ||
|
||
/** | ||
* Retrieve the product certificate associated with a device already registered. | ||
* HTTP GET /devices/${deviceId}/certificate/product | ||
* @returns {ProductCertificate} | ||
*/ | ||
public getProductCert(deviceId: string) { | ||
return this.rest | ||
.get(API_CONFIG.baseURL + `/devices/${deviceId}/certificate/product`, this.config) | ||
.then(response => response.data) | ||
.catch(error => error.response.statusText) | ||
} | ||
|
||
/** | ||
* Retrieve a device's consumption for a given year. | ||
* HTTP GET /devices/${deviceId}/consumption/${year} | ||
* @returns {id, deviceConsumptions} | ||
*/ | ||
public getDeviceConsYearly(deviceId: string, year: number) { | ||
return this.rest | ||
.get(API_CONFIG.baseURL + `/devices/${deviceId}/consumption/${year}`, this.config) | ||
.then(response => response.data) | ||
.catch(error => error.response.statusText) | ||
} | ||
|
||
/** | ||
* Retrieve a device's consumption for a given month during a given year. | ||
* HTTP GET /devices/${deviceId}/consumption/${year}/${month} | ||
* @returns {id, deviceConsumptions} | ||
*/ | ||
public getDeviceConsMonthly(deviceId: string, year: number, month: number) { | ||
return this.rest | ||
.get(API_CONFIG.baseURL + `/devices/${deviceId}/consumption/${year}/${month}`, this.config) | ||
.then(response => response.data) | ||
.catch(error => error.response.statusText) | ||
} | ||
|
||
/** | ||
* Retrieve a list of messages for a given device according to request filters, with a 3-day history. | ||
* HTTP GET /devices/${deviceId}/messages | ||
* @returns {infoMessages} | ||
*/ | ||
public getMessagesList(deviceId: string) { | ||
return this.rest | ||
.get(API_CONFIG.baseURL + `/devices/${deviceId}/messages`, this.config) | ||
.then(response => response.data) | ||
.catch(error => error.response.statusText) | ||
} | ||
|
||
/** | ||
* Return the number of messages for a given device, for the last day, last week and last month. | ||
* HTTP GET /devices/${deviceId}/messages/metric | ||
* @returns {lastDay, lastWeek, lastMonth} | ||
*/ | ||
public getMessagesMetric(deviceId: string) { | ||
return this.rest | ||
.get(API_CONFIG.baseURL + `/devices/${deviceId}/messages/metric`, this.config) | ||
.then(response => response.data) | ||
.catch(error => error.response.statusText) | ||
} | ||
|
||
/** | ||
* Retrieve a list of location data of a device according to request filters. | ||
* HTTP GET /devices/${deviceId}/locations | ||
* @returns {data} | ||
*/ | ||
public getLocations(deviceId: string) { | ||
return this.rest | ||
.get(API_CONFIG.baseURL + `/devices/${deviceId}/locations`, this.config) | ||
.then(response => response.data) | ||
.catch(error => error.response.statusText) | ||
} | ||
|
||
/** | ||
* Retrieve the async job status for an unsubscribe devices action. | ||
* HTTP GET /devices/bulk/unsubscribe/${jobId} | ||
* @returns {jobDone, states} | ||
*/ | ||
public unsubscribeActions(jobId: string) { | ||
return this.rest | ||
.get(API_CONFIG.baseURL + `/devices/bulk/unsubscribe/${jobId}`, this.config) | ||
.then(response => response.data) | ||
.catch(error => error.response.statusText) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,25 @@ | ||
import axios, { AxiosInstance } from 'axios' | ||
|
||
import { ConfigParams } from './types/config-params' | ||
import { Device } from './types/device' | ||
import { API_CONFIG } from './config/constants' | ||
import { Devices } from './modules/devices' | ||
|
||
/** | ||
* @class SigfoxApiWrapper | ||
* | ||
*/ | ||
|
||
export default class SigfoxApi { | ||
public rest: AxiosInstance | ||
public customParams: object | ||
public devices: Devices | ||
|
||
/** | ||
* @constructor | ||
* @param {ConfigParams} customParams ID Client Setup | ||
*/ | ||
constructor(ConfigParams: ConfigParams) { | ||
this.rest = axios.create({ baseURL: API_CONFIG.baseURL }) | ||
this.customParams = { | ||
auth: ConfigParams, | ||
API_CONFIG | ||
} | ||
} | ||
|
||
/** | ||
* The endpoint to get Device Info. | ||
* @returns {device} | ||
*/ | ||
public getDeviceInfo(deviceId: string) { | ||
return this.rest | ||
.get<Device>(API_CONFIG.baseURL + `/devices/${deviceId}`, this.customParams) | ||
.then(response => response.data) | ||
.catch(error => error.response.statusText) | ||
this.devices = new Devices(this.customParams) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
export interface Location { | ||
lat: number | ||
lng: number | ||
} | ||
|
||
export interface DeviceType { | ||
id: string | ||
} | ||
|
||
export interface Group { | ||
id: string | ||
} | ||
|
||
export interface Token { | ||
state: number | ||
detailMessage: string | ||
end: any | ||
} | ||
|
||
export interface Contract { | ||
id: string | ||
} | ||
|
||
export interface ModemCertificate { | ||
id: string | ||
} | ||
|
||
export interface Datum { | ||
id: string | ||
name: string | ||
lastCom: any | ||
state: number | ||
comState: number | ||
location: Location | ||
deviceType: DeviceType | ||
group: Group | ||
lqi: number | ||
activationTime: any | ||
token: Token | ||
contract: Contract | ||
creationTime: any | ||
modemCertificate: ModemCertificate | ||
prototype: boolean | ||
automaticRenewal: boolean | ||
automaticRenewalStatus: number | ||
createdBy: string | ||
lastEditionTime: any | ||
lastEditedBy: string | ||
activable: boolean | ||
} | ||
|
||
export interface Paging {} | ||
|
||
export interface RootObject { | ||
data: Datum[] | ||
paging: Paging | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
export interface Manufacturer { | ||
id: string | ||
} | ||
|
||
export interface RadioConfiguration { | ||
id: number | ||
outputPower: number | ||
balancedLinkBudget: boolean | ||
} | ||
|
||
export interface ModemCertificate { | ||
id: string | ||
manufacturer: Manufacturer | ||
name: string | ||
key: string | ||
version: string | ||
description: string | ||
status: number | ||
radioConfigurations: RadioConfiguration[] | ||
inputSensitivity: number | ||
modes: number[] | ||
repeaterFunction: boolean | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import * as nock from 'nock' | ||
|
||
import { API_CONFIG } from '../src/config/constants' | ||
import { Devices } from '../src/modules/devices' | ||
|
||
describe('Devices Test', () => { | ||
it('should be a class', () => { | ||
const devices = new Devices({} as any) | ||
expect(devices instanceof Devices).toBeTruthy() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.