0.0.5 • Published 5 years ago

iotery-client-sdk v0.0.5

Weekly downloads
-
License
MIT
Repository
-
Last release
5 years ago

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

methodNameinputlinkdescription
createDeviceTypelinkCreates a new device type
createDevicedeviceTypeUuidlinkCreates 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

methodNameinputlinkdescription
getDeviceTypeslinkGets all device types
getDeviceTypeByUuiddeviceTypeUuidlinkGets 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

methodNameinputlinkdescription
updateDeviceTypedeviceTypeUuidlinkUpdates 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

methodNameinputlinkdescription
deleteDeviceTypedeviceTypeUuidlinkDeletes 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.

0.0.5

5 years ago

0.0.49

5 years ago

0.0.48

5 years ago

0.0.47

5 years ago

0.0.46

5 years ago

0.0.45

5 years ago

0.0.44

5 years ago

0.0.43

5 years ago

0.0.42

5 years ago

0.0.41

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago