Skip to content

Commit

Permalink
Map customer address fields on get_customers
Browse files Browse the repository at this point in the history
  • Loading branch information
huoxito committed Oct 27, 2014
1 parent 3ed80bb commit 56eccc8
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
18 changes: 18 additions & 0 deletions lib/SF_services/contact.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,24 @@ def latest_updates(time = Time.now.utc.iso8601)
"Contact.Lastname",
"Contact.Email",
"Contact.Account.Name",
"Contact.Account.BillingCity",
"Contact.Account.BillingCountry",
# "Contact.Account.BillingCountryCode",
"Contact.Account.BillingPostalCode",
"Contact.Account.BillingState",
# "Contact.Account.BillingStateCode",
"Contact.Account.BillingStreet",
"Contact.Account.Rating",
"Contact.Account.Phone",
"Contact.Account.ShippingCity",
"Contact.Account.ShippingCountry",
# "Contact.Account.ShippingCountryCode",
"Contact.Account.ShippingPostalCode",
"Contact.Account.ShippingState",
# "Contact.Account.ShippingStateCode",
"Contact.Account.ShippingStreet",
"Contact.Account.Website",
"Contact.Account.Type",
"Contact.LastModifiedDate"]

filter = "LastModifiedDate > #{since} ORDER BY LastModifiedDate ASC LIMIT 100"
Expand Down
22 changes: 18 additions & 4 deletions lib/integrations/contact_account.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
module Integration
class ContactAccount < Base

attr_reader :object

def initialize(config, object)
Expand All @@ -16,13 +15,17 @@ def fetch_updates
return [] if latest_contacts.to_a.empty?

latest_contacts.map do |contact|
account = contact["Account"] || {}

{
id: contact["Id"],
first_name: contact["Firstname"],
last_name: contact["Lastname"],
first_name: contact["FirstName"],
last_name: contact["LastName"],
email: contact["Email"],
account_name: contact["Account"]["Name"],
salesforce_id: contact["Id"]
salesforce_id: contact["Id"],
shipping_address: build_address(account, "Shipping"),
billing_address: build_address(account)
}
end
end
Expand All @@ -35,6 +38,17 @@ def latest_timestamp_update(contacts = nil)
end
end

def build_address(account, kind = "Billing")
{
address1: account["#{kind}Street"],
zipcode: account["#{kind}PostalCode"],
city: account["#{kind}City"],
country: account["#{kind}Country"],
state: account["#{kind}State"],
phone: account["Phone"]
}
end

private
def latest_contacts
@latest_contacts ||= contact_service.latest_updates config[:salesforce_contacts_since]
Expand Down

0 comments on commit 56eccc8

Please sign in to comment.