Move Cylon API config to the Cylon.configure block
This commit is contained in:
parent
b7467e7a63
commit
333dc881ea
|
@ -1,6 +1,10 @@
|
||||||
var Cylon = require('../..');
|
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 = [
|
var bots = [
|
||||||
{ port: '/dev/rfcomm0', name: 'Thelma' },
|
{ port: '/dev/rfcomm0', name: 'Thelma' },
|
||||||
|
|
|
@ -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
|
Next up, we'll configure the API Cylon will serve, telling it to serve on port
|
||||||
`8080`.
|
`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
|
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.
|
the different parts of each robot in objects so we can initialize them later.
|
||||||
|
|
|
@ -4,7 +4,11 @@ var __bind = function(fn, me) {
|
||||||
|
|
||||||
var Cylon = require('../..');
|
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() {
|
var PebbleRobot = (function() {
|
||||||
function PebbleRobot() { this.message = __bind(this.message, this); }
|
function PebbleRobot() { this.message = __bind(this.message, this); }
|
||||||
|
|
|
@ -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
|
Next up, we'll configure the API Cylon will serve, telling it to serve on port
|
||||||
`8080`.
|
`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:
|
We'll also setup a convenince function for some binding we'll need to do later:
|
||||||
|
|
||||||
|
|
12
lib/cylon.js
12
lib/cylon.js
|
@ -61,17 +61,13 @@ Cylon.robot = function robot(opts) {
|
||||||
|
|
||||||
// Public: Creates a new API based on passed options
|
// Public: Creates a new API based on passed options
|
||||||
//
|
//
|
||||||
// opts - object containing API options
|
|
||||||
//
|
|
||||||
// Returns nothing
|
// Returns nothing
|
||||||
Cylon.api = function api(opts) {
|
Cylon.api = function api() {
|
||||||
if (opts == null) {
|
|
||||||
opts = {};
|
|
||||||
}
|
|
||||||
|
|
||||||
var API = require('./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();
|
this.api_instance.listen();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -72,8 +72,9 @@ describe("Cylon", function() {
|
||||||
expect(Cylon.api_instance).to.be.an.instanceOf(API);
|
expect(Cylon.api_instance).to.be.an.instanceOf(API);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('passes arguments to the API constructor', function() {
|
it('passes configuration to the API constructor', function() {
|
||||||
Cylon.api({ port: '1234' });
|
Cylon.config({ api: { port: '1234' }});
|
||||||
|
Cylon.api();
|
||||||
expect(Cylon.api_instance.port).to.be.eql('1234');
|
expect(Cylon.api_instance.port).to.be.eql('1234');
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue