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
@@ -6,9 +6,7 @@ describe SendGrid4r::REST::Asm::Suppressions do
6
6
  before do
7
7
  begin
8
8
  Dotenv.load
9
- @client = SendGrid4r::Client.new(
10
- username: ENV['SENDGRID_USERNAME'],
11
- password: ENV['SENDGRID_PASSWORD'])
9
+ @client = SendGrid4r::Client.new(api_key: ENV['API_KEY'])
12
10
  @email1 = 'test1@test.com'
13
11
  @email2 = 'test2@test.com'
14
12
  @email3 = 'test3@test.com'
@@ -19,17 +17,21 @@ describe SendGrid4r::REST::Asm::Suppressions do
19
17
  grps = @client.get_groups
20
18
  grps.each do |grp|
21
19
  next if grp.name != @group_name
22
- emails = @client.get_suppressed_emails(grp.id)
20
+ emails = @client.get_suppressed_emails(group_id: grp.id)
23
21
  emails.each do |email|
24
- @client.delete_suppressed_email(grp.id, email)
22
+ @client.delete_suppressed_email(
23
+ group_id: grp.id, email_address: email
24
+ )
25
25
  end
26
- @client.delete_group(grp.id)
26
+ @client.delete_group(group_id: grp.id)
27
27
  end
28
28
  # post a group
29
- @group = @client.post_group(@group_name, @group_desc)
29
+ @group = @client.post_group(name: @group_name, description: @group_desc)
30
30
  # post suppressed email
31
- @client.post_suppressed_emails(@group.id, [@email1])
32
- rescue => e
31
+ @client.post_suppressed_emails(
32
+ group_id: @group.id, recipient_emails: [@email1]
33
+ )
34
+ rescue RestClient::ExceptionWithResponse => e
33
35
  puts e.inspect
34
36
  raise e
35
37
  end
@@ -39,12 +41,12 @@ describe SendGrid4r::REST::Asm::Suppressions do
39
41
  it '#post_suppressed_emails' do
40
42
  begin
41
43
  emails = @client.post_suppressed_emails(
42
- @group.id, [@email2, @email3]
44
+ group_id: @group.id, recipient_emails: [@email2, @email3]
43
45
  )
44
46
  expect(emails.recipient_emails.length).to eq(2)
45
47
  expect(emails.recipient_emails[0]).to eq(@email2)
46
48
  expect(emails.recipient_emails[1]).to eq(@email3)
47
- rescue => e
49
+ rescue RestClient::ExceptionWithResponse => e
48
50
  puts e.inspect
49
51
  raise e
50
52
  end
@@ -52,10 +54,10 @@ describe SendGrid4r::REST::Asm::Suppressions do
52
54
 
53
55
  it '#get_suppressed_emails' do
54
56
  begin
55
- emails = @client.get_suppressed_emails(@group.id)
57
+ emails = @client.get_suppressed_emails(group_id: @group.id)
56
58
  expect(emails.length).to eq(1)
57
59
  expect(emails[0]).to eq(@email1)
58
- rescue => e
60
+ rescue RestClient::ExceptionWithResponse => e
59
61
  puts e.inspect
60
62
  raise e
61
63
  end
@@ -63,7 +65,7 @@ describe SendGrid4r::REST::Asm::Suppressions do
63
65
 
64
66
  it '#get_suppressions' do
65
67
  begin
66
- suppressions = @client.get_suppressions(@email1)
68
+ suppressions = @client.get_suppressions(email_address: @email1)
67
69
  expect(suppressions.suppressions).to be_a(Array)
68
70
  suppressions.suppressions.each do |suppression|
69
71
  next unless suppression.name == @group_name
@@ -71,7 +73,7 @@ describe SendGrid4r::REST::Asm::Suppressions do
71
73
  expect(suppression.description).to eq(@group_desc)
72
74
  expect(suppression.suppressed).to eq(true)
73
75
  end
74
- rescue => e
76
+ rescue RestClient::ExceptionWithResponse => e
75
77
  puts e.inspect
76
78
  raise e
77
79
  end
@@ -79,65 +81,18 @@ describe SendGrid4r::REST::Asm::Suppressions do
79
81
 
80
82
  it '#delete_suppressed_email' do
81
83
  begin
82
- @client.delete_suppressed_email(@group.id, @email1)
83
- @client.delete_suppressed_email(@group.id, @email2)
84
- @client.delete_suppressed_email(@group.id, @email3)
85
- rescue => e
86
- puts e.inspect
87
- raise e
88
- end
89
- end
90
- end
91
-
92
- context 'with block call' do
93
- it '#post_suppressed_emails' do
94
- @client.post_suppressed_emails(
95
- @group.id, [@email2, @email3]
96
- ) do |resp, req, res|
97
- resp =
98
- SendGrid4r::REST::Asm.create_recipient_emails(
99
- JSON.parse(resp)
100
- )
101
- expect(resp).to be_a(
102
- SendGrid4r::REST::Asm::RecipientEmails
84
+ @client.delete_suppressed_email(
85
+ group_id: @group.id, email_address: @email1
103
86
  )
104
- expect(req).to be_a(RestClient::Request)
105
- expect(res).to be_a(Net::HTTPCreated)
106
- end
107
- end
108
-
109
- it '#get_suppressed_emails' do
110
- @client.get_suppressed_emails(@group.id) do |resp, req, res|
111
- resp =
112
- SendGrid4r::REST::Asm::Suppressions.create_emails(JSON.parse(resp))
113
- expect(resp).to be_a(Array)
114
- resp.each do |email|
115
- expect(email).to be_a(String)
116
- end
117
- expect(req).to be_a(RestClient::Request)
118
- expect(res).to be_a(Net::HTTPOK)
119
- end
120
- end
121
-
122
- it '#get_suppressions' do
123
- @client.get_suppressions(@email1) do |resp, req, res|
124
- resp =
125
- SendGrid4r::REST::Asm::Suppressions.create_suppressions(
126
- JSON.parse(resp)
127
- )
128
- expect(resp).to be_a(
129
- SendGrid4r::REST::Asm::Suppressions::Suppressions
87
+ @client.delete_suppressed_email(
88
+ group_id: @group.id, email_address: @email2
130
89
  )
131
- expect(req).to be_a(RestClient::Request)
132
- expect(res).to be_a(Net::HTTPOK)
133
- end
134
- end
135
-
136
- it '#delete_suppressed_email' do
137
- @client.delete_suppressed_email(@group.id, @email1) do |resp, req, res|
138
- expect(resp).to eq('')
139
- expect(req).to be_a(RestClient::Request)
140
- expect(res).to be_a(Net::HTTPNoContent)
90
+ @client.delete_suppressed_email(
91
+ group_id: @group.id, email_address: @email3
92
+ )
93
+ rescue RestClient::ExceptionWithResponse => e
94
+ puts e.inspect
95
+ raise e
141
96
  end
142
97
  end
143
98
  end
@@ -207,19 +162,21 @@ describe SendGrid4r::REST::Asm::Suppressions do
207
162
 
208
163
  it '#post_suppressed_emails' do
209
164
  allow(client).to receive(:execute).and_return(recipient_emails)
210
- actual = client.post_suppressed_emails(0, ['', ''])
165
+ actual = client.post_suppressed_emails(
166
+ group_id: 0, recipient_emails: ['', '']
167
+ )
211
168
  expect(actual).to be_a(SendGrid4r::REST::Asm::RecipientEmails)
212
169
  end
213
170
 
214
171
  it '#get_suppressed_emails' do
215
172
  allow(client).to receive(:execute).and_return(emails)
216
- actual = client.get_suppressed_emails(0)
173
+ actual = client.get_suppressed_emails(group_id: 0)
217
174
  expect(actual).to be_a(Array)
218
175
  end
219
176
 
220
177
  it '#get_suppressions' do
221
178
  allow(client).to receive(:execute).and_return(suppressions)
222
- actual = client.get_suppressions('')
179
+ actual = client.get_suppressions(email_address: '')
223
180
  expect(actual.suppressions).to be_a(Array)
224
181
  actual.suppressions.each do |suppression|
225
182
  expect(suppression).to be_a(
@@ -230,7 +187,7 @@ describe SendGrid4r::REST::Asm::Suppressions do
230
187
 
231
188
  it '#delete_suppressed_email' do
232
189
  allow(client).to receive(:execute).and_return('')
233
- actual = client.delete_suppressed_email(0, '')
190
+ actual = client.delete_suppressed_email(group_id: 0, email_address: '')
234
191
  expect(actual).to eq('')
235
192
  end
236
193
 
@@ -5,9 +5,7 @@ describe SendGrid4r::REST::Categories 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
  end
12
10
 
13
11
  context 'without block call' do
@@ -18,7 +16,7 @@ describe SendGrid4r::REST::Categories do
18
16
  categories.each do |category|
19
17
  expect(category.category).to be_a(String)
20
18
  end
21
- rescue => e
19
+ rescue RestClient::ExceptionWithResponse => e
22
20
  puts e.inspect
23
21
  raise e
24
22
  end
@@ -26,12 +24,12 @@ describe SendGrid4r::REST::Categories do
26
24
 
27
25
  it '#get_categories if name was specified' do
28
26
  begin
29
- categories = @client.get_categories('Newsletter')
27
+ categories = @client.get_categories(category: 'Newsletter')
30
28
  expect(categories.length).to eq(1)
31
29
  categories.each do |category|
32
30
  expect(category.category).to eq('Newsletter')
33
31
  end
34
- rescue => e
32
+ rescue RestClient::ExceptionWithResponse => e
35
33
  puts e.inspect
36
34
  raise e
37
35
  end
@@ -39,36 +37,19 @@ describe SendGrid4r::REST::Categories do
39
37
 
40
38
  it '#get_categories if offset & limit were specified' do
41
39
  begin
42
- categories = @client.get_categories(nil, 5, 2)
40
+ categories = @client.get_categories(
41
+ category: nil, limit: 5, offset: 2
42
+ )
43
43
  expect(categories.length).to be > 0
44
44
  categories.each do |category|
45
45
  expect(category.category).to be_a(String)
46
46
  end
47
- rescue => e
47
+ rescue RestClient::ExceptionWithResponse => e
48
48
  puts e.inspect
49
49
  raise e
50
50
  end
51
51
  end
52
52
  end
53
-
54
- context 'with block call' do
55
- it '#get_categories' do
56
- @client.get_categories do |resp, req, res|
57
- resp =
58
- SendGrid4r::REST::Categories::Categories.create_categories(
59
- JSON.parse(resp)
60
- )
61
- expect(resp).to be_a(Array)
62
- resp.each do |category|
63
- expect(category).to be_a(
64
- SendGrid4r::REST::Categories::Categories::Category
65
- )
66
- end
67
- expect(req).to be_a(RestClient::Request)
68
- expect(res).to be_a(Net::HTTPOK)
69
- end
70
- end
71
- end
72
53
  end
73
54
 
74
55
  describe 'unit test', :ut do
@@ -6,9 +6,7 @@ describe SendGrid4r::REST::Contacts::CustomFields do
6
6
  before do
7
7
  begin
8
8
  Dotenv.load
9
- @client = SendGrid4r::Client.new(
10
- username: ENV['SENDGRID_USERNAME'],
11
- password: ENV['SENDGRID_PASSWORD'])
9
+ @client = SendGrid4r::Client.new(api_key: ENV['API_KEY'])
12
10
  @name1 = 'birthday'
13
11
  @type1 = 'text'
14
12
  @name2 = 'born_at'
@@ -18,11 +16,11 @@ describe SendGrid4r::REST::Contacts::CustomFields do
18
16
  fields = @client.get_custom_fields
19
17
  fields.custom_fields.each do |field|
20
18
  next if field.name != @name1 && field.name != @name2
21
- @client.delete_custom_field(field.id)
19
+ @client.delete_custom_field(custom_field_id: field.id)
22
20
  end
23
21
  # post a custom field
24
- @new_field = @client.post_custom_field(@name1, @type1)
25
- rescue => e
22
+ @new_field = @client.post_custom_field(name: @name1, type: @type1)
23
+ rescue RestClient::ExceptionWithResponse => e
26
24
  puts e.inspect
27
25
  raise e
28
26
  end
@@ -31,11 +29,11 @@ describe SendGrid4r::REST::Contacts::CustomFields do
31
29
  context 'without block call' do
32
30
  it '#post_custom_field' do
33
31
  begin
34
- new_field = @client.post_custom_field(@name2, @type2)
32
+ new_field = @client.post_custom_field(name: @name2, type: @type2)
35
33
  expect(new_field.id).to be_a(Fixnum)
36
34
  expect(new_field.name).to eq(@name2)
37
35
  expect(new_field.type).to eq(@type2)
38
- rescue => e
36
+ rescue RestClient::ExceptionWithResponse => e
39
37
  puts e.inspect
40
38
  raise e
41
39
  end
@@ -44,9 +42,9 @@ describe SendGrid4r::REST::Contacts::CustomFields do
44
42
  it '#post_custom_field for same key' do
45
43
  begin
46
44
  expect do
47
- @client.post_custom_field(@name1, @type1)
45
+ @client.post_custom_field(name: @name1, type: @type1)
48
46
  end.to raise_error(RestClient::BadRequest)
49
- rescue => e
47
+ rescue RestClient::ExceptionWithResponse => e
50
48
  puts e.inspect
51
49
  raise e
52
50
  end
@@ -62,7 +60,7 @@ describe SendGrid4r::REST::Contacts::CustomFields do
62
60
  expect(field.name).to eq(@new_field.name)
63
61
  expect(field.type).to eq(@new_field.type)
64
62
  end
65
- rescue => e
63
+ rescue RestClient::ExceptionWithResponse => e
66
64
  puts e.inspect
67
65
  raise e
68
66
  end
@@ -70,11 +68,13 @@ describe SendGrid4r::REST::Contacts::CustomFields do
70
68
 
71
69
  it '#get_custom_field' do
72
70
  begin
73
- actual_field = @client.get_custom_field(@new_field.id)
71
+ actual_field = @client.get_custom_field(
72
+ custom_field_id: @new_field.id
73
+ )
74
74
  expect(actual_field.id).to eq(@new_field.id)
75
75
  expect(actual_field.name).to eq(@new_field.name)
76
76
  expect(actual_field.type).to eq(@new_field.type)
77
- rescue => e
77
+ rescue RestClient::ExceptionWithResponse => e
78
78
  puts e.inspect
79
79
  raise e
80
80
  end
@@ -82,66 +82,13 @@ describe SendGrid4r::REST::Contacts::CustomFields do
82
82
 
83
83
  it '#delete_custom_field' do
84
84
  begin
85
- @client.delete_custom_field(@new_field.id)
86
- rescue => e
85
+ @client.delete_custom_field(custom_field_id: @new_field.id)
86
+ rescue RestClient::ExceptionWithResponse => e
87
87
  puts e.inspect
88
88
  raise e
89
89
  end
90
90
  end
91
91
  end
92
-
93
- context 'with block call' do
94
- it '#post_custom_field' do
95
- @client.post_custom_field(@name2, @type2) do |resp, req, res|
96
- resp =
97
- SendGrid4r::REST::Contacts::CustomFields.create_field(
98
- JSON.parse(resp)
99
- )
100
- expect(resp).to be_a(SendGrid4r::REST::Contacts::CustomFields::Field)
101
- expect(req).to be_a(RestClient::Request)
102
- expect(res).to be_a(Net::HTTPCreated)
103
- end
104
- end
105
-
106
- it '#post_custom_field for same key' do
107
- @client.post_custom_field(@name1, @type1) do |_resp, req, res|
108
- # TODO: _resp
109
- expect(req).to be_a(RestClient::Request)
110
- expect(res).to be_a(Net::HTTPBadRequest)
111
- end
112
- end
113
-
114
- it '#get_custom_fields' do
115
- @client.get_custom_fields do |resp, req, res|
116
- resp =
117
- SendGrid4r::REST::Contacts::CustomFields.create_fields(
118
- JSON.parse(resp)
119
- )
120
- expect(resp).to be_a(SendGrid4r::REST::Contacts::CustomFields::Fields)
121
- expect(req).to be_a(RestClient::Request)
122
- expect(res).to be_a(Net::HTTPOK)
123
- end
124
- end
125
-
126
- it '#get_custom_field' do
127
- @client.get_custom_field(@new_field.id) do |resp, req, res|
128
- resp = SendGrid4r::REST::Contacts::CustomFields.create_field(
129
- JSON.parse(resp)
130
- )
131
- expect(resp).to be_a(SendGrid4r::REST::Contacts::CustomFields::Field)
132
- expect(req).to be_a(RestClient::Request)
133
- expect(res).to be_a(Net::HTTPOK)
134
- end
135
- end
136
-
137
- it '#delete_custom_field' do
138
- @client.delete_custom_field(@new_field.id) do |resp, req, res|
139
- expect(resp).to eq('')
140
- expect(req).to be_a(RestClient::Request)
141
- expect(res).to be_a(Net::HTTPNoContent)
142
- end
143
- end
144
- end
145
92
  end
146
93
 
147
94
  describe 'unit test', :ut do
@@ -185,7 +132,7 @@ describe SendGrid4r::REST::Contacts::CustomFields do
185
132
 
186
133
  it '#post_custom_field' do
187
134
  allow(client).to receive(:execute).and_return(field)
188
- actual = client.post_custom_field('', '')
135
+ actual = client.post_custom_field(name: '', type: '')
189
136
  expect(actual).to be_a(SendGrid4r::REST::Contacts::CustomFields::Field)
190
137
  end
191
138
 
@@ -197,13 +144,13 @@ describe SendGrid4r::REST::Contacts::CustomFields do
197
144
 
198
145
  it '#get_custom_field' do
199
146
  allow(client).to receive(:execute).and_return(field)
200
- actual = client.get_custom_field(0)
147
+ actual = client.get_custom_field(custom_field_id: 0)
201
148
  expect(actual).to be_a(SendGrid4r::REST::Contacts::CustomFields::Field)
202
149
  end
203
150
 
204
151
  it '#delete_custom_field' do
205
152
  allow(client).to receive(:execute).and_return('')
206
- actual = client.delete_custom_field(0)
153
+ actual = client.delete_custom_field(custom_field_id: 0)
207
154
  expect(actual).to eq('')
208
155
  end
209
156