Class: AFCSalesforce::Forms::LeadPlus

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ LeadPlus

Returns a new instance of LeadPlus.



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

def initialize(options={})
  @borrowers = options.fetch(:borrowers, [])
  @account   = options.fetch(:account, nil)
end

Instance Attribute Details

#accountObject

Returns the value of attribute account.



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

def 
  @account
end

#borrowersObject

Returns the value of attribute borrowers.



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

def borrowers
  @borrowers
end

Instance Method Details

#salesforce_hashObject



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

def salesforce_hash
  form_hash                         = {long_form: {}}
  form_hash[:long_form][:borrowers] = @borrowers.empty? ? [] : @borrowers.map(&:to_h)
  form_hash[:long_form][:account]   = @account.to_h
  form_hash
end

#send_to_salesforceObject



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

def send_to_salesforce
  Restforce.new(
    username:                AFCSalesforce.configuration.salesforce_username,
    password:                AFCSalesforce.configuration.salesforce_password,
    security_token:          AFCSalesforce.configuration.salesforce_security_token,
    client_id:               AFCSalesforce.configuration.salesforce_client_id,
    client_secret:           AFCSalesforce.configuration.salesforce_client_secret,
    api_version:             AFCSalesforce.configuration.salesforce_api_version,
    host:                    AFCSalesforce.configuration.salesforce_host,
    authentication_callback: AFCSalesforce.configuration.salesforce_authentication_callback
  ).post(URI('/services/apexrest/v1/lead_plus_form'), salesforce_hash)
end

#valid?Boolean

Returns:

  • (Boolean)


11
12
13
14
# File 'lib/afc_salesforce/forms/lead_plus.rb', line 11

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

#validate!Object



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

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