Skip to content

Instantly share code, notes, and snippets.

@monkbroc
Created November 11, 2015 00:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save monkbroc/9defac8f67da6afd5484 to your computer and use it in GitHub Desktop.
Save monkbroc/9defac8f67da6afd5484 to your computer and use it in GitHub Desktop.
List devices hook
module['exports'] = function particle (hook) {
var Spark = require('spark');
function output(data) {
hook.res.end(JSON.stringify(data, true, 2));
}
var token = hook.env.PARTICLE_API_TOKEN;
Spark.login({ accessToken: token }).
then(function () {
return Spark.listDevices();
}).then(function (devices) {
output(devices.map(function (d) { return d.name; }));
}).catch(function (err) {
output(err);
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment