cylon/examples/salesforce/salesforce.markdown

57 lines
1.5 KiB
Markdown
Raw Normal View History

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-03-28 00:31:56 +08:00
connection: {
name: '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,
2014-02-21 08:29:18 +08:00
redirectUri: 'http://localhost:3000/oauth/_callback'
2014-03-28 00:31:56 +08:00
}
},
2014-02-21 08:29:18 +08:00
2014-03-28 00:31:56 +08:00
device: { name: '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-03-28 00:31:56 +08:00
work: function(me) {
me.salesforce.on('start', function() {
me.salesforce.subscribe('/topic/SpheroMsgOutbound', function(data) {
var msg = "Sphero: " + data.sobject.Sphero_Name__c + ",";
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({
spheroName: "" + me.name,
bucks: "" + i
});
me.salesforce.push('SpheroController', 'POST', data);
});
}
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();