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::Recipients 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
  @email1 = 'jones@example.com'
14
12
  @email2 = 'miller@example.com'
15
13
  @last_name1 = 'Jones'
@@ -22,21 +20,21 @@ describe SendGrid4r::REST::Contacts::Recipients do
22
20
  recipients = @client.get_recipients
23
21
  recipients.recipients.each do |recipient|
24
22
  next if recipient.email != @email1 && recipient.email != @email2
25
- @client.delete_recipient(recipient.id)
23
+ @client.delete_recipient(recipient_id: recipient.id)
26
24
  end
27
25
  custom_fields = @client.get_custom_fields
28
26
  custom_fields.custom_fields.each do |custom_field|
29
27
  next if custom_field.name != @custom_field_name
30
- @client.delete_custom_field(custom_field.id)
28
+ @client.delete_custom_field(custom_field_id: custom_field.id)
31
29
  end
32
- @client.post_custom_field(@custom_field_name, 'text')
30
+ @client.post_custom_field(name: @custom_field_name, type: 'text')
33
31
  # post a recipient
34
32
  params = {}
35
33
  params['email'] = @email1
36
34
  params['last_name'] = @last_name1
37
35
  params[@custom_field_name] = @pet1
38
- @new_recipient = @client.post_recipient(params)
39
- rescue => e
36
+ @new_recipient = @client.post_recipient(params: params)
37
+ rescue RestClient::ExceptionWithResponse => e
40
38
  puts e.inspect
41
39
  raise e
42
40
  end
@@ -49,7 +47,7 @@ describe SendGrid4r::REST::Contacts::Recipients do
49
47
  params['email'] = @email2
50
48
  params['last_name'] = @last_name2
51
49
  params[@custom_field_name] = @pet2
52
- new_recipient = @client.post_recipient(params)
50
+ new_recipient = @client.post_recipient(params: params)
53
51
  expect(new_recipient.created_at).to be_a(Time)
54
52
  new_recipient.custom_fields.each do |custom_field|
55
53
  expect(
@@ -64,7 +62,7 @@ describe SendGrid4r::REST::Contacts::Recipients do
64
62
  expect(new_recipient.last_name).to eq(@last_name2)
65
63
  expect(new_recipient.last_opened).to eq(nil)
66
64
  expect(new_recipient.updated_at).to be_a(Time)
67
- rescue => e
65
+ rescue RestClient::ExceptionWithResponse => e
68
66
  puts e.inspect
69
67
  raise e
70
68
  end
@@ -76,8 +74,8 @@ describe SendGrid4r::REST::Contacts::Recipients do
76
74
  params['email'] = @email1
77
75
  params['last_name'] = @last_name1
78
76
  params[@custom_field_name] = @pet1
79
- @client.post_recipient(params)
80
- rescue => e
77
+ @client.post_recipient(params: params)
78
+ rescue RestClient::ExceptionWithResponse => e
81
79
  puts e.inspect
82
80
  raise e
83
81
  end
@@ -85,14 +83,14 @@ describe SendGrid4r::REST::Contacts::Recipients do
85
83
 
86
84
  it '#get_recipients' do
87
85
  begin
88
- recipients = @client.get_recipients(100, 0)
86
+ recipients = @client.get_recipients(limit: 100, offset: 0)
89
87
  expect(recipients.recipients.length).to be > 0
90
88
  recipients.recipients.each do |recipient|
91
89
  expect(
92
90
  recipient
93
91
  ).to be_a(SendGrid4r::REST::Contacts::Recipients::Recipient)
94
92
  end
95
- rescue => e
93
+ rescue RestClient::ExceptionWithResponse => e
96
94
  puts e.inspect
97
95
  raise e
98
96
  end
@@ -102,7 +100,7 @@ describe SendGrid4r::REST::Contacts::Recipients do
102
100
  begin
103
101
  actual_count = @client.get_recipients_count
104
102
  expect(actual_count).to be >= 0
105
- rescue => e
103
+ rescue RestClient::ExceptionWithResponse => e
106
104
  puts e.inspect
107
105
  raise e
108
106
  end
@@ -112,9 +110,9 @@ describe SendGrid4r::REST::Contacts::Recipients do
112
110
  begin
113
111
  params = {}
114
112
  params['email'] = @email1
115
- recipients = @client.search_recipients(params)
113
+ recipients = @client.search_recipients(params: params)
116
114
  expect(recipients.recipients).to be_a(Array)
117
- rescue => e
115
+ rescue RestClient::ExceptionWithResponse => e
118
116
  puts e.inspect
119
117
  raise e
120
118
  end
@@ -122,11 +120,11 @@ describe SendGrid4r::REST::Contacts::Recipients do
122
120
 
123
121
  it '#get_recipient' do
124
122
  begin
125
- recipient = @client.get_recipient(@new_recipient.id)
123
+ recipient = @client.get_recipient(recipient_id: @new_recipient.id)
126
124
  expect(
127
125
  recipient
128
126
  ).to be_a(SendGrid4r::REST::Contacts::Recipients::Recipient)
129
- rescue => e
127
+ rescue RestClient::ExceptionWithResponse => e
130
128
  puts e.inspect
131
129
  raise e
132
130
  end
@@ -134,13 +132,15 @@ describe SendGrid4r::REST::Contacts::Recipients do
134
132
 
135
133
  it '#get_lists_recipient_belong' do
136
134
  begin
137
- lists = @client.get_lists_recipient_belong(@new_recipient.id)
135
+ lists = @client.get_lists_recipient_belong(
136
+ recipient_id: @new_recipient.id
137
+ )
138
138
  lists.lists.each do |list|
139
139
  expect(
140
140
  list.is_a?(SendGrid4r::REST::Contacts::Lists::List)
141
141
  ).to eq(true)
142
142
  end
143
- rescue => e
143
+ rescue RestClient::ExceptionWithResponse => e
144
144
  puts e.inspect
145
145
  raise e
146
146
  end
@@ -157,14 +157,14 @@ describe SendGrid4r::REST::Contacts::Recipients do
157
157
  recipient2['last_name'] = @last_name2
158
158
  recipient2[@custom_field_name] = @pet2
159
159
  params = [recipient1, recipient2]
160
- result = @client.post_recipients(params)
160
+ result = @client.post_recipients(params: params)
161
161
  expect(result.error_count).to eq(0)
162
162
  result.error_indices.each do |index|
163
163
  expect(index).to be_a(Fixnum)
164
164
  end
165
165
  expect(result.new_count).to be_a(Fixnum)
166
166
  expect(result.updated_count).to be_a(Fixnum)
167
- rescue => e
167
+ rescue RestClient::ExceptionWithResponse => e
168
168
  puts e.inspect
169
169
  raise e
170
170
  end
@@ -173,7 +173,9 @@ describe SendGrid4r::REST::Contacts::Recipients do
173
173
  it '#get_recipients_by_id' do
174
174
  begin
175
175
  recipient_ids = [@email1, @email2]
176
- actual_recipients = @client.get_recipients_by_id(recipient_ids)
176
+ actual_recipients = @client.get_recipients_by_id(
177
+ recipient_ids: recipient_ids
178
+ )
177
179
  expect(actual_recipients.recipients).to be_a(Array)
178
180
  expect(actual_recipients.recipients.length).to eq(1)
179
181
  actual_recipients.recipients.each do |recip|
@@ -181,7 +183,7 @@ describe SendGrid4r::REST::Contacts::Recipients do
181
183
  recip
182
184
  ).to be_a(SendGrid4r::REST::Contacts::Recipients::Recipient)
183
185
  end
184
- rescue => e
186
+ rescue RestClient::ExceptionWithResponse => e
185
187
  puts e.inspect
186
188
  raise e
187
189
  end
@@ -189,11 +191,11 @@ describe SendGrid4r::REST::Contacts::Recipients do
189
191
 
190
192
  it '#delete_recipient' do
191
193
  begin
192
- @client.delete_recipient(@new_recipient.id)
194
+ @client.delete_recipient(recipient_id: @new_recipient.id)
193
195
  expect do
194
- @client.get_recipient(@new_recipient.id)
196
+ @client.get_recipient(recipient_id: @new_recipient.id)
195
197
  end.to raise_error(RestClient::ResourceNotFound)
196
- rescue => e
198
+ rescue RestClient::ExceptionWithResponse => e
197
199
  puts e.inspect
198
200
  raise e
199
201
  end
@@ -201,170 +203,13 @@ describe SendGrid4r::REST::Contacts::Recipients do
201
203
 
202
204
  it '#delete_recipients' do
203
205
  begin
204
- @client.delete_recipients([@email1, @email2])
205
- rescue => e
206
+ @client.delete_recipients(emails: [@email1, @email2])
207
+ rescue RestClient::ExceptionWithResponse => e
206
208
  puts e.inspect
207
209
  raise e
208
210
  end
209
211
  end
210
212
  end
211
-
212
- context 'with block call' do
213
- it '#post_recipient' do
214
- params = {}
215
- params['email'] = @email2
216
- params['last_name'] = @last_name2
217
- params[@custom_field_name] = @pet2
218
- @client.post_recipient(params) do |resp, req, res|
219
- resp =
220
- SendGrid4r::REST::Contacts::Recipients.create_recipient(
221
- JSON.parse(resp)
222
- )
223
- expect(resp).to be_a(
224
- SendGrid4r::REST::Contacts::Recipients::Recipient
225
- )
226
- expect(req).to be_a(RestClient::Request)
227
- expect(res).to be_a(Net::HTTPCreated)
228
- end
229
- end
230
-
231
- it '#delete_recipient' do
232
- params = {}
233
- params['email'] = @email1
234
- params['last_name'] = @last_name1
235
- params[@custom_field_name] = @pet1
236
- recipient = @client.post_recipient(params)
237
- @client.delete_recipient(recipient.id) do |resp, req, res|
238
- expect(resp).to eq('')
239
- expect(req).to be_a(RestClient::Request)
240
- expect(res).to be_a(Net::HTTPNoContent)
241
- end
242
- end
243
-
244
- it '#delete_recipients' do
245
- @client.delete_recipients([@email1, @email2]) do |resp, req, res|
246
- expect(resp).to eq('')
247
- expect(req).to be_a(RestClient::Request)
248
- expect(res).to be_a(Net::HTTPNoContent)
249
- end
250
- end
251
-
252
- it '#get_recipients' do
253
- @client.get_recipients do |resp, req, res|
254
- resp =
255
- SendGrid4r::REST::Contacts::Recipients.create_recipients(
256
- JSON.parse(resp)
257
- )
258
- expect(resp).to be_a(
259
- SendGrid4r::REST::Contacts::Recipients::Recipients
260
- )
261
- expect(req).to be_a(RestClient::Request)
262
- expect(res).to be_a(Net::HTTPOK)
263
- end
264
- end
265
-
266
- it '#get_recipients_by_id' do
267
- params = {}
268
- params['email'] = @email1
269
- params['last_name'] = @last_name1
270
- params[@custom_field_name] = @pet1
271
- recipient = @client.post_recipient(params)
272
- @client.get_recipients_by_id([recipient.id]) do |resp, req, res|
273
- resp =
274
- SendGrid4r::REST::Contacts::Recipients.create_recipients(
275
- JSON.parse(resp)
276
- )
277
- expect(resp).to be_a(
278
- SendGrid4r::REST::Contacts::Recipients::Recipients
279
- )
280
- expect(req).to be_a(RestClient::Request)
281
- expect(res).to be_a(Net::HTTPOK)
282
- end
283
- end
284
-
285
- it '#get_recipients_count' do
286
- @client.get_recipients_count do |resp, req, res|
287
- expect(JSON.parse(resp)['recipient_count']).to be_a(Fixnum)
288
- expect(req).to be_a(RestClient::Request)
289
- expect(res).to be_a(Net::HTTPOK)
290
- end
291
- end
292
-
293
- it '#search_recipients' do
294
- params = {}
295
- params['email'] = @email1
296
- @client.search_recipients(params) do |resp, req, res|
297
- resp =
298
- SendGrid4r::REST::Contacts::Recipients.create_recipients(
299
- JSON.parse(resp)
300
- )
301
- expect(resp).to be_a(
302
- SendGrid4r::REST::Contacts::Recipients::Recipients
303
- )
304
- expect(req).to be_a(RestClient::Request)
305
- expect(res).to be_a(Net::HTTPOK)
306
- end
307
- end
308
-
309
- it '#get_recipient' do
310
- params = {}
311
- params['email'] = @email1
312
- params['last_name'] = @last_name1
313
- params[@custom_field_name] = @pet1
314
- recipient = @client.post_recipient(params)
315
- @client.get_recipient(recipient.id) do |resp, req, res|
316
- resp =
317
- SendGrid4r::REST::Contacts::Recipients.create_recipient(
318
- JSON.parse(resp)
319
- )
320
- expect(resp).to be_a(
321
- SendGrid4r::REST::Contacts::Recipients::Recipient
322
- )
323
- expect(req).to be_a(RestClient::Request)
324
- expect(res).to be_a(Net::HTTPOK)
325
- end
326
- end
327
-
328
- it '#get_lists_recipient_belong' do
329
- params = {}
330
- params['email'] = @email1
331
- params['last_name'] = @last_name1
332
- params[@custom_field_name] = @pet1
333
- recipient = @client.post_recipient(params)
334
- @client.get_lists_recipient_belong(recipient.id) do |resp, req, res|
335
- resp =
336
- SendGrid4r::REST::Contacts::Lists.create_lists(
337
- JSON.parse(resp)
338
- )
339
- expect(resp).to be_a(SendGrid4r::REST::Contacts::Lists::Lists)
340
- expect(req).to be_a(RestClient::Request)
341
- expect(res).to be_a(Net::HTTPOK)
342
- end
343
- end
344
-
345
- it '#post_recipients' do
346
- recipient1 = {}
347
- recipient1['email'] = @email1
348
- recipient1['last_name'] = @last_name1
349
- recipient1[@custom_field_name] = @pet1
350
- recipient2 = {}
351
- recipient2['email'] = @email2
352
- recipient2['last_name'] = @last_name2
353
- recipient2[@custom_field_name] = @pet2
354
- params = [recipient1, recipient2]
355
- @client.post_recipients(params) do |resp, req, res|
356
- resp =
357
- SendGrid4r::REST::Contacts::Recipients.create_result(
358
- JSON.parse(resp)
359
- )
360
- expect(resp).to be_a(
361
- SendGrid4r::REST::Contacts::Recipients::ResultAddMultiple
362
- )
363
- expect(req).to be_a(RestClient::Request)
364
- expect(res).to be_a(Net::HTTPCreated)
365
- end
366
- end
367
- end
368
213
  end
369
214
 
370
215
  describe 'unit test', :ut do
@@ -464,13 +309,13 @@ describe SendGrid4r::REST::Contacts::Recipients do
464
309
 
465
310
  it '#post_recipient' do
466
311
  allow(client).to receive(:execute).and_return(recipient)
467
- actual = client.post_recipient({})
312
+ actual = client.post_recipient(params: {})
468
313
  expect(actual).to be_a(SendGrid4r::REST::Contacts::Recipients::Recipient)
469
314
  end
470
315
 
471
316
  it '#get_recipients' do
472
317
  allow(client).to receive(:execute).and_return(recipients)
473
- actual = client.get_recipients(0, 0)
318
+ actual = client.get_recipients(limit: 0, offset: 0)
474
319
  expect(actual).to be_a(SendGrid4r::REST::Contacts::Recipients::Recipients)
475
320
  end
476
321
 
@@ -482,25 +327,25 @@ describe SendGrid4r::REST::Contacts::Recipients do
482
327
 
483
328
  it '#search_recipients' do
484
329
  allow(client).to receive(:execute).and_return(recipients)
485
- actual = client.search_recipients({})
330
+ actual = client.search_recipients(params: {})
486
331
  expect(actual).to be_a(SendGrid4r::REST::Contacts::Recipients::Recipients)
487
332
  end
488
333
 
489
334
  it '#get_recipient' do
490
335
  allow(client).to receive(:execute).and_return(recipient)
491
- actual = client.get_recipient(0)
336
+ actual = client.get_recipient(recipient_id: 0)
492
337
  expect(actual).to be_a(SendGrid4r::REST::Contacts::Recipients::Recipient)
493
338
  end
494
339
 
495
340
  it '#get_lists_recipient_belong' do
496
341
  allow(client).to receive(:execute).and_return(lists)
497
- actual = client.get_lists_recipient_belong(0)
342
+ actual = client.get_lists_recipient_belong(recipient_id: 0)
498
343
  expect(actual).to be_a(SendGrid4r::REST::Contacts::Lists::Lists)
499
344
  end
500
345
 
501
346
  it '#post_recipients' do
502
347
  allow(client).to receive(:execute).and_return(result)
503
- actual = client.post_recipients([{}, {}])
348
+ actual = client.post_recipients(recipients: [{}, {}])
504
349
  expect(actual).to be_a(
505
350
  SendGrid4r::REST::Contacts::Recipients::ResultAddMultiple
506
351
  )
@@ -508,19 +353,19 @@ describe SendGrid4r::REST::Contacts::Recipients do
508
353
 
509
354
  it '#get_recipients_by_id' do
510
355
  allow(client).to receive(:execute).and_return(recipients)
511
- actual = client.get_recipients_by_id(['', ''])
356
+ actual = client.get_recipients_by_id(recipient_ids: ['', ''])
512
357
  expect(actual).to be_a(SendGrid4r::REST::Contacts::Recipients::Recipients)
513
358
  end
514
359
 
515
360
  it '#delete_recipient' do
516
361
  allow(client).to receive(:execute).and_return('')
517
- actual = client.delete_recipient(0)
362
+ actual = client.delete_recipient(recipient_id: 0)
518
363
  expect(actual).to eq('')
519
364
  end
520
365
 
521
366
  it '#delete_recipients' do
522
367
  allow(client).to receive(:execute).and_return('')
523
- actual = client.delete_recipients(['', ''])
368
+ actual = client.delete_recipients(emails: ['', ''])
524
369
  expect(actual).to eq('')
525
370
  end
526
371
 
@@ -5,9 +5,7 @@ describe SendGrid4r::REST::Contacts::ReservedFields do
5
5
  describe 'integration test', :it do
6
6
  before do
7
7
  Dotenv.load
8
- @client = SendGrid4r::Client.new(
9
- username: ENV['SENDGRID_USERNAME'],
10
- password: ENV['SENDGRID_PASSWORD'])
8
+ @client = SendGrid4r::Client.new(api_key: ENV['API_KEY'])
11
9
  @first_name =
12
10
  SendGrid4r::REST::Contacts::ReservedFields::Field.new(
13
11
  'first_name', 'text'
@@ -57,28 +55,12 @@ describe SendGrid4r::REST::Contacts::ReservedFields do
57
55
  expect(set.include?(@last_emailed)).to eq(true)
58
56
  expect(set.include?(@last_clicked)).to eq(true)
59
57
  expect(set.include?(@last_opened)).to eq(true)
60
- rescue => e
58
+ rescue RestClient::ExceptionWithResponse => e
61
59
  puts e.inspect
62
60
  raise e
63
61
  end
64
62
  end
65
63
  end
66
-
67
- context 'with block call' do
68
- it '#get_reserved_fields' do
69
- @client.get_reserved_fields do |resp, req, res|
70
- resp =
71
- SendGrid4r::REST::Contacts::ReservedFields.create_fields(
72
- JSON.parse(resp)
73
- )
74
- expect(resp).to be_a(
75
- SendGrid4r::REST::Contacts::ReservedFields::Fields
76
- )
77
- expect(req).to be_a(RestClient::Request)
78
- expect(res).to be_a(Net::HTTPOK)
79
- end
80
- end
81
- end
82
64
  end
83
65
 
84
66
  describe 'unit test', :ut do