Permalink
Browse files

Initial commit with subscribe and devices

  • Loading branch information...
thatguydan committed Sep 5, 2012
0 parents commit 9d432ef2464babb45815ba5ea547b11b3f35b2b8
Showing with 71 additions and 0 deletions.
  1. +1 −0 .gitignore
  2. 0 README.md
  3. +43 −0 index.js
  4. +27 −0 package.json
@@ -0,0 +1 @@
+node_modules/
No changes.
@@ -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)
+ });
+ }
+ }
+}
@@ -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.