2014-02-21 08:29:18 +08:00
|
|
|
# Sales Force
|
|
|
|
|
|
|
|
First, let's import Cylon:
|
|
|
|
|
2014-03-28 00:31:56 +08:00
|
|
|
var Cylon = require('../..');
|
2014-02-21 08:29:18 +08:00
|
|
|
|
|
|
|
Now that we have Cylon imported, we can start defining our robot
|
|
|
|
|
2014-03-28 00:31:56 +08:00
|
|
|
Cylon.robot({
|
2014-02-21 08:29:18 +08:00
|
|
|
|
|
|
|
Let's define the connections and devices:
|
|
|
|
|
2014-11-26 08:01:31 +08:00
|
|
|
connections: {
|
|
|
|
sfcon: {
|
|
|
|
adaptor: 'force',
|
|
|
|
sfuser: process.env.SF_USERNAME,
|
|
|
|
sfpass: process.env.SF_SECURITY_TOKEN,
|
|
|
|
orgCreds: {
|
|
|
|
clientId: process.env.SF_CLIENT_ID,
|
|
|
|
clientSecret: process.env.SF_CLIENT_SECRET,
|
|
|
|
redirectUri: 'http://localhost:3000/oauth/_callback'
|
|
|
|
}
|
2014-03-28 00:31:56 +08:00
|
|
|
}
|
|
|
|
},
|
2014-02-21 08:29:18 +08:00
|
|
|
|
2014-11-26 08:01:31 +08:00
|
|
|
devices: {
|
|
|
|
salesforce: { driver: 'force' }
|
|
|
|
},
|
2014-02-21 08:29:18 +08:00
|
|
|
|
|
|
|
Now that Cylon knows about the necessary hardware we're going to be using, we'll
|
|
|
|
tell it what work we want to do:
|
|
|
|
|
2014-11-26 06:39:24 +08:00
|
|
|
work: function(my) {
|
|
|
|
my.salesforce.on('start', function() {
|
|
|
|
my.salesforce.subscribe('/topic/SpheroMsgOutbound', function(data) {
|
2014-12-14 08:19:25 +08:00
|
|
|
var msg = "Sphero: " + data.sobject.Sphero_Name__c + ",";
|
2014-03-28 00:31:56 +08:00
|
|
|
msg += "Bucks: " + data.sobject.Bucks__c + ",";
|
|
|
|
msg += "SM_Id: " + data.sobject.Id;
|
2014-02-21 08:29:18 +08:00
|
|
|
|
2014-03-28 00:31:56 +08:00
|
|
|
console.log(msg);
|
|
|
|
});
|
|
|
|
});
|
2014-02-21 08:29:18 +08:00
|
|
|
|
2014-03-28 00:31:56 +08:00
|
|
|
var i = 0;
|
2014-02-21 08:29:18 +08:00
|
|
|
|
2014-03-28 00:31:56 +08:00
|
|
|
every((2).seconds(), function() {
|
|
|
|
var data = JSON.stringify({
|
2014-12-14 08:19:25 +08:00
|
|
|
spheroName: "" + my.name,
|
2014-03-28 00:31:56 +08:00
|
|
|
bucks: "" + i
|
|
|
|
});
|
|
|
|
|
2014-11-26 06:39:24 +08:00
|
|
|
my.salesforce.push('SpheroController', 'POST', data);
|
2014-03-28 00:31:56 +08:00
|
|
|
});
|
|
|
|
}
|
2014-02-21 08:29:18 +08:00
|
|
|
|
|
|
|
Now that our robot knows what work to do, and the work it will be doing that
|
|
|
|
hardware with, we can start it:
|
|
|
|
|
2014-03-28 00:31:56 +08:00
|
|
|
}).start();
|