Advertisement
Guest User

Untitled

a guest
Apr 28th, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. class Restforce
  2. attr_reader :client
  3.  
  4. def initialize
  5. @client = initialize_client
  6. @client.authenticate!
  7. end
  8.  
  9. def initialize_client
  10. config = Rails.application.secrets.salesforce
  11. Restforce.new(
  12. security_token: config["security_token"],
  13. client_secret: config["client_secret"],
  14. client_id: config["client_id"],
  15. api_version: config["api_version"]
  16. username: config["username"],
  17. password: config["password"],
  18. host: config["host"]
  19. )
  20. end
  21.  
  22. def obtain_account(model, id_externo)
  23. client.find(model, id_externo)
  24. end
  25.  
  26. def destroy_account(model, id_externo)
  27. client.destroy(model, id_externo)
  28. end
  29.  
  30. def obtain_description_from_account(id_externo)
  31. client.query("select Description from Account where External__c = '#{id_externo}'").first
  32. end
  33.  
  34. def create_or_update_account(account)
  35. client.upsert!('Account', 'External__c',
  36. Name: account.id.to_s,
  37. External__c: account.id.to_s,
  38. Description: account.description
  39. )
  40. end
  41.  
  42. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement