Added adaptor extra params and updated salesforce example.
This commit is contained in:
parent
6f2c84b516
commit
19d094bb16
|
@ -38,7 +38,7 @@
|
|||
this.robot = opts.robot;
|
||||
this.name = opts.name;
|
||||
this.connection_id = opts.id;
|
||||
this.adaptor = this.requireAdaptor(opts.adaptor);
|
||||
this.adaptor = this.requireAdaptor(opts);
|
||||
this.port = new Cylon.Port(opts.port);
|
||||
proxyFunctionsToObject(this.adaptor.commands(), this.adaptor, this.self);
|
||||
}
|
||||
|
@ -72,9 +72,9 @@
|
|||
return this.adaptor.disconnect();
|
||||
};
|
||||
|
||||
Connection.prototype.requireAdaptor = function(adaptorName) {
|
||||
Logger.debug("Loading adaptor '" + adaptorName + "'");
|
||||
return this.robot.requireAdaptor(adaptorName, this.self);
|
||||
Connection.prototype.requireAdaptor = function(opts) {
|
||||
Logger.debug("Loading adaptor '" + opts.adaptor + "'");
|
||||
return this.robot.requireAdaptor(opts.adaptor, this.self, opts);
|
||||
};
|
||||
|
||||
return Connection;
|
||||
|
|
|
@ -182,19 +182,24 @@
|
|||
return _results;
|
||||
};
|
||||
|
||||
Robot.prototype.requireAdaptor = function(adaptorName, connection) {
|
||||
Robot.prototype.requireAdaptor = function(adaptorName, connection, opts) {
|
||||
if (opts == null) {
|
||||
opts = {};
|
||||
}
|
||||
if (this.robot.adaptors[adaptorName] != null) {
|
||||
if (typeof this.robot.adaptors[adaptorName] === 'string') {
|
||||
this.robot.adaptors[adaptorName] = require(this.robot.adaptors[adaptorName]).adaptor({
|
||||
name: adaptorName,
|
||||
connection: connection
|
||||
connection: connection,
|
||||
extraParams: opts
|
||||
});
|
||||
}
|
||||
} else {
|
||||
require("cylon-" + adaptorName).register(this);
|
||||
this.robot.adaptors[adaptorName] = require("cylon-" + adaptorName).adaptor({
|
||||
name: adaptorName,
|
||||
connection: connection
|
||||
connection: connection,
|
||||
extraParams: opts
|
||||
});
|
||||
}
|
||||
return this.robot.adaptors[adaptorName];
|
||||
|
|
|
@ -2,37 +2,28 @@ Cylon = require('..')
|
|||
|
||||
Cylon.robot
|
||||
connection:
|
||||
name: 'sfcon', adaptor: 'force'
|
||||
name: 'sfcon',
|
||||
adaptor: 'force',
|
||||
sfuser: "edgarsilva@hybridgroup.com",
|
||||
sfpass: "password1232YOQR0HQMpQ5f74msKqaPuCD6",
|
||||
orgCreds: {
|
||||
clientId: '3MVG9A2kN3Bn17huqBLyrtmQ9Cgwc.FjKA4769ApTRhNNjgKEetcGv23W97cJQ3ER3VXxzyREIaD0Bp1Or8ou',
|
||||
clientSecret: '6079348238616906521',
|
||||
redirectUri: 'http://localhost:3000/oauth/_callback'
|
||||
}
|
||||
|
||||
device:
|
||||
name: 'salesforce', driver: 'force'
|
||||
|
||||
work: (me) ->
|
||||
|
||||
me.salesforce.on('authenticate', (oauth) ->
|
||||
console.log('We are authenticated ===>')
|
||||
console.log(oauth)
|
||||
me.salesforce.on('start', () ->
|
||||
me.salesforce.subscribe('/topic/SpheroMsgOutbound', (data) ->
|
||||
Logger.info "Sphero: #{ data.sobject.Sphero_Name__c }, data Content: #{ data.sobject.Content__c }, SM_Id: #{ data.sobject.Id }"
|
||||
)
|
||||
|
||||
# push(apexPath, method, body)
|
||||
toSend = "{ \"identifier\" :\"#{ me.name }\", \"msg\": \"#{ 'Salesforce Bot #2' }\" }"
|
||||
me.salesforce.push('SpheroController', 'POST', toSend)
|
||||
)
|
||||
|
||||
me.salesforce.on('subscribe', (subs) ->
|
||||
console.log('Subscription ->')
|
||||
console.log(subs)
|
||||
)
|
||||
|
||||
me.salesforce.authenticate(
|
||||
sfuser: "edgarsilva@hybridgroup.com"
|
||||
sfpass: "password1232YOQR0HQMpQ5f74msKqaPuCD6"
|
||||
orgCreds: {
|
||||
clientId: '3MVG9A2kN3Bn17huqBLyrtmQ9Cgwc.FjKA4769ApTRhNNjgKEetcGv23W97cJQ3ER3VXxzyREIaD0Bp1Or8ou'
|
||||
clientSecret: '6079348238616906521'
|
||||
redirectUri: 'http://localhost:3000/oauth/_callback'
|
||||
}
|
||||
)
|
||||
# push(apexPath, method, body)
|
||||
toSend = "{ \"identifier\" :\"#{ me.name }\", \"msg\": \"#{ 'Salesforce Bot #2' }\" }"
|
||||
me.salesforce.push('SpheroController', 'POST', toSend)
|
||||
.start()
|
||||
|
|
|
@ -35,7 +35,7 @@ namespace 'Cylon', ->
|
|||
@robot = opts.robot
|
||||
@name = opts.name
|
||||
@connection_id = opts.id
|
||||
@adaptor = @requireAdaptor(opts.adaptor) # or 'loopback')
|
||||
@adaptor = @requireAdaptor(opts) # or 'loopback')
|
||||
@port = new Cylon.Port(opts.port)
|
||||
proxyFunctionsToObject @adaptor.commands(), @adaptor, @self
|
||||
|
||||
|
@ -75,8 +75,8 @@ namespace 'Cylon', ->
|
|||
# adaptorName - module name of adaptor to require
|
||||
#
|
||||
# Returns the set-up adaptor
|
||||
requireAdaptor: (adaptorName) ->
|
||||
Logger.debug "Loading adaptor '#{adaptorName}'"
|
||||
@robot.requireAdaptor(adaptorName, @self)
|
||||
requireAdaptor: (opts) ->
|
||||
Logger.debug "Loading adaptor '#{opts.adaptor}'"
|
||||
@robot.requireAdaptor(opts.adaptor, @self, opts)
|
||||
|
||||
module.exports = Cylon.Connection
|
||||
|
|
|
@ -168,13 +168,13 @@ namespace 'Cylon', ->
|
|||
# connection - the Connection that requested the adaptor be required
|
||||
#
|
||||
# Returns the set-up adaptor
|
||||
requireAdaptor: (adaptorName, connection) ->
|
||||
requireAdaptor: (adaptorName, connection, opts = {}) ->
|
||||
if @robot.adaptors[adaptorName]?
|
||||
if typeof @robot.adaptors[adaptorName] is 'string'
|
||||
@robot.adaptors[adaptorName] = require(@robot.adaptors[adaptorName]).adaptor(name: adaptorName, connection: connection)
|
||||
@robot.adaptors[adaptorName] = require(@robot.adaptors[adaptorName]).adaptor(name: adaptorName, connection: connection, extraParams: opts)
|
||||
else
|
||||
require("cylon-#{adaptorName}").register(this)
|
||||
@robot.adaptors[adaptorName] = require("cylon-#{adaptorName}").adaptor(name: adaptorName, connection: connection)
|
||||
@robot.adaptors[adaptorName] = require("cylon-#{adaptorName}").adaptor(name: adaptorName, connection: connection, extraParams: opts)
|
||||
|
||||
return @robot.adaptors[adaptorName]
|
||||
|
||||
|
|
Loading…
Reference in New Issue