mrkt 0.8.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.rubocop.yml +59 -5
- data/.travis.yml +19 -10
- data/Gemfile.lock +68 -63
- data/LICENSE +21 -0
- data/README.md +11 -7
- data/lib/mrkt.rb +16 -3
- data/lib/mrkt/concerns/authentication.rb +27 -12
- data/lib/mrkt/concerns/connection.rb +2 -5
- data/lib/mrkt/concerns/crud_activities.rb +10 -7
- data/lib/mrkt/concerns/crud_asset_folders.rb +43 -0
- data/lib/mrkt/concerns/crud_asset_static_lists.rb +30 -0
- data/lib/mrkt/concerns/crud_campaigns.rb +2 -4
- data/lib/mrkt/concerns/crud_custom_activities.rb +3 -2
- data/lib/mrkt/concerns/crud_custom_objects.rb +12 -13
- data/lib/mrkt/concerns/crud_helpers.rb +7 -0
- data/lib/mrkt/concerns/crud_leads.rb +28 -15
- data/lib/mrkt/concerns/crud_lists.rb +13 -10
- data/lib/mrkt/concerns/crud_programs.rb +6 -5
- data/lib/mrkt/concerns/import_custom_objects.rb +24 -0
- data/lib/mrkt/concerns/import_leads.rb +7 -4
- data/lib/mrkt/errors.rb +3 -2
- data/lib/mrkt/version.rb +1 -1
- data/mrkt.gemspec +11 -12
- data/spec/concerns/authentication_spec.rb +57 -5
- data/spec/concerns/crud_activities_spec.rb +46 -7
- data/spec/concerns/crud_asset_folders_spec.rb +273 -0
- data/spec/concerns/crud_asset_static_lists_spec.rb +183 -0
- data/spec/concerns/crud_custom_activities_spec.rb +3 -1
- data/spec/concerns/crud_custom_objects_spec.rb +1 -1
- data/spec/concerns/crud_leads_spec.rb +103 -1
- data/spec/concerns/crud_lists_spec.rb +33 -0
- data/spec/concerns/import_custom_objects_spec.rb +89 -0
- data/spec/concerns/import_leads_spec.rb +3 -3
- data/spec/spec_helper.rb +3 -1
- data/spec/support/webmock.rb +1 -7
- metadata +43 -46
@@ -0,0 +1,183 @@
|
|
1
|
+
describe Mrkt::CrudAssetStaticLists do
|
2
|
+
include_context 'initialized client'
|
3
|
+
|
4
|
+
let(:response_static_list_result) do
|
5
|
+
{
|
6
|
+
id: 1001,
|
7
|
+
name: 'Test Static List Name',
|
8
|
+
description: 'Provided description',
|
9
|
+
createdAt: '2019-03-15T21:41:46Z+0000',
|
10
|
+
updatedAt: '2019-03-15T21:41:46Z+0000',
|
11
|
+
folder: {
|
12
|
+
id: 14,
|
13
|
+
type: 'Folder'
|
14
|
+
},
|
15
|
+
computedUrl: 'https://app-devlocal1.marketo.com/#ST1001A1'
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '#create_static_list' do
|
20
|
+
subject { client.create_static_list(name, folder, description: description) }
|
21
|
+
|
22
|
+
let(:name) { 'Test Static List Name' }
|
23
|
+
let(:folder) do
|
24
|
+
{ id: 14, type: 'Folder' }
|
25
|
+
end
|
26
|
+
let(:description) { 'Provided description' }
|
27
|
+
let(:response_stub) do
|
28
|
+
{
|
29
|
+
requestId: 'eba#16982091b99',
|
30
|
+
result: [
|
31
|
+
response_static_list_result
|
32
|
+
],
|
33
|
+
success: true,
|
34
|
+
errors: [],
|
35
|
+
warnings: []
|
36
|
+
}
|
37
|
+
end
|
38
|
+
|
39
|
+
let(:json_folder) { JSON.generate(folder) }
|
40
|
+
let(:request_body) do
|
41
|
+
{
|
42
|
+
name: name,
|
43
|
+
folder: json_folder,
|
44
|
+
description: description
|
45
|
+
}
|
46
|
+
end
|
47
|
+
|
48
|
+
before do
|
49
|
+
stub_request(:post, "https://#{host}/rest/asset/v1/staticLists.json")
|
50
|
+
.with(body: request_body)
|
51
|
+
.to_return(json_stub(response_stub))
|
52
|
+
end
|
53
|
+
|
54
|
+
it { is_expected.to eq(response_stub) }
|
55
|
+
end
|
56
|
+
|
57
|
+
describe '#get_static_list_by_id' do
|
58
|
+
subject { client.get_static_list_by_id(id) }
|
59
|
+
|
60
|
+
let(:id) { response_static_list_result[:id] }
|
61
|
+
let(:response_stub) do
|
62
|
+
{
|
63
|
+
requestId: '378a#16983419fff',
|
64
|
+
result: [
|
65
|
+
response_static_list_result
|
66
|
+
],
|
67
|
+
success: true,
|
68
|
+
errors: [],
|
69
|
+
warnings: []
|
70
|
+
}
|
71
|
+
end
|
72
|
+
|
73
|
+
before do
|
74
|
+
stub_request(:get, "https://#{host}/rest/asset/v1/staticList/#{id}.json")
|
75
|
+
.to_return(json_stub(response_stub))
|
76
|
+
end
|
77
|
+
|
78
|
+
context 'when a static list with the given id exists' do
|
79
|
+
let(:response_stub) do
|
80
|
+
{
|
81
|
+
requestId: '378a#16983419fff',
|
82
|
+
result: [
|
83
|
+
response_static_list_result
|
84
|
+
],
|
85
|
+
success: true,
|
86
|
+
errors: [],
|
87
|
+
warnings: []
|
88
|
+
}
|
89
|
+
end
|
90
|
+
|
91
|
+
it { is_expected.to eq(response_stub) }
|
92
|
+
end
|
93
|
+
|
94
|
+
context 'when a static list with the given id does not exist' do
|
95
|
+
let(:response_stub) do
|
96
|
+
{
|
97
|
+
requestId: 'a8d#1698369857b',
|
98
|
+
success: false,
|
99
|
+
warnings: [],
|
100
|
+
errors: [
|
101
|
+
{
|
102
|
+
code: '702',
|
103
|
+
message: 'Static List not found or it has been deleted'
|
104
|
+
}
|
105
|
+
]
|
106
|
+
}
|
107
|
+
end
|
108
|
+
|
109
|
+
it 'should raise an Error' do
|
110
|
+
expect { subject }.to raise_error(Mrkt::Errors::RecordNotFound)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
describe '#get_static_list_by_name' do
|
116
|
+
subject { client.get_static_list_by_name(name) }
|
117
|
+
|
118
|
+
let(:name) { 'Test Static List Name' }
|
119
|
+
let(:request_query) { "name=#{name}" }
|
120
|
+
|
121
|
+
before do
|
122
|
+
stub_request(:get, "https://#{host}/rest/asset/v1/staticList/byName.json?#{request_query}")
|
123
|
+
.to_return(json_stub(response_stub))
|
124
|
+
end
|
125
|
+
|
126
|
+
context 'when a static list with the given name exists' do
|
127
|
+
let(:response_stub) do
|
128
|
+
{
|
129
|
+
requestId: '13a74#169834522b9',
|
130
|
+
result: [
|
131
|
+
response_static_list_result
|
132
|
+
],
|
133
|
+
success: true,
|
134
|
+
errors: [],
|
135
|
+
warnings: []
|
136
|
+
}
|
137
|
+
end
|
138
|
+
|
139
|
+
it { is_expected.to eq(response_stub) }
|
140
|
+
end
|
141
|
+
|
142
|
+
context 'when a static list with the given name does not exist' do
|
143
|
+
let(:response_stub) do
|
144
|
+
{
|
145
|
+
requestId: '4ec2#1698384ae02',
|
146
|
+
success: true,
|
147
|
+
errors: [],
|
148
|
+
warnings: [
|
149
|
+
'No assets found for the given search criteria.'
|
150
|
+
]
|
151
|
+
}
|
152
|
+
end
|
153
|
+
|
154
|
+
it { is_expected.to eq(response_stub) }
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
describe '#delete_static_list' do
|
159
|
+
subject { client.delete_static_list(id) }
|
160
|
+
|
161
|
+
let(:id) { 1001 }
|
162
|
+
let(:response_stub) do
|
163
|
+
{
|
164
|
+
requestId: '94c3#169833275df',
|
165
|
+
result: [
|
166
|
+
{
|
167
|
+
id: 1001
|
168
|
+
}
|
169
|
+
],
|
170
|
+
success: true,
|
171
|
+
errors: [],
|
172
|
+
warnings: []
|
173
|
+
}
|
174
|
+
end
|
175
|
+
|
176
|
+
before do
|
177
|
+
stub_request(:post, "https://#{host}/rest/asset/v1/staticList/#{id}/delete.json")
|
178
|
+
.to_return(json_stub(response_stub))
|
179
|
+
end
|
180
|
+
|
181
|
+
it { is_expected.to eq(response_stub) }
|
182
|
+
end
|
183
|
+
end
|
@@ -162,7 +162,9 @@ describe Mrkt::CrudCustomObjects do
|
|
162
162
|
}
|
163
163
|
end
|
164
164
|
|
165
|
-
subject
|
165
|
+
subject do
|
166
|
+
client.create_custom_activity(lead_id, activity_type_id, primary_attribute_value, attributes: attributes, date: date)
|
167
|
+
end
|
166
168
|
|
167
169
|
it { is_expected.to eq(response_stub) }
|
168
170
|
end
|
@@ -55,7 +55,7 @@ describe Mrkt::CrudCustomObjects do
|
|
55
55
|
end
|
56
56
|
|
57
57
|
context 'with object names' do
|
58
|
-
let(:object_names) { %w
|
58
|
+
let(:object_names) { %w[device_c manufacturer_c] }
|
59
59
|
|
60
60
|
before do
|
61
61
|
stub_request(:get, "https://#{host}/rest/v1/customobjects.json")
|
@@ -1,9 +1,63 @@
|
|
1
1
|
describe Mrkt::CrudLeads do
|
2
2
|
include_context 'initialized client'
|
3
3
|
|
4
|
+
describe 'get_lead_by_id' do
|
5
|
+
subject { client.get_lead_by_id(id, fields: fields) }
|
6
|
+
|
7
|
+
let(:id) { 200 }
|
8
|
+
|
9
|
+
let(:fields_query) { fields ? "fields=#{fields.join(',')}" : nil }
|
10
|
+
|
11
|
+
before do
|
12
|
+
stub_request(:get, "https://#{host}/rest/v1/lead/#{id}.json?#{fields_query}")
|
13
|
+
.to_return(json_stub(response_stub))
|
14
|
+
end
|
15
|
+
|
16
|
+
context 'when no fields are given' do
|
17
|
+
let(:fields) { nil }
|
18
|
+
let(:response_stub) do
|
19
|
+
{
|
20
|
+
requestId: '1134#169a69aae86',
|
21
|
+
result: [
|
22
|
+
{
|
23
|
+
id: id,
|
24
|
+
firstName: 'John',
|
25
|
+
lastName: 'Snow',
|
26
|
+
email: 'jfrost@mrkt.com',
|
27
|
+
updatedAt: '2019-03-19T20:39:23Z',
|
28
|
+
createdAt: '2019-03-14T13:41:37Z'
|
29
|
+
}
|
30
|
+
],
|
31
|
+
success: true
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
35
|
+
it { is_expected.to eq(response_stub) }
|
36
|
+
end
|
37
|
+
|
38
|
+
context 'when an array of fields is given' do
|
39
|
+
let(:fields) { %w[email dateOfBirth] }
|
40
|
+
let(:response_stub) do
|
41
|
+
{
|
42
|
+
requestId: '33dd#169a6b5ba65',
|
43
|
+
result: [
|
44
|
+
{
|
45
|
+
id: id,
|
46
|
+
email: 'jfrost@mrkt.com',
|
47
|
+
dateOfBirth: '1813-03-15'
|
48
|
+
}
|
49
|
+
],
|
50
|
+
success: true
|
51
|
+
}
|
52
|
+
end
|
53
|
+
|
54
|
+
it { is_expected.to eq(response_stub) }
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
4
58
|
describe '#get_leads' do
|
5
59
|
let(:filter_type) { 'email' }
|
6
|
-
let(:filter_values) { %w
|
60
|
+
let(:filter_values) { %w[user@example.com] }
|
7
61
|
let(:response_stub) do
|
8
62
|
{
|
9
63
|
requestId: 'c245#14cd6830ae2',
|
@@ -196,4 +250,52 @@ describe Mrkt::CrudLeads do
|
|
196
250
|
end
|
197
251
|
end
|
198
252
|
end
|
253
|
+
|
254
|
+
describe '#describe_lead' do
|
255
|
+
let(:response_stub) do
|
256
|
+
{
|
257
|
+
requestId: '5c9e#169a68fa806',
|
258
|
+
result: [
|
259
|
+
{
|
260
|
+
id: 4,
|
261
|
+
displayName: 'Company Name',
|
262
|
+
dataType: 'string',
|
263
|
+
length: 255,
|
264
|
+
rest: {
|
265
|
+
name: 'company',
|
266
|
+
readOnly: false
|
267
|
+
},
|
268
|
+
soap: {
|
269
|
+
name: 'Company',
|
270
|
+
readOnly: false
|
271
|
+
}
|
272
|
+
},
|
273
|
+
{
|
274
|
+
id: 56,
|
275
|
+
displayName: 'Email Address',
|
276
|
+
dataType: 'email',
|
277
|
+
length: 255,
|
278
|
+
rest: {
|
279
|
+
name: 'email',
|
280
|
+
readOnly: false
|
281
|
+
},
|
282
|
+
soap: {
|
283
|
+
name: 'Email',
|
284
|
+
readOnly: false
|
285
|
+
}
|
286
|
+
}
|
287
|
+
],
|
288
|
+
success: true
|
289
|
+
}
|
290
|
+
end
|
291
|
+
|
292
|
+
subject { client.describe_lead }
|
293
|
+
|
294
|
+
before do
|
295
|
+
stub_request(:get, "https://#{host}/rest/v1/leads/describe.json")
|
296
|
+
.to_return(json_stub(response_stub))
|
297
|
+
end
|
298
|
+
|
299
|
+
it { is_expected.to eq(response_stub) }
|
300
|
+
end
|
199
301
|
end
|
@@ -63,4 +63,37 @@ describe Mrkt::CrudLists do
|
|
63
63
|
|
64
64
|
it { is_expected.to eq(response_stub) }
|
65
65
|
end
|
66
|
+
|
67
|
+
describe '#remove_leads_from_list' do
|
68
|
+
let(:list_id) { '1001' }
|
69
|
+
let(:lead_ids) { ['1'] }
|
70
|
+
let(:request_body) do
|
71
|
+
{
|
72
|
+
input: [
|
73
|
+
{ id: '1' }
|
74
|
+
]
|
75
|
+
}
|
76
|
+
end
|
77
|
+
let(:response_stub) do
|
78
|
+
{
|
79
|
+
requestId: '10de4#1697e81c821',
|
80
|
+
result: [
|
81
|
+
{
|
82
|
+
id: 1,
|
83
|
+
status: 'removed'
|
84
|
+
}
|
85
|
+
],
|
86
|
+
success: true
|
87
|
+
}
|
88
|
+
end
|
89
|
+
subject { client.remove_leads_from_list(list_id, lead_ids) }
|
90
|
+
|
91
|
+
before do
|
92
|
+
stub_request(:delete, "https://#{host}/rest/v1/lists/#{list_id}/leads.json")
|
93
|
+
.with(json_stub(request_body))
|
94
|
+
.to_return(json_stub(response_stub))
|
95
|
+
end
|
96
|
+
|
97
|
+
it { is_expected.to eq(response_stub) }
|
98
|
+
end
|
66
99
|
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
require 'tempfile'
|
2
|
+
|
3
|
+
describe Mrkt::ImportCustomObjects do
|
4
|
+
include_context 'initialized client'
|
5
|
+
let(:custom_object) { 'car_c' }
|
6
|
+
|
7
|
+
describe '#import_custom_object' do
|
8
|
+
let(:file) { StringIO.new }
|
9
|
+
let(:response_stub) do
|
10
|
+
{
|
11
|
+
requestId: 'c015#15a68a23418',
|
12
|
+
success: true,
|
13
|
+
result: [
|
14
|
+
{
|
15
|
+
batchId: 1,
|
16
|
+
status: 'Importing',
|
17
|
+
objectApiName: custom_object
|
18
|
+
}
|
19
|
+
]
|
20
|
+
}
|
21
|
+
end
|
22
|
+
subject { client.import_custom_object(file, custom_object) }
|
23
|
+
|
24
|
+
before do
|
25
|
+
stub_request(:post, "https://#{host}/bulk/v1/customobjects/#{custom_object}/import.json")
|
26
|
+
.with(headers: { content_type: %r{multipart/form-data; boundary=\S+} })
|
27
|
+
.to_return(json_stub(response_stub))
|
28
|
+
end
|
29
|
+
|
30
|
+
it { is_expected.to eq(response_stub) }
|
31
|
+
end
|
32
|
+
|
33
|
+
describe '#import_custom_object_status' do
|
34
|
+
let(:id) { 1 }
|
35
|
+
let(:response_stub) do
|
36
|
+
{
|
37
|
+
requestId: '2a5#15a68dd9be1',
|
38
|
+
result: [
|
39
|
+
{
|
40
|
+
batchId: id,
|
41
|
+
operation: 'import',
|
42
|
+
status: 'Complete',
|
43
|
+
objectApiName: 'car_c',
|
44
|
+
numOfObjectsProcessed: 3,
|
45
|
+
numOfRowsFailed: 0,
|
46
|
+
numOfRowsWithWarning: 0,
|
47
|
+
importTime: '2 second(s)',
|
48
|
+
message: 'Import succeeded, 3 records imported (3 members)'
|
49
|
+
}
|
50
|
+
],
|
51
|
+
success: true
|
52
|
+
}
|
53
|
+
end
|
54
|
+
subject { client.import_custom_object_status(1, custom_object) }
|
55
|
+
|
56
|
+
before do
|
57
|
+
stub_request(:get, "https://#{host}/bulk/v1/customobjects/#{custom_object}/import/#{id}/status.json")
|
58
|
+
.to_return(json_stub(response_stub))
|
59
|
+
end
|
60
|
+
|
61
|
+
it { is_expected.to eq(response_stub) }
|
62
|
+
end
|
63
|
+
|
64
|
+
describe '#import_custom_object_failures' do
|
65
|
+
let(:id) { 1 }
|
66
|
+
let(:response_stub) { '' }
|
67
|
+
subject { client.import_custom_object_failures(1, custom_object) }
|
68
|
+
|
69
|
+
before do
|
70
|
+
stub_request(:get, "https://#{host}/bulk/v1/customobjects/#{custom_object}/import/#{id}/failures.json")
|
71
|
+
.to_return(headers: { content_length: 0 })
|
72
|
+
end
|
73
|
+
|
74
|
+
it { is_expected.to eq(response_stub) }
|
75
|
+
end
|
76
|
+
|
77
|
+
describe '#import_custom_object_warnings' do
|
78
|
+
let(:id) { 1 }
|
79
|
+
let(:response_stub) { '' }
|
80
|
+
subject { client.import_custom_object_warnings(1, custom_object) }
|
81
|
+
|
82
|
+
before do
|
83
|
+
stub_request(:get, "https://#{host}/bulk/v1/customobjects/#{custom_object}/import/#{id}/warnings.json")
|
84
|
+
.to_return(headers: { content_length: 0 })
|
85
|
+
end
|
86
|
+
|
87
|
+
it { is_expected.to eq(response_stub) }
|
88
|
+
end
|
89
|
+
end
|