iotery-client-sdk
v0.0.5
Published
iotery.io client SDK for ES6
Downloads
9
Readme
iotery.io Client SDK
WARNING: The is not officially supported and should be used with caution given its requirement for you to handle your own transpilation and bundling.
The iotery.io client SDK is intended to be used by our ES6 enabled build toolchain in order to interact with the itoery.io IoT Platform. The SDK is a fully featured wrapper for the REST API.
Getting Started
Setup your free account on iotery.io and go to your settings dashboard to get your server API Key.
After you get your key, install the SDK:
npm install iotery-client-sdk
And finally, some simple example usage:
import React, { Component } from "react";
import logo from "./logo.svg";
import "./App.css";
import Iotery from "iotery-client-sdk";
const iotery = new Iotery("my-api-key", {
baseUrl: "http://localhost:3005",
token: "jwtToken"
});
class App extends Component {
async componentDidMount() {
let d = await iotery.getDeviceTypes();
console.log(d);
}
render() {
return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<p>
Edit <code>src/App.js</code> and save to reload.
</p>
<a
className="App-link"
href="https://reactjs.org"
target="_blank"
rel="noopener noreferrer"
>
Learn React
</a>
</header>
</div>
);
}
}
export default App;
The above code connects you to the iotary.io platform, creates a device type, and a device, then retrieves all your device types.
Next, you might want to create a data type for the the device type you created...here's an example snippet:
let temperatureDataType = await iotery.createDataType(
{ deviceTypeUuid: thermalSensorDeviceType.uuid },
{
name: "Temperature",
enum: "TEMPERATURE",
units: "C",
isNumber: true
}
);
For a tutorial on setting up a full stack system in 15 minutes using iotery.io, check this link out.
API
This SDK simply wraps the REST API, so more information and specifics can be found there. Since the API is a wrapper around the REST API, the syntax is standard for each of the Create, Read, Update, and Delete operations on iotery.io resources. All methods return a Promise
.
Creating Resources
The generalized syntax for creating resources in iotery.io looks like:
methodName({ input: "parameters" }, { data: "variables" });
For example, to create a device, the javascript would look like
createDevice(
{ deviceTypeUuid: "a-valid-device-type-uuid" },
{ name: "My Device", other: "parameter" }
);
where createDevice
maps to methodName
, deviceTypeUuid
maps to input
, and name
and other
map to data : "variables"
in the generalized form given above.
The available resource creation methods are
| methodName
| input
| link | description
|:-----------:|:-----------:|:-----------:|:-----------:|
| createDeviceType | | link | Creates a new device type |
| createDevice | deviceTypeUuid | link | Creates a new device with a given device type |
Reading Resources
The generalized syntax for reading resources looks like:
methodName({ input: "parameters" }, { query: "variables" });
For example, to get a device, the javascript would look like
getDeviceByUuid({ deviceUuid: "a-valid-device-uuid" }, { limit: 1 });
where getDeviceByUuid
maps to methodName
, deviceUuid
maps to input
, and limit
maps to query
in the generalized form given above.
The available resource reading methods are
| methodName
| input
| link | description
|:-----------:|:-----------:|:-----------:|:-----------:|
| getDeviceTypes | | link | Gets all device types |
| getDeviceTypeByUuid | deviceTypeUuid | link | Gets a device type by uuid |
Updating Resources
The generalized syntax for updating resources in iotery.io looks like:
methodName({ input: "parameters" }, { data: "variables to update" });
For example, to create a device, the javascript would look like
updateDevice(
{ deviceUuid: "a-valid-device-uuid" },
{ name: "My New Device Name", other: "new value" }
);
where updateDevice
maps to methodName
, deviceUuid
maps to input
, and name
and other
map to data : "variables to update"
in the generalized form given above.
The available update methods are
| methodName
| input
| link | description
|:-----------:|:-----------:|:-----------:|:-----------:|
| updateDeviceType | deviceTypeUuid | link | Updates a device type by uuid |
Deleting Resources
The generalized syntax for deleting resources looks like:
methodName({ input: "parameters" });
For example, to delete a device, the javascript would look like
deleteDevice({ deviceUuid: "a-valid-device-uuid" });
where deleteDevice
maps to methodName
and deviceUuid
maps to input
in the generalized form given above.
The available resource deleting methods are
| methodName
| input
| link | description
|:-----------:|:-----------:|:-----------:|:-----------:|
| deleteDeviceType | deviceTypeUuid | link | Deletes a device type by uuid |
Contributing
We welcome contributors and PRs! Let us know if you are interested.
Testing
To test, start the mock-server.js
in /test
and use mocha
to run test/index.js
.