Class: Rd::Salesforce::Client
- Inherits:
-
Object
- Object
- Rd::Salesforce::Client
- Defined in:
- lib/rd/salesforce/client.rb
Constant Summary collapse
- VALID_PARAMS =
%i(oauth_token host instance_url)
Instance Method Summary collapse
-
#initialize(params) ⇒ Client
constructor
A new instance of Client.
- #save_lead(person) ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(params) ⇒ Client
Returns a new instance of Client.
7 8 9 10 |
# File 'lib/rd/salesforce/client.rb', line 7 def initialize params raise ArgumentError.new("Invalid Params: #{params.inspect} not in #{VALID_PARAMS.inspect}") if not valid_params? params @api = Restforce.new(params) end |
Instance Method Details
#save_lead(person) ⇒ Object
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/rd/salesforce/client.rb', line 12 def save_lead(person) if not person.valid? raise ArgumentError.new("can't upload an invalid record to sales force. person is invalid: #{person.inspect}\n #{person.errors.inspect}") end if person.salesforce_id @api.update!("Lead", person.translate_attributes.merge(Id: person.salesforce_id)) else person.salesforce_id = @api.create!("Lead", person.translate_attributes) end end |
#valid? ⇒ Boolean
23 24 25 |
# File 'lib/rd/salesforce/client.rb', line 23 def valid? not @api.nil? end |