Move Cylon API config to the Cylon.configure block

This commit is contained in:
Andrew Stewart 2014-09-19 11:59:11 -07:00
parent b7467e7a63
commit 333dc881ea
6 changed files with 27 additions and 14 deletions

View File

@ -1,6 +1,10 @@
var Cylon = require('../..');
Cylon.api({ host: '0.0.0.0', port: '8080' });
Cylon.config({
api: { host: '0.0.0.0', port: '8080' }
});
Cylon.api();
var bots = [
{ port: '/dev/rfcomm0', name: 'Thelma' },

View File

@ -13,7 +13,11 @@ First, let's import Cylon:
Next up, we'll configure the API Cylon will serve, telling it to serve on port
`8080`.
Cylon.api({host: '0.0.0.0', port: '8080'});
Cylon.config({
api: { host: '0.0.0.0', port: '8080' }
});
Cylon.api();
Since we're making two very similar robots (Spheros, in this case), let's put
the different parts of each robot in objects so we can initialize them later.

View File

@ -4,7 +4,11 @@ var __bind = function(fn, me) {
var Cylon = require('../..');
Cylon.api({ host: '0.0.0.0', port: '8080' });
Cylon.config({
api: { host: '0.0.0.0', port: '8080' }
});
Cylon.api();
var PebbleRobot = (function() {
function PebbleRobot() { this.message = __bind(this.message, this); }

View File

@ -7,7 +7,11 @@ First, let's import Cylon:
Next up, we'll configure the API Cylon will serve, telling it to serve on port
`8080`.
Cylon.api({ host: '0.0.0.0', port: '8080' });
Cylon.config({
api: { host: '0.0.0.0', port: '8080' }
});
Cylon.api();
We'll also setup a convenince function for some binding we'll need to do later:

View File

@ -61,17 +61,13 @@ Cylon.robot = function robot(opts) {
// Public: Creates a new API based on passed options
//
// opts - object containing API options
//
// Returns nothing
Cylon.api = function api(opts) {
if (opts == null) {
opts = {};
}
Cylon.api = function api() {
var API = require('./api');
this.api_instance = new API(opts);
var config = Utils.fetch(Config, 'api', {});
this.api_instance = new API(config);
this.api_instance.listen();
};

View File

@ -72,8 +72,9 @@ describe("Cylon", function() {
expect(Cylon.api_instance).to.be.an.instanceOf(API);
});
it('passes arguments to the API constructor', function() {
Cylon.api({ port: '1234' });
it('passes configuration to the API constructor', function() {
Cylon.config({ api: { port: '1234' }});
Cylon.api();
expect(Cylon.api_instance.port).to.be.eql('1234');
})
});