Permalink
Browse files

Fetch one device's details

  • Loading branch information...
1 parent a645501 commit 28dbdcc0ca0a4653d4bd8e73a2cc51ea8fb44f16 @thatguydan thatguydan committed Dec 30, 2012
Showing with 31 additions and 8 deletions.
  1. +30 −7 index.js
  2. +1 −1 package.json
View
37 index.js
@@ -46,7 +46,7 @@ exports.app = function(opts) {
cb({statusCode:r.statusCode,error:b.error})
}
}
- });
+ });
return;
}
@@ -75,7 +75,7 @@ exports.app = function(opts) {
cb({statusCode:r.statusCode,error:b.error})
}
}
- });
+ });
},
/**
* Fetches the user's pucher channel
@@ -101,7 +101,7 @@ exports.app = function(opts) {
cb({statusCode:b.id||200,error:b.error})
}
}
- });
+ });
},
}
},
@@ -110,6 +110,29 @@ exports.app = function(opts) {
return {
/**
+ * Fetch data about one device
+ *
+ * Example:
+ * app.device(a_led_guid).fetch(function(err) { ... })
+ *
+ * @param {Function} cb
+ * @api public
+ */
+ fetch: function(cb) {
+ var opts = {
+ url: uri + 'device/'+device,
+ method: 'GET',
+ qs: qs,
+ json: true
+ };
+ request(opts,function(e,r,b) {
+ if (!cb) return;
+ if (e) cb(e)
+ else if (b.result===1) cb(null,b.data)
+ else cb({statusCode:b.id||200,error:b.error})
+ });
+ },
+ /**
* Actuates a device, sending a given `command`.
*
* Example:
@@ -136,7 +159,7 @@ exports.app = function(opts) {
/**
* Subscribes to a device's data feed.
- *
+ *
* Optionally `overwrite`s an existing callback `url`
* Default is false.
*
@@ -186,7 +209,7 @@ exports.app = function(opts) {
/**
* Unubscribes to a device's data feed.
- *
+ *
* Example:
* app.device(guid).unsubscribe(function(err) { ... })
*
@@ -279,8 +302,8 @@ exports.app = function(opts) {
/**
* Fetches 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.
+ * it will filter by the parameters. If a string is provided,
+ * it will assume it's the device type intended for filtering.
*
* Example:
* app.devices('rgbled',function(err, data) { ... })
View
2 package.json
@@ -1,6 +1,6 @@
{
"name": "ninja-blocks",
- "version": "0.1.1",
+ "version": "0.1.3",
"description": "Library for interfacing with Ninja Blocks platform.",
"main": "index.js",
"scripts": {

0 comments on commit 28dbdcc

Please sign in to comment.