Add method for fetching a specific device belonging to a Robot
This commit is contained in:
parent
65a2e20959
commit
1b4e05575c
|
@ -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;
|
||||
|
||||
})();
|
||||
|
|
|
@ -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}"
|
||||
|
|
Loading…
Reference in New Issue