node-wio-link
Advanced tools
Comparing version 0.0.3 to 1.0.0
28
index.js
'use strict'; | ||
var axios = require('axios'); | ||
const axios = require('axios'); | ||
function WioLinkClient(serverLocation) { | ||
var clientLib = {}; | ||
const clientLib = {}; | ||
@@ -17,3 +17,3 @@ if (!serverLocation) | ||
function configureHeaders(token, usingUrlEncoded) { | ||
var headers = {}; | ||
const headers = {}; | ||
if (token) | ||
@@ -25,3 +25,3 @@ headers['Authorization'] = 'token ' + token; | ||
var rest = { | ||
const rest = { | ||
client: axios.create({ | ||
@@ -50,3 +50,3 @@ baseURL: `https://${serverLocation}.wio.seeed.io/v1/`, | ||
login: (email, password) => rest.post(null, 'user/login', { email, password }) | ||
} | ||
}; | ||
@@ -58,3 +58,3 @@ clientLib.nodeManagement = { | ||
delete: (userToken, nodeSN) => rest.post(userToken, 'nodes/delete', { node_sn: nodeSN }) | ||
} | ||
}; | ||
@@ -64,7 +64,7 @@ clientLib.groveDriver = { | ||
scanStatus: (userToken) => rest.get(userToken, 'scan/status') | ||
} | ||
}; | ||
clientLib.boards = { | ||
list: (userToken) => rest.get(userToken, 'boards/list') | ||
} | ||
}; | ||
@@ -81,3 +81,3 @@ clientLib.node = { | ||
changeDataExchangeServer: (nodeToken, address, dataxurl) => rest.post(nodeToken, `node/setting/dataxserver/${address}`, { dataxurl }) | ||
} | ||
}; | ||
@@ -90,4 +90,12 @@ clientLib.cotf = { | ||
callFunction: (nodeToken, funcName, arg) => rest.post(nodeToken, `node/function/${funcName}`, { arg }) | ||
} | ||
}; | ||
clientLib.custom = { | ||
head: url => rest.head(url), | ||
get: (url, parameters) => rest.get(url, parameters), | ||
post: (url, parameters) => rest.post(url, parameters), | ||
put: (url, parameters) => rest.put(url, parameters), | ||
delete: url => rest.delete(url) | ||
}; | ||
return clientLib; | ||
@@ -94,0 +102,0 @@ } |
{ | ||
"name": "node-wio-link", | ||
"version": "0.0.3", | ||
"version": "1.0.0", | ||
"description": "A node.js client library for using the Wio Link API.", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"test": "echo \"Error: no test specified\" && exit 1", | ||
"lint": "eslint ./src", | ||
"lint-fix": "eslint ./src --fix" | ||
}, | ||
@@ -20,4 +22,7 @@ "repository": { | ||
"dependencies": { | ||
"axios": "^0.17.1" | ||
"axios": "^0.18.0" | ||
}, | ||
"devDependencies": { | ||
"eslint": "^5.10.0" | ||
} | ||
} |
111
README.md
# node-wio-link | ||
[![NPM Version](https://img.shields.io/npm/v/node-alexa-smapi.svg)](https://www.npmjs.com/package/node-alexa-smapi) | ||
A node.js client library for using the Wio Link API. | ||
@@ -7,13 +10,12 @@ | ||
* [Documentation](#documentation) | ||
* [User Management](#user-management) | ||
* [Node Management](#node-management) | ||
* [Grove Driver](#grove-driver) | ||
* [Boards/Platform](#boardsplatform) | ||
* [Single Node](#single-node) | ||
* [Coding on the fly](#coding-on-the-fly) | ||
* [User Management](#user-management) | ||
* [Node Management](#node-management) | ||
* [Grove Driver](#grove-driver) | ||
* [Boards/Platform](#boardsplatform) | ||
* [Single Node](#single-node) | ||
* [Coding on the fly](#coding-on-the-fly) | ||
* [Custom API calls](#custom-api-calls) | ||
* [Examples](#examples) | ||
* [Using Promises (normal functions)](#using-promises-normal-functions) | ||
* [Using Promises (arrow functions)](#using-promises-arrow-functions) | ||
* [Using Async/Await](#using-asyncawait) | ||
* [TODO](#todo) | ||
* [Using Promises](#using-promises) | ||
* [Using Async/Await](#using-asyncawait) | ||
@@ -30,12 +32,12 @@ ## Documentation | ||
// Creates a new user account. | ||
Object wioClient.user.create(String email, String password) | ||
wioClient.user.create(String email, String password) | ||
// Changes the password of an existing account. | ||
Object wioClient.user.changePassword(String userToken, String newPassword) | ||
wioClient.user.changePassword(String userToken, String newPassword) | ||
// Retrieve the password of an existing account. | ||
Object wioClient.user.retrievePassword(String email) | ||
wioClient.user.retrievePassword(String email) | ||
// Log in to the server with the given credentials. | ||
Object wioClient.user.login(String email, String password) | ||
wioClient.user.login(String email, String password) | ||
``` | ||
@@ -46,12 +48,12 @@ | ||
// Creates a new node. | ||
Object wioClient.nodeManagement.create(String userToken, String name, optional String boardType) | ||
wioClient.nodeManagement.create(String userToken, String name, optional String boardType) | ||
// List the nodes associated with the user. | ||
Object wioClient.nodeManagement.list(String userToken) | ||
wioClient.nodeManagement.list(String userToken) | ||
// Rename an existing node. | ||
Object wioClient.nodeManagement.rename(String userToken, String newName, String nodeSN) | ||
wioClient.nodeManagement.rename(String userToken, String newName, String nodeSN) | ||
// Delete an existing node. | ||
Object wioClient.nodeManagement.delete(String userToken, String nodeSN) | ||
wioClient.nodeManagement.delete(String userToken, String nodeSN) | ||
``` | ||
@@ -62,6 +64,6 @@ | ||
// Retrieve all of the grove drivers' information. | ||
Object wioClient.groveDriver.info(String userToken) | ||
wioClient.groveDriver.info(String userToken) | ||
// Retrieve the status of last driver scanning. | ||
Object wioClient.groveDriver.scanStatus(String userToken) | ||
wioClient.groveDriver.scanStatus(String userToken) | ||
``` | ||
@@ -72,3 +74,3 @@ | ||
// List all of the supported boards. | ||
Object wioClient.boards.list(String userToken) | ||
wioClient.boards.list(String userToken) | ||
``` | ||
@@ -79,27 +81,27 @@ | ||
// Lists all of the available resources on a node. | ||
Object wioClient.node.wellKnown(String nodeToken) | ||
wioClient.node.wellKnown(String nodeToken) | ||
// Read the property of a Grove module. | ||
Object wioClient.node.read(String nodeToken, String groveInstName, String property, String...args) | ||
wioClient.node.read(String nodeToken, String groveInstName, String property, String...args) | ||
// Write to a Grove module. | ||
Object wioClient.node.write(String nodeToken, String groveInstName, String PropertyOrMethodOrAction, String...args) | ||
wioClient.node.write(String nodeToken, String groveInstName, String PropertyOrMethodOrAction, String...args) | ||
// Put the node to sleep. | ||
Object wioClient.node.sleep(String nodeToken, Number sleepAmount) | ||
wioClient.node.sleep(String nodeToken, Number sleepAmount) | ||
// Retrieve the API reference page from the node. | ||
Object wioClient.node.resources(String nodeToken) | ||
wioClient.node.resources(String nodeToken) | ||
// Trigger the OTA process for the node. | ||
Object wioClient.node.otaTrigger(String nodeToken, Object data, optional Number buildPhase) | ||
wioClient.node.otaTrigger(String nodeToken, Object data, optional Number buildPhase) | ||
// Track the OTA status of the node. | ||
Object wioClient.node.otaStatus(String nodeToken) | ||
wioClient.node.otaStatus(String nodeToken) | ||
// Get the configuration of the node. | ||
Object wioClient.node.config(String nodeToken) | ||
wioClient.node.config(String nodeToken) | ||
// Change the data exchange server for the node. | ||
Object wioClient.node.changeDataExchangeServer(String nodeToken, String address, String dataxurl) | ||
wioClient.node.changeDataExchangeServer(String nodeToken, String address, String dataxurl) | ||
``` | ||
@@ -110,35 +112,43 @@ | ||
// Upload a user's logic block to a node. | ||
Object wioClient.cotf.uploadULB(String nodeToken, Object data) | ||
wioClient.cotf.uploadULB(String nodeToken, Object data) | ||
// Download a user's logic block from a node. | ||
Object wioClient.cotf.downloadULB(String nodeToken) | ||
wioClient.cotf.downloadULB(String nodeToken) | ||
// Get the value of a variable on the node. | ||
Object wioClient.cotf.getVariable(String nodeToken, String varName) | ||
wioClient.cotf.getVariable(String nodeToken, String varName) | ||
// Set the value of a variable on the node. | ||
Object wioClient.cotf.setVariable(String nodeToken, String varName, String varValue) | ||
wioClient.cotf.setVariable(String nodeToken, String varName, String varValue) | ||
// Call a function on the node. | ||
Object wioClient.cotf.callFunction(String nodeToken, String funcName, String arg) | ||
wioClient.cotf.callFunction(String nodeToken, String funcName, String arg) | ||
``` | ||
## Examples | ||
### Using Promises (normal functions) | ||
### Custom API calls | ||
In case there's a few APIs that aren't covered in this library, a bunch of custom functions are available to use. They will return the response received from making the call. | ||
```javascript | ||
// serverLocation can be 'us' or 'cn' | ||
var wioClient = require('node-wio-link')(serverLocation) | ||
wioClient.node.read(nodeToken, 'GroveAirqualityA0', 'quality') | ||
.then(function(data) { | ||
console.log(data) | ||
}) | ||
.catch(function(error) { | ||
console.log(error) | ||
}); | ||
// Perform a custom HEAD request | ||
wioClient.custom.head(String url) | ||
// Perform a custom GET request | ||
wioClient.custom.get(String url, Object parameters) | ||
// Perform a custom POST request | ||
wioClient.custom.post(String url, Object parameters) | ||
// Perform a custom PUT request | ||
wioClient.custom.put(String url, Object parameters) | ||
// Perform a custom DELETE request | ||
wioClient.custom.delete(String url) | ||
``` | ||
## Examples | ||
### Using Promises (arrow functions) | ||
```javascript | ||
// serverLocation can be 'us' or 'cn' | ||
var wioClient = require('node-wio-link')(serverLocation) | ||
const wioClient = require('node-wio-link')(serverLocation); | ||
wioClient.node.read(nodeToken, 'GroveAirqualityA0', 'quality') | ||
@@ -152,7 +162,7 @@ .then(data => console.log(data)) | ||
// serverLocation can be 'us' or 'cn' | ||
var wioClient = require('node-wio-link')(serverLocation) | ||
const wioClient = require('node-wio-link')(serverLocation); | ||
(async function() { | ||
try { | ||
var airQuality = await wioClient.node.read(nodeToken, 'GroveAirqualityA0', 'quality'); | ||
const airQuality = await wioClient.node.read(nodeToken, 'GroveAirqualityA0', 'quality'); | ||
console.log(airQuality); | ||
@@ -164,4 +174,1 @@ } catch (error) { | ||
``` | ||
## TODO | ||
* add unit testing |
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
11893
5
125
1
166
1
+ Addedaxios@0.18.1(transitive)
+ Addedfollow-redirects@1.5.10(transitive)
+ Addedis-buffer@2.0.5(transitive)
- Removedaxios@0.17.1(transitive)
- Removedfollow-redirects@1.15.9(transitive)
- Removedis-buffer@1.1.6(transitive)
Updatedaxios@^0.18.0