-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'markadrianagbuya-sync_multiple_leads'
- Loading branch information
Showing
15 changed files
with
271 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
module Markety | ||
module Command | ||
module SyncMultipleLeads | ||
|
||
def sync_multiple_leads(leads, dedup_enabled=true) | ||
send_request(:sync_multiple_leads, sync_lead_request_hash(leads, dedup_enabled)) | ||
end | ||
|
||
private | ||
|
||
def sync_lead_request_hash(leads, dedup_enabled) | ||
{ | ||
"leadRecordList" => { | ||
"leadRecord" => leads.map(&:synchronisation_hash), | ||
}, | ||
"dedupEnabled" => dedup_enabled | ||
} | ||
end | ||
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
module Markety | ||
module Response | ||
class LeadResponse | ||
|
||
attr_accessor :status, :error_message, :lead_id | ||
|
||
def initialize(response) | ||
self.status = response[:status] | ||
self.error_message = response[:error] | ||
self.lead_id = response[:lead_id] | ||
end | ||
|
||
def success? | ||
!failed? | ||
end | ||
|
||
private | ||
|
||
def failed? | ||
status == "FAILED" | ||
end | ||
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
module Markety | ||
module Response | ||
# Response class for SyncLead commands | ||
class SyncMultipleLeadsResponse < GenericResponse | ||
|
||
def initialize(response) | ||
super(:sync_multiple_leads_response, response) | ||
end | ||
|
||
def lead_responses | ||
response_hashes.map do |response_hash| | ||
LeadResponse.new(response_hash) | ||
end | ||
end | ||
|
||
def response_hashes | ||
[to_hash.fetch(:success_sync_multiple_leads, {}).fetch(:result, {}).fetch(:sync_status_list, {}).fetch(:sync_status, {})].flatten | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module Markety | ||
VERSION = "2.2.1" | ||
VERSION = "2.3.1" | ||
end |
16 changes: 16 additions & 0 deletions
16
spec/fixtures/leads/sync_multiple_leads/single_response.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<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/"> | ||
<SOAP-ENV:Body> | ||
<ns1:successSyncMultipleLeads> | ||
<result> | ||
<syncStatusList> | ||
<syncStatus> | ||
<leadId>1090240</leadId> | ||
<status>UPDATED</status> | ||
<error xsi:nil="true" /> | ||
</syncStatus> | ||
</syncStatusList> | ||
</result> | ||
</ns1:successSyncMultipleLeads> | ||
</SOAP-ENV:Body> | ||
</SOAP-ENV:Envelope> |
21 changes: 21 additions & 0 deletions
21
spec/fixtures/leads/sync_multiple_leads/successful_response.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<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/"> | ||
<SOAP-ENV:Body> | ||
<ns1:successSyncMultipleLeads> | ||
<result> | ||
<syncStatusList> | ||
<syncStatus> | ||
<leadId>1090240</leadId> | ||
<status>UPDATED</status> | ||
<error xsi:nil="true" /> | ||
</syncStatus> | ||
<syncStatus> | ||
<leadId>1090239</leadId> | ||
<status>UPDATED</status> | ||
<error xsi:nil="true" /> | ||
</syncStatus> | ||
</syncStatusList> | ||
</result> | ||
</ns1:successSyncMultipleLeads> | ||
</SOAP-ENV:Body> | ||
</SOAP-ENV:Envelope> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
require 'spec_helper' | ||
|
||
module Markety | ||
module Command | ||
describe SyncMultipleLeads do | ||
|
||
let(:client){ double("client", send_request: nil) } | ||
|
||
describe '#sync_multiple_leads' do | ||
it "calls send_request on the client with the correct params" do | ||
lead = double(Lead, synchronisation_hash: {"lead" => "hash1"}) | ||
lead2 = double(Lead, synchronisation_hash: {"lead" => "hash2"}) | ||
client.extend(SyncMultipleLeads) | ||
client.sync_multiple_leads([lead, lead2]) | ||
expect(client).to have_received(:send_request).with(:sync_multiple_leads, {"leadRecordList" => {"leadRecord" => [{"lead" => "hash1"}, {"lead" => "hash2"}] }, "dedupEnabled" => true}) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,8 +3,8 @@ | |
module Markety | ||
EMAIL = '[email protected]' | ||
IDNUM = 93480938 | ||
|
||
|
||
describe Lead do | ||
it "should store the idnum" do | ||
lead_record = Lead.new(email:EMAIL, idnum:IDNUM) | ||
|
@@ -54,32 +54,32 @@ module Markety | |
:foreign_sys_type => nil, | ||
:lead_attribute_list => nil | ||
} | ||
|
||
actual = Lead.from_hash(savon_hash) | ||
expected = Lead.new(email:EMAIL, idnum:IDNUM) | ||
|
||
actual.should == expected | ||
end | ||
|
||
# When there is only one attribute, Marketo returns a Hash, not an Array | ||
it 'should be instantiable from savon hash with only one attribute' do | ||
savon_hash = { | ||
:id => IDNUM, | ||
:email => EMAIL, | ||
:foreign_sys_person_id => nil, | ||
:foreign_sys_type => nil, | ||
:lead_attribute_list => | ||
:lead_attribute_list => | ||
{:attribute => { :attr_name => 'FirstName', :attr_value => 'Yaya', :attr_type => 'string'}} | ||
} | ||
|
||
actual = Lead.from_hash(savon_hash) | ||
|
||
expected = Lead.new(email:EMAIL, idnum:IDNUM) | ||
expected.set_attribute('FirstName', 'Yaya') | ||
|
||
actual.should == expected | ||
end | ||
|
||
it "should be instantiable from a savon hash" do | ||
savon_hash = { | ||
:email => EMAIL, | ||
|
@@ -105,5 +105,33 @@ module Markety | |
actual.should == expected | ||
end | ||
|
||
describe "synchronisation_hash" do | ||
it "returns a correctly formatted hash for synchronisation" do | ||
lead = Lead.new(email: "[email protected]", idnum: 123123) | ||
lead.set_attribute('Company', 'Yaya') | ||
lead.set_attribute('FirstName', 'James') | ||
|
||
expect(lead.synchronisation_hash).to eq( | ||
{ | ||
"id" => 123123, | ||
"Email" => "[email protected]", | ||
"leadAttributeList" => { | ||
"attribute" => [ | ||
{ | ||
:attr_name => "Company", | ||
:attr_value => "Yaya", | ||
:attr_type => "string", | ||
}, | ||
{ | ||
:attr_name => "FirstName", | ||
:attr_value => "James", | ||
:attr_type => "string", | ||
} | ||
] | ||
} | ||
}) | ||
end | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
require 'spec_helper' | ||
|
||
module Markety | ||
module Response | ||
describe LeadResponse do | ||
|
||
describe "#success?" do | ||
context "with a successful created status" do | ||
it "returns true" do | ||
response = LeadResponse.new({:lead_id=>"30609", :status=>"CREATED", :error=>nil}) | ||
expect(response.success?).to eq true | ||
end | ||
end | ||
context "with a successful updated status" do | ||
it "returns true" do | ||
response = LeadResponse.new({:lead_id=>"30660", :status=>"UPDATED", :error=>nil}) | ||
expect(response.success?).to eq true | ||
end | ||
end | ||
context "with a failed response" do | ||
it "returns false" do | ||
response = LeadResponse.new({:lead_id=>"60960", :status=>"FAILED", :error=>"some error"}) | ||
expect(response.success?).to eq false | ||
end | ||
end | ||
end | ||
|
||
describe "#error_message" do | ||
it "returns the error" do | ||
response = LeadResponse.new({:lead_id=>"60960", :status=>"FAILED", :error=>"Lead Not Found"}) | ||
expect(response.error_message).to eq "Lead Not Found" | ||
end | ||
end | ||
|
||
describe "#status" do | ||
it "returns the status" do | ||
response = LeadResponse.new({:lead_id=>"60960", :status=>"FAILED", :error=>"Lead Not Found"}) | ||
expect(response.status).to eq "FAILED" | ||
end | ||
end | ||
|
||
describe "#lead_id" do | ||
it "returns the lead_id" do | ||
response = LeadResponse.new({:lead_id=>"60912360", :status=>"FAILED", :error=>"Lead Not Found"}) | ||
expect(response.lead_id).to eq "60912360" | ||
end | ||
end | ||
|
||
end | ||
end | ||
end |
33 changes: 33 additions & 0 deletions
33
spec/markety/response/sync_multiple_leads_response_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
require 'spec_helper' | ||
|
||
module Markety | ||
module Response | ||
describe SyncMultipleLeadsResponse do | ||
let (:successful_response) {SavonHelper.create_response(File.read(File.expand_path("../../../fixtures/leads/sync_multiple_leads/successful_response.xml", __FILE__)))} | ||
let (:single_response) {SavonHelper.create_response(File.read(File.expand_path("../../../fixtures/leads/sync_multiple_leads/single_response.xml", __FILE__)))} | ||
|
||
describe "#lead_responses" do | ||
context "with multiple updates" do | ||
it "returns an array of hashes containing the lead responses" do | ||
response = SyncMultipleLeadsResponse.new(successful_response) | ||
first_lead_response, second_lead_response = response.lead_responses[0], response.lead_responses[1] | ||
expect(first_lead_response.success?).to eq true | ||
expect(first_lead_response.lead_id).to eq "1090240" | ||
expect(second_lead_response.success?).to eq true | ||
expect(second_lead_response.lead_id).to eq "1090239" | ||
end | ||
end | ||
context "with a single update" do | ||
it "returns an array of hashes containing the lead response" do | ||
response = SyncMultipleLeadsResponse.new(single_response) | ||
lead_response = response.lead_responses.first | ||
expect(response.lead_responses.size).to eq 1 | ||
expect(lead_response.lead_id).to eq "1090240" | ||
expect(lead_response.success?).to eq true | ||
end | ||
end | ||
end | ||
|
||
end | ||
end | ||
end |