Created
May 11, 2016 06:22
-
-
Save sicktastic/7a66a0ddc415bf25a7517bd3aacbf9db to your computer and use it in GitHub Desktop.
Using Restforce Gem to connect Rails with Salesforce platform.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Salesforce | |
include Singleton | |
def restforce | |
@client ||= \ | |
Restforce.new :oauth_token => ENV['SALESFORCE_OAUTH'], | |
:refresh_token => ENV['SALESFORCE_REFRESH_TOKEN'], | |
:instance_url => ENV['SALESFORCE_INSTANCE_URL'], | |
:client_id => ENV['SALESFORCE_CLIENT_ID'], | |
:client_secret => ENV['SALESFORCE_SECRET'] | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SalesforceContact | |
def create(first_name, last_name, email) | |
connect_to_salesforce.create( | |
'Contact', | |
FirstName: "#{first_name}", | |
LastName: "#{last_name}", | |
Email: "#{email}" | |
) | |
end | |
def update(uid, email) | |
connect_to_salesforce.upsert( | |
'Contact', | |
'ywam__Devise_UID__c', | |
ywam__Devise_UID__c: "#{uid}", | |
Email: "#{email}" | |
) | |
end | |
private | |
def connect_to_salesforce | |
Salesforce.instance.restforce | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment