sendgrid4r 0.5.0 → 1.0.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 (57) hide show
  1. checksums.yaml +4 -4
  2. data/.env.example +6 -8
  3. data/.rubocop.yml +1 -1
  4. data/README.md +0 -2
  5. data/lib/sendgrid4r/rest/api.rb +6 -0
  6. data/lib/sendgrid4r/rest/api_keys/api_keys.rb +5 -5
  7. data/lib/sendgrid4r/rest/asm/global_suppressions.rb +3 -3
  8. data/lib/sendgrid4r/rest/asm/groups.rb +4 -4
  9. data/lib/sendgrid4r/rest/asm/suppressions.rb +4 -4
  10. data/lib/sendgrid4r/rest/categories/categories.rb +1 -1
  11. data/lib/sendgrid4r/rest/contacts/custom_fields.rb +3 -3
  12. data/lib/sendgrid4r/rest/contacts/lists.rb +10 -10
  13. data/lib/sendgrid4r/rest/contacts/recipients.rb +10 -10
  14. data/lib/sendgrid4r/rest/contacts/segments.rb +5 -5
  15. data/lib/sendgrid4r/rest/ips/addresses.rb +3 -3
  16. data/lib/sendgrid4r/rest/ips/pools.rb +4 -4
  17. data/lib/sendgrid4r/rest/ips/warmup.rb +6 -6
  18. data/lib/sendgrid4r/rest/request.rb +2 -2
  19. data/lib/sendgrid4r/rest/subusers/subusers.rb +63 -3
  20. data/lib/sendgrid4r/rest/templates/templates.rb +14 -9
  21. data/lib/sendgrid4r/rest/templates/versions.rb +12 -10
  22. data/lib/sendgrid4r/rest/whitelabel/domains.rb +257 -0
  23. data/lib/sendgrid4r/rest/whitelabel/ips.rb +140 -0
  24. data/lib/sendgrid4r/rest/whitelabel/links.rb +185 -0
  25. data/lib/sendgrid4r/version.rb +1 -1
  26. data/sendgrid4r.gemspec +1 -1
  27. data/spec/client_spec.rb +93 -1
  28. data/spec/rest/api_keys/api_keys_spec.rb +23 -55
  29. data/spec/rest/asm/global_suppressions_spec.rb +40 -68
  30. data/spec/rest/asm/groups_spec.rb +31 -82
  31. data/spec/rest/asm/suppressions_spec.rb +33 -76
  32. data/spec/rest/categories/categories_spec.rb +8 -27
  33. data/spec/rest/contacts/custom_fields_spec.rb +18 -71
  34. data/spec/rest/contacts/lists_spec.rb +64 -187
  35. data/spec/rest/contacts/recipients_spec.rb +41 -196
  36. data/spec/rest/contacts/reserved_fields_spec.rb +2 -20
  37. data/spec/rest/contacts/segments_spec.rb +47 -33
  38. data/spec/rest/email_activity/email_activity_spec.rb +8 -21
  39. data/spec/rest/ips/addresses_spec.rb +18 -77
  40. data/spec/rest/ips/pools_spec.rb +21 -80
  41. data/spec/rest/ips/warmup_spec.rb +11 -58
  42. data/spec/rest/settings/enforced_tls_spec.rb +3 -40
  43. data/spec/rest/settings/mail_spec.rb +21 -294
  44. data/spec/rest/settings/partner_spec.rb +6 -79
  45. data/spec/rest/settings/tracking_spec.rb +10 -147
  46. data/spec/rest/stats/advanced_spec.rb +13 -135
  47. data/spec/rest/stats/category_spec.rb +5 -48
  48. data/spec/rest/stats/global_spec.rb +3 -5
  49. data/spec/rest/stats/parse_spec.rb +1 -24
  50. data/spec/rest/stats/subuser_spec.rb +6 -49
  51. data/spec/rest/subusers/subusers_spec.rb +156 -81
  52. data/spec/rest/templates/templates_spec.rb +32 -81
  53. data/spec/rest/templates/versions_spec.rb +50 -28
  54. data/spec/rest/whitelabel/domains_spec.rb +637 -0
  55. data/spec/rest/whitelabel/ips_spec.rb +231 -0
  56. data/spec/rest/whitelabel/links_spec.rb +359 -0
  57. metadata +22 -8
@@ -7,9 +7,7 @@ describe SendGrid4r::REST::Contacts::Lists do
7
7
  begin
8
8
  pending 'waiting sendgrid documentation update'
9
9
  Dotenv.load
10
- @client = SendGrid4r::Client.new(
11
- username: ENV['SENDGRID_USERNAME'],
12
- password: ENV['SENDGRID_PASSWORD'])
10
+ @client = SendGrid4r::Client.new(api_key: ENV['API_KEY'])
13
11
  @list_name1 = 'test_list1'
14
12
  @edit_name1 = 'test_list1_edit'
15
13
  @list_name2 = 'test_list2'
@@ -25,34 +23,42 @@ describe SendGrid4r::REST::Contacts::Lists do
25
23
  # celan up test env(lists)
26
24
  lists = @client.get_lists
27
25
  lists.lists.each do |list|
28
- @client.delete_list(list.id) if list.name == @list_name1
29
- @client.delete_list(list.id) if list.name == @edit_name1
30
- @client.delete_list(list.id) if list.name == @list_name2
26
+ @client.delete_list(list_id: list.id) if list.name == @list_name1
27
+ @client.delete_list(list_id: list.id) if list.name == @edit_name1
28
+ @client.delete_list(list_id: list.id) if list.name == @list_name2
31
29
  end
32
30
  # celan up test env(recipients)
33
31
  recipients = @client.get_recipients
34
32
  recipients.recipients.each do |recipient|
35
- @client.delete_recipient(recipient.id) if recipient.email == @email1
36
- @client.delete_recipient(recipient.id) if recipient.email == @email2
33
+ @client.delete_recipient(
34
+ recipient_id: recipient.id
35
+ ) if recipient.email == @email1
36
+ @client.delete_recipient(
37
+ recipient_id: recipient.id
38
+ ) if recipient.email == @email2
37
39
  end
38
40
  # post a first list
39
- @list1 = @client.post_list(@list_name1)
41
+ @list1 = @client.post_list(name: @list_name1)
40
42
  # add multiple recipients
41
43
  recipient1 = {}
42
44
  recipient1['email'] = @email1
43
45
  recipient1['last_name'] = @last_name1
44
46
  recipient1[@custom_field_name] = @pet1
45
- recipient1 = @client.post_recipient(recipient1)
46
- @client.post_recipient_to_list(@list1.id, recipient1.id)
47
+ recipient1 = @client.post_recipient(params: recipient1)
48
+ @client.post_recipient_to_list(
49
+ list_id: @list1.id, recipient_id: recipient1.id
50
+ )
47
51
  recipient2 = {}
48
52
  recipient2['email'] = @email2
49
53
  recipient2['last_name'] = @last_name2
50
54
  recipient2[@custom_field_name] = @pet2
51
- recipient2 = @client.post_recipient(recipient2)
52
- @client.post_recipient_to_list(@list1.id, recipient2.id)
55
+ recipient2 = @client.post_recipient(params: recipient2)
56
+ @client.post_recipient_to_list(
57
+ list_id: @list1.id, recipient_id: recipient2.id
58
+ )
53
59
  # # Add multiple recipients to a single list
54
60
  # @client.post_recipients_to_list(@list1.id, @recipients)
55
- rescue => e
61
+ rescue RestClient::ExceptionWithResponse => e
56
62
  puts e.inspect
57
63
  raise e
58
64
  end
@@ -61,12 +67,12 @@ describe SendGrid4r::REST::Contacts::Lists do
61
67
  context 'without block call' do
62
68
  it '#post_list' do
63
69
  begin
64
- list2 = @client.post_list(@list_name2)
70
+ list2 = @client.post_list(name: @list_name2)
65
71
  expect(list2.id).to be_a(Fixnum)
66
72
  expect(list2.name).to eq(@list_name2)
67
73
  expect(list2.recipient_count).to eq(0)
68
- @client.delete_list(list2.id)
69
- rescue => e
74
+ @client.delete_list(list_id: list2.id)
75
+ rescue RestClient::ExceptionWithResponse => e
70
76
  puts e.inspect
71
77
  raise e
72
78
  end
@@ -75,9 +81,9 @@ describe SendGrid4r::REST::Contacts::Lists do
75
81
  it '#post_list for same key' do
76
82
  begin
77
83
  expect do
78
- @client.post_list(@list_name1)
84
+ @client.post_list(name: @list_name1)
79
85
  end.to raise_error(RestClient::BadRequest)
80
- rescue => e
86
+ rescue RestClient::ExceptionWithResponse => e
81
87
  puts e.inspect
82
88
  raise e
83
89
  end
@@ -93,7 +99,7 @@ describe SendGrid4r::REST::Contacts::Lists do
93
99
  expect(list.name).to eq(@list1.name)
94
100
  expect(list.recipient_count).to be_a(Fixnum)
95
101
  end
96
- rescue => e
102
+ rescue RestClient::ExceptionWithResponse => e
97
103
  puts e.inspect
98
104
  raise e
99
105
  end
@@ -101,11 +107,11 @@ describe SendGrid4r::REST::Contacts::Lists do
101
107
 
102
108
  it '#get_list' do
103
109
  begin
104
- actual_list = @client.get_list(@list1.id)
110
+ actual_list = @client.get_list(list_id: @list1.id)
105
111
  expect(actual_list.id).to eq(@list1.id)
106
112
  expect(actual_list.name).to eq(@list1.name)
107
113
  expect(actual_list.recipient_count).to be_a(Fixnum)
108
- rescue => e
114
+ rescue RestClient::ExceptionWithResponse => e
109
115
  puts e.inspect
110
116
  raise e
111
117
  end
@@ -113,10 +119,10 @@ describe SendGrid4r::REST::Contacts::Lists do
113
119
 
114
120
  it '#patch_list' do
115
121
  begin
116
- edit_list = @client.patch_list(@list1.id, @edit_name1)
122
+ edit_list = @client.patch_list(list_id: @list1.id, name: @edit_name1)
117
123
  expect(edit_list.id).to eq(@list1.id)
118
124
  expect(edit_list.name).to eq(@edit_name1)
119
- rescue => e
125
+ rescue RestClient::ExceptionWithResponse => e
120
126
  puts e.inspect
121
127
  raise e
122
128
  end
@@ -124,13 +130,13 @@ describe SendGrid4r::REST::Contacts::Lists do
124
130
 
125
131
  it '#get_recipients_from_list' do
126
132
  begin
127
- recipients = @client.get_recipients_from_list(@list1.id)
133
+ recipients = @client.get_recipients_from_list(list_id: @list1.id)
128
134
  recipients.recipients.each do |recipient|
129
135
  expect(
130
136
  recipient
131
137
  ).to be_a(SendGrid4r::REST::Contacts::Recipients::Recipient)
132
138
  end
133
- rescue => e
139
+ rescue RestClient::ExceptionWithResponse => e
134
140
  puts e.inspect
135
141
  raise e
136
142
  end
@@ -138,13 +144,15 @@ describe SendGrid4r::REST::Contacts::Lists do
138
144
 
139
145
  it '#get_recipients_from_list with offset & limit' do
140
146
  begin
141
- recipients = @client.get_recipients_from_list(@list1.id, 10, 0)
147
+ recipients = @client.get_recipients_from_list(
148
+ list_id: @list1.id, limit: 10, offset: 0
149
+ )
142
150
  recipients.recipients.each do |recipient|
143
151
  expect(
144
152
  recipient
145
153
  ).to be_a(SendGrid4r::REST::Contacts::Recipients::Recipient)
146
154
  end
147
- rescue => e
155
+ rescue RestClient::ExceptionWithResponse => e
148
156
  puts e.inspect
149
157
  raise e
150
158
  end
@@ -152,8 +160,10 @@ describe SendGrid4r::REST::Contacts::Lists do
152
160
 
153
161
  it '#delete_recipient_from_list' do
154
162
  begin
155
- @client.delete_recipient_from_list(@list1.id, @email1)
156
- rescue => e
163
+ @client.delete_recipient_from_list(
164
+ list_id: @list1.id, recipient_id: @email1
165
+ )
166
+ rescue RestClient::ExceptionWithResponse => e
157
167
  puts e.inspect
158
168
  raise e
159
169
  end
@@ -161,11 +171,11 @@ describe SendGrid4r::REST::Contacts::Lists do
161
171
 
162
172
  it '#delete_list' do
163
173
  begin
164
- @client.delete_list(@list1.id)
174
+ @client.delete_list(list_id: @list1.id)
165
175
  expect do
166
- @client.get_list(@list1.id)
176
+ @client.get_list(list_id: @list1.id)
167
177
  end.to raise_error(RestClient::ResourceNotFound)
168
- rescue => e
178
+ rescue RestClient::ExceptionWithResponse => e
169
179
  puts e.inspect
170
180
  raise e
171
181
  end
@@ -173,9 +183,9 @@ describe SendGrid4r::REST::Contacts::Lists do
173
183
 
174
184
  it '#delete_lists' do
175
185
  begin
176
- list2 = @client.post_list(@list_name2)
177
- @client.delete_lists([@list1.id, list2.id])
178
- rescue => e
186
+ list2 = @client.post_list(name: @list_name2)
187
+ @client.delete_lists(list_ids: [@list1.id, list2.id])
188
+ rescue RestClient::ExceptionWithResponse => e
179
189
  puts e.inspect
180
190
  raise e
181
191
  end
@@ -183,8 +193,10 @@ describe SendGrid4r::REST::Contacts::Lists do
183
193
 
184
194
  it '#post_recipients_to_list' do
185
195
  begin
186
- @client.post_recipients_to_list(@list1.id, @recipients)
187
- rescue => e
196
+ @client.post_recipients_to_list(
197
+ list_id: @list1.id, recipients: @recipients
198
+ )
199
+ rescue RestClient::ExceptionWithResponse => e
188
200
  puts e.inspect
189
201
  raise e
190
202
  end
@@ -196,151 +208,16 @@ describe SendGrid4r::REST::Contacts::Lists do
196
208
  recipient1['email'] = @email1
197
209
  recipient1['last_name'] = @last_name1
198
210
  recipient1[@custom_field_name] = @pet1
199
- recipient1 = @client.post_recipient(recipient1)
200
- @client.post_recipient_to_list(@list1.id, recipient1.id)
201
- rescue => e
211
+ recipient1 = @client.post_recipient(params: recipient1)
212
+ @client.post_recipient_to_list(
213
+ list_id: @list1.id, recipient_id: recipient1.id
214
+ )
215
+ rescue RestClient::ExceptionWithResponse => e
202
216
  puts e.inspect
203
217
  raise e
204
218
  end
205
219
  end
206
220
  end
207
-
208
- context 'with block call' do
209
- it '#post_list' do
210
- @client.post_list(@list_name2) do |resp, req, res|
211
- resp =
212
- SendGrid4r::REST::Contacts::Lists.create_list(
213
- JSON.parse(resp)
214
- )
215
- expect(resp).to be_a(SendGrid4r::REST::Contacts::Lists::List)
216
- expect(req).to be_a(RestClient::Request)
217
- expect(res).to be_a(Net::HTTPCreated)
218
- end
219
- end
220
-
221
- it '#post_list for same key' do
222
- @client.post_list(@list_name1) do |_resp, req, res|
223
- # TODO: _resp
224
- expect(req).to be_a(RestClient::Request)
225
- expect(res).to be_a(Net::HTTPBadRequest)
226
- end
227
- end
228
-
229
- it '#get_lists' do
230
- @client.get_lists do |resp, req, res|
231
- resp =
232
- SendGrid4r::REST::Contacts::Lists.create_lists(
233
- JSON.parse(resp)
234
- )
235
- expect(resp).to be_a(SendGrid4r::REST::Contacts::Lists::Lists)
236
- expect(req).to be_a(RestClient::Request)
237
- expect(res).to be_a(Net::HTTPOK)
238
- end
239
- end
240
-
241
- it '#get_list' do
242
- @client.get_list(@list1.id) do |resp, req, res|
243
- resp =
244
- SendGrid4r::REST::Contacts::Lists.create_list(
245
- JSON.parse(resp)
246
- )
247
- expect(resp).to be_a(SendGrid4r::REST::Contacts::Lists::List)
248
- expect(req).to be_a(RestClient::Request)
249
- expect(res).to be_a(Net::HTTPOK)
250
- end
251
- end
252
-
253
- it '#patch_list' do
254
- @client.patch_list(@list1.id, @edit_name1) do |resp, req, res|
255
- resp =
256
- SendGrid4r::REST::Contacts::Lists.create_list(
257
- JSON.parse(resp)
258
- )
259
- expect(resp).to be_a(SendGrid4r::REST::Contacts::Lists::List)
260
- expect(req).to be_a(RestClient::Request)
261
- expect(res).to be_a(Net::HTTPOK)
262
- end
263
- end
264
-
265
- it '#get_recipients_from_list' do
266
- @client.get_recipients_from_list(@list1.id) do |resp, req, res|
267
- resp =
268
- SendGrid4r::REST::Contacts::Recipients.create_recipients(
269
- JSON.parse(resp)
270
- )
271
- expect(resp).to be_a(
272
- SendGrid4r::REST::Contacts::Recipients::Recipients
273
- )
274
- expect(req).to be_a(RestClient::Request)
275
- expect(res).to be_a(Net::HTTPOK)
276
- end
277
- end
278
-
279
- it '#get_recipients_from_list with offset & limit' do
280
- @client.get_recipients_from_list(@list1.id, 10, 0) do |resp, req, res|
281
- resp =
282
- SendGrid4r::REST::Contacts::Recipients.create_recipients(
283
- JSON.parse(resp)
284
- )
285
- expect(resp).to be_a(
286
- SendGrid4r::REST::Contacts::Recipients::Recipients
287
- )
288
- expect(req).to be_a(RestClient::Request)
289
- expect(res).to be_a(Net::HTTPOK)
290
- end
291
- end
292
-
293
- it '#delete_recipient_from_list' do
294
- @client.delete_recipient_from_list(
295
- @list1.id, @email1
296
- ) do |resp, req, res|
297
- expect(resp).to eq('')
298
- expect(req).to be_a(RestClient::Request)
299
- expect(res).to be_a(Net::HTTPNoContent)
300
- end
301
- end
302
-
303
- it '#delete_list' do
304
- @client.delete_list(@list1.id) do |resp, req, res|
305
- expect(resp).to eq('')
306
- expect(req).to be_a(RestClient::Request)
307
- expect(res).to be_a(Net::HTTPNoContent)
308
- end
309
- end
310
-
311
- it '#delete_lists' do
312
- @client.delete_lists([@list1.id]) do |resp, req, res|
313
- expect(resp).to eq('')
314
- expect(req).to be_a(RestClient::Request)
315
- expect(res).to be_a(Net::HTTPNoContent)
316
- end
317
- end
318
-
319
- it '#post_recipients_to_list' do
320
- @client.post_recipients_to_list(
321
- @list1.id, @recipients
322
- ) do |resp, req, res|
323
- expect(resp).to eq('')
324
- expect(req).to be_a(RestClient::Request)
325
- expect(res).to be_a(Net::HTTPCreated)
326
- end
327
- end
328
-
329
- it '#post_recipient_to_list' do
330
- recipient1 = {}
331
- recipient1['email'] = @email1
332
- recipient1['last_name'] = @last_name1
333
- recipient1[@custom_field_name] = @pet1
334
- recipient1 = @client.post_recipient(recipient1)
335
- @client.post_recipient_to_list(
336
- @list1.id, recipient1.id
337
- ) do |resp, req, res|
338
- expect(resp).to eq('')
339
- expect(req).to be_a(RestClient::Request)
340
- expect(res).to be_a(Net::HTTPCreated)
341
- end
342
- end
343
- end
344
221
  end
345
222
 
346
223
  describe 'unit test', :ut do
@@ -426,7 +303,7 @@ describe SendGrid4r::REST::Contacts::Lists do
426
303
 
427
304
  it '#post_list' do
428
305
  allow(client).to receive(:execute).and_return(list)
429
- actual = client.post_list('')
306
+ actual = client.post_list(name: '')
430
307
  expect(actual).to be_a(SendGrid4r::REST::Contacts::Lists::List)
431
308
  end
432
309
 
@@ -438,49 +315,49 @@ describe SendGrid4r::REST::Contacts::Lists do
438
315
 
439
316
  it '#get_list' do
440
317
  allow(client).to receive(:execute).and_return(list)
441
- actual = client.get_list(0)
318
+ actual = client.get_list(list_id: 0)
442
319
  expect(actual).to be_a(SendGrid4r::REST::Contacts::Lists::List)
443
320
  end
444
321
 
445
322
  it '#patch_list' do
446
323
  allow(client).to receive(:execute).and_return(list)
447
- actual = client.patch_list(0, '')
324
+ actual = client.patch_list(list_id: 0, name: '')
448
325
  expect(actual).to be_a(SendGrid4r::REST::Contacts::Lists::List)
449
326
  end
450
327
 
451
328
  it '#get_recipients_from_list' do
452
329
  allow(client).to receive(:execute).and_return(recipients)
453
- actual = client.get_recipients_from_list(0)
330
+ actual = client.get_recipients_from_list(list_id: 0)
454
331
  expect(actual).to be_a(SendGrid4r::REST::Contacts::Recipients::Recipients)
455
332
  end
456
333
 
457
334
  it '#delete_recipient_from_list' do
458
335
  allow(client).to receive(:execute).and_return('')
459
- actual = client.delete_recipient_from_list(0, '')
336
+ actual = client.delete_recipient_from_list(list_id: 0, recipient_id: '')
460
337
  expect(actual).to eq('')
461
338
  end
462
339
 
463
340
  it '#delete_list' do
464
341
  allow(client).to receive(:execute).and_return('')
465
- actual = client.delete_list(0)
342
+ actual = client.delete_list(list_id: 0)
466
343
  expect(actual).to eq('')
467
344
  end
468
345
 
469
346
  it '#delete_lists' do
470
347
  allow(client).to receive(:execute).and_return('')
471
- actual = client.delete_lists([0, 1])
348
+ actual = client.delete_lists(list_ids: [0, 1])
472
349
  expect(actual).to eq('')
473
350
  end
474
351
 
475
352
  it '#post_recipients_to_list' do
476
353
  allow(client).to receive(:execute).and_return('')
477
- actual = client.post_recipients_to_list(0, ['', ''])
354
+ actual = client.post_recipients_to_list(list_id: 0, recipients: ['', ''])
478
355
  expect(actual).to eq('')
479
356
  end
480
357
 
481
358
  it '#post_recipient_to_list' do
482
359
  allow(client).to receive(:execute).and_return('')
483
- actual = client.post_recipient_to_list(0, 0)
360
+ actual = client.post_recipient_to_list(list_id: 0, recipient_id: 0)
484
361
  expect(actual).to eq('')
485
362
  end
486
363