Skip to content

Commit

Permalink
Initial commit with subscribe and devices
Browse files Browse the repository at this point in the history
  • Loading branch information
thatguydan committed Sep 5, 2012
0 parents commit 9d432ef
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
node_modules/
Empty file added README.md
Empty file.
43 changes: 43 additions & 0 deletions index.js
@@ -0,0 +1,43 @@
var EventEmitter = require('events').EventEmitter;
var util = require('util');
var request = require('request');
var subscriptions = {};


exports.app = function(opts) {
var access_token = opts.access_token;
return {
subscribe: function(params,cb) {
var opts = {
url:'https://api.ninja.is/rest/v0/device/'+params.guid+'/callback',
method:'POST',
qs: {
access_token:access_token
},
json: {
url:params.url
}
};
request(opts,function(e,r,b) {
if (e) cb(e)
else {
if (b.result===1) cb(null)
else cb(new Error(b.error))
}
});
},

devices: function(cb) {
var opts = {
url:'https://api.ninja.is/rest/v0/devices',
qs: {
access_token:access_token
}
};

request(opts,function(e,r,b) {
cb(e ? null : r.statusCode, JSON.parse(b).data)
});
}
}
}
27 changes: 27 additions & 0 deletions package.json
@@ -0,0 +1,27 @@
{
"name": "ninja-blocks",
"version": "0.0.1",
"description": "Library for interfacing with Ninja Blocks platform.",
"main": "index.js",
"scripts": {
"test": "make test"
},
"dependencies": {
"request": "2.11.1"
},
"devDependenvies": {
"should": "*",
"mocha": "*"
},
"author": "Daniel Friedman",
"license": "MIT",
"devDependencies": {},
"repository": {
"type": "git",
"url": "git@github.com:ninjablocks/node-ninja-blocks.git"
},
"keywords": [
"Ninja",
"Blocks"
]
}

0 comments on commit 9d432ef

Please sign in to comment.