Class: Rd::Salesforce::Person

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Model, ActiveModel::Validations
Defined in:
lib/rd/salesforce/person.rb

Overview

Basic structure to handle a contact. It stores and validates basic person info and upload_to_salesforce!

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#companyObject

Returns the value of attribute company.



32
33
34
# File 'lib/rd/salesforce/person.rb', line 32

def company
  @company
end

#emailObject

Returns the value of attribute email.



32
33
34
# File 'lib/rd/salesforce/person.rb', line 32

def email
  @email
end

#first_nameObject

Returns the value of attribute first_name.



32
33
34
# File 'lib/rd/salesforce/person.rb', line 32

def first_name
  @first_name
end

#job_titleObject

Returns the value of attribute job_title.



32
33
34
# File 'lib/rd/salesforce/person.rb', line 32

def job_title
  @job_title
end

#last_nameObject

Returns the value of attribute last_name.



32
33
34
# File 'lib/rd/salesforce/person.rb', line 32

def last_name
  @last_name
end

#phoneObject

Returns the value of attribute phone.



32
33
34
# File 'lib/rd/salesforce/person.rb', line 32

def phone
  @phone
end

#salesforce_idObject

Returns the value of attribute salesforce_id.



33
34
35
# File 'lib/rd/salesforce/person.rb', line 33

def salesforce_id
  @salesforce_id
end

#websiteObject

Returns the value of attribute website.



32
33
34
# File 'lib/rd/salesforce/person.rb', line 32

def website
  @website
end

Instance Method Details

#translate_attributesObject

Translates person fields to salesforce Lead attributes. see more about Lead object at: www.salesforce.com/developer/docs/api/Content/sforce_api_objects_lead.htm



61
62
63
64
65
66
67
# File 'lib/rd/salesforce/person.rb', line 61

def translate_attributes
  info = {}
  translate.each do |attribute_name, label|
    info[label] = send(attribute_name)
  end
  info
end

#upload_to_salesforce!(client) ⇒ Object

Uploads current person to salesforce.

Raises ArgumentError if the client is nil or client is invalid Raises StandardError if the current instance is invalid

Raises:

  • (ArgumentError)


49
50
51
52
53
54
55
# File 'lib/rd/salesforce/person.rb', line 49

def upload_to_salesforce!(client)
  raise ArgumentError.new("client is nil") if not client
  raise ArgumentError.new("client is invalid: #{client.inspect}") if not client.valid?
  raise ArgumentError.new("client does not respond to :save_lead method. client: #{client.inspect}") if not client.respond_to? :save_lead

  client.save_lead self
end