marketo 1.1.6 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/marketo/client.rb +38 -11
- data/lib/marketo/lead_record.rb +1 -1
- data/spec/marketo/client_spec.rb +165 -87
- data/spec/marketo/lead_record_spec.rb +6 -10
- metadata +5 -5
data/lib/marketo/client.rb
CHANGED
@@ -21,17 +21,35 @@ module Rapleaf
|
|
21
21
|
#
|
22
22
|
# client = Rapleaf::Marketo.new_client(<access_key>, <secret_key>)
|
23
23
|
#
|
24
|
-
# get_lead_by_email
|
24
|
+
# *get_lead_by_email:*
|
25
25
|
#
|
26
26
|
# lead_record = client.get_lead_by_email('sombody@examnple.com')
|
27
|
+
#
|
27
28
|
# puts lead_record.idnum
|
29
|
+
#
|
28
30
|
# puts lead_record.get_attribute('FirstName')
|
31
|
+
#
|
29
32
|
# puts lead_record.get_attribute('LastName')
|
30
33
|
#
|
31
|
-
# sync_lead (update)
|
34
|
+
# *sync_lead: (update)*
|
32
35
|
#
|
33
36
|
# lead_record = client.sync_lead('example@rapleaf.com', 'Joe', 'Smith', 'Company 1', '415 911')
|
34
|
-
#
|
37
|
+
#
|
38
|
+
# *sync_lead_record: (update with custom fields)*
|
39
|
+
#
|
40
|
+
# lead_record = Rapleaf::Marketo::LeadRecord.new('harry@rapleaf.com')
|
41
|
+
#
|
42
|
+
# lead_record.set_attribute('FirstName', 'harry')
|
43
|
+
#
|
44
|
+
# lead_record.set_attribute('LastName', 'smith')
|
45
|
+
#
|
46
|
+
# lead_record.set_attribute('Email', 'harry@somesite.com')
|
47
|
+
#
|
48
|
+
# lead_record.set_attribute('Company', 'Rapleaf')
|
49
|
+
#
|
50
|
+
# lead_record.set_attribute('MobilePhone', '123 456')
|
51
|
+
#
|
52
|
+
# response = client.sync_lead_record(lead_record)
|
35
53
|
class Client
|
36
54
|
def initialize(savon_client, authentication_header)
|
37
55
|
@client = savon_client
|
@@ -59,19 +77,28 @@ module Rapleaf
|
|
59
77
|
#
|
60
78
|
# returns the LeadRecord instance on success otherwise nil
|
61
79
|
def sync_lead(email, first, last, company, mobile)
|
80
|
+
lead_record = LeadRecord.new(email)
|
81
|
+
lead_record.set_attribute('FirstName', first)
|
82
|
+
lead_record.set_attribute('LastName', last)
|
83
|
+
lead_record.set_attribute('Email', email)
|
84
|
+
lead_record.set_attribute('Company', company)
|
85
|
+
lead_record.set_attribute('MobilePhone', mobile)
|
86
|
+
sync_lead_record(lead_record)
|
87
|
+
end
|
88
|
+
|
89
|
+
def sync_lead_record(lead_record)
|
62
90
|
begin
|
91
|
+
attributes = []
|
92
|
+
lead_record.each_attribute_pair do |name, value|
|
93
|
+
attributes << {:attr_name => name, :attr_type => 'string', :attr_value => value}
|
94
|
+
end
|
95
|
+
|
63
96
|
response = send_request("ns1:paramsSyncLead", {
|
64
97
|
:return_lead => true,
|
65
98
|
:lead_record =>
|
66
|
-
{:email => email,
|
99
|
+
{:email => lead_record.email,
|
67
100
|
:lead_attribute_list => {
|
68
|
-
:attribute =>
|
69
|
-
{:attr_name => 'FirstName', :attr_type => 'string', :attr_value => first},
|
70
|
-
{:attr_name => 'LastName', :attr_type => 'string', :attr_value => last},
|
71
|
-
{:attr_name => 'Email', :attr_type => 'string', :attr_value => email},
|
72
|
-
{:attr_name => 'Company', :attr_type => 'string', :attr_value => company},
|
73
|
-
{:attr_name => 'MobilePhone', :attr_type => 'string', :attr_value => mobile}
|
74
|
-
]}}})
|
101
|
+
:attribute => attributes}}})
|
75
102
|
return LeadRecord.from_hash(response[:success_sync_lead][:result][:lead_record])
|
76
103
|
rescue Exception => e
|
77
104
|
return nil
|
data/lib/marketo/lead_record.rb
CHANGED
data/spec/marketo/client_spec.rb
CHANGED
@@ -60,9 +60,10 @@ module Rapleaf
|
|
60
60
|
}
|
61
61
|
expect_request(savon_client,
|
62
62
|
authentication_header,
|
63
|
-
|
63
|
+
equals_matcher(:lead_key => {
|
64
64
|
:key_value => IDNUM,
|
65
|
-
:key_type => LeadKeyType::IDNUM
|
65
|
+
:key_type => LeadKeyType::IDNUM
|
66
|
+
}),
|
66
67
|
'ns1:paramsGetLead',
|
67
68
|
response_hash)
|
68
69
|
expected_lead_record = LeadRecord.new(EMAIL, IDNUM)
|
@@ -102,9 +103,9 @@ module Rapleaf
|
|
102
103
|
}
|
103
104
|
expect_request(savon_client,
|
104
105
|
authentication_header,
|
105
|
-
{:lead_key => {
|
106
|
+
equals_matcher({:lead_key => {
|
106
107
|
:key_value => EMAIL,
|
107
|
-
:key_type => LeadKeyType::EMAIL}},
|
108
|
+
:key_type => LeadKeyType::EMAIL}}),
|
108
109
|
'ns1:paramsGetLead',
|
109
110
|
response_hash)
|
110
111
|
expected_lead_record = LeadRecord.new(EMAIL, IDNUM)
|
@@ -115,6 +116,66 @@ module Rapleaf
|
|
115
116
|
client.get_lead_by_email(EMAIL).should == expected_lead_record
|
116
117
|
end
|
117
118
|
|
119
|
+
it "should have the correct body format on sync_lead_record" do
|
120
|
+
savon_client = mock('savon_client')
|
121
|
+
authentication_header = mock('authentication_header')
|
122
|
+
client = Rapleaf::Marketo::Client.new(savon_client, authentication_header)
|
123
|
+
response_hash = {
|
124
|
+
:success_sync_lead => {
|
125
|
+
:result => {
|
126
|
+
:lead_id => IDNUM,
|
127
|
+
:sync_status => {
|
128
|
+
:error => nil,
|
129
|
+
:status => 'UPDATED',
|
130
|
+
:lead_id => IDNUM
|
131
|
+
},
|
132
|
+
:lead_record => {
|
133
|
+
:email => EMAIL,
|
134
|
+
:lead_attribute_list => {
|
135
|
+
:attribute => [
|
136
|
+
{:attr_name => 'name1', :attr_type => 'string', :attr_value => 'val1'},
|
137
|
+
{:attr_name => 'name2', :attr_type => 'string', :attr_value => 'val2'},
|
138
|
+
{:attr_name => 'name3', :attr_type => 'string', :attr_value => 'val3'},
|
139
|
+
{:attr_name => 'name4', :attr_type => 'string', :attr_value => 'val4'}
|
140
|
+
]
|
141
|
+
},
|
142
|
+
:foreign_sys_type => nil,
|
143
|
+
:foreign_sys_person_id => nil,
|
144
|
+
:id => IDNUM.to_s
|
145
|
+
}
|
146
|
+
}
|
147
|
+
}
|
148
|
+
}
|
149
|
+
expect_request(savon_client,
|
150
|
+
authentication_header,
|
151
|
+
equals_matcher({
|
152
|
+
:return_lead => true,
|
153
|
+
:lead_record => {
|
154
|
+
:email => "some@email.com",
|
155
|
+
:lead_attribute_list =>
|
156
|
+
{
|
157
|
+
:attribute => [
|
158
|
+
{:attr_value => "val1",
|
159
|
+
:attr_name => "name1",
|
160
|
+
:attr_type => "string"},
|
161
|
+
{:attr_value => "val2",
|
162
|
+
:attr_name => "name2",
|
163
|
+
:attr_type => "string"}
|
164
|
+
]}}}),
|
165
|
+
'ns1:paramsSyncLead',
|
166
|
+
response_hash)
|
167
|
+
lead_record = LeadRecord.new(EMAIL)
|
168
|
+
lead_record.set_attribute('name1', 'val1')
|
169
|
+
lead_record.set_attribute('name2', 'val2')
|
170
|
+
|
171
|
+
expected_lead_record = LeadRecord.new(EMAIL, IDNUM)
|
172
|
+
expected_lead_record.set_attribute('name1', 'val1')
|
173
|
+
expected_lead_record.set_attribute('name2', 'val2')
|
174
|
+
expected_lead_record.set_attribute('name3', 'val3')
|
175
|
+
expected_lead_record.set_attribute('name4', 'val4')
|
176
|
+
client.sync_lead_record(lead_record).should == expected_lead_record
|
177
|
+
end
|
178
|
+
|
118
179
|
it "should have the correct body format on sync_lead" do
|
119
180
|
savon_client = mock('savon_client')
|
120
181
|
authentication_header = mock('authentication_header')
|
@@ -122,54 +183,62 @@ module Rapleaf
|
|
122
183
|
response_hash = {
|
123
184
|
:success_sync_lead => {
|
124
185
|
:result => {
|
125
|
-
:lead_id
|
186
|
+
:lead_id => IDNUM,
|
126
187
|
:sync_status => {
|
127
|
-
|
128
|
-
|
129
|
-
|
188
|
+
:error => nil,
|
189
|
+
:status => 'UPDATED',
|
190
|
+
:lead_id => IDNUM
|
130
191
|
},
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
192
|
+
:lead_record => {
|
193
|
+
:email => EMAIL,
|
194
|
+
:lead_attribute_list => {
|
195
|
+
:attribute => [
|
196
|
+
{:attr_name => 'name1', :attr_type => 'string', :attr_value => 'val1'},
|
197
|
+
{:attr_name => 'name2', :attr_type => 'string', :attr_value => 'val2'},
|
198
|
+
{:attr_name => 'name3', :attr_type => 'string', :attr_value => 'val3'},
|
199
|
+
{:attr_name => 'name4', :attr_type => 'string', :attr_value => 'val4'}
|
200
|
+
]
|
201
|
+
},
|
202
|
+
:foreign_sys_type => nil,
|
203
|
+
:foreign_sys_person_id => nil,
|
204
|
+
:id => IDNUM.to_s
|
205
|
+
}
|
145
206
|
}
|
146
207
|
}
|
147
208
|
}
|
209
|
+
|
148
210
|
expect_request(savon_client,
|
149
211
|
authentication_header,
|
150
|
-
{
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
212
|
+
Proc.new { |actual|
|
213
|
+
actual_attribute_list = actual[:lead_record][:lead_attribute_list][:attribute]
|
214
|
+
actual[:lead_record][:lead_attribute_list][:attribute] = nil
|
215
|
+
expected = {
|
216
|
+
:return_lead => true,
|
217
|
+
:lead_record => {
|
218
|
+
:email => "some@email.com",
|
219
|
+
:lead_attribute_list =>
|
220
|
+
{
|
221
|
+
:attribute => nil}}
|
222
|
+
}
|
223
|
+
actual.should == expected
|
224
|
+
actual_attribute_list.should =~ [
|
225
|
+
{:attr_value => FIRST,
|
226
|
+
:attr_name => "FirstName",
|
227
|
+
:attr_type => "string"},
|
228
|
+
{:attr_value => LAST,
|
229
|
+
:attr_name => "LastName",
|
230
|
+
:attr_type => "string"},
|
231
|
+
{:attr_value => EMAIL,
|
232
|
+
:attr_name =>"Email",
|
233
|
+
:attr_type => "string"},
|
234
|
+
{:attr_value => COMPANY,
|
235
|
+
:attr_name => "Company",
|
236
|
+
:attr_type => "string"},
|
237
|
+
{:attr_value => MOBILE,
|
238
|
+
:attr_name => "MobilePhone",
|
239
|
+
:attr_type => "string"}
|
240
|
+
]
|
241
|
+
},
|
173
242
|
'ns1:paramsSyncLead',
|
174
243
|
response_hash)
|
175
244
|
expected_lead_record = LeadRecord.new(EMAIL, IDNUM)
|
@@ -181,8 +250,9 @@ module Rapleaf
|
|
181
250
|
end
|
182
251
|
|
183
252
|
context "list operations" do
|
253
|
+
LIST_KEY = 'awesome leads list'
|
254
|
+
|
184
255
|
before(:each) do
|
185
|
-
LIST_KEY = 'awesome leads list'
|
186
256
|
@savon_client = mock('savon_client')
|
187
257
|
@authentication_header = mock('authentication_header')
|
188
258
|
@client = Rapleaf::Marketo::Client.new(@savon_client, @authentication_header)
|
@@ -192,19 +262,19 @@ module Rapleaf
|
|
192
262
|
response_hash = {} # TODO
|
193
263
|
expect_request(@savon_client,
|
194
264
|
@authentication_header,
|
195
|
-
{
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
265
|
+
equals_matcher({
|
266
|
+
:list_operation => ListOperationType::ADD_TO,
|
267
|
+
:list_key => LIST_KEY,
|
268
|
+
:strict => 'false',
|
269
|
+
:list_member_list => {
|
270
|
+
:lead_key => [
|
271
|
+
{
|
272
|
+
:key_type => 'EMAIL',
|
273
|
+
:key_value => EMAIL
|
274
|
+
}
|
275
|
+
]
|
276
|
+
}
|
277
|
+
}),
|
208
278
|
'ns1:paramsListOperation',
|
209
279
|
response_hash)
|
210
280
|
|
@@ -215,19 +285,19 @@ module Rapleaf
|
|
215
285
|
response_hash = {} # TODO
|
216
286
|
expect_request(@savon_client,
|
217
287
|
@authentication_header,
|
218
|
-
{
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
288
|
+
equals_matcher({
|
289
|
+
:list_operation => ListOperationType::REMOVE_FROM,
|
290
|
+
:list_key => LIST_KEY,
|
291
|
+
:strict => 'false',
|
292
|
+
:list_member_list => {
|
293
|
+
:lead_key => [
|
294
|
+
{
|
295
|
+
:key_type => 'EMAIL',
|
296
|
+
:key_value => EMAIL
|
297
|
+
}
|
298
|
+
]
|
299
|
+
}
|
300
|
+
}),
|
231
301
|
'ns1:paramsListOperation',
|
232
302
|
response_hash)
|
233
303
|
|
@@ -238,19 +308,19 @@ module Rapleaf
|
|
238
308
|
response_hash = {} # TODO
|
239
309
|
expect_request(@savon_client,
|
240
310
|
@authentication_header,
|
241
|
-
{
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
311
|
+
equals_matcher({
|
312
|
+
:list_operation => ListOperationType::IS_MEMBER_OF,
|
313
|
+
:list_key => LIST_KEY,
|
314
|
+
:strict => 'false',
|
315
|
+
:list_member_list => {
|
316
|
+
:lead_key => [
|
317
|
+
{
|
318
|
+
:key_type => 'EMAIL',
|
319
|
+
:key_value => EMAIL
|
320
|
+
}
|
321
|
+
]
|
322
|
+
}
|
323
|
+
}),
|
254
324
|
'ns1:paramsListOperation',
|
255
325
|
response_hash)
|
256
326
|
|
@@ -261,7 +331,13 @@ module Rapleaf
|
|
261
331
|
|
262
332
|
private
|
263
333
|
|
264
|
-
def
|
334
|
+
def equals_matcher(expected)
|
335
|
+
Proc.new { |actual|
|
336
|
+
actual.should == expected
|
337
|
+
}
|
338
|
+
end
|
339
|
+
|
340
|
+
def expect_request(savon_client, authentication_header, expected_body_matcher, expected_namespace, response_hash)
|
265
341
|
header_hash = stub('header_hash')
|
266
342
|
soap_response = stub('soap_response')
|
267
343
|
request_namespace = mock('namespace')
|
@@ -273,7 +349,9 @@ module Rapleaf
|
|
273
349
|
request_header.should_receive(:[]=).with("ns1:AuthenticationHeader", header_hash)
|
274
350
|
soap_request.should_receive(:namespaces).and_return(request_namespace)
|
275
351
|
soap_request.should_receive(:header).and_return(request_header)
|
276
|
-
soap_request.should_receive(:body=)
|
352
|
+
soap_request.should_receive(:body=) do |actual_body|
|
353
|
+
expected_body_matcher.call(actual_body)
|
354
|
+
end
|
277
355
|
soap_response.should_receive(:to_hash).and_return(response_hash)
|
278
356
|
savon_client.should_receive(:request).with(expected_namespace).and_yield(soap_request).and_return(soap_response)
|
279
357
|
end
|
@@ -73,16 +73,12 @@ module Rapleaf
|
|
73
73
|
|
74
74
|
actual = LeadRecord.from_hash(savon_hash)
|
75
75
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
pairs.size.should == 3
|
83
|
-
pairs.should include(['Company', 'Rapleaf'])
|
84
|
-
pairs.should include(['FirstName', 'James'])
|
85
|
-
pairs.should include(['LastName', 'O\'Brien'])
|
76
|
+
expected = LeadRecord.new(EMAIL, IDNUM)
|
77
|
+
expected.set_attribute('Company', 'Rapleaf')
|
78
|
+
expected.set_attribute('FirstName', 'James')
|
79
|
+
expected.set_attribute('LastName', 'O\'Brien')
|
80
|
+
|
81
|
+
actual.should == expected
|
86
82
|
end
|
87
83
|
end
|
88
84
|
end
|
metadata
CHANGED
@@ -5,9 +5,9 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 1.
|
8
|
+
- 2
|
9
|
+
- 0
|
10
|
+
version: 1.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- James O'Brien
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-02-08 00:00:00 -08:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -50,7 +50,7 @@ dependencies:
|
|
50
50
|
version: 0.8.3
|
51
51
|
type: :runtime
|
52
52
|
version_requirements: *id002
|
53
|
-
description: " Allows easy integration with marketo from ruby. You can synchronize leads and fetch them back by email
|
53
|
+
description: " Allows easy integration with marketo from ruby. You can synchronize leads and fetch them back by email. This is based on the SOAP wsdl file: http://app.marketo.com/soap/mktows/1_4?WSDL\n"
|
54
54
|
email: james@rapleaf.com
|
55
55
|
executables: []
|
56
56
|
|