sensit-api

1.0.0 • Public • Published

sensit-api NPM version Build Status Dependency Status Coverage percentage

A Javascript API wrapper for the Sens'it API

Install

$ npm install --save sensit-api

Usage

var Sensit = require('sensit-api');
 
// If you do not want to use the token
// You will can use credentials with the function  auth().getToken(credentials)
var client = new Sensit();
 
// You can also use the token :)
var client = new Sensit({token: 'my-token'});

Authentication

getToken

You can use your credentials to get your access token:

var credentials = {
  email: 'my@email.com',
  password: 'my-clear-password'
};
 
client.auth()
  .getToken(credentials)
  .then(function (result) {
    console.log(result.data.token);
  });

setToken

And you can set the token and the client will it for your next requests:

var credentials = {
  email: 'my@email.com',
  password: 'my-clear-password'
};
 
client.auth()
  .getToken(credentials)
  .then(function (result) {
    client.setToken(result.data.token);
 
    return client.devices().get()
  })
  .then(function(result) {
    console.log(result);
  });

Devices

get

client.devices().get()
  .then(function (result) {
    console.log(result);
  });

Device

get

var deviceId = '1234';
 
client.device(deviceId).get()
  .then(function (result) {
    console.log(result);
  });

updateConfiguration

var deviceId = '1234';
var aConfiguration = {
  ...
};
 
client.device(deviceId)
  .updateConfiguration(aConfiguration)
  .then(function (result) {
    console.log(result);
  });

Sensor

get

var deviceId = '1234';
var sensorId = '5678';
 
client.sensor(deviceId, sensorId).get()
  .then(function (result) {
    console.log(result);
  });
 
client.device(deviceId).sensor(sensorId).get()
  .then(function (result) {
    console.log(result);
  });

License

MIT © Anthonny Querouil (@anthonny_q)

Package Sidebar

Install

npm i sensit-api

Weekly Downloads

2

Version

1.0.0

License

MIT

Last publish

Collaborators

  • anthonny.querouil