Add API method for fetching device commands

This commit is contained in:
Andrew Stewart 2013-10-31 14:48:47 -07:00
parent fbadbac5c6
commit d9c0229a62
2 changed files with 18 additions and 0 deletions

10
dist/api/api.js vendored
View File

@ -38,6 +38,7 @@
this.server.get("/robots/:robotid", this.getRobotByName);
this.server.get("/robots/:robotid/devices", this.getDevices);
this.server.get("/robots/:robotid/devices/:deviceid", this.getDeviceByName);
this.server.get("/robots/:robotid/devices/:deviceid/commands", this.getDeviceCommands);
this.server.listen(this.port, this.host, function() {
return Logger.info("" + _this.server.name + " is listening at " + _this.server.url);
});
@ -78,6 +79,15 @@
});
};
Server.prototype.getDeviceCommands = function(req, res, next) {
var deviceid, robotid;
robotid = req.params.robotid;
deviceid = req.params.deviceid;
return master.findRobotDevice(robotid, deviceid, function(err, device) {
return res.send(err ? err : device.data().commands);
});
};
return Server;
})();

View File

@ -29,6 +29,7 @@ namespace "Api", ->
@server.get "/robots/:robotid", @getRobotByName
@server.get "/robots/:robotid/devices", @getDevices
@server.get "/robots/:robotid/devices/:deviceid", @getDeviceByName
@server.get "/robots/:robotid/devices/:deviceid/commands", @getDeviceCommands
@server.listen @port, @host, =>
Logger.info "#{@server.name} is listening at #{@server.url}"
@ -50,3 +51,10 @@ namespace "Api", ->
master.findRobotDevice robotid, deviceid, (err, device) ->
res.send if err then err else device.data()
getDeviceCommands: (req, res, next) ->
robotid = req.params.robotid
deviceid = req.params.deviceid
master.findRobotDevice robotid, deviceid, (err, device) ->
res.send if err then err else device.data().commands