Class: G5YglClient20::PostLeadRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/g5_ygl_client_20/requests/post_lead_request.rb

Class Method Summary collapse

Class Method Details

.execute(auth, url, source_id, sub_source_id, property_id, lead) ⇒ Object

just for future reference Sub source id’s are specific forms (tour request, Contact us, etc.) Source id’s are more general, (Internet, G5, etc.) If there is a sub source id, pass it as the LeadSourceId, and pass source id as the RootLeadSourceId If the sub source id is nil, pass source id as the LeadSourceId, and don’t pass a RootLeadSourceId



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/g5_ygl_client_20/requests/post_lead_request.rb', line 8

def self.execute(auth, url, source_id, sub_source_id, property_id, lead)
  referral_source_array = [{"LeadSourceId" => "#{sub_source_id.blank? ? source_id : sub_source_id}", "LeadSourceRank" => "1"}]
  referral_source_array.first.merge!("RootLeadSourceId" => "#{source_id}") unless sub_source_id.blank?
  response = HTTParty.post("#{url}#{property_id}/leads",
                          :headers => {"Authorization" => auth,
                                       "Host" => HOST,
                                       "Accept" => "application/json",
                                       "Content-Type" => "application/json"},
                          :body =>{"PrimaryContact" => {"FirstName" => "#{lead[:first_name]}",
                                                        "LastName" => "#{lead[:last_name]}",
                                                        "Address" => {"Email" => "#{lead[:email]}",
                                                                      "PhoneCell" => "#{lead[:phone]}"}},
                                    "CallCenterId" => "G5-#{lead[:id]}",
                                    "Notes" => {"Notes" => "#{lead[:notes]}"},
                                    "ReferralSources" => referral_source_array
                                  }.to_json)
end