Skip to content

Commit f88a9e6

Browse files
author
David Santoso
committed
Merge branch 'markadrianagbuya-sync_multiple_leads'
2 parents 95e94dc + 1754989 commit f88a9e6

File tree

15 files changed

+271
-15
lines changed

15 files changed

+271
-15
lines changed

lib/markety/client.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ module Markety
66
class Client
77
include Markety::Command::GetLead
88
include Markety::Command::SyncLead
9+
include Markety::Command::SyncMultipleLeads
910
include Markety::Command::GetCustomObject
1011
include Markety::Command::SyncCustomObject
1112
include Markety::Command::ListOperation

lib/markety/command.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
require 'markety/command/get_lead'
22
require 'markety/command/sync_lead'
3+
require 'markety/command/sync_multiple_leads'
34
require 'markety/command/get_custom_object'
45
require 'markety/command/sync_custom_object'
56
require 'markety/command/list_operation'
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
module Markety
2+
module Command
3+
module SyncMultipleLeads
4+
5+
def sync_multiple_leads(leads, dedup_enabled=true)
6+
send_request(:sync_multiple_leads, sync_lead_request_hash(leads, dedup_enabled))
7+
end
8+
9+
private
10+
11+
def sync_lead_request_hash(leads, dedup_enabled)
12+
{
13+
"leadRecordList" => {
14+
"leadRecord" => leads.map(&:synchronisation_hash),
15+
},
16+
"dedupEnabled" => dedup_enabled
17+
}
18+
end
19+
20+
end
21+
end
22+
end

lib/markety/lead.rb

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,19 @@ def ==(other)
2323
# hydrates an instance from a savon hash returned from the marketo API
2424
def self.from_hash(savon_hash)
2525
lead = Lead.new(email: savon_hash[:email], idnum:savon_hash[:id].to_i)
26-
26+
2727
unless savon_hash[:lead_attribute_list].nil?
2828
if savon_hash[:lead_attribute_list][:attribute].kind_of? Hash
2929
attributes = [savon_hash[:lead_attribute_list][:attribute]]
3030
else
3131
attributes = savon_hash[:lead_attribute_list][:attribute]
3232
end
33-
33+
3434
attributes.each do |attribute|
3535
lead.set_attribute(attribute[:attr_name], attribute[:attr_value], attribute[:attr_type])
3636
end
3737
end
38-
38+
3939
lead
4040
end
4141

@@ -56,9 +56,21 @@ def get_attribute_type(name)
5656
@types[name]
5757
end
5858

59+
def synchronisation_hash
60+
keys_hash.merge({"leadAttributeList" => {"attribute" => attributes_soap_array}})
61+
end
5962

6063
private
61-
def attributes_soap_array()
64+
65+
def keys_hash
66+
keys_hash = {}
67+
keys_hash.merge!({"id" => idnum}) unless idnum.nil?
68+
keys_hash.merge!({"foreignSysPersonId" => foreign_sys_person_id}) unless foreign_sys_person_id.nil?
69+
keys_hash.merge!({"Email" => email}) unless email.nil?
70+
keys_hash
71+
end
72+
73+
def attributes_soap_array
6274
arr = []
6375
@attributes.each_pair do |name,value|
6476
arr << {attr_name: name, attr_type: self.get_attribute_type(name), attr_value: value }

lib/markety/response.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
require 'markety/response/get_lead_response'
55
require 'markety/response/get_custom_object_response'
66
require 'markety/response/sync_lead_response'
7+
require 'markety/response/lead_response'
8+
require 'markety/response/sync_multiple_leads_response'
79
require 'markety/response/sync_custom_object_response'
810
require 'markety/response/list_operation_response'
911

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
module Markety
2+
module Response
3+
class LeadResponse
4+
5+
attr_accessor :status, :error_message, :lead_id
6+
7+
def initialize(response)
8+
self.status = response[:status]
9+
self.error_message = response[:error]
10+
self.lead_id = response[:lead_id]
11+
end
12+
13+
def success?
14+
!failed?
15+
end
16+
17+
private
18+
19+
def failed?
20+
status == "FAILED"
21+
end
22+
23+
end
24+
end
25+
end

lib/markety/response/response_factory.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
require 'markety/response/generic_response'
22
require 'markety/response/get_lead_response'
33
require 'markety/response/sync_lead_response'
4+
require 'markety/response/sync_multiple_leads_response'
45
require 'markety/response/list_operation_response'
56

67
module Markety
@@ -15,6 +16,8 @@ def self.create_response(cmd_type,savon_response)
1516
GetLeadResponse.new(savon_response)
1617
when :sync_lead
1718
SyncLeadResponse.new(savon_response)
19+
when :sync_multiple_leads
20+
SyncMultipleLeadsResponse.new(savon_response)
1821
when :list_operation
1922
ListOperationResponse.new(savon_response)
2023
when :get_custom_objects
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
module Markety
2+
module Response
3+
# Response class for SyncLead commands
4+
class SyncMultipleLeadsResponse < GenericResponse
5+
6+
def initialize(response)
7+
super(:sync_multiple_leads_response, response)
8+
end
9+
10+
def lead_responses
11+
response_hashes.map do |response_hash|
12+
LeadResponse.new(response_hash)
13+
end
14+
end
15+
16+
def response_hashes
17+
[to_hash.fetch(:success_sync_multiple_leads, {}).fetch(:result, {}).fetch(:sync_status_list, {}).fetch(:sync_status, {})].flatten
18+
end
19+
end
20+
end
21+
end

lib/markety/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module Markety
2-
VERSION = "2.2.1"
2+
VERSION = "2.3.1"
33
end
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns1="http://www.marketo.com/mktows/">
3+
<SOAP-ENV:Body>
4+
<ns1:successSyncMultipleLeads>
5+
<result>
6+
<syncStatusList>
7+
<syncStatus>
8+
<leadId>1090240</leadId>
9+
<status>UPDATED</status>
10+
<error xsi:nil="true" />
11+
</syncStatus>
12+
</syncStatusList>
13+
</result>
14+
</ns1:successSyncMultipleLeads>
15+
</SOAP-ENV:Body>
16+
</SOAP-ENV:Envelope>

0 commit comments

Comments
 (0)