Class: Rd::Salesforce::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/rd/salesforce/client.rb

Constant Summary collapse

VALID_PARAMS =
%i(oauth_token host instance_url)

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ Client

Returns a new instance of Client.

Raises:

  • (ArgumentError)


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

Returns:

  • (Boolean)


23
24
25
# File 'lib/rd/salesforce/client.rb', line 23

def valid?
  not @api.nil?
end