mrkt 0.6.2 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. checksums.yaml +5 -5
  2. data/.github/dependabot.yml +11 -0
  3. data/.github/workflows/ruby.yml +41 -0
  4. data/.rubocop.yml +31 -6
  5. data/Gemfile.lock +95 -69
  6. data/LICENSE +21 -0
  7. data/README.md +35 -7
  8. data/lib/mrkt/concerns/authentication.rb +32 -6
  9. data/lib/mrkt/concerns/connection.rb +13 -4
  10. data/lib/mrkt/concerns/crud_activities.rb +32 -0
  11. data/lib/mrkt/concerns/crud_asset_folders.rb +43 -0
  12. data/lib/mrkt/concerns/crud_asset_static_lists.rb +30 -0
  13. data/lib/mrkt/concerns/crud_campaigns.rb +2 -4
  14. data/lib/mrkt/concerns/crud_custom_activities.rb +36 -0
  15. data/lib/mrkt/concerns/crud_custom_objects.rb +14 -15
  16. data/lib/mrkt/concerns/crud_helpers.rb +7 -0
  17. data/lib/mrkt/concerns/crud_leads.rb +41 -15
  18. data/lib/mrkt/concerns/crud_lists.rb +13 -10
  19. data/lib/mrkt/concerns/crud_programs.rb +6 -5
  20. data/lib/mrkt/concerns/import_custom_objects.rb +24 -0
  21. data/lib/mrkt/concerns/import_leads.rb +8 -5
  22. data/lib/mrkt/errors.rb +23 -3
  23. data/lib/mrkt/faraday/params_encoder.rb +20 -0
  24. data/lib/mrkt/faraday.rb +4 -0
  25. data/lib/mrkt/faraday_middleware/response.rb +4 -4
  26. data/lib/mrkt/faraday_middleware.rb +3 -7
  27. data/lib/mrkt/version.rb +1 -1
  28. data/lib/mrkt.rb +29 -3
  29. data/mrkt.gemspec +13 -12
  30. data/spec/concerns/authentication_spec.rb +95 -0
  31. data/spec/concerns/crud_activities_spec.rb +279 -0
  32. data/spec/concerns/crud_asset_folders_spec.rb +273 -0
  33. data/spec/concerns/crud_asset_static_lists_spec.rb +183 -0
  34. data/spec/concerns/crud_custom_activities_spec.rb +172 -0
  35. data/spec/concerns/crud_custom_objects_spec.rb +99 -89
  36. data/spec/concerns/crud_leads_spec.rb +151 -1
  37. data/spec/concerns/crud_lists_spec.rb +33 -0
  38. data/spec/concerns/import_custom_objects_spec.rb +89 -0
  39. data/spec/concerns/import_leads_spec.rb +3 -3
  40. data/spec/faraday/params_encoder_spec.rb +24 -0
  41. data/spec/spec_helper.rb +3 -6
  42. data/spec/support/initialized_client.rb +1 -1
  43. data/spec/support/webmock.rb +1 -7
  44. metadata +82 -40
  45. data/.travis.yml +0 -8
@@ -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
@@ -0,0 +1,172 @@
1
+ describe Mrkt::CrudCustomObjects do
2
+ include_context 'initialized client'
3
+
4
+ describe '#get_list_of_custom_activity_types' do
5
+ let(:response_stub) do
6
+ {
7
+ requestId: '14ff3#1579a716c12',
8
+ result: [
9
+ {
10
+ id: 1,
11
+ name: 'Visit Webpage',
12
+ description: 'User visits a web page',
13
+ primaryAttribute: {
14
+ name: 'Webpage ID',
15
+ dataType: 'integer'
16
+ },
17
+ attributes: [
18
+ {
19
+ name: 'Client IP Address',
20
+ dataType: 'string'
21
+ },
22
+ {
23
+ name: 'Query Parameters',
24
+ dataType: 'string'
25
+ }
26
+ ]
27
+ },
28
+ {
29
+ id: 1,
30
+ name: 'Visit Webpage',
31
+ description: 'User visits a web page',
32
+ primaryAttribute: {
33
+ name: 'Webpage ID',
34
+ dataType: 'integer'
35
+ },
36
+ attributes: [
37
+ {
38
+ name: 'Client IP Address',
39
+ dataType: 'string'
40
+ },
41
+ {
42
+ name: 'Query Parameters',
43
+ dataType: 'string'
44
+ }
45
+ ]
46
+ }
47
+ ],
48
+ success: true
49
+ }
50
+ end
51
+
52
+ context 'all activities' do
53
+ before do
54
+ stub_request(:get, "https://#{host}/rest/v1/activities/types.json")
55
+ .to_return(json_stub(response_stub))
56
+ end
57
+
58
+ subject { client.get_list_of_custom_activity_types }
59
+
60
+ it { is_expected.to eq(response_stub) }
61
+ end
62
+ end
63
+
64
+ describe '#create_custom_activity' do
65
+ let(:response_stub) do
66
+ {
67
+ requestId: 'c245#14cd6830ae2',
68
+ result: [
69
+ {
70
+ activityDate: 'string',
71
+ activityTypeId: 0,
72
+ apiName: 'string',
73
+ attributes: [
74
+ {
75
+ apiName: 'string',
76
+ name: 'string',
77
+ value: {}
78
+ }
79
+ ],
80
+ id: 0,
81
+ leadId: 0,
82
+ primaryAttributeValue: 'string',
83
+ status: 'created'
84
+ }
85
+ ],
86
+ success: true
87
+ }
88
+ end
89
+
90
+ let(:lead_id) do
91
+ 1
92
+ end
93
+
94
+ let(:activity_type_id) do
95
+ 100_000
96
+ end
97
+
98
+ let(:primary_attribute_value) do
99
+ 'Friday'
100
+ end
101
+
102
+ let(:date) do
103
+ Time.now
104
+ end
105
+
106
+ context 'with no additional attributes' do
107
+ let(:request_body) do
108
+ {
109
+ input: [{
110
+ leadId: lead_id,
111
+ activityDate: date.utc.iso8601,
112
+ activityTypeId: activity_type_id,
113
+ primaryAttributeValue: primary_attribute_value,
114
+ attributes: []
115
+ }]
116
+ }
117
+ end
118
+
119
+ before do
120
+ stub_request(:post, "https://#{host}/rest/v1/activities/external.json")
121
+ .with(json_stub(request_body))
122
+ .to_return(json_stub(response_stub))
123
+ end
124
+
125
+ subject { client.create_custom_activity(lead_id, activity_type_id, primary_attribute_value, date: date) }
126
+
127
+ it { is_expected.to eq(response_stub) }
128
+ end
129
+
130
+ context 'with additional attributes' do
131
+ let(:request_body) do
132
+ {
133
+ input: [{
134
+ leadId: lead_id,
135
+ activityDate: date.utc.iso8601,
136
+ activityTypeId: activity_type_id,
137
+ primaryAttributeValue: primary_attribute_value,
138
+ attributes: [
139
+ {
140
+ name: 'percent',
141
+ value: '0.20'
142
+ },
143
+ {
144
+ name: 'resourceId',
145
+ value: '_Hy8Sfk9938005SSF'
146
+ }
147
+ ]
148
+ }]
149
+ }
150
+ end
151
+
152
+ before do
153
+ stub_request(:post, "https://#{host}/rest/v1/activities/external.json")
154
+ .with(json_stub(request_body))
155
+ .to_return(json_stub(response_stub))
156
+ end
157
+
158
+ let(:attributes) do
159
+ {
160
+ percent: '0.20',
161
+ resourceId: '_Hy8Sfk9938005SSF'
162
+ }
163
+ end
164
+
165
+ subject do
166
+ client.create_custom_activity(lead_id, activity_type_id, primary_attribute_value, attributes: attributes, date: date)
167
+ end
168
+
169
+ it { is_expected.to eq(response_stub) }
170
+ end
171
+ end
172
+ end
@@ -5,35 +5,40 @@ describe Mrkt::CrudCustomObjects do
5
5
  let(:response_stub) do
6
6
  {
7
7
  requestId: 'c245#14cd6830ae2',
8
- result: [{
9
- name: 'device_c',
10
- displayName: 'Device',
11
- description: 'this is a device object',
12
- createdAt: '2016-01-23T00:51:18Z',
13
- updatedAt: '2016-01-23T00:51:18Z',
14
- idField: 'marketoGUID',
15
- dedupeFields: ['serialNumber'],
16
- searchableFields: [['serialNumber'], ['marketoGUID']],
17
- relationships: [{
18
- field: 'email',
19
- type: 'child',
20
- relatedTo: { name: 'Lead', field: 'email' }
21
- }],
22
- },
23
- {
24
- name: 'manufacturer_c',
25
- displayName: 'Manufacturer',
26
- createdAt: '2016-01-23T00:55:18Z',
27
- updatedAt: '2016-01-23T00:55:18Z',
28
- idField: 'marketoGUID',
29
- dedupeFields: ['name'],
30
- searchableFields: [['name'], ['marketoGUID']],
31
- relationships: [{
32
- field: 'email',
33
- type: 'child',
34
- relatedTo: { name: 'Lead', field: 'email' }
35
- }]
36
- }],
8
+ result: [
9
+ {
10
+ name: 'device_c',
11
+ displayName: 'Device',
12
+ description: 'this is a device object',
13
+ createdAt: '2016-01-23T00:51:18Z',
14
+ updatedAt: '2016-01-23T00:51:18Z',
15
+ idField: 'marketoGUID',
16
+ dedupeFields: ['serialNumber'],
17
+ searchableFields: [['serialNumber'], ['marketoGUID']],
18
+ relationships: [
19
+ {
20
+ field: 'email',
21
+ type: 'child',
22
+ relatedTo: { name: 'Lead', field: 'email' }
23
+ }
24
+ ]
25
+ }, {
26
+ name: 'manufacturer_c',
27
+ displayName: 'Manufacturer',
28
+ createdAt: '2016-01-23T00:55:18Z',
29
+ updatedAt: '2016-01-23T00:55:18Z',
30
+ idField: 'marketoGUID',
31
+ dedupeFields: ['name'],
32
+ searchableFields: [['name'], ['marketoGUID']],
33
+ relationships: [
34
+ {
35
+ field: 'email',
36
+ type: 'child',
37
+ relatedTo: { name: 'Lead', field: 'email' }
38
+ }
39
+ ]
40
+ }
41
+ ],
37
42
  success: true
38
43
  }
39
44
  end
@@ -50,11 +55,11 @@ describe Mrkt::CrudCustomObjects do
50
55
  end
51
56
 
52
57
  context 'with object names' do
53
- let(:object_names) { %w(device_c manufacturer_c) }
58
+ let(:object_names) { %w[device_c manufacturer_c] }
54
59
 
55
60
  before do
56
61
  stub_request(:get, "https://#{host}/rest/v1/customobjects.json")
57
- .with(query: {names: object_names.join(',')})
62
+ .with(query: { names: object_names.join(',') })
58
63
  .to_return(json_stub(response_stub))
59
64
  end
60
65
 
@@ -67,50 +72,56 @@ describe Mrkt::CrudCustomObjects do
67
72
  describe '#describe_custom_object' do
68
73
  let(:response_stub) do
69
74
  {
70
- requestId: "eeef#152858b17d2",
71
- result: [{
72
- name: "device_c",
73
- displayName: "Device",
74
- description: "this is a device object",
75
- createdAt: "2016-01-23T00:51:18Z",
76
- updatedAt: "2016-01-23T00:51:18Z",
77
- idField: "marketoGUID",
78
- dedupeFields: ["serialNumber"],
79
- searchableFields: [["serialNumber"], ["marketoGUID"]],
80
- relationships: [{
81
- field: "serialNumber",
82
- type: "child",
83
- relatedTo: {
84
- name: "Lead",
85
- field: "serialNumber"
86
- }
87
- }],
88
- fields: [{
89
- name: "createdAt",
90
- displayName: "Created At",
91
- dataType: "datetime",
92
- updateable: false
93
- },
94
- { name: "marketoGUID",
95
- displayName: "Marketo GUID",
96
- dataType: "string",
97
- length:36,
98
- updateable: false
99
- },
100
- { name: "updatedAt",
101
- displayName: "Updated At",
102
- dataType: "datetime",
103
- updateable: false
104
- },
105
- { name: "serialNumber",
106
- displayName: "serial number",
107
- dataType: "string",
108
- length: 255,
109
- updateable: true
110
- }]
111
- }],
112
- success: true
113
- }
75
+ requestId: 'eeef#152858b17d2',
76
+ result: [
77
+ {
78
+ name: 'device_c',
79
+ displayName: 'Device',
80
+ description: 'this is a device object',
81
+ createdAt: '2016-01-23T00:51:18Z',
82
+ updatedAt: '2016-01-23T00:51:18Z',
83
+ idField: 'marketoGUID',
84
+ dedupeFields: ['serialNumber'],
85
+ searchableFields: [['serialNumber'], ['marketoGUID']],
86
+ relationships: [
87
+ {
88
+ field: 'serialNumber',
89
+ type: 'child',
90
+ relatedTo: {
91
+ name: 'Lead',
92
+ field: 'serialNumber'
93
+ }
94
+ }
95
+ ],
96
+ fields: [
97
+ {
98
+ name: 'createdAt',
99
+ displayName: 'Created At',
100
+ dataType: 'datetime',
101
+ updateable: false
102
+ }, {
103
+ name: 'marketoGUID',
104
+ displayName: 'Marketo GUID',
105
+ dataType: 'string',
106
+ length: 36,
107
+ updateable: false
108
+ }, {
109
+ name: 'updatedAt',
110
+ displayName: 'Updated At',
111
+ dataType: 'datetime',
112
+ updateable: false
113
+ }, {
114
+ name: 'serialNumber',
115
+ displayName: 'serial number',
116
+ dataType: 'string',
117
+ length: 255,
118
+ updateable: true
119
+ }
120
+ ]
121
+ }
122
+ ],
123
+ success: true
124
+ }
114
125
  end
115
126
 
116
127
  before do
@@ -120,23 +131,22 @@ describe Mrkt::CrudCustomObjects do
120
131
 
121
132
  subject { client.describe_custom_object(object_name) }
122
133
 
123
- context "when the object name is valid" do
134
+ context 'when the object name is valid' do
124
135
  let(:object_name) { :device_c }
125
136
 
126
137
  it { is_expected.to eq(response_stub) }
127
138
  end
128
139
 
129
- context "when the object name is invalid" do
140
+ context 'when the object name is invalid' do
130
141
  let(:object_name) { nil }
131
142
 
132
143
  it 'should raise an Error' do
133
- object_name = []
134
144
  expect { subject }.to raise_error(Mrkt::Errors::Unknown)
135
145
  end
136
146
  end
137
147
  end
138
148
 
139
- describe "#createupdate_custom_objects" do
149
+ describe '#createupdate_custom_objects' do
140
150
  let(:object_name) { 'device' }
141
151
 
142
152
  let(:devices) do
@@ -179,7 +189,7 @@ describe Mrkt::CrudCustomObjects do
179
189
  it { is_expected.to eq(response_stub) }
180
190
  end
181
191
 
182
- describe "#delete_custom_objects" do
192
+ describe '#delete_custom_objects' do
183
193
  let(:object_name) { 'device' }
184
194
 
185
195
  let(:search_fields) do
@@ -199,8 +209,8 @@ describe Mrkt::CrudCustomObjects do
199
209
  success: true,
200
210
  result: [{
201
211
  seq: 0,
202
- status: "deleted",
203
- marketoGUID: "1fc49d4fcb86"
212
+ status: 'deleted',
213
+ marketoGUID: '1fc49d4fcb86'
204
214
  }]
205
215
  }
206
216
  end
@@ -216,8 +226,8 @@ describe Mrkt::CrudCustomObjects do
216
226
  it { is_expected.to eq(response_stub) }
217
227
  end
218
228
 
219
- describe "#get_custom_objects" do
220
- let(:object_name) { 'device'}
229
+ describe '#get_custom_objects' do
230
+ let(:object_name) { 'device' }
221
231
 
222
232
  let(:filter_values) do
223
233
  [{
@@ -234,13 +244,13 @@ describe Mrkt::CrudCustomObjects do
234
244
 
235
245
  let(:response_stub) do
236
246
  {
237
- requestId: "1490d#1528af5232",
247
+ requestId: '1490d#1528af5232',
238
248
  result: [{
239
249
  seq: 0,
240
- marketoGUID: "163b231LPr23200e570",
241
- serialNumber: "serial_number_1",
242
- createdAt: "2016-01-23T05:01:01Z",
243
- updatedAt: "2016-01-29T00:26:00Z"
250
+ marketoGUID: '163b231LPr23200e570',
251
+ serialNumber: 'serial_number_1',
252
+ createdAt: '2016-01-23T05:01:01Z',
253
+ updatedAt: '2016-01-29T00:26:00Z'
244
254
  }],
245
255
  success: true
246
256
  }