marketo-api-ruby 0.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,158 @@
1
+ require 'minitest_helper'
2
+
3
+ class TestMarketoAPIMObjects < Minitest::Test
4
+ include MarketoTestHelper
5
+
6
+ def setup
7
+ super
8
+ @subject = @client.mobjects
9
+ end
10
+
11
+ def test_delete_no_args
12
+ assert_raises(ArgumentError) {
13
+ subject.delete
14
+ }
15
+ end
16
+
17
+ def test_delete_bad_type
18
+ assert_raises(ArgumentError) {
19
+ subject.delete(MarketoAPI::MObject.program)
20
+ }
21
+ end
22
+
23
+ def test_delete_no_id
24
+ assert_raises(ArgumentError) {
25
+ subject.delete(MarketoAPI::MObject.opportunity)
26
+ }
27
+ end
28
+
29
+ def test_delete
30
+ subject.stub :extract_mobject_status_list, ARGS_STUB do
31
+ stub_soap_call do
32
+ source = MarketoAPI::MObject.opportunity(3)
33
+ method, params = subject.delete(source)
34
+ assert_equal :delete_m_objects, method
35
+ assert_equal({ m_object_list: [ source.params_for_delete ] }, params)
36
+ end
37
+ end
38
+
39
+ extractor = ->(*args) {
40
+ {
41
+ m_obj_status_list: args.last[:m_object_list].map { |mobject|
42
+ {
43
+ m_object_status: { id: mobject[:id], status: 'DELETED' }
44
+ }
45
+ }
46
+ }
47
+ }
48
+
49
+ subject.stub :call, extractor do
50
+ source = MarketoAPI::MObject.opportunity(3)
51
+ result = subject.delete(source)
52
+ assert_equal({ source.id => 'DELETED' }, result)
53
+ end
54
+ end
55
+
56
+ def test_list
57
+ subject.stub :extract_from_response, ARGS_STUB do
58
+ stub_soap_call do
59
+ method, _ = subject.list.first
60
+ assert_equal :list_m_objects, method
61
+ end
62
+ end
63
+
64
+ list = ->(*args) {
65
+ { objects: MarketoAPI::MObject::ALL_TYPES.map(&:to_s) }
66
+ }
67
+ subject.stub :call, list do
68
+ assert_equal MarketoAPI::MObject::ALL_TYPES.map(&:to_s),
69
+ subject.list
70
+ end
71
+ end
72
+
73
+ def test_describe_bad_type
74
+ assert_raises(ArgumentError) {
75
+ subject.describe(:foo)
76
+ }
77
+ end
78
+
79
+ def test_describe
80
+ subject.stub :extract_from_response, ARGS_STUB do
81
+ stub_soap_call do
82
+ method, params = subject.describe('Opportunity')
83
+ assert_equal :describe_m_object, method
84
+ assert_equal({ object_name: 'Opportunity' }, params)
85
+ end
86
+ end
87
+
88
+ output = ->(*args) {
89
+ { metadata: 'description' }
90
+ }
91
+ subject.stub :call, output do
92
+ assert_equal 'description', subject.describe('Opportunity')
93
+ end
94
+ end
95
+
96
+ def test_get_bad_type
97
+ assert_raises(ArgumentError) {
98
+ subject.get(MarketoAPI::MObject.activityrecord)
99
+ }
100
+ end
101
+
102
+ def test_get
103
+ MarketoAPI::MObjects::Get.stub :new, ARGS_STUB do
104
+ stub_soap_call do
105
+ method, params = subject.get(MarketoAPI::MObject.opportunity)
106
+ assert_equal :get_m_objects, method
107
+ assert_equal({ type: :Opportunity, include_details: false }, params)
108
+ end
109
+ end
110
+ end
111
+
112
+ def test_get_object
113
+ object = {
114
+ type: :Opportunity,
115
+ id: 99,
116
+ attrib_list: {
117
+ attrib: [
118
+ { name: 'String', value: 'string' },
119
+ { name: 'Int', value: 5 },
120
+ ]
121
+ },
122
+ type_attrib_list: {
123
+ type_attrib: [
124
+ {
125
+ attr_type: 'Tag',
126
+ attr_list: {
127
+ attrib: [
128
+ { name: 'String', value: 'string' },
129
+ { name: 'Int', value: 5 },
130
+ ]
131
+ }
132
+ }
133
+ ]
134
+ }
135
+ }
136
+
137
+ response = MarketoAPI::MObjects::Get.new(
138
+ return_count: 1,
139
+ has_more: true,
140
+ new_stream_position: 'you are here',
141
+ m_object_list: [ { m_object: object } ]
142
+ )
143
+
144
+ expected = MarketoAPI::MObject.opportunity(99) do |mobject|
145
+ { String: 'string', Int: 5, }.each { |k, v|
146
+ mobject.attributes[k] = v
147
+ }
148
+ { Tag: { String: 'string', Int: 5 } }.each { |k, v|
149
+ mobject.types[k] = v
150
+ }
151
+ end
152
+
153
+ assert_equal 1, response.return_count
154
+ assert_equal 'you are here', response.stream_position
155
+ assert_equal [ expected ], response.mobjects
156
+ assert response.more?
157
+ end
158
+ end
@@ -0,0 +1,69 @@
1
+ # -*- ruby encoding: utf-8 -*-
2
+
3
+ require 'marketo-api-ruby'
4
+
5
+ def try_require(resource)
6
+ require resource
7
+ yield if block_given?
8
+ rescue LoadError
9
+ end
10
+
11
+ gem 'minitest'
12
+ require 'minitest/autorun'
13
+ try_require 'minitest/emoji'
14
+
15
+ module MarketoTestHelper
16
+ ARGS_STUB = ->(*args) {
17
+ args = args.flatten(1)
18
+
19
+ def args.to_hash
20
+ self
21
+ end
22
+
23
+ args
24
+ }
25
+
26
+ def setup
27
+ super
28
+ @client = setup_client
29
+ end
30
+
31
+ def setup_client(options = {})
32
+ MarketoAPI.client(options.merge(user_id: 'user', encryption_key: 'key'))
33
+ end
34
+
35
+ attr_reader :subject
36
+
37
+ def stub_specialized method, object = subject, &block
38
+ object.stub method, ARGS_STUB do
39
+ block.call if block
40
+ end
41
+ end
42
+
43
+ def stub_soap_call object = subject, &block
44
+ object.stub :call, ARGS_STUB do
45
+ block.call if block
46
+ end
47
+ end
48
+
49
+ def lead_key *ids
50
+ keys = ids.map { |id| MarketoAPI::Lead.key(:id, id) }
51
+ case
52
+ when keys.empty?
53
+ nil
54
+ when keys.size == 1
55
+ keys.first
56
+ else
57
+ keys
58
+ end
59
+ end
60
+ alias_method :lead_keys, :lead_key
61
+
62
+ def assert_missing_keys object, *keys
63
+ keys.each { |key| refute object.has_key? key }
64
+ end
65
+
66
+ def refute_missing_keys object, *keys
67
+ keys.each { |key| assert object.has_key? key }
68
+ end
69
+ end
@@ -0,0 +1,38 @@
1
+ require "minitest_helper"
2
+
3
+ class TestMarketoAPI < Minitest::Test
4
+ def test_self_bad_client
5
+ assert_raises(ArgumentError) {
6
+ MarketoAPI.client
7
+ }
8
+ end
9
+
10
+ def test_self_client
11
+ actual = MarketoAPI.client(user_id: 'user', encryption_key: 'key')
12
+ assert_instance_of MarketoAPI::Client, actual
13
+ end
14
+
15
+ def test_self_array_hash
16
+ input = { a: 1 }
17
+ expected = [ input ]
18
+ actual = MarketoAPI.array(input)
19
+ assert_equal expected, actual
20
+ assert_same expected.first, actual.first
21
+ end
22
+
23
+ def test_self_array_array
24
+ input = [ 1 ]
25
+ assert_same input, MarketoAPI.array(input)
26
+ end
27
+
28
+ def test_self_array_other
29
+ assert_equal [ 1 ], MarketoAPI.array(1)
30
+ end
31
+
32
+ def test_self_freeze
33
+ actual = MarketoAPI.
34
+ freeze(%w(The quick brown fox jumps over the lazy dog.))
35
+ assert actual.frozen?
36
+ assert actual.all?(&:frozen?)
37
+ end
38
+ end
metadata ADDED
@@ -0,0 +1,302 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: marketo-api-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.8'
5
+ platform: ruby
6
+ authors:
7
+ - Austin Ziegler
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain:
11
+ - !binary |-
12
+ LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUROakNDQWg2Z0F3SUJB
13
+ Z0lCQVRBTkJna3Foa2lHOXcwQkFRVUZBREJCTVE4d0RRWURWUVFEREFaaGRY
14
+ TjAKYVc0eEdUQVhCZ29Ka2lhSmsvSXNaQUVaRmdseWRXSjVabTl5WjJVeEV6
15
+ QVJCZ29Ka2lhSmsvSXNaQUVaRmdOdgpjbWN3SGhjTk1UUXdNakl5TURNME1U
16
+ UXpXaGNOTVRVd01qSXlNRE0wTVRReldqQkJNUTh3RFFZRFZRUUREQVpoCmRY
17
+ TjBhVzR4R1RBWEJnb0praWFKay9Jc1pBRVpGZ2x5ZFdKNVptOXlaMlV4RXpB
18
+ UkJnb0praWFKay9Jc1pBRVoKRmdOdmNtY3dnZ0VpTUEwR0NTcUdTSWIzRFFF
19
+ QkFRVUFBNElCRHdBd2dnRUtBb0lCQVFDMm1QTmY0TDM3R2hLSQpTUENZc3ZZ
20
+ V1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zay9FVEZoaSs3cElVV2xGbzBpbXJkeUxoZCtKdzNib1ZqM0NtdnloY3dt
37
+ cG9NMEs5bApBT21yVWlFbFVxTE9aQT09Ci0tLS0tRU5EIENFUlRJRklDQVRF
38
+ LS0tLS0K
39
+ date: 2014-04-16 00:00:00.000000000 Z
40
+ dependencies:
41
+ - !ruby/object:Gem::Dependency
42
+ name: savon
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '2.4'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '2.4'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '5.3'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '5.3'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rdoc
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: '4.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: '4.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: hoe-doofus
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: '1.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ version: '1.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: hoe-gemspec2
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ~>
102
+ - !ruby/object:Gem::Version
103
+ version: '1.1'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ~>
109
+ - !ruby/object:Gem::Version
110
+ version: '1.1'
111
+ - !ruby/object:Gem::Dependency
112
+ name: hoe-git
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ~>
116
+ - !ruby/object:Gem::Version
117
+ version: '1.6'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ~>
123
+ - !ruby/object:Gem::Version
124
+ version: '1.6'
125
+ - !ruby/object:Gem::Dependency
126
+ name: hoe-rubygems
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ~>
130
+ - !ruby/object:Gem::Version
131
+ version: '1.0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ~>
137
+ - !ruby/object:Gem::Version
138
+ version: '1.0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: hoe-travis
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ~>
144
+ - !ruby/object:Gem::Version
145
+ version: '1.2'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ~>
151
+ - !ruby/object:Gem::Version
152
+ version: '1.2'
153
+ - !ruby/object:Gem::Dependency
154
+ name: rake
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ~>
158
+ - !ruby/object:Gem::Version
159
+ version: '10.0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ~>
165
+ - !ruby/object:Gem::Version
166
+ version: '10.0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: simplecov
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ~>
172
+ - !ruby/object:Gem::Version
173
+ version: '0.7'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ~>
179
+ - !ruby/object:Gem::Version
180
+ version: '0.7'
181
+ - !ruby/object:Gem::Dependency
182
+ name: coveralls
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ~>
186
+ - !ruby/object:Gem::Version
187
+ version: '0.7'
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ~>
193
+ - !ruby/object:Gem::Version
194
+ version: '0.7'
195
+ - !ruby/object:Gem::Dependency
196
+ name: hoe
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - ~>
200
+ - !ruby/object:Gem::Version
201
+ version: '3.11'
202
+ type: :development
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - ~>
207
+ - !ruby/object:Gem::Version
208
+ version: '3.11'
209
+ description: ! 'MarketoAPI (marketo-api-ruby) provides a native Ruby interface to
210
+ the
211
+
212
+ {Marketo SOAP API}[http://developers.marketo.com/documentation/soap/], using
213
+
214
+ {savon}[https://github.com/savonrb/savon]. While understanding the Marketo SOAP
215
+
216
+ API is necessary for using marketo-api-ruby, it is an explicit goal that
217
+
218
+ working with MarketoAPI not feel like working with a hinky Java port.
219
+
220
+
221
+ This is release 0.8, targeting Marketo API version
222
+
223
+ {2.3}[http://app.marketo.com/soap/mktows/2_3?WSDL].'
224
+ email:
225
+ - halostatue@gmail.com
226
+ executables: []
227
+ extensions: []
228
+ extra_rdoc_files:
229
+ - Contributing.rdoc
230
+ - History.rdoc
231
+ - Licence.rdoc
232
+ - Manifest.txt
233
+ - README.rdoc
234
+ files:
235
+ - .gemtest
236
+ - Contributing.rdoc
237
+ - Gemfile
238
+ - History.rdoc
239
+ - Licence.rdoc
240
+ - Manifest.txt
241
+ - README.rdoc
242
+ - Rakefile
243
+ - lib/marketo-api-ruby.rb
244
+ - lib/marketo_api.rb
245
+ - lib/marketo_api/campaigns.rb
246
+ - lib/marketo_api/client.rb
247
+ - lib/marketo_api/client_proxy.rb
248
+ - lib/marketo_api/lead.rb
249
+ - lib/marketo_api/leads.rb
250
+ - lib/marketo_api/lists.rb
251
+ - lib/marketo_api/mobject.rb
252
+ - lib/marketo_api/mobjects.rb
253
+ - spec/marketo/authentication_header_spec.rb
254
+ - spec/marketo/client_spec.rb
255
+ - spec/marketo/lead_key_spec.rb
256
+ - spec/marketo/lead_record_spec.rb
257
+ - spec/spec_helper.rb
258
+ - test/marketo_api/test_campaigns.rb
259
+ - test/marketo_api/test_client.rb
260
+ - test/marketo_api/test_lead.rb
261
+ - test/marketo_api/test_leads.rb
262
+ - test/marketo_api/test_lists.rb
263
+ - test/marketo_api/test_mobject.rb
264
+ - test/marketo_api/test_mobjects.rb
265
+ - test/minitest_helper.rb
266
+ - test/test_marketo_api.rb
267
+ homepage: https://github.com/ClearFit/marketo-api-ruby
268
+ licenses:
269
+ - MIT
270
+ metadata: {}
271
+ post_install_message:
272
+ rdoc_options:
273
+ - --main
274
+ - README.rdoc
275
+ require_paths:
276
+ - lib
277
+ required_ruby_version: !ruby/object:Gem::Requirement
278
+ requirements:
279
+ - - ! '>='
280
+ - !ruby/object:Gem::Version
281
+ version: 1.9.2
282
+ required_rubygems_version: !ruby/object:Gem::Requirement
283
+ requirements:
284
+ - - ! '>='
285
+ - !ruby/object:Gem::Version
286
+ version: '0'
287
+ requirements: []
288
+ rubyforge_project:
289
+ rubygems_version: 2.2.2
290
+ signing_key:
291
+ specification_version: 4
292
+ summary: MarketoAPI (marketo-api-ruby) provides a native Ruby interface to the {Marketo
293
+ SOAP API}[http://developers.marketo.com/documentation/soap/], using {savon}[https://github.com/savonrb/savon]
294
+ test_files:
295
+ - test/marketo_api/test_campaigns.rb
296
+ - test/marketo_api/test_client.rb
297
+ - test/marketo_api/test_lead.rb
298
+ - test/marketo_api/test_leads.rb
299
+ - test/marketo_api/test_lists.rb
300
+ - test/marketo_api/test_mobject.rb
301
+ - test/marketo_api/test_mobjects.rb
302
+ - test/test_marketo_api.rb