diff --git a/dist/api/api.js b/dist/api/api.js index 5104ffc..e732a11 100644 --- a/dist/api/api.js +++ b/dist/api/api.js @@ -37,6 +37,7 @@ this.server.get("/robots", this.getRobots); this.server.get("/robots/:robotid", this.getRobotByName); this.server.get("/robots/:robotid/devices", this.getRobotDevices); + this.server.get("/robots/:robotid/devices/:deviceid", this.getRobotDeviceByName); this.server.listen(this.port, this.host, function() { return Logger.info("" + _this.server.name + " is listening at " + _this.server.url); }); @@ -74,6 +75,20 @@ return res.send(robot.data().devices); }; + Server.prototype.getRobotDeviceByName = function(req, res, next) { + var deviceName, robot, robotName; + robotName = req.params.robotid; + deviceName = req.params.deviceid; + robot = master.findRobot(robotName); + if (robot.devices[deviceName]) { + return res.send(robot.devices[deviceName].data()); + } else { + return res.send({ + error: "Robot " + robotName + " does not have a device " + deviceName + }); + } + }; + return Server; })(); diff --git a/src/api/api.coffee b/src/api/api.coffee index b820a16..64ec7e0 100644 --- a/src/api/api.coffee +++ b/src/api/api.coffee @@ -28,6 +28,7 @@ namespace "Api", -> @server.get "/robots", @getRobots @server.get "/robots/:robotid", @getRobotByName @server.get "/robots/:robotid/devices", @getRobotDevices + @server.get "/robots/:robotid/devices/:deviceid", @getRobotDeviceByName @server.listen @port, @host, => Logger.info "#{@server.name} is listening at #{@server.url}" @@ -45,3 +46,15 @@ namespace "Api", -> getRobotDevices: (req, res, next) -> robot = master.findRobot(req.params.robotid) res.send robot.data().devices + + getRobotDeviceByName: (req, res, next) -> + robotName = req.params.robotid + deviceName = req.params.deviceid + + robot = master.findRobot robotName + + if robot.devices[deviceName] + res.send robot.devices[deviceName].data() + else + res.send + error: "Robot #{robotName} does not have a device #{deviceName}"