Refactor api, basestar & config to pure JS style

This commit is contained in:
deadprogram 2014-02-27 10:58:50 -08:00
parent 30228c7f3c
commit c28baa8eeb
3 changed files with 222 additions and 230 deletions

View File

@ -2,21 +2,17 @@
* api
* cylonjs.com
*
* Copyright (c) 2013 The Hybrid Group
* Copyright (c) 2013-2014 The Hybrid Group
* Licensed under the Apache 2.0 license.
*/
"use strict";
(function() {
'use strict';
var express, namespace;
var express = require('express.io');
var namespace = require('node-namespace');
express = require('express.io');
namespace = require('node-namespace');
namespace('Cylon', function() {
return this.ApiServer = (function() {
namespace("Cylon", function() {
this.ApiServer = (function() {
var master;
master = null;
@ -62,6 +58,7 @@
ApiServer.prototype.configureRoutes = function() {
var _this = this;
this.server.get("/robots", function(req, res) {
var robot;
return res.json((function() {
@ -75,16 +72,19 @@
return _results;
})());
});
this.server.get("/robots/:robotname", function(req, res) {
return master.findRobot(req.params.robotname, function(err, robot) {
return res.json(err ? err : robot.data());
});
});
this.server.get("/robots/:robotname/commands", function(req, res) {
return master.findRobot(req.params.robotname, function(err, robot) {
return res.json(err ? err : robot.data().commands);
});
});
this.server.all("/robots/:robotname/commands/:commandname", function(req, res) {
var params;
params = _this.parseCommandParams(req);
@ -99,11 +99,13 @@
});
});
});
this.server.get("/robots/:robotname/devices", function(req, res) {
return master.findRobot(req.params.robotname, function(err, robot) {
return res.json(err ? err : robot.data().devices);
});
});
this.server.get("/robots/:robotname/devices/:devicename", function(req, res) {
var devicename, robotname, _ref;
_ref = [req.params.robotname, req.params.devicename], robotname = _ref[0], devicename = _ref[1];
@ -111,6 +113,7 @@
return res.json(err ? err : device.data());
});
});
this.server.get("/robots/:robotname/devices/:devicename/commands", function(req, res) {
var devicename, robotname, _ref;
_ref = [req.params.robotname, req.params.devicename], robotname = _ref[0], devicename = _ref[1];
@ -118,6 +121,7 @@
return res.json(err ? err : device.data().commands);
});
});
this.server.all("/robots/:robot/devices/:device/commands/:commandname", function(req, res) {
var commandname, devicename, params, robotname;
params = [req.params.robot, req.params.device, req.params.commandname];
@ -134,11 +138,13 @@
});
});
});
this.server.get("/robots/:robotname/connections", function(req, res) {
return master.findRobot(req.params.robotname, function(err, robot) {
return res.json(err ? err : robot.data().connections);
});
});
this.server.get("/robots/:robot/connections/:connection", function(req, res) {
var connectionname, robotname, _ref;
_ref = [req.params.robot, req.params.connection], robotname = _ref[0], connectionname = _ref[1];
@ -146,9 +152,11 @@
return res.json(err ? err : connection.data());
});
});
this.server.get("/robots/:robotname/devices/:devicename/events", function(req, res) {
return req.io.route('events');
});
return this.server.io.route('events', function(req) {
var devicename, robotname, _ref;
_ref = [req.params.robotname, req.params.devicename], robotname = _ref[0], devicename = _ref[1];
@ -168,8 +176,6 @@
return ApiServer;
})();
});
});
module.exports = Cylon.ApiServer;
}).call(this);
module.exports = Cylon.ApiServer;

View File

@ -2,27 +2,19 @@
* basestar
* cylonjs.com
*
* Copyright (c) 2013 The Hybrid Group
* Copyright (c) 2013-2014 The Hybrid Group
* Licensed under the Apache 2.0 license.
*/
"use strict";
(function() {
'use strict';
var EventEmitter, namespace,
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
__slice = [].slice;
require('./utils');
var namespace = require('node-namespace');
var EventEmitter = require('events').EventEmitter;
require('./utils');
namespace = require('node-namespace');
EventEmitter = require('events').EventEmitter;
namespace('Cylon', function() {
return this.Basestar = (function(_super) {
__extends(Basestar, _super);
namespace("Cylon", function() {
this.Basestar = (function(klass) {
subclass(Basestar, klass);
function Basestar(opts) {
this.self = this;
@ -72,6 +64,4 @@
return Basestar;
})(EventEmitter);
});
}).call(this);
});

View File

@ -2,17 +2,15 @@
* cylon configuration loader
* cylonjs.com
*
* Copyright (c) 2013 The Hybrid Group
* Copyright (c) 2013-2014 The Hybrid Group
* Licensed under the Apache 2.0 license.
*/
'use strict';
(function() {
var fetch, namespace;
var namespace = require('node-namespace');
namespace = require('node-namespace');
fetch = function(variable, defaultValue) {
var fetch = function(variable, defaultValue) {
if (defaultValue == null) {
defaultValue = false;
}
@ -21,12 +19,10 @@
} else {
return defaultValue;
}
};
};
namespace('CylonConfig', function() {
namespace('CylonConfig', function() {
return this.testing_mode = fetch("CYLON_TEST", false);
});
});
module.exports = CylonConfig;
}).call(this);
module.exports = CylonConfig;