Added example using salesforce driver and adaptor.
This commit is contained in:
parent
027a82c17e
commit
6f2c84b516
|
@ -0,0 +1,38 @@
|
|||
Cylon = require('..')
|
||||
|
||||
Cylon.robot
|
||||
connection:
|
||||
name: 'sfcon', adaptor: 'force'
|
||||
|
||||
device:
|
||||
name: 'salesforce', driver: 'force'
|
||||
|
||||
work: (me) ->
|
||||
|
||||
me.salesforce.on('authenticate', (oauth) ->
|
||||
console.log('We are authenticated ===>')
|
||||
console.log(oauth)
|
||||
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'
|
||||
}
|
||||
)
|
||||
.start()
|
|
@ -1,7 +1,6 @@
|
|||
'use strict';
|
||||
|
||||
nforce = require('nforce')
|
||||
http = require('http')
|
||||
faye = require('faye')
|
||||
|
||||
namespace = require('node-namespace')
|
||||
|
@ -18,7 +17,6 @@ namespace 'SF', ->
|
|||
|
||||
_processOutboundMessages: () ->
|
||||
# Do work here
|
||||
console.log(msg) for msg in @outboundMessages
|
||||
|
||||
_handleStreamingAPI: (outboundCB) ->
|
||||
client = new faye.Client(@oauth.instance_url + '/cometd/28.0')
|
||||
|
@ -35,8 +33,6 @@ namespace 'SF', ->
|
|||
process.exit(code=0)
|
||||
else
|
||||
console.log("authenticated")
|
||||
console.log("oauth")
|
||||
console.log(_oauth)
|
||||
@oauth = _oauth
|
||||
@_handleStreamingAPI(outboundCB)
|
||||
@_processOutboundMessages()
|
||||
|
@ -46,6 +42,8 @@ namespace 'SF', ->
|
|||
#jsonBody = JSON.parse(msg)
|
||||
#jsonString = JSON.stringify(msg)
|
||||
jsonString = msg
|
||||
console.log("SpheroController post msg:")
|
||||
console.log(msg)
|
||||
@org.apexRest({uri:'SpheroController', method: 'POST', body: jsonString}, @oauth, (err,resp) =>
|
||||
if(err)
|
||||
console.log(err)
|
||||
|
|
|
@ -1,7 +1,12 @@
|
|||
require '../examples/sf-client'
|
||||
Cylon = require('..')
|
||||
|
||||
Cylon.robot
|
||||
bots = [
|
||||
{ port: '/dev/rfcomm0', name: 'sphy-rgr' },
|
||||
{ port: '/dev/rfcomm1', name: 'sphy-bpy' }
|
||||
]
|
||||
|
||||
class SpheroRobot
|
||||
connection:
|
||||
name: 'sphero', adaptor: 'sphero', port: '/dev/rfcomm0'
|
||||
|
||||
|
@ -34,18 +39,26 @@ Cylon.robot
|
|||
)
|
||||
|
||||
me.sphero.on 'collision', (data) ->
|
||||
Logger.info 'collision:'
|
||||
#Logger.info 'collision:'
|
||||
me.sphero.setRGB(0xFF0000, me)
|
||||
me.sphero.stop()
|
||||
console.log("Collision Data:")
|
||||
console.log(data[0][0])
|
||||
toSend = "{ \"identifier\" :\"#{ me.name }\", \"msg\": \"#{ 'hello' }\" }"
|
||||
#console.log("Collision Data:")
|
||||
#console.log(data[0][0])
|
||||
toSend = "{ \"identifier\" :\"#{ me.name }\", \"msg\": \"#{ 'Collision detected' }\" }"
|
||||
me.sf.push(toSend)
|
||||
|
||||
me.sf.authenticate((msg) =>
|
||||
Logger.info 'SF Outbound Msg:'
|
||||
#Logger.info 'SF Outbound Msg:'
|
||||
Logger.info "Sphero: #{ msg.sobject.Sphero_Name__c }, Msg Content: #{ msg.sobject.Content__c }, SM_Id: #{ msg.sobject.Id }"
|
||||
me.sphero.setRGB(0x00FF00)
|
||||
me.sphero.roll 90, Math.floor(Math.random() * 360)
|
||||
)
|
||||
|
||||
.start()
|
||||
for bot in bots
|
||||
robot = new SpheroRobot
|
||||
robot.connection.port = bot.port
|
||||
robot.name = bot.name
|
||||
console.log("Name: #{ robot.name }")
|
||||
Cylon.robot robot
|
||||
|
||||
Cylon.start()
|
||||
|
|
Loading…
Reference in New Issue