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.
- checksums.yaml +4 -4
- data/.env.example +6 -8
- data/.rubocop.yml +1 -1
- data/README.md +0 -2
- data/lib/sendgrid4r/rest/api.rb +6 -0
- data/lib/sendgrid4r/rest/api_keys/api_keys.rb +5 -5
- data/lib/sendgrid4r/rest/asm/global_suppressions.rb +3 -3
- data/lib/sendgrid4r/rest/asm/groups.rb +4 -4
- data/lib/sendgrid4r/rest/asm/suppressions.rb +4 -4
- data/lib/sendgrid4r/rest/categories/categories.rb +1 -1
- data/lib/sendgrid4r/rest/contacts/custom_fields.rb +3 -3
- data/lib/sendgrid4r/rest/contacts/lists.rb +10 -10
- data/lib/sendgrid4r/rest/contacts/recipients.rb +10 -10
- data/lib/sendgrid4r/rest/contacts/segments.rb +5 -5
- data/lib/sendgrid4r/rest/ips/addresses.rb +3 -3
- data/lib/sendgrid4r/rest/ips/pools.rb +4 -4
- data/lib/sendgrid4r/rest/ips/warmup.rb +6 -6
- data/lib/sendgrid4r/rest/request.rb +2 -2
- data/lib/sendgrid4r/rest/subusers/subusers.rb +63 -3
- data/lib/sendgrid4r/rest/templates/templates.rb +14 -9
- data/lib/sendgrid4r/rest/templates/versions.rb +12 -10
- data/lib/sendgrid4r/rest/whitelabel/domains.rb +257 -0
- data/lib/sendgrid4r/rest/whitelabel/ips.rb +140 -0
- data/lib/sendgrid4r/rest/whitelabel/links.rb +185 -0
- data/lib/sendgrid4r/version.rb +1 -1
- data/sendgrid4r.gemspec +1 -1
- data/spec/client_spec.rb +93 -1
- data/spec/rest/api_keys/api_keys_spec.rb +23 -55
- data/spec/rest/asm/global_suppressions_spec.rb +40 -68
- data/spec/rest/asm/groups_spec.rb +31 -82
- data/spec/rest/asm/suppressions_spec.rb +33 -76
- data/spec/rest/categories/categories_spec.rb +8 -27
- data/spec/rest/contacts/custom_fields_spec.rb +18 -71
- data/spec/rest/contacts/lists_spec.rb +64 -187
- data/spec/rest/contacts/recipients_spec.rb +41 -196
- data/spec/rest/contacts/reserved_fields_spec.rb +2 -20
- data/spec/rest/contacts/segments_spec.rb +47 -33
- data/spec/rest/email_activity/email_activity_spec.rb +8 -21
- data/spec/rest/ips/addresses_spec.rb +18 -77
- data/spec/rest/ips/pools_spec.rb +21 -80
- data/spec/rest/ips/warmup_spec.rb +11 -58
- data/spec/rest/settings/enforced_tls_spec.rb +3 -40
- data/spec/rest/settings/mail_spec.rb +21 -294
- data/spec/rest/settings/partner_spec.rb +6 -79
- data/spec/rest/settings/tracking_spec.rb +10 -147
- data/spec/rest/stats/advanced_spec.rb +13 -135
- data/spec/rest/stats/category_spec.rb +5 -48
- data/spec/rest/stats/global_spec.rb +3 -5
- data/spec/rest/stats/parse_spec.rb +1 -24
- data/spec/rest/stats/subuser_spec.rb +6 -49
- data/spec/rest/subusers/subusers_spec.rb +156 -81
- data/spec/rest/templates/templates_spec.rb +32 -81
- data/spec/rest/templates/versions_spec.rb +50 -28
- data/spec/rest/whitelabel/domains_spec.rb +637 -0
- data/spec/rest/whitelabel/ips_spec.rb +231 -0
- data/spec/rest/whitelabel/links_spec.rb +359 -0
- metadata +22 -8
@@ -6,9 +6,7 @@ describe SendGrid4r::REST::Contacts::Segments 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 = 'test_segment1'
|
13
11
|
@name2 = 'test_segment2'
|
14
12
|
@edit_name1 = 'test_segment_edit'
|
@@ -21,24 +19,32 @@ describe SendGrid4r::REST::Contacts::Segments do
|
|
21
19
|
|
22
20
|
# celan up test env(segment)
|
23
21
|
@client.get_segments.segments.each do |segment|
|
24
|
-
@client.delete_segment(
|
25
|
-
|
26
|
-
|
22
|
+
@client.delete_segment(
|
23
|
+
segment_id: segment.id
|
24
|
+
) if segment.name == @name1
|
25
|
+
@client.delete_segment(
|
26
|
+
segment_id: segment.id
|
27
|
+
) if segment.name == @edit_name1
|
28
|
+
@client.delete_segment(
|
29
|
+
segment_id: segment.id
|
30
|
+
) if segment.name == @name2
|
27
31
|
end
|
28
32
|
# clean up test env(custom_fields)
|
29
33
|
@client.get_custom_fields.custom_fields.each do |field|
|
30
|
-
@client.delete_custom_field(
|
34
|
+
@client.delete_custom_field(
|
35
|
+
custom_field_id: field.id
|
36
|
+
) if field.name == @field
|
31
37
|
end
|
32
38
|
# post a custom field and a segment
|
33
|
-
@client.post_custom_field(@field, 'text')
|
39
|
+
@client.post_custom_field(name: @field, type: 'text')
|
34
40
|
@condition = @condition_factory.create(
|
35
41
|
field: @field, value: @value, operator: @operator, and_or: @and_or
|
36
42
|
)
|
37
43
|
params1 = @segment_factory.create(
|
38
44
|
name: @name1, conditions: [@condition]
|
39
45
|
)
|
40
|
-
@segment1 = @client.post_segment(params1)
|
41
|
-
rescue => e
|
46
|
+
@segment1 = @client.post_segment(params: params1)
|
47
|
+
rescue RestClient::ExceptionWithResponse => e
|
42
48
|
puts e.inspect
|
43
49
|
raise e
|
44
50
|
end
|
@@ -50,7 +56,7 @@ describe SendGrid4r::REST::Contacts::Segments do
|
|
50
56
|
params2 = @segment_factory.create(
|
51
57
|
name: @name2, conditions: [@condition]
|
52
58
|
)
|
53
|
-
segment = @client.post_segment(params2)
|
59
|
+
segment = @client.post_segment(params: params2)
|
54
60
|
expect(segment.id).to be_a(Fixnum)
|
55
61
|
expect(segment.name).to eq(@name2)
|
56
62
|
expect(segment.list_id).to eq(nil)
|
@@ -62,7 +68,7 @@ describe SendGrid4r::REST::Contacts::Segments do
|
|
62
68
|
expect(condition.operator).to eq(@operator)
|
63
69
|
expect(condition.and_or).to eq(nil)
|
64
70
|
expect(segment.recipient_count).to eq(0)
|
65
|
-
rescue => e
|
71
|
+
rescue RestClient::ExceptionWithResponse => e
|
66
72
|
puts e.inspect
|
67
73
|
raise e
|
68
74
|
end
|
@@ -76,7 +82,7 @@ describe SendGrid4r::REST::Contacts::Segments do
|
|
76
82
|
segment
|
77
83
|
).to be_a(SendGrid4r::REST::Contacts::Segments::Segment)
|
78
84
|
end
|
79
|
-
rescue => e
|
85
|
+
rescue RestClient::ExceptionWithResponse => e
|
80
86
|
puts e.inspect
|
81
87
|
raise e
|
82
88
|
end
|
@@ -84,7 +90,7 @@ describe SendGrid4r::REST::Contacts::Segments do
|
|
84
90
|
|
85
91
|
it '#get_segment' do
|
86
92
|
begin
|
87
|
-
segment = @client.get_segment(@segment1.id)
|
93
|
+
segment = @client.get_segment(segment_id: @segment1.id)
|
88
94
|
expect(segment.id).to eq(@segment1.id)
|
89
95
|
expect(segment.name).to eq(@segment1.name)
|
90
96
|
expect(segment.list_id).to eq(nil)
|
@@ -94,7 +100,7 @@ describe SendGrid4r::REST::Contacts::Segments do
|
|
94
100
|
expect(condition.operator).to eq(@operator)
|
95
101
|
expect(condition.and_or).to eq(nil)
|
96
102
|
expect(segment.recipient_count).to be_a(Fixnum)
|
97
|
-
rescue => e
|
103
|
+
rescue RestClient::ExceptionWithResponse => e
|
98
104
|
puts e.inspect
|
99
105
|
raise e
|
100
106
|
end
|
@@ -102,13 +108,15 @@ describe SendGrid4r::REST::Contacts::Segments do
|
|
102
108
|
|
103
109
|
it '#put_segment' do
|
104
110
|
begin
|
105
|
-
pending 'waiting sendgrid documentation update'
|
111
|
+
pending 'waiting for sendgrid documentation update'
|
106
112
|
edit_params = @segment_factory.create(
|
107
113
|
name: @edit_name1, conditions: [@condition]
|
108
114
|
)
|
109
|
-
edit_segment = @client.put_segment(
|
115
|
+
edit_segment = @client.put_segment(
|
116
|
+
segment_id: @segment1.id, params: edit_params
|
117
|
+
)
|
110
118
|
expect(edit_segment.name).to eq(@edit_name1)
|
111
|
-
rescue => e
|
119
|
+
rescue RestClient::ExceptionWithResponse => e
|
112
120
|
puts e.inspect
|
113
121
|
raise e
|
114
122
|
end
|
@@ -117,13 +125,15 @@ describe SendGrid4r::REST::Contacts::Segments do
|
|
117
125
|
it '#get_recipients_from_segment' do
|
118
126
|
begin
|
119
127
|
# list recipients from a single segment
|
120
|
-
recipients = @client.get_recipients_from_segment(
|
128
|
+
recipients = @client.get_recipients_from_segment(
|
129
|
+
segment_id: @segment1.id
|
130
|
+
)
|
121
131
|
recipients.recipients.each do |recipient|
|
122
132
|
expect(
|
123
133
|
recipient
|
124
134
|
).to be_a(SendGrid4r::REST::Contacts::Recipients::Recipient)
|
125
135
|
end
|
126
|
-
rescue => e
|
136
|
+
rescue RestClient::ExceptionWithResponse => e
|
127
137
|
puts e.inspect
|
128
138
|
raise e
|
129
139
|
end
|
@@ -132,8 +142,8 @@ describe SendGrid4r::REST::Contacts::Segments do
|
|
132
142
|
it '#delete_segment' do
|
133
143
|
begin
|
134
144
|
# delete the segment
|
135
|
-
@client.delete_segment(@segment1.id)
|
136
|
-
rescue => e
|
145
|
+
@client.delete_segment(segment_id: @segment1.id)
|
146
|
+
rescue RestClient::ExceptionWithResponse => e
|
137
147
|
puts e.inspect
|
138
148
|
raise e
|
139
149
|
end
|
@@ -145,7 +155,7 @@ describe SendGrid4r::REST::Contacts::Segments do
|
|
145
155
|
params2 = @segment_factory.create(
|
146
156
|
name: @name2, conditions: [@condition]
|
147
157
|
)
|
148
|
-
@client.post_segment(params2) do |resp, req, res|
|
158
|
+
@client.post_segment(params: params2) do |resp, req, res|
|
149
159
|
resp =
|
150
160
|
SendGrid4r::REST::Contacts::Segments.create_segment(
|
151
161
|
JSON.parse(resp)
|
@@ -169,7 +179,7 @@ describe SendGrid4r::REST::Contacts::Segments do
|
|
169
179
|
end
|
170
180
|
|
171
181
|
it '#get_segment' do
|
172
|
-
@client.get_segment(@segment1.id) do |resp, req, res|
|
182
|
+
@client.get_segment(segment_id: @segment1.id) do |resp, req, res|
|
173
183
|
resp =
|
174
184
|
SendGrid4r::REST::Contacts::Segments.create_segment(
|
175
185
|
JSON.parse(resp)
|
@@ -181,11 +191,13 @@ describe SendGrid4r::REST::Contacts::Segments do
|
|
181
191
|
end
|
182
192
|
|
183
193
|
it '#put_segment' do
|
184
|
-
pending 'waiting sendgrid documentation update'
|
194
|
+
pending 'waiting for sendgrid documentation update'
|
185
195
|
edit_params = @segment_factory.create(
|
186
196
|
name: @edit_name1, conditions: [@condition]
|
187
197
|
)
|
188
|
-
@client.put_segment(
|
198
|
+
@client.put_segment(
|
199
|
+
segment_id: @segment1.id, params: edit_params
|
200
|
+
) do |resp, req, res|
|
189
201
|
resp =
|
190
202
|
SendGrid4r::REST::Contacts::Segments.create_segment(
|
191
203
|
JSON.parse(resp)
|
@@ -197,7 +209,9 @@ describe SendGrid4r::REST::Contacts::Segments do
|
|
197
209
|
end
|
198
210
|
|
199
211
|
it '#get_recipients_from_segment' do
|
200
|
-
@client.get_recipients_from_segment(
|
212
|
+
@client.get_recipients_from_segment(
|
213
|
+
segment_id: @segment1.id
|
214
|
+
) do |resp, req, res|
|
201
215
|
resp =
|
202
216
|
SendGrid4r::REST::Contacts::Recipients.create_recipients(
|
203
217
|
JSON.parse(resp)
|
@@ -211,7 +225,7 @@ describe SendGrid4r::REST::Contacts::Segments do
|
|
211
225
|
end
|
212
226
|
|
213
227
|
it '#delete_segment' do
|
214
|
-
@client.delete_segment(@segment1.id) do |resp, req, res|
|
228
|
+
@client.delete_segment(segment_id: @segment1.id) do |resp, req, res|
|
215
229
|
expect(resp).to eq('')
|
216
230
|
expect(req).to be_a(RestClient::Request)
|
217
231
|
expect(res).to be_a(Net::HTTPNoContent)
|
@@ -308,7 +322,7 @@ describe SendGrid4r::REST::Contacts::Segments do
|
|
308
322
|
|
309
323
|
it '#post_segment' do
|
310
324
|
allow(client).to receive(:execute).and_return(segment)
|
311
|
-
actual = client.post_segment(nil)
|
325
|
+
actual = client.post_segment(params: nil)
|
312
326
|
expect(actual).to be_a(SendGrid4r::REST::Contacts::Segments::Segment)
|
313
327
|
end
|
314
328
|
|
@@ -320,25 +334,25 @@ describe SendGrid4r::REST::Contacts::Segments do
|
|
320
334
|
|
321
335
|
it '#get_segment' do
|
322
336
|
allow(client).to receive(:execute).and_return(segment)
|
323
|
-
actual = client.get_segment(0)
|
337
|
+
actual = client.get_segment(segment_id: 0)
|
324
338
|
expect(actual).to be_a(SendGrid4r::REST::Contacts::Segments::Segment)
|
325
339
|
end
|
326
340
|
|
327
341
|
it '#put_segment' do
|
328
342
|
allow(client).to receive(:execute).and_return(segment)
|
329
|
-
actual = client.put_segment(0, nil)
|
343
|
+
actual = client.put_segment(segment_id: 0, params: nil)
|
330
344
|
expect(actual).to be_a(SendGrid4r::REST::Contacts::Segments::Segment)
|
331
345
|
end
|
332
346
|
|
333
347
|
it '#get_recipients_from_segment' do
|
334
348
|
allow(client).to receive(:execute).and_return(recipients)
|
335
|
-
actual = client.get_recipients_from_segment(0)
|
349
|
+
actual = client.get_recipients_from_segment(segment_id: 0)
|
336
350
|
expect(actual).to be_a(SendGrid4r::REST::Contacts::Recipients::Recipients)
|
337
351
|
end
|
338
352
|
|
339
353
|
it '#delete_segment' do
|
340
354
|
allow(client).to receive(:execute).and_return('')
|
341
|
-
actual = client.delete_segment(0)
|
355
|
+
actual = client.delete_segment(segment_id: 0)
|
342
356
|
expect(actual).to eq('')
|
343
357
|
end
|
344
358
|
|
@@ -6,10 +6,8 @@ describe SendGrid4r::REST::EmailActivity do
|
|
6
6
|
before do
|
7
7
|
begin
|
8
8
|
Dotenv.load
|
9
|
-
@client = SendGrid4r::Client.new(
|
10
|
-
|
11
|
-
password: ENV['SENDGRID_PASSWORD'])
|
12
|
-
rescue => e
|
9
|
+
@client = SendGrid4r::Client.new(api_key: ENV['API_KEY'])
|
10
|
+
rescue RestClient::ExceptionWithResponse => e
|
13
11
|
puts e.inspect
|
14
12
|
raise e
|
15
13
|
end
|
@@ -22,7 +20,7 @@ describe SendGrid4r::REST::EmailActivity do
|
|
22
20
|
activities.each do |activity|
|
23
21
|
expect(activity).to be_a(SendGrid4r::REST::EmailActivity::Activity)
|
24
22
|
end
|
25
|
-
rescue => e
|
23
|
+
rescue RestClient::ExceptionWithResponse => e
|
26
24
|
puts e.inspect
|
27
25
|
raise e
|
28
26
|
end
|
@@ -34,7 +32,7 @@ describe SendGrid4r::REST::EmailActivity do
|
|
34
32
|
activities.each do |activity|
|
35
33
|
expect(activity).to be_a(SendGrid4r::REST::EmailActivity::Activity)
|
36
34
|
end
|
37
|
-
rescue => e
|
35
|
+
rescue RestClient::ExceptionWithResponse => e
|
38
36
|
puts e.inspect
|
39
37
|
raise e
|
40
38
|
end
|
@@ -50,7 +48,7 @@ describe SendGrid4r::REST::EmailActivity do
|
|
50
48
|
expect(activity).to be_a(SendGrid4r::REST::EmailActivity::Activity)
|
51
49
|
expect(activity.event).to eq('drop')
|
52
50
|
end
|
53
|
-
rescue => e
|
51
|
+
rescue RestClient::ExceptionWithResponse => e
|
54
52
|
puts e.inspect
|
55
53
|
raise e
|
56
54
|
end
|
@@ -78,7 +76,7 @@ describe SendGrid4r::REST::EmailActivity do
|
|
78
76
|
activities.each do |activity|
|
79
77
|
expect(activity).to be_a(SendGrid4r::REST::EmailActivity::Activity)
|
80
78
|
end
|
81
|
-
rescue => e
|
79
|
+
rescue RestClient::ExceptionWithResponse => e
|
82
80
|
puts e.inspect
|
83
81
|
raise e
|
84
82
|
end
|
@@ -86,6 +84,7 @@ describe SendGrid4r::REST::EmailActivity do
|
|
86
84
|
|
87
85
|
it '#get_email_activities with start_time and end_time' do
|
88
86
|
begin
|
87
|
+
pending('unknown field')
|
89
88
|
start_time = Time.local(2015, 5, 20, 12, 23, 45)
|
90
89
|
end_time = Time.local(2015, 5, 23, 12, 23, 45)
|
91
90
|
activities = @client.get_email_activities(
|
@@ -96,24 +95,12 @@ describe SendGrid4r::REST::EmailActivity do
|
|
96
95
|
expect(activity).to be_a(SendGrid4r::REST::EmailActivity::Activity)
|
97
96
|
puts activity.inspect
|
98
97
|
end
|
99
|
-
rescue => e
|
98
|
+
rescue RestClient::ExceptionWithResponse => e
|
100
99
|
puts e.inspect
|
101
100
|
raise e
|
102
101
|
end
|
103
102
|
end
|
104
103
|
end
|
105
|
-
|
106
|
-
context 'with block call' do
|
107
|
-
it '#get_email_activities' do
|
108
|
-
@client.get_api_keys do |resp, req, res|
|
109
|
-
resp =
|
110
|
-
SendGrid4r::REST::ApiKeys.create_api_keys(JSON.parse(resp))
|
111
|
-
expect(resp).to be_a(SendGrid4r::REST::ApiKeys::ApiKeys)
|
112
|
-
expect(req).to be_a(RestClient::Request)
|
113
|
-
expect(res).to be_a(Net::HTTPOK)
|
114
|
-
end
|
115
|
-
end
|
116
|
-
end
|
117
104
|
end
|
118
105
|
|
119
106
|
describe 'unit test', :ut do
|
@@ -5,9 +5,7 @@ describe SendGrid4r::REST::Ips::Addresses 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 'account is free' do
|
@@ -15,11 +13,11 @@ describe SendGrid4r::REST::Ips::Addresses do
|
|
15
13
|
it 'raise error' do
|
16
14
|
begin
|
17
15
|
expect do
|
18
|
-
@client.get_ip('10.10.10.10').to raise_error(
|
16
|
+
@client.get_ip(ip: '10.10.10.10').to raise_error(
|
19
17
|
RestClient::Forbidden
|
20
18
|
)
|
21
19
|
end
|
22
|
-
rescue => e
|
20
|
+
rescue RestClient::ExceptionWithResponse => e
|
23
21
|
puts e.inspect
|
24
22
|
raise e
|
25
23
|
end
|
@@ -32,16 +30,14 @@ describe SendGrid4r::REST::Ips::Addresses do
|
|
32
30
|
|
33
31
|
before do
|
34
32
|
begin
|
35
|
-
@client = SendGrid4r::Client.new(
|
36
|
-
username: ENV['SILVER_SENDGRID_USERNAME'],
|
37
|
-
password: ENV['SILVER_SENDGRID_PASSWORD'])
|
33
|
+
@client = SendGrid4r::Client.new(api_key: ENV['SILVER_API_KEY'])
|
38
34
|
# refresh the pool
|
39
35
|
pools = @client.get_pools
|
40
36
|
pools.each do |pool|
|
41
|
-
@client.delete_pool(TEST_POOL) if pool.name == TEST_POOL
|
37
|
+
@client.delete_pool(name: TEST_POOL) if pool.name == TEST_POOL
|
42
38
|
end
|
43
|
-
@client.post_pool(TEST_POOL)
|
44
|
-
rescue => e
|
39
|
+
@client.post_pool(name: TEST_POOL)
|
40
|
+
rescue RestClient::ExceptionWithResponse => e
|
45
41
|
puts e.inspect
|
46
42
|
raise e
|
47
43
|
end
|
@@ -57,7 +53,7 @@ describe SendGrid4r::REST::Ips::Addresses do
|
|
57
53
|
expect(ip.ip).to be_a(String)
|
58
54
|
expect(ip.pools).to be_a(Array)
|
59
55
|
expect(ip.warmup ? true : true).to eq(true)
|
60
|
-
rescue => e
|
56
|
+
rescue RestClient::ExceptionWithResponse => e
|
61
57
|
puts e.inspect
|
62
58
|
raise e
|
63
59
|
end
|
@@ -68,7 +64,7 @@ describe SendGrid4r::REST::Ips::Addresses do
|
|
68
64
|
ips = @client.get_ips_assigned
|
69
65
|
expect(ips.length).to be > 0
|
70
66
|
expect(ips[0]).to be_a(SendGrid4r::REST::Ips::Addresses::Address)
|
71
|
-
rescue => e
|
67
|
+
rescue RestClient::ExceptionWithResponse => e
|
72
68
|
puts e.inspect
|
73
69
|
raise e
|
74
70
|
end
|
@@ -78,9 +74,9 @@ describe SendGrid4r::REST::Ips::Addresses do
|
|
78
74
|
begin
|
79
75
|
ips = @client.get_ips_assigned
|
80
76
|
expect(
|
81
|
-
@client.get_ip(ips[0].ip)
|
77
|
+
@client.get_ip(ip: ips[0].ip)
|
82
78
|
).to be_a(SendGrid4r::REST::Ips::Addresses::Address)
|
83
|
-
rescue => e
|
79
|
+
rescue RestClient::ExceptionWithResponse => e
|
84
80
|
puts e.inspect
|
85
81
|
raise e
|
86
82
|
end
|
@@ -89,74 +85,19 @@ describe SendGrid4r::REST::Ips::Addresses do
|
|
89
85
|
it '#post_ip_to_pool' do
|
90
86
|
begin
|
91
87
|
ips = @client.get_ips_assigned
|
92
|
-
actual = @client.post_ip_to_pool(
|
88
|
+
actual = @client.post_ip_to_pool(
|
89
|
+
pool_name: TEST_POOL, ip: ips[0].ip
|
90
|
+
)
|
93
91
|
expect(actual.ip).to eq(ips[0].ip)
|
94
92
|
expect(actual.pools).to include(TEST_POOL)
|
95
93
|
expect(actual.pools).to be_a(Array)
|
96
|
-
@client.delete_ip_from_pool(TEST_POOL, ips[0].ip)
|
97
|
-
rescue => e
|
94
|
+
@client.delete_ip_from_pool(pool_name: TEST_POOL, ip: ips[0].ip)
|
95
|
+
rescue RestClient::ExceptionWithResponse => e
|
98
96
|
puts e.inspect
|
99
97
|
raise e
|
100
98
|
end
|
101
99
|
end
|
102
100
|
end
|
103
|
-
|
104
|
-
context 'with block call' do
|
105
|
-
it '#get_ips' do
|
106
|
-
@client.get_ips do |resp, req, res|
|
107
|
-
resp =
|
108
|
-
SendGrid4r::REST::Ips::Addresses.create_addresses(
|
109
|
-
JSON.parse(resp)
|
110
|
-
)
|
111
|
-
expect(resp).to be_a(Array)
|
112
|
-
expect(req).to be_a(RestClient::Request)
|
113
|
-
expect(res).to be_a(Net::HTTPOK)
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
it '#get_ips_assigned' do
|
118
|
-
@client.get_ips_assigned do |resp, req, res|
|
119
|
-
resp =
|
120
|
-
SendGrid4r::REST::Ips::Addresses.create_addresses(
|
121
|
-
JSON.parse(resp)
|
122
|
-
)
|
123
|
-
expect(resp).to be_a(Array)
|
124
|
-
expect(req).to be_a(RestClient::Request)
|
125
|
-
expect(res).to be_a(Net::HTTPOK)
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
it '#get_ip' do
|
130
|
-
ips = @client.get_ips_assigned
|
131
|
-
@client.get_ip(ips[0].ip) do |resp, req, res|
|
132
|
-
resp =
|
133
|
-
SendGrid4r::REST::Ips::Addresses.create_address(
|
134
|
-
JSON.parse(resp)
|
135
|
-
)
|
136
|
-
expect(resp).to be_a(SendGrid4r::REST::Ips::Addresses::Address)
|
137
|
-
expect(req).to be_a(RestClient::Request)
|
138
|
-
expect(res).to be_a(Net::HTTPOK)
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
|
-
it '#post_ip_to_pool' do
|
143
|
-
ips = @client.get_ips_assigned
|
144
|
-
@client.post_ip_to_pool(TEST_POOL, ips[0].ip) do |resp, req, res|
|
145
|
-
resp =
|
146
|
-
SendGrid4r::REST::Ips::Addresses.create_address(
|
147
|
-
JSON.parse(resp)
|
148
|
-
)
|
149
|
-
expect(resp).to be_a(SendGrid4r::REST::Ips::Addresses::Address)
|
150
|
-
expect(req).to be_a(RestClient::Request)
|
151
|
-
expect(res).to be_a(Net::HTTPCreated)
|
152
|
-
end
|
153
|
-
@client.delete_ip_from_pool(TEST_POOL, ips[0].ip) do |resp, req, res|
|
154
|
-
expect(resp).to eq('')
|
155
|
-
expect(req).to be_a(RestClient::Request)
|
156
|
-
expect(res).to be_a(Net::HTTPNoContent)
|
157
|
-
end
|
158
|
-
end
|
159
|
-
end
|
160
101
|
end
|
161
102
|
|
162
103
|
describe 'unit test', :ut do
|
@@ -213,13 +154,13 @@ describe SendGrid4r::REST::Ips::Addresses do
|
|
213
154
|
|
214
155
|
it '#get_ip' do
|
215
156
|
allow(client).to receive(:execute).and_return(address)
|
216
|
-
actual = client.get_ip('')
|
157
|
+
actual = client.get_ip(ip: '')
|
217
158
|
expect(actual).to be_a(SendGrid4r::REST::Ips::Addresses::Address)
|
218
159
|
end
|
219
160
|
|
220
161
|
it '#post_ip_to_pool' do
|
221
162
|
allow(client).to receive(:execute).and_return(address)
|
222
|
-
actual = client.post_ip_to_pool('', '')
|
163
|
+
actual = client.post_ip_to_pool(pool_name: '', ip: '')
|
223
164
|
expect(actual).to be_a(SendGrid4r::REST::Ips::Addresses::Address)
|
224
165
|
end
|
225
166
|
|
data/spec/rest/ips/pools_spec.rb
CHANGED
@@ -6,10 +6,7 @@ describe SendGrid4r::REST::Ips::Pools do
|
|
6
6
|
before do
|
7
7
|
begin
|
8
8
|
Dotenv.load
|
9
|
-
@client = SendGrid4r::Client.new(
|
10
|
-
username: ENV['SILVER_SENDGRID_USERNAME'],
|
11
|
-
password: ENV['SILVER_SENDGRID_PASSWORD'])
|
12
|
-
|
9
|
+
@client = SendGrid4r::Client.new(api_key: ENV['SILVER_API_KEY'])
|
13
10
|
@pool_name1 = 'pool_test1'
|
14
11
|
@pool_name2 = 'pool_test2'
|
15
12
|
@pool_edit1 = 'pool_edit1'
|
@@ -17,13 +14,13 @@ describe SendGrid4r::REST::Ips::Pools do
|
|
17
14
|
# clean up test env
|
18
15
|
pools = @client.get_pools
|
19
16
|
pools.each do |pool|
|
20
|
-
@client.delete_pool(pool.name) if pool.name == @pool_name1
|
21
|
-
@client.delete_pool(pool.name) if pool.name == @pool_name2
|
22
|
-
@client.delete_pool(pool.name) if pool.name == @pool_edit1
|
17
|
+
@client.delete_pool(name: pool.name) if pool.name == @pool_name1
|
18
|
+
@client.delete_pool(name: pool.name) if pool.name == @pool_name2
|
19
|
+
@client.delete_pool(name: pool.name) if pool.name == @pool_edit1
|
23
20
|
end
|
24
21
|
# post a pool
|
25
|
-
@client.post_pool(@pool_name1)
|
26
|
-
rescue => e
|
22
|
+
@client.post_pool(name: @pool_name1)
|
23
|
+
rescue RestClient::ExceptionWithResponse => e
|
27
24
|
puts e.inspect
|
28
25
|
raise e
|
29
26
|
end
|
@@ -33,9 +30,9 @@ describe SendGrid4r::REST::Ips::Pools do
|
|
33
30
|
context 'without block call' do
|
34
31
|
it '#post_pool' do
|
35
32
|
begin
|
36
|
-
new_pool = @client.post_pool(@pool_name2)
|
33
|
+
new_pool = @client.post_pool(name: @pool_name2)
|
37
34
|
expect(new_pool.name).to eq(@pool_name2)
|
38
|
-
rescue => e
|
35
|
+
rescue RestClient::ExceptionWithResponse => e
|
39
36
|
puts e.inspect
|
40
37
|
raise e
|
41
38
|
end
|
@@ -49,7 +46,7 @@ describe SendGrid4r::REST::Ips::Pools do
|
|
49
46
|
expect(pool).to be_a(SendGrid4r::REST::Ips::Pools::Pool)
|
50
47
|
expect(pool.name).to be_a(String)
|
51
48
|
end
|
52
|
-
rescue => e
|
49
|
+
rescue RestClient::ExceptionWithResponse => e
|
53
50
|
puts e.inspect
|
54
51
|
raise e
|
55
52
|
end
|
@@ -57,11 +54,11 @@ describe SendGrid4r::REST::Ips::Pools do
|
|
57
54
|
|
58
55
|
it '#get_pool' do
|
59
56
|
begin
|
60
|
-
pool = @client.get_pool(@pool_name1)
|
57
|
+
pool = @client.get_pool(name: @pool_name1)
|
61
58
|
expect(pool).to be_a(SendGrid4r::REST::Ips::Pools::Pool)
|
62
59
|
expect(pool.pool_name).to eq(@pool_name1)
|
63
60
|
expect(pool.ips).to be_a(Array)
|
64
|
-
rescue => e
|
61
|
+
rescue RestClient::ExceptionWithResponse => e
|
65
62
|
puts e.inspect
|
66
63
|
raise e
|
67
64
|
end
|
@@ -69,9 +66,11 @@ describe SendGrid4r::REST::Ips::Pools do
|
|
69
66
|
|
70
67
|
it '#put_pool' do
|
71
68
|
begin
|
72
|
-
edit_pool = @client.put_pool(
|
69
|
+
edit_pool = @client.put_pool(
|
70
|
+
name: @pool_name1, new_name: @pool_edit1
|
71
|
+
)
|
73
72
|
expect(edit_pool.name).to eq(@pool_edit1)
|
74
|
-
rescue => e
|
73
|
+
rescue RestClient::ExceptionWithResponse => e
|
75
74
|
puts e.inspect
|
76
75
|
raise e
|
77
76
|
end
|
@@ -79,71 +78,13 @@ describe SendGrid4r::REST::Ips::Pools do
|
|
79
78
|
|
80
79
|
it '#delete_pool' do
|
81
80
|
begin
|
82
|
-
@client.delete_pool(@pool_name1)
|
83
|
-
rescue => e
|
81
|
+
@client.delete_pool(name: @pool_name1)
|
82
|
+
rescue RestClient::ExceptionWithResponse => e
|
84
83
|
puts e.inspect
|
85
84
|
raise e
|
86
85
|
end
|
87
86
|
end
|
88
87
|
end
|
89
|
-
|
90
|
-
context 'with block call' do
|
91
|
-
it '#post_pool' do
|
92
|
-
@client.post_pool(@pool_name2) do |resp, req, res|
|
93
|
-
resp =
|
94
|
-
SendGrid4r::REST::Ips::Pools.create_pool(
|
95
|
-
JSON.parse(resp)
|
96
|
-
)
|
97
|
-
expect(resp).to be_a(SendGrid4r::REST::Ips::Pools::Pool)
|
98
|
-
expect(req).to be_a(RestClient::Request)
|
99
|
-
expect(res).to be_a(Net::HTTPCreated)
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
it '#get_pools' do
|
104
|
-
@client.get_pools do |resp, req, res|
|
105
|
-
resp =
|
106
|
-
SendGrid4r::REST::Ips::Pools.create_pools(
|
107
|
-
JSON.parse(resp)
|
108
|
-
)
|
109
|
-
expect(resp).to be_a(Array)
|
110
|
-
expect(req).to be_a(RestClient::Request)
|
111
|
-
expect(res).to be_a(Net::HTTPOK)
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
it '#get_pool' do
|
116
|
-
@client.get_pool(@pool_name1) do |resp, req, res|
|
117
|
-
resp =
|
118
|
-
SendGrid4r::REST::Ips::Pools.create_pool(
|
119
|
-
JSON.parse(resp)
|
120
|
-
)
|
121
|
-
expect(resp).to be_a(SendGrid4r::REST::Ips::Pools::Pool)
|
122
|
-
expect(req).to be_a(RestClient::Request)
|
123
|
-
expect(res).to be_a(Net::HTTPOK)
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
it '#put_pool' do
|
128
|
-
@client.put_pool(@pool_name1, @pool_edit1) do |resp, req, res|
|
129
|
-
resp =
|
130
|
-
SendGrid4r::REST::Ips::Pools.create_pool(
|
131
|
-
JSON.parse(resp)
|
132
|
-
)
|
133
|
-
expect(resp).to be_a(SendGrid4r::REST::Ips::Pools::Pool)
|
134
|
-
expect(req).to be_a(RestClient::Request)
|
135
|
-
expect(res).to be_a(Net::HTTPOK)
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
it '#delete_pool' do
|
140
|
-
@client.delete_pool(@pool_name1) do |resp, req, res|
|
141
|
-
expect(resp).to eq('')
|
142
|
-
expect(req).to be_a(RestClient::Request)
|
143
|
-
expect(res).to be_a(Net::HTTPNoContent)
|
144
|
-
end
|
145
|
-
end
|
146
|
-
end
|
147
88
|
end
|
148
89
|
end
|
149
90
|
|
@@ -182,7 +123,7 @@ describe SendGrid4r::REST::Ips::Pools do
|
|
182
123
|
|
183
124
|
it '#post_pool' do
|
184
125
|
allow(client).to receive(:execute).and_return(pool)
|
185
|
-
actual = client.post_pool('')
|
126
|
+
actual = client.post_pool(name: '')
|
186
127
|
expect(actual).to be_a(SendGrid4r::REST::Ips::Pools::Pool)
|
187
128
|
end
|
188
129
|
|
@@ -197,19 +138,19 @@ describe SendGrid4r::REST::Ips::Pools do
|
|
197
138
|
|
198
139
|
it '#get_pool' do
|
199
140
|
allow(client).to receive(:execute).and_return(pool)
|
200
|
-
actual = client.get_pool('')
|
141
|
+
actual = client.get_pool(name: '')
|
201
142
|
expect(actual).to be_a(SendGrid4r::REST::Ips::Pools::Pool)
|
202
143
|
end
|
203
144
|
|
204
145
|
it '#put_pool' do
|
205
146
|
allow(client).to receive(:execute).and_return(pool)
|
206
|
-
actual = client.put_pool('', '')
|
147
|
+
actual = client.put_pool(name: '', new_name: '')
|
207
148
|
expect(actual).to be_a(SendGrid4r::REST::Ips::Pools::Pool)
|
208
149
|
end
|
209
150
|
|
210
151
|
it '#delete_pool' do
|
211
152
|
allow(client).to receive(:execute).and_return('')
|
212
|
-
actual = client.delete_pool('')
|
153
|
+
actual = client.delete_pool(name: '')
|
213
154
|
expect(actual).to eq('')
|
214
155
|
end
|
215
156
|
|