markety 2.2.1 → 2.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a79839fea206fe31310530563f8d22a2db6fa7c1
4
- data.tar.gz: 3a293a9a3ae68ef163d92e8992787053c38451d3
3
+ metadata.gz: 44c6d934ebba2a3da13ecbc50b8abdf867a8853d
4
+ data.tar.gz: 7889f1b1819357bd65ba575a267297d777440f28
5
5
  SHA512:
6
- metadata.gz: 522ed97102cdbd68b4f4c63ff2378dbbd168460fa47d736fb64827279dc2763332ef6a783efbcefbe9f3623b8eaea72ebb693765e1a1263b245d7a1fd3538ba9
7
- data.tar.gz: 2a6089896d245175942dca6373a0136ca110d7456a88fdfae57cacbba0e86d262d51c5c1c67036e6ed76508209bd22ee640eb269be89f4cba65cc9350191fa29
6
+ metadata.gz: f090cf31984ba04f4589d318d5af7d7cba8c8041d422077a7def4d4325fbeea2468542533cca55454454040d6fd0a4711157ee7e12369e81d289a9354d4b4813
7
+ data.tar.gz: 48a0328489ab3c623d01a516106ee73ad952e44ac700f8d6564dcb0f0c858ebcc232c54ed4fe406e799b9cf162a673e3ef76316dbb88d2104fb8db52d2da1d12
@@ -6,6 +6,7 @@ module Markety
6
6
  class Client
7
7
  include Markety::Command::GetLead
8
8
  include Markety::Command::SyncLead
9
+ include Markety::Command::SyncMultipleLeads
9
10
  include Markety::Command::GetCustomObject
10
11
  include Markety::Command::SyncCustomObject
11
12
  include Markety::Command::ListOperation
@@ -1,5 +1,6 @@
1
1
  require 'markety/command/get_lead'
2
2
  require 'markety/command/sync_lead'
3
+ require 'markety/command/sync_multiple_leads'
3
4
  require 'markety/command/get_custom_object'
4
5
  require 'markety/command/sync_custom_object'
5
6
  require 'markety/command/list_operation'
@@ -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
data/lib/markety/lead.rb CHANGED
@@ -23,19 +23,19 @@ module Markety
23
23
  # hydrates an instance from a savon hash returned from the marketo API
24
24
  def self.from_hash(savon_hash)
25
25
  lead = Lead.new(email: savon_hash[:email], idnum:savon_hash[:id].to_i)
26
-
26
+
27
27
  unless savon_hash[:lead_attribute_list].nil?
28
28
  if savon_hash[:lead_attribute_list][:attribute].kind_of? Hash
29
29
  attributes = [savon_hash[:lead_attribute_list][:attribute]]
30
30
  else
31
31
  attributes = savon_hash[:lead_attribute_list][:attribute]
32
32
  end
33
-
33
+
34
34
  attributes.each do |attribute|
35
35
  lead.set_attribute(attribute[:attr_name], attribute[:attr_value], attribute[:attr_type])
36
36
  end
37
37
  end
38
-
38
+
39
39
  lead
40
40
  end
41
41
 
@@ -56,9 +56,21 @@ module Markety
56
56
  @types[name]
57
57
  end
58
58
 
59
+ def synchronisation_hash
60
+ keys_hash.merge({"leadAttributeList" => {"attribute" => attributes_soap_array}})
61
+ end
59
62
 
60
63
  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
62
74
  arr = []
63
75
  @attributes.each_pair do |name,value|
64
76
  arr << {attr_name: name, attr_type: self.get_attribute_type(name), attr_value: value }
@@ -4,6 +4,8 @@ require 'markety/response/generic_response'
4
4
  require 'markety/response/get_lead_response'
5
5
  require 'markety/response/get_custom_object_response'
6
6
  require 'markety/response/sync_lead_response'
7
+ require 'markety/response/lead_response'
8
+ require 'markety/response/sync_multiple_leads_response'
7
9
  require 'markety/response/sync_custom_object_response'
8
10
  require 'markety/response/list_operation_response'
9
11
 
@@ -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
@@ -1,6 +1,7 @@
1
1
  require 'markety/response/generic_response'
2
2
  require 'markety/response/get_lead_response'
3
3
  require 'markety/response/sync_lead_response'
4
+ require 'markety/response/sync_multiple_leads_response'
4
5
  require 'markety/response/list_operation_response'
5
6
 
6
7
  module Markety
@@ -15,6 +16,8 @@ module Markety
15
16
  GetLeadResponse.new(savon_response)
16
17
  when :sync_lead
17
18
  SyncLeadResponse.new(savon_response)
19
+ when :sync_multiple_leads
20
+ SyncMultipleLeadsResponse.new(savon_response)
18
21
  when :list_operation
19
22
  ListOperationResponse.new(savon_response)
20
23
  when :get_custom_objects
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Markety
2
- VERSION = "2.2.1"
2
+ VERSION = "2.3.1"
3
3
  end
@@ -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,0 +1,21 @@
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
+ <syncStatus>
13
+ <leadId>1090239</leadId>
14
+ <status>UPDATED</status>
15
+ <error xsi:nil="true" />
16
+ </syncStatus>
17
+ </syncStatusList>
18
+ </result>
19
+ </ns1:successSyncMultipleLeads>
20
+ </SOAP-ENV:Body>
21
+ </SOAP-ENV:Envelope>
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ module Markety
4
+ module Command
5
+ describe SyncMultipleLeads do
6
+
7
+ let(:client){ double("client", send_request: nil) }
8
+
9
+ describe '#sync_multiple_leads' do
10
+ it "calls send_request on the client with the correct params" do
11
+ lead = double(Lead, synchronisation_hash: {"lead" => "hash1"})
12
+ lead2 = double(Lead, synchronisation_hash: {"lead" => "hash2"})
13
+ client.extend(SyncMultipleLeads)
14
+ client.sync_multiple_leads([lead, lead2])
15
+ expect(client).to have_received(:send_request).with(:sync_multiple_leads, {"leadRecordList" => {"leadRecord" => [{"lead" => "hash1"}, {"lead" => "hash2"}] }, "dedupEnabled" => true})
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -3,8 +3,8 @@ require 'spec_helper'
3
3
  module Markety
4
4
  EMAIL = 'some@email.com'
5
5
  IDNUM = 93480938
6
-
7
-
6
+
7
+
8
8
  describe Lead do
9
9
  it "should store the idnum" do
10
10
  lead_record = Lead.new(email:EMAIL, idnum:IDNUM)
@@ -54,13 +54,13 @@ module Markety
54
54
  :foreign_sys_type => nil,
55
55
  :lead_attribute_list => nil
56
56
  }
57
-
57
+
58
58
  actual = Lead.from_hash(savon_hash)
59
59
  expected = Lead.new(email:EMAIL, idnum:IDNUM)
60
-
60
+
61
61
  actual.should == expected
62
62
  end
63
-
63
+
64
64
  # When there is only one attribute, Marketo returns a Hash, not an Array
65
65
  it 'should be instantiable from savon hash with only one attribute' do
66
66
  savon_hash = {
@@ -68,18 +68,18 @@ module Markety
68
68
  :email => EMAIL,
69
69
  :foreign_sys_person_id => nil,
70
70
  :foreign_sys_type => nil,
71
- :lead_attribute_list =>
71
+ :lead_attribute_list =>
72
72
  {:attribute => { :attr_name => 'FirstName', :attr_value => 'Yaya', :attr_type => 'string'}}
73
73
  }
74
-
74
+
75
75
  actual = Lead.from_hash(savon_hash)
76
-
76
+
77
77
  expected = Lead.new(email:EMAIL, idnum:IDNUM)
78
78
  expected.set_attribute('FirstName', 'Yaya')
79
-
79
+
80
80
  actual.should == expected
81
81
  end
82
-
82
+
83
83
  it "should be instantiable from a savon hash" do
84
84
  savon_hash = {
85
85
  :email => EMAIL,
@@ -105,5 +105,33 @@ module Markety
105
105
  actual.should == expected
106
106
  end
107
107
 
108
+ describe "synchronisation_hash" do
109
+ it "returns a correctly formatted hash for synchronisation" do
110
+ lead = Lead.new(email: "some_email@gmail.com", idnum: 123123)
111
+ lead.set_attribute('Company', 'Yaya')
112
+ lead.set_attribute('FirstName', 'James')
113
+
114
+ expect(lead.synchronisation_hash).to eq(
115
+ {
116
+ "id" => 123123,
117
+ "Email" => "some_email@gmail.com",
118
+ "leadAttributeList" => {
119
+ "attribute" => [
120
+ {
121
+ :attr_name => "Company",
122
+ :attr_value => "Yaya",
123
+ :attr_type => "string",
124
+ },
125
+ {
126
+ :attr_name => "FirstName",
127
+ :attr_value => "James",
128
+ :attr_type => "string",
129
+ }
130
+ ]
131
+ }
132
+ })
133
+ end
134
+ end
135
+
108
136
  end
109
137
  end
@@ -0,0 +1,51 @@
1
+ require 'spec_helper'
2
+
3
+ module Markety
4
+ module Response
5
+ describe LeadResponse do
6
+
7
+ describe "#success?" do
8
+ context "with a successful created status" do
9
+ it "returns true" do
10
+ response = LeadResponse.new({:lead_id=>"30609", :status=>"CREATED", :error=>nil})
11
+ expect(response.success?).to eq true
12
+ end
13
+ end
14
+ context "with a successful updated status" do
15
+ it "returns true" do
16
+ response = LeadResponse.new({:lead_id=>"30660", :status=>"UPDATED", :error=>nil})
17
+ expect(response.success?).to eq true
18
+ end
19
+ end
20
+ context "with a failed response" do
21
+ it "returns false" do
22
+ response = LeadResponse.new({:lead_id=>"60960", :status=>"FAILED", :error=>"some error"})
23
+ expect(response.success?).to eq false
24
+ end
25
+ end
26
+ end
27
+
28
+ describe "#error_message" do
29
+ it "returns the error" do
30
+ response = LeadResponse.new({:lead_id=>"60960", :status=>"FAILED", :error=>"Lead Not Found"})
31
+ expect(response.error_message).to eq "Lead Not Found"
32
+ end
33
+ end
34
+
35
+ describe "#status" do
36
+ it "returns the status" do
37
+ response = LeadResponse.new({:lead_id=>"60960", :status=>"FAILED", :error=>"Lead Not Found"})
38
+ expect(response.status).to eq "FAILED"
39
+ end
40
+ end
41
+
42
+ describe "#lead_id" do
43
+ it "returns the lead_id" do
44
+ response = LeadResponse.new({:lead_id=>"60912360", :status=>"FAILED", :error=>"Lead Not Found"})
45
+ expect(response.lead_id).to eq "60912360"
46
+ end
47
+ end
48
+
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ module Markety
4
+ module Response
5
+ describe SyncMultipleLeadsResponse do
6
+ let (:successful_response) {SavonHelper.create_response(File.read(File.expand_path("../../../fixtures/leads/sync_multiple_leads/successful_response.xml", __FILE__)))}
7
+ let (:single_response) {SavonHelper.create_response(File.read(File.expand_path("../../../fixtures/leads/sync_multiple_leads/single_response.xml", __FILE__)))}
8
+
9
+ describe "#lead_responses" do
10
+ context "with multiple updates" do
11
+ it "returns an array of hashes containing the lead responses" do
12
+ response = SyncMultipleLeadsResponse.new(successful_response)
13
+ first_lead_response, second_lead_response = response.lead_responses[0], response.lead_responses[1]
14
+ expect(first_lead_response.success?).to eq true
15
+ expect(first_lead_response.lead_id).to eq "1090240"
16
+ expect(second_lead_response.success?).to eq true
17
+ expect(second_lead_response.lead_id).to eq "1090239"
18
+ end
19
+ end
20
+ context "with a single update" do
21
+ it "returns an array of hashes containing the lead response" do
22
+ response = SyncMultipleLeadsResponse.new(single_response)
23
+ lead_response = response.lead_responses.first
24
+ expect(response.lead_responses.size).to eq 1
25
+ expect(lead_response.lead_id).to eq "1090240"
26
+ expect(lead_response.success?).to eq true
27
+ end
28
+ end
29
+ end
30
+
31
+ end
32
+ end
33
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: markety
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.1
4
+ version: 2.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Santoso
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-10 00:00:00.000000000 Z
11
+ date: 2015-04-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -149,6 +149,7 @@ files:
149
149
  - lib/markety/command/list_operation.rb
150
150
  - lib/markety/command/sync_custom_object.rb
151
151
  - lib/markety/command/sync_lead.rb
152
+ - lib/markety/command/sync_multiple_leads.rb
152
153
  - lib/markety/custom_object.rb
153
154
  - lib/markety/enums.rb
154
155
  - lib/markety/lead.rb
@@ -157,10 +158,12 @@ files:
157
158
  - lib/markety/response/generic_response.rb
158
159
  - lib/markety/response/get_custom_object_response.rb
159
160
  - lib/markety/response/get_lead_response.rb
161
+ - lib/markety/response/lead_response.rb
160
162
  - lib/markety/response/list_operation_response.rb
161
163
  - lib/markety/response/response_factory.rb
162
164
  - lib/markety/response/sync_custom_object_response.rb
163
165
  - lib/markety/response/sync_lead_response.rb
166
+ - lib/markety/response/sync_multiple_leads_response.rb
164
167
  - lib/markety/version.rb
165
168
  - markety.gemspec
166
169
  - spec/fixtures/custom_objects/get_custom_objects/multiple_custom_objects_found.xml
@@ -170,18 +173,23 @@ files:
170
173
  - spec/fixtures/custom_objects/sync_custom_objects/multiple_syncs.xml
171
174
  - spec/fixtures/custom_objects/sync_custom_objects/successful_sync.xml
172
175
  - spec/fixtures/custom_objects/sync_custom_objects/unknown_attribute.xml
176
+ - spec/fixtures/leads/sync_multiple_leads/single_response.xml
177
+ - spec/fixtures/leads/sync_multiple_leads/successful_response.xml
173
178
  - spec/markety/authentication_header_spec.rb
174
179
  - spec/markety/client_spec.rb
175
180
  - spec/markety/command/get_custom_object_spec.rb
176
181
  - spec/markety/command/sync_custom_object_spec.rb
182
+ - spec/markety/command/sync_multiple_leads_spec.rb
177
183
  - spec/markety/custom_object_spec.rb
178
184
  - spec/markety/lead_key_spec.rb
179
185
  - spec/markety/lead_spec.rb
180
186
  - spec/markety/response/get_custom_object_response_spec.rb
181
187
  - spec/markety/response/get_lead_response_spec.rb
188
+ - spec/markety/response/lead_response_spec.rb
182
189
  - spec/markety/response/list_operation_response_spec.rb
183
190
  - spec/markety/response/sync_custom_object_response_spec.rb
184
191
  - spec/markety/response/sync_lead_response_spec.rb
192
+ - spec/markety/response/sync_multiple_leads_response_spec.rb
185
193
  - spec/spec_helper.rb
186
194
  - spec/support/savon_helper.rb
187
195
  homepage: https://github.com/davidsantoso/markety
@@ -216,18 +224,23 @@ test_files:
216
224
  - spec/fixtures/custom_objects/sync_custom_objects/multiple_syncs.xml
217
225
  - spec/fixtures/custom_objects/sync_custom_objects/successful_sync.xml
218
226
  - spec/fixtures/custom_objects/sync_custom_objects/unknown_attribute.xml
227
+ - spec/fixtures/leads/sync_multiple_leads/single_response.xml
228
+ - spec/fixtures/leads/sync_multiple_leads/successful_response.xml
219
229
  - spec/markety/authentication_header_spec.rb
220
230
  - spec/markety/client_spec.rb
221
231
  - spec/markety/command/get_custom_object_spec.rb
222
232
  - spec/markety/command/sync_custom_object_spec.rb
233
+ - spec/markety/command/sync_multiple_leads_spec.rb
223
234
  - spec/markety/custom_object_spec.rb
224
235
  - spec/markety/lead_key_spec.rb
225
236
  - spec/markety/lead_spec.rb
226
237
  - spec/markety/response/get_custom_object_response_spec.rb
227
238
  - spec/markety/response/get_lead_response_spec.rb
239
+ - spec/markety/response/lead_response_spec.rb
228
240
  - spec/markety/response/list_operation_response_spec.rb
229
241
  - spec/markety/response/sync_custom_object_response_spec.rb
230
242
  - spec/markety/response/sync_lead_response_spec.rb
243
+ - spec/markety/response/sync_multiple_leads_response_spec.rb
231
244
  - spec/spec_helper.rb
232
245
  - spec/support/savon_helper.rb
233
246
  has_rdoc: