Skip to content
This repository has been archived by the owner on Apr 25, 2023. It is now read-only.

Commit

Permalink
Merge pull request #55 from JorisM/feature/rcswitch_api
Browse files Browse the repository at this point in the history
Feature/rcswitch api
  • Loading branch information
ni-c committed Feb 16, 2014
2 parents 4c431db + bb104ce commit a268886
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion plugins/arduino/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ define([ 'duino' ], function(duino) {
* @param {String} data.value The value to set (0 or 1)
*/
Arduino.prototype.rcswitch = function(data) {

var that = this;
this.pluginHelper.findItem(that.collection, data.id, function(err, item, collection) {
if ((!err) && (item)) {
Expand Down Expand Up @@ -219,6 +218,40 @@ define([ 'duino' ], function(duino) {
return callback(null, items);
}

/**
* API functions of the Arduino Plugin
*
* @method api
* @param {Object} req The request
* @param {Object} res The response
*/

Arduino.prototype.api = function(req, res, next) {
/*
* GET
*/
if (req.method == 'POST') {
var that = this;
var method = req.body.method;
if(method === "rcswitch") {
this.app.get('db').collection("Arduino", function(err, collection) {
collection.find({}).toArray(function(err, items) {
if (!err) {
that.beforeRender(items, function() {
res.send(200, items);
});
} else {
res.send(500, '[]');
}
});
});
} else {
next();
}
}
};


var exports = Arduino;

return exports;
Expand Down

0 comments on commit a268886

Please sign in to comment.