Node Ninja Blocks
A simple library to help interacting with the Ninja Blocks Platform.
Installation
npm install ninja-blocks
OAuth 2 Usage
var ninjaBlocks = ;// ACCESS_TOKEN acquired via OAuthvar ninja = ninjaBlocks; ninja;
User Access Token Usage
var ninjaBlocks = ;// USER_ACCESS_TOKEN acquired via settings page in Ninja Cloudvar ninja = ninjaBlocks; ninja;
API Overview
User
// Fetch a user's profile anyformationninja; // Fetch a user's activity streamninja // Fetch a user's pusher channelninja
Device
/** * Fetch all the user's device details. * Optionally if an object is passed as the first argument, * it will filter by the parameters. If a string is provided, * it will assume it's the device type intended for filtering. * * NOTE: The returned data is in the form guid => meta data * You will need the guid for all the other device commands. */ninja;ninjaninja // Fetch one device's detailsninja; // Send `command` to device `guid`ninja // Subscribe to a device's data feed. Ninja Blocks will POST the requested// device's data to the `url` provided here.// Optionally `overwrite`s an existing callback `url`ninja // Unubscribe from a device's data feed.ninja // Fetch any historical data about this device. Optionally specify the period's `start` and `end` timestamp.ninjadatastart end { ... } // Fetch the last heartbeat received by this device.ninja
Helpers
// Returns found subdevices within a set of devicesninjautils;
This is by no means exhaustive, and more functionality will be forthcoming.
Example
var _ = ;var ninjaBlocks = ;// Use the API Access Token from https://a.ninja.is/hackingvar ninja = ninjaBlocks; // Get the most recent temperature reading from all temperature sensorsninja; // Execute an RF command by name - turn a "Lamp Off" ninja;