sendgrid4r 0.2.0 → 0.3.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 (61) hide show
  1. checksums.yaml +4 -4
  2. data/.env.example +5 -0
  3. data/.rubocop.yml +8 -8
  4. data/README.md +2 -0
  5. data/lib/auth.rb +5 -2
  6. data/lib/client.rb +4 -2
  7. data/lib/sendgrid4r/factory/version_factory.rb +1 -1
  8. data/lib/sendgrid4r/rest/api.rb +4 -0
  9. data/lib/sendgrid4r/rest/api_keys/api_keys.rb +73 -0
  10. data/lib/sendgrid4r/rest/asm/asm.rb +28 -0
  11. data/lib/sendgrid4r/rest/asm/global_suppressions.rb +12 -8
  12. data/lib/sendgrid4r/rest/asm/groups.rb +29 -22
  13. data/lib/sendgrid4r/rest/asm/suppressions.rb +25 -15
  14. data/lib/sendgrid4r/rest/categories/categories.rb +19 -9
  15. data/lib/sendgrid4r/rest/contacts/custom_fields.rb +14 -8
  16. data/lib/sendgrid4r/rest/contacts/lists.rb +32 -20
  17. data/lib/sendgrid4r/rest/contacts/recipients.rb +42 -31
  18. data/lib/sendgrid4r/rest/contacts/reserved_fields.rb +6 -2
  19. data/lib/sendgrid4r/rest/contacts/segments.rb +22 -12
  20. data/lib/sendgrid4r/rest/ips/addresses.rb +36 -22
  21. data/lib/sendgrid4r/rest/ips/pools.rb +31 -16
  22. data/lib/sendgrid4r/rest/ips/warmup.rb +34 -15
  23. data/lib/sendgrid4r/rest/request.rb +33 -19
  24. data/lib/sendgrid4r/rest/settings/enforced_tls.rb +12 -5
  25. data/lib/sendgrid4r/rest/stats/advanced.rb +73 -25
  26. data/lib/sendgrid4r/rest/stats/category.rb +11 -6
  27. data/lib/sendgrid4r/rest/stats/global.rb +6 -4
  28. data/lib/sendgrid4r/rest/stats/parse.rb +10 -4
  29. data/lib/sendgrid4r/rest/stats/stats.rb +13 -18
  30. data/lib/sendgrid4r/rest/stats/subuser.rb +10 -6
  31. data/lib/sendgrid4r/rest/templates/templates.rb +23 -16
  32. data/lib/sendgrid4r/rest/templates/versions.rb +39 -36
  33. data/lib/sendgrid4r/version.rb +1 -1
  34. data/spec/api_keys/api_keys_spec.rb +152 -0
  35. data/spec/asm/asm_spec.rb +33 -0
  36. data/spec/asm/global_suppressions_spec.rb +111 -45
  37. data/spec/asm/groups_spec.rb +172 -48
  38. data/spec/asm/suppressions_spec.rb +180 -54
  39. data/spec/categories/categories_spec.rb +81 -25
  40. data/spec/client_spec.rb +11 -4
  41. data/spec/contacts/custom_fields_spec.rb +135 -44
  42. data/spec/contacts/lists_spec.rb +314 -84
  43. data/spec/contacts/recipients_spec.rb +337 -92
  44. data/spec/contacts/reserved_fields_spec.rb +80 -60
  45. data/spec/contacts/segments_spec.rb +219 -88
  46. data/spec/factory/condition_factory_spec.rb +12 -12
  47. data/spec/factory/segment_factory_spec.rb +19 -19
  48. data/spec/factory/version_factory_spec.rb +6 -6
  49. data/spec/ips/addresses_spec.rb +177 -84
  50. data/spec/ips/pools_spec.rb +190 -34
  51. data/spec/ips/warmup_spec.rb +106 -38
  52. data/spec/settings/enforced_tls_spec.rb +76 -18
  53. data/spec/stats/advanced_spec.rb +373 -196
  54. data/spec/stats/category_spec.rb +133 -71
  55. data/spec/stats/global_spec.rb +74 -47
  56. data/spec/stats/parse_spec.rb +46 -29
  57. data/spec/stats/stats_spec.rb +246 -0
  58. data/spec/stats/subuser_spec.rb +99 -54
  59. data/spec/templates/templates_spec.rb +219 -54
  60. data/spec/templates/versions_spec.rb +171 -67
  61. metadata +10 -2
@@ -1,30 +1,28 @@
1
1
  # encoding: utf-8
2
2
  require File.dirname(__FILE__) + '/../spec_helper'
3
3
 
4
- describe 'SendGrid4r::REST::Contacts::Lists' do
5
- context 'it test' do
6
- before :all do
7
- Dotenv.load
8
- @client = SendGrid4r::Client.new(
9
- ENV['SENDGRID_USERNAME'], ENV['SENDGRID_PASSWORD'])
10
- @list_name1 = 'test_list1'
11
- @edit_name1 = 'test_list1_edit'
12
- @list_name2 = 'test_list2'
13
- @email1 = 'jones@example.com'
14
- @email2 = 'miller@example.com'
15
- @last_name1 = 'Jones'
16
- @last_name2 = 'Miller'
17
- @pet1 = 'Fluffy'
18
- @pet2 = 'FrouFrou'
19
- @custom_field_name = 'pet'
20
- @recipients = [@email1, @email2]
21
- end
22
-
23
- it 'is normal' do
4
+ describe SendGrid4r::REST::Contacts::Lists do
5
+ describe 'integration test' do
6
+ before do
24
7
  begin
8
+ Dotenv.load
9
+ @client = SendGrid4r::Client.new(
10
+ username: ENV['SENDGRID_USERNAME'],
11
+ password: ENV['SENDGRID_PASSWORD'])
12
+ @list_name1 = 'test_list1'
13
+ @edit_name1 = 'test_list1_edit'
14
+ @list_name2 = 'test_list2'
15
+ @email1 = 'jones@example.com'
16
+ @email2 = 'miller@example.com'
17
+ @last_name1 = 'Jones'
18
+ @last_name2 = 'Miller'
19
+ @pet1 = 'Fluffy'
20
+ @pet2 = 'FrouFrou'
21
+ @custom_field_name = 'pet'
22
+ @recipients = [@email1, @email2]
23
+
25
24
  # celan up test env(lists)
26
25
  lists = @client.get_lists
27
- expect(lists.lists.length >= 0).to eq(true)
28
26
  lists.lists.each do |list|
29
27
  @client.delete_list(list.id) if list.name == @list_name1
30
28
  @client.delete_list(list.id) if list.name == @edit_name1
@@ -32,86 +30,319 @@ describe 'SendGrid4r::REST::Contacts::Lists' do
32
30
  end
33
31
  # celan up test env(recipients)
34
32
  recipients = @client.get_recipients
35
- expect(recipients.recipients.length >= 0).to eq(true)
36
33
  recipients.recipients.each do |recipient|
37
34
  @client.delete_recipient(recipient.id) if recipient.email == @email1
38
35
  @client.delete_recipient(recipient.id) if recipient.email == @email2
39
36
  end
40
37
  # post a first list
41
- new_list = @client.post_list(@list_name1)
42
- expect(new_list.id.is_a?(Fixnum)).to eq(true)
43
- expect(new_list.name).to eq(@list_name1)
44
- expect(new_list.recipient_count).to eq(0)
45
- # post same list
46
- expect do
47
- @client.post_list(@list_name1)
48
- end.to raise_error(RestClient::BadRequest)
49
- # get all list
50
- lists = @client.get_lists
51
- expect(lists.length >= 1).to eq(true)
52
- lists.lists.each do |list|
53
- next if list.name != @list_name1
54
- expect(list.id).to eq(new_list.id)
55
- expect(list.name).to eq(new_list.name)
56
- expect(list.recipient_count).to eq(0)
57
- end
58
- # get a single list
59
- actual_list = @client.get_list(new_list.id)
60
- expect(actual_list.id).to eq(new_list.id)
61
- expect(actual_list.name).to eq(new_list.name)
62
- expect(actual_list.recipient_count).to eq(0)
63
- # update the list
64
- edit_list = @client.patch_list(new_list.id, @edit_name1)
65
- expect(edit_list.id).to eq(new_list.id)
66
- expect(edit_list.name).to eq(@edit_name1)
38
+ @list1 = @client.post_list(@list_name1)
67
39
  # add multiple recipients
68
40
  recipient1 = {}
69
41
  recipient1['email'] = @email1
70
42
  recipient1['last_name'] = @last_name1
71
43
  recipient1[@custom_field_name] = @pet1
72
- @client.post_recipient(recipient1)
44
+ recipient1 = @client.post_recipient(recipient1)
45
+ @client.post_recipient_to_list(@list1.id, recipient1.id)
73
46
  recipient2 = {}
74
47
  recipient2['email'] = @email2
75
48
  recipient2['last_name'] = @last_name2
76
49
  recipient2[@custom_field_name] = @pet2
77
- @client.post_recipient(recipient2)
78
- # Add multiple recipients to a single list
79
- @client.post_recipients_to_list(edit_list.id, @recipients)
80
- # list recipients from a single list
81
- recipients = @client.get_recipients_from_list(new_list.id)
82
- recipients.recipients.each do |recipient|
83
- expect(
84
- recipient.is_a?(SendGrid4r::REST::Contacts::Recipients::Recipient)
85
- ).to eq(true)
86
- end
87
- # list recipients from a single list with offset & limit
88
- recipients = @client.get_recipients_from_list(new_list.id, 10, 0)
89
- recipients.recipients.each do |recipient|
90
- expect(
91
- recipient.is_a?(SendGrid4r::REST::Contacts::Recipients::Recipient)
92
- ).to eq(true)
93
- end
94
- # Add single recipient to a list
95
- @client.post_recipient_to_list(edit_list.id, @email1)
96
- # delete a single recipient from a single list
97
- @client.delete_recipient_from_list(edit_list.id, @email1)
98
- # delete the list
99
- @client.delete_list(new_list.id)
100
- expect do
101
- @client.get_list(new_list.id)
102
- end.to raise_error(RestClient::ResourceNotFound)
103
- # post 2 lists
104
- list1 = @client.post_list(@list_name1)
105
- list2 = @client.post_list(@list_name2)
106
- @client.delete_lists([list1.id, list2.id])
50
+ recipient2 = @client.post_recipient(recipient2)
51
+ @client.post_recipient_to_list(@list1.id, recipient2.id)
52
+ # # Add multiple recipients to a single list
53
+ # @client.post_recipients_to_list(@list1.id, @recipients)
107
54
  rescue => e
108
55
  puts e.inspect
109
56
  raise e
110
57
  end
111
58
  end
59
+
60
+ context 'without block call' do
61
+ it '#post_list' do
62
+ begin
63
+ list2 = @client.post_list(@list_name2)
64
+ expect(list2.id).to be_a(Fixnum)
65
+ expect(list2.name).to eq(@list_name2)
66
+ expect(list2.recipient_count).to eq(0)
67
+ @client.delete_list(list2.id)
68
+ rescue => e
69
+ puts e.inspect
70
+ raise e
71
+ end
72
+ end
73
+
74
+ it '#post_list for same key' do
75
+ begin
76
+ expect do
77
+ @client.post_list(@list_name1)
78
+ end.to raise_error(RestClient::BadRequest)
79
+ rescue => e
80
+ puts e.inspect
81
+ raise e
82
+ end
83
+ end
84
+
85
+ it '#get_lists' do
86
+ begin
87
+ lists = @client.get_lists
88
+ expect(lists.length).to be >= 1
89
+ lists.lists.each do |list|
90
+ next if list.name != @list_name1
91
+ expect(list.id).to eq(@list1.id)
92
+ expect(list.name).to eq(@list1.name)
93
+ expect(list.recipient_count).to be_a(Fixnum)
94
+ end
95
+ rescue => e
96
+ puts e.inspect
97
+ raise e
98
+ end
99
+ end
100
+
101
+ it '#get_list' do
102
+ begin
103
+ actual_list = @client.get_list(@list1.id)
104
+ expect(actual_list.id).to eq(@list1.id)
105
+ expect(actual_list.name).to eq(@list1.name)
106
+ expect(actual_list.recipient_count).to be_a(Fixnum)
107
+ rescue => e
108
+ puts e.inspect
109
+ raise e
110
+ end
111
+ end
112
+
113
+ it '#patch_list' do
114
+ begin
115
+ edit_list = @client.patch_list(@list1.id, @edit_name1)
116
+ expect(edit_list.id).to eq(@list1.id)
117
+ expect(edit_list.name).to eq(@edit_name1)
118
+ rescue => e
119
+ puts e.inspect
120
+ raise e
121
+ end
122
+ end
123
+
124
+ it '#get_recipients_from_list' do
125
+ begin
126
+ recipients = @client.get_recipients_from_list(@list1.id)
127
+ recipients.recipients.each do |recipient|
128
+ expect(
129
+ recipient
130
+ ).to be_a(SendGrid4r::REST::Contacts::Recipients::Recipient)
131
+ end
132
+ rescue => e
133
+ puts e.inspect
134
+ raise e
135
+ end
136
+ end
137
+
138
+ it '#get_recipients_from_list with offset & limit' do
139
+ begin
140
+ recipients = @client.get_recipients_from_list(@list1.id, 10, 0)
141
+ recipients.recipients.each do |recipient|
142
+ expect(
143
+ recipient
144
+ ).to be_a(SendGrid4r::REST::Contacts::Recipients::Recipient)
145
+ end
146
+ rescue => e
147
+ puts e.inspect
148
+ raise e
149
+ end
150
+ end
151
+
152
+ it '#delete_recipient_from_list' do
153
+ begin
154
+ @client.delete_recipient_from_list(@list1.id, @email1)
155
+ rescue => e
156
+ puts e.inspect
157
+ raise e
158
+ end
159
+ end
160
+
161
+ it '#delete_list' do
162
+ begin
163
+ @client.delete_list(@list1.id)
164
+ expect do
165
+ @client.get_list(@list1.id)
166
+ end.to raise_error(RestClient::ResourceNotFound)
167
+ rescue => e
168
+ puts e.inspect
169
+ raise e
170
+ end
171
+ end
172
+
173
+ it '#delete_lists' do
174
+ begin
175
+ list2 = @client.post_list(@list_name2)
176
+ @client.delete_lists([@list1.id, list2.id])
177
+ rescue => e
178
+ puts e.inspect
179
+ raise e
180
+ end
181
+ end
182
+
183
+ it '#post_recipients_to_list' do
184
+ begin
185
+ @client.post_recipients_to_list(@list1.id, @recipients)
186
+ rescue => e
187
+ puts e.inspect
188
+ raise e
189
+ end
190
+ end
191
+
192
+ it '#post_recipient_to_list' do
193
+ begin
194
+ recipient1 = {}
195
+ recipient1['email'] = @email1
196
+ recipient1['last_name'] = @last_name1
197
+ recipient1[@custom_field_name] = @pet1
198
+ recipient1 = @client.post_recipient(recipient1)
199
+ @client.post_recipient_to_list(@list1.id, recipient1.id)
200
+ rescue => e
201
+ puts e.inspect
202
+ raise e
203
+ end
204
+ end
205
+ end
206
+
207
+ context 'with block call' do
208
+ it '#post_list' do
209
+ @client.post_list(@list_name2) do |resp, req, res|
210
+ resp =
211
+ SendGrid4r::REST::Contacts::Lists.create_list(
212
+ JSON.parse(resp)
213
+ )
214
+ expect(resp).to be_a(SendGrid4r::REST::Contacts::Lists::List)
215
+ expect(req).to be_a(RestClient::Request)
216
+ expect(res).to be_a(Net::HTTPCreated)
217
+ end
218
+ end
219
+
220
+ it '#post_list for same key' do
221
+ @client.post_list(@list_name1) do |_resp, req, res|
222
+ # TODO: _resp
223
+ expect(req).to be_a(RestClient::Request)
224
+ expect(res).to be_a(Net::HTTPBadRequest)
225
+ end
226
+ end
227
+
228
+ it '#get_lists' do
229
+ @client.get_lists do |resp, req, res|
230
+ resp =
231
+ SendGrid4r::REST::Contacts::Lists.create_lists(
232
+ JSON.parse(resp)
233
+ )
234
+ expect(resp).to be_a(SendGrid4r::REST::Contacts::Lists::Lists)
235
+ expect(req).to be_a(RestClient::Request)
236
+ expect(res).to be_a(Net::HTTPOK)
237
+ end
238
+ end
239
+
240
+ it '#get_list' do
241
+ @client.get_list(@list1.id) do |resp, req, res|
242
+ resp =
243
+ SendGrid4r::REST::Contacts::Lists.create_list(
244
+ JSON.parse(resp)
245
+ )
246
+ expect(resp).to be_a(SendGrid4r::REST::Contacts::Lists::List)
247
+ expect(req).to be_a(RestClient::Request)
248
+ expect(res).to be_a(Net::HTTPOK)
249
+ end
250
+ end
251
+
252
+ it '#patch_list' do
253
+ @client.patch_list(@list1.id, @edit_name1) do |resp, req, res|
254
+ resp =
255
+ SendGrid4r::REST::Contacts::Lists.create_list(
256
+ JSON.parse(resp)
257
+ )
258
+ expect(resp).to be_a(SendGrid4r::REST::Contacts::Lists::List)
259
+ expect(req).to be_a(RestClient::Request)
260
+ expect(res).to be_a(Net::HTTPOK)
261
+ end
262
+ end
263
+
264
+ it '#get_recipients_from_list' do
265
+ @client.get_recipients_from_list(@list1.id) do |resp, req, res|
266
+ resp =
267
+ SendGrid4r::REST::Contacts::Recipients.create_recipients(
268
+ JSON.parse(resp)
269
+ )
270
+ expect(resp).to be_a(
271
+ SendGrid4r::REST::Contacts::Recipients::Recipients
272
+ )
273
+ expect(req).to be_a(RestClient::Request)
274
+ expect(res).to be_a(Net::HTTPOK)
275
+ end
276
+ end
277
+
278
+ it '#get_recipients_from_list with offset & limit' do
279
+ @client.get_recipients_from_list(@list1.id, 10, 0) do |resp, req, res|
280
+ resp =
281
+ SendGrid4r::REST::Contacts::Recipients.create_recipients(
282
+ JSON.parse(resp)
283
+ )
284
+ expect(resp).to be_a(
285
+ SendGrid4r::REST::Contacts::Recipients::Recipients
286
+ )
287
+ expect(req).to be_a(RestClient::Request)
288
+ expect(res).to be_a(Net::HTTPOK)
289
+ end
290
+ end
291
+
292
+ it '#delete_recipient_from_list' do
293
+ @client.delete_recipient_from_list(
294
+ @list1.id, @email1
295
+ ) do |resp, req, res|
296
+ expect(resp).to eq('')
297
+ expect(req).to be_a(RestClient::Request)
298
+ expect(res).to be_a(Net::HTTPNoContent)
299
+ end
300
+ end
301
+
302
+ it '#delete_list' do
303
+ @client.delete_list(@list1.id) do |resp, req, res|
304
+ expect(resp).to eq('')
305
+ expect(req).to be_a(RestClient::Request)
306
+ expect(res).to be_a(Net::HTTPNoContent)
307
+ end
308
+ end
309
+
310
+ it '#delete_lists' do
311
+ @client.delete_lists([@list1.id]) do |resp, req, res|
312
+ expect(resp).to eq('')
313
+ expect(req).to be_a(RestClient::Request)
314
+ expect(res).to be_a(Net::HTTPNoContent)
315
+ end
316
+ end
317
+
318
+ it '#post_recipients_to_list' do
319
+ @client.post_recipients_to_list(
320
+ @list1.id, @recipients
321
+ ) do |resp, req, res|
322
+ expect(resp).to eq('')
323
+ expect(req).to be_a(RestClient::Request)
324
+ expect(res).to be_a(Net::HTTPCreated)
325
+ end
326
+ end
327
+
328
+ it '#post_recipient_to_list' do
329
+ recipient1 = {}
330
+ recipient1['email'] = @email1
331
+ recipient1['last_name'] = @last_name1
332
+ recipient1[@custom_field_name] = @pet1
333
+ recipient1 = @client.post_recipient(recipient1)
334
+ @client.post_recipient_to_list(
335
+ @list1.id, recipient1.id
336
+ ) do |resp, req, res|
337
+ expect(resp).to eq('')
338
+ expect(req).to be_a(RestClient::Request)
339
+ expect(res).to be_a(Net::HTTPCreated)
340
+ end
341
+ end
342
+ end
112
343
  end
113
344
 
114
- context 'unit test' do
345
+ describe 'unit test' do
115
346
  it 'creates list instance' do
116
347
  json =
117
348
  '{'\
@@ -121,6 +352,7 @@ describe 'SendGrid4r::REST::Contacts::Lists' do
121
352
  '}'
122
353
  hash = JSON.parse(json)
123
354
  actual = SendGrid4r::REST::Contacts::Lists.create_list(hash)
355
+ expect(actual).to be_a(SendGrid4r::REST::Contacts::Lists::List)
124
356
  expect(actual.id).to eq(1)
125
357
  expect(actual.name).to eq('listname')
126
358
  expect(actual.recipient_count).to eq(0)
@@ -139,11 +371,9 @@ describe 'SendGrid4r::REST::Contacts::Lists' do
139
371
  '}'
140
372
  hash = JSON.parse(json)
141
373
  actual = SendGrid4r::REST::Contacts::Lists.create_lists(hash)
142
- expect(actual.lists.is_a?(Array)).to eq(true)
374
+ expect(actual.lists).to be_a(Array)
143
375
  actual.lists.each do |list|
144
- expect(
145
- list.is_a?(SendGrid4r::REST::Contacts::Lists::List)
146
- ).to eq(true)
376
+ expect(list).to be_a(SendGrid4r::REST::Contacts::Lists::List)
147
377
  end
148
378
  end
149
379
  end