Class: AFCSalesforce::Forms::ShortLead

Inherits:
Object
  • Object
show all
Defined in:
lib/afc_salesforce/forms/short_lead.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ ShortLead

Returns a new instance of ShortLead.



6
7
8
# File 'lib/afc_salesforce/forms/short_lead.rb', line 6

def initialize(options={})
  @lead = options[:lead]
end

Instance Attribute Details

#leadObject

Returns the value of attribute lead.



4
5
6
# File 'lib/afc_salesforce/forms/short_lead.rb', line 4

def lead
  @lead
end

Instance Method Details

#salesforce_hashObject



24
25
26
27
28
29
30
# File 'lib/afc_salesforce/forms/short_lead.rb', line 24

def salesforce_hash
  {
    short_lead: {
      lead: @lead.to_h
    }
  }
end

#send_to_salesforceObject



32
33
34
35
36
37
38
39
40
# File 'lib/afc_salesforce/forms/short_lead.rb', line 32

def send_to_salesforce
  Restforce.new(
    username: AFCSalesforce.configuration.salesforce_username,
    password: AFCSalesforce.configuration.salesforce_password,
    client_id: AFCSalesforce.configuration.salesforce_client_id,
    client_secret: AFCSalesforce.configuration.salesforce_client_secret,
    api_version: AFCSalesforce.configuration.salesforce_api_version
  ).post(URI('/services/apexrest/v1/lead_form'), salesforce_hash)
end

#valid?Boolean

Returns:

  • (Boolean)


10
11
12
13
# File 'lib/afc_salesforce/forms/short_lead.rb', line 10

def valid?
  validator = LeadValidator.new(self)
  validator.valid?
end

#validate!Object



15
16
17
18
19
20
21
22
# File 'lib/afc_salesforce/forms/short_lead.rb', line 15

def validate!
  validator = LeadValidator.new(self)
  if validator.valid?
    return true
  else
    return validator.errors
  end
end