Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial commit with subscribe and devices
- Loading branch information
0 parents
commit 9d432ef
Showing
4 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules/ |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
] | ||
} |