Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Initial commit with subscribe and devices

  • Loading branch information...
commit 9d432ef2464babb45815ba5ea547b11b3f35b2b8 0 parents
Daniel Friedman thatguydan authored
1  .gitignore
... ... @@ -0,0 +1 @@
  1 +node_modules/
0  README.md
Source Rendered
No changes.
43 index.js
... ... @@ -0,0 +1,43 @@
  1 +var EventEmitter = require('events').EventEmitter;
  2 +var util = require('util');
  3 +var request = require('request');
  4 +var subscriptions = {};
  5 +
  6 +
  7 +exports.app = function(opts) {
  8 + var access_token = opts.access_token;
  9 + return {
  10 + subscribe: function(params,cb) {
  11 + var opts = {
  12 + url:'https://api.ninja.is/rest/v0/device/'+params.guid+'/callback',
  13 + method:'POST',
  14 + qs: {
  15 + access_token:access_token
  16 + },
  17 + json: {
  18 + url:params.url
  19 + }
  20 + };
  21 + request(opts,function(e,r,b) {
  22 + if (e) cb(e)
  23 + else {
  24 + if (b.result===1) cb(null)
  25 + else cb(new Error(b.error))
  26 + }
  27 + });
  28 + },
  29 +
  30 + devices: function(cb) {
  31 + var opts = {
  32 + url:'https://api.ninja.is/rest/v0/devices',
  33 + qs: {
  34 + access_token:access_token
  35 + }
  36 + };
  37 +
  38 + request(opts,function(e,r,b) {
  39 + cb(e ? null : r.statusCode, JSON.parse(b).data)
  40 + });
  41 + }
  42 + }
  43 +}
27 package.json
... ... @@ -0,0 +1,27 @@
  1 +{
  2 + "name": "ninja-blocks",
  3 + "version": "0.0.1",
  4 + "description": "Library for interfacing with Ninja Blocks platform.",
  5 + "main": "index.js",
  6 + "scripts": {
  7 + "test": "make test"
  8 + },
  9 + "dependencies": {
  10 + "request": "2.11.1"
  11 + },
  12 + "devDependenvies": {
  13 + "should": "*",
  14 + "mocha": "*"
  15 + },
  16 + "author": "Daniel Friedman",
  17 + "license": "MIT",
  18 + "devDependencies": {},
  19 + "repository": {
  20 + "type": "git",
  21 + "url": "git@github.com:ninjablocks/node-ninja-blocks.git"
  22 + },
  23 + "keywords": [
  24 + "Ninja",
  25 + "Blocks"
  26 + ]
  27 +}

0 comments on commit 9d432ef

Please sign in to comment.
Something went wrong with that request. Please try again.