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.
- checksums.yaml +4 -4
- data/.env.example +5 -0
- data/.rubocop.yml +8 -8
- data/README.md +2 -0
- data/lib/auth.rb +5 -2
- data/lib/client.rb +4 -2
- data/lib/sendgrid4r/factory/version_factory.rb +1 -1
- data/lib/sendgrid4r/rest/api.rb +4 -0
- data/lib/sendgrid4r/rest/api_keys/api_keys.rb +73 -0
- data/lib/sendgrid4r/rest/asm/asm.rb +28 -0
- data/lib/sendgrid4r/rest/asm/global_suppressions.rb +12 -8
- data/lib/sendgrid4r/rest/asm/groups.rb +29 -22
- data/lib/sendgrid4r/rest/asm/suppressions.rb +25 -15
- data/lib/sendgrid4r/rest/categories/categories.rb +19 -9
- data/lib/sendgrid4r/rest/contacts/custom_fields.rb +14 -8
- data/lib/sendgrid4r/rest/contacts/lists.rb +32 -20
- data/lib/sendgrid4r/rest/contacts/recipients.rb +42 -31
- data/lib/sendgrid4r/rest/contacts/reserved_fields.rb +6 -2
- data/lib/sendgrid4r/rest/contacts/segments.rb +22 -12
- data/lib/sendgrid4r/rest/ips/addresses.rb +36 -22
- data/lib/sendgrid4r/rest/ips/pools.rb +31 -16
- data/lib/sendgrid4r/rest/ips/warmup.rb +34 -15
- data/lib/sendgrid4r/rest/request.rb +33 -19
- data/lib/sendgrid4r/rest/settings/enforced_tls.rb +12 -5
- data/lib/sendgrid4r/rest/stats/advanced.rb +73 -25
- data/lib/sendgrid4r/rest/stats/category.rb +11 -6
- data/lib/sendgrid4r/rest/stats/global.rb +6 -4
- data/lib/sendgrid4r/rest/stats/parse.rb +10 -4
- data/lib/sendgrid4r/rest/stats/stats.rb +13 -18
- data/lib/sendgrid4r/rest/stats/subuser.rb +10 -6
- data/lib/sendgrid4r/rest/templates/templates.rb +23 -16
- data/lib/sendgrid4r/rest/templates/versions.rb +39 -36
- data/lib/sendgrid4r/version.rb +1 -1
- data/spec/api_keys/api_keys_spec.rb +152 -0
- data/spec/asm/asm_spec.rb +33 -0
- data/spec/asm/global_suppressions_spec.rb +111 -45
- data/spec/asm/groups_spec.rb +172 -48
- data/spec/asm/suppressions_spec.rb +180 -54
- data/spec/categories/categories_spec.rb +81 -25
- data/spec/client_spec.rb +11 -4
- data/spec/contacts/custom_fields_spec.rb +135 -44
- data/spec/contacts/lists_spec.rb +314 -84
- data/spec/contacts/recipients_spec.rb +337 -92
- data/spec/contacts/reserved_fields_spec.rb +80 -60
- data/spec/contacts/segments_spec.rb +219 -88
- data/spec/factory/condition_factory_spec.rb +12 -12
- data/spec/factory/segment_factory_spec.rb +19 -19
- data/spec/factory/version_factory_spec.rb +6 -6
- data/spec/ips/addresses_spec.rb +177 -84
- data/spec/ips/pools_spec.rb +190 -34
- data/spec/ips/warmup_spec.rb +106 -38
- data/spec/settings/enforced_tls_spec.rb +76 -18
- data/spec/stats/advanced_spec.rb +373 -196
- data/spec/stats/category_spec.rb +133 -71
- data/spec/stats/global_spec.rb +74 -47
- data/spec/stats/parse_spec.rb +46 -29
- data/spec/stats/stats_spec.rb +246 -0
- data/spec/stats/subuser_spec.rb +99 -54
- data/spec/templates/templates_spec.rb +219 -54
- data/spec/templates/versions_spec.rb +171 -67
- metadata +10 -2
data/spec/ips/addresses_spec.rb
CHANGED
@@ -1,116 +1,209 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require File.dirname(__FILE__) + '/../spec_helper'
|
3
3
|
|
4
|
-
describe
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
context 'if account is free' do
|
10
|
-
before :all do
|
4
|
+
describe SendGrid4r::REST::Ips::Addresses do
|
5
|
+
describe 'integration test' do
|
6
|
+
before do
|
7
|
+
Dotenv.load
|
11
8
|
@client = SendGrid4r::Client.new(
|
12
|
-
ENV['SENDGRID_USERNAME'],
|
9
|
+
username: ENV['SENDGRID_USERNAME'],
|
10
|
+
password: ENV['SENDGRID_PASSWORD'])
|
13
11
|
end
|
14
12
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
13
|
+
context 'account is free' do
|
14
|
+
describe '#get_ip' do
|
15
|
+
it 'raise error' do
|
16
|
+
begin
|
17
|
+
expect do
|
18
|
+
@client.get_ip('10.10.10.10').to raise_error(
|
19
|
+
RestClient::Forbidden
|
20
|
+
)
|
21
|
+
end
|
22
|
+
rescue => e
|
23
|
+
puts e.inspect
|
24
|
+
raise e
|
25
|
+
end
|
26
|
+
end
|
20
27
|
end
|
21
28
|
end
|
22
29
|
|
23
|
-
|
24
|
-
|
30
|
+
context 'account is silver' do
|
31
|
+
TEST_POOL = 'test_pool'
|
32
|
+
|
33
|
+
before do
|
25
34
|
begin
|
26
|
-
|
27
|
-
|
35
|
+
@client = SendGrid4r::Client.new(
|
36
|
+
username: ENV['SILVER_SENDGRID_USERNAME'],
|
37
|
+
password: ENV['SILVER_SENDGRID_PASSWORD'])
|
38
|
+
# refresh the pool
|
39
|
+
pools = @client.get_pools
|
40
|
+
pools.each do |pool|
|
41
|
+
@client.delete_pool(TEST_POOL) if pool.name == TEST_POOL
|
28
42
|
end
|
43
|
+
@client.post_pool(TEST_POOL)
|
29
44
|
rescue => e
|
30
45
|
puts e.inspect
|
31
46
|
raise e
|
32
47
|
end
|
33
48
|
end
|
34
|
-
end
|
35
|
-
end
|
36
49
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
50
|
+
context 'without block call' do
|
51
|
+
it '#get_ips' do
|
52
|
+
begin
|
53
|
+
ips = @client.get_ips
|
54
|
+
expect(ips.length).to be > 0
|
55
|
+
ip = ips[0]
|
56
|
+
expect(ip).to be_a(SendGrid4r::REST::Ips::Addresses::Address)
|
57
|
+
expect(ip.ip).to be_a(String)
|
58
|
+
expect(ip.pools).to be_a(Array)
|
59
|
+
expect(ip.warmup ? true : true).to eq(true)
|
60
|
+
rescue => e
|
61
|
+
puts e.inspect
|
62
|
+
raise e
|
63
|
+
end
|
47
64
|
end
|
48
|
-
@client.post_pool(TEST_POOL)
|
49
|
-
# ips = @client.get_ips
|
50
|
-
# @client.delete_ip_from_pool(TEST_POOL, ips[0].ip)
|
51
|
-
rescue => e
|
52
|
-
puts e.inspect
|
53
|
-
raise e
|
54
|
-
end
|
55
|
-
end
|
56
65
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
66
|
+
it '#get_ips_assigned' do
|
67
|
+
begin
|
68
|
+
ips = @client.get_ips_assigned
|
69
|
+
expect(ips.length).to be > 0
|
70
|
+
expect(ips[0]).to be_a(SendGrid4r::REST::Ips::Addresses::Address)
|
71
|
+
rescue => e
|
72
|
+
puts e.inspect
|
73
|
+
raise e
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
it '#get_ip' do
|
78
|
+
begin
|
79
|
+
ips = @client.get_ips_assigned
|
80
|
+
expect(
|
81
|
+
@client.get_ip(ips[0].ip)
|
82
|
+
).to be_a(SendGrid4r::REST::Ips::Addresses::Address)
|
83
|
+
rescue => e
|
84
|
+
puts e.inspect
|
85
|
+
raise e
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
it '#post_ip_to_pool' do
|
90
|
+
begin
|
91
|
+
ips = @client.get_ips_assigned
|
92
|
+
actual = @client.post_ip_to_pool(TEST_POOL, ips[0].ip)
|
93
|
+
expect(actual.ip).to eq(ips[0].ip)
|
94
|
+
expect(actual.pools).to include(TEST_POOL)
|
95
|
+
expect(actual.pools).to be_a(Array)
|
96
|
+
@client.delete_ip_from_pool(TEST_POOL, ips[0].ip)
|
97
|
+
rescue => e
|
98
|
+
puts e.inspect
|
99
|
+
raise e
|
100
|
+
end
|
101
|
+
end
|
67
102
|
end
|
68
|
-
end
|
69
103
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
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
|
75
159
|
end
|
76
160
|
end
|
77
161
|
|
78
|
-
describe '
|
79
|
-
it '
|
80
|
-
|
81
|
-
|
162
|
+
describe 'unit test' do
|
163
|
+
it 'creates addresses instance' do
|
164
|
+
json =
|
165
|
+
'['\
|
166
|
+
'{'\
|
167
|
+
'"ip":"000.00.00.0",'\
|
168
|
+
'"pools":["new_test5"],'\
|
169
|
+
'"warmup":true,'\
|
170
|
+
'"start_date":1409616000,'\
|
171
|
+
'"subusers": ["username1", "username2"],'\
|
172
|
+
'"rdns": "01.email.test.com",'\
|
173
|
+
'"pools": ["pool1", "pool2"]'\
|
174
|
+
'}'\
|
175
|
+
']'
|
176
|
+
hash = JSON.parse(json)
|
177
|
+
actual = SendGrid4r::REST::Ips::Addresses.create_addresses(hash)
|
178
|
+
expect(actual).to be_a(Array)
|
179
|
+
actual.each do |address|
|
82
180
|
expect(
|
83
|
-
|
84
|
-
).to
|
85
|
-
rescue => e
|
86
|
-
puts e.inspect
|
87
|
-
raise e
|
181
|
+
address
|
182
|
+
).to be_a(SendGrid4r::REST::Ips::Addresses::Address)
|
88
183
|
end
|
89
184
|
end
|
90
|
-
end
|
91
185
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
186
|
+
it 'creates address instance' do
|
187
|
+
json =
|
188
|
+
'{'\
|
189
|
+
'"ip": "000.00.00.0",'\
|
190
|
+
'"pools": ['\
|
191
|
+
'"test1"'\
|
192
|
+
'],'\
|
193
|
+
'"start_date": 1409616000,'\
|
194
|
+
'"warmup": true'\
|
195
|
+
'}'
|
196
|
+
hash = JSON.parse(json)
|
197
|
+
actual = SendGrid4r::REST::Ips::Addresses.create_address(hash)
|
198
|
+
expect(actual).to be_a(SendGrid4r::REST::Ips::Addresses::Address)
|
199
|
+
expect(actual.ip).to eq('000.00.00.0')
|
200
|
+
expect(actual.pools).to be_a(Array)
|
201
|
+
actual.pools.each do |pool|
|
202
|
+
expect(pool).to eq('test1')
|
203
|
+
end
|
204
|
+
expect(actual.start_date).to eq(Time.at(1409616000))
|
205
|
+
expect(actual.warmup).to eq(true)
|
99
206
|
end
|
100
207
|
end
|
101
|
-
|
102
|
-
# Could not test because POST an IP to a pool takes 60 sec
|
103
|
-
# describe '#delete_ip_from_pool' do
|
104
|
-
# it 'delete ip from pool successfully' do
|
105
|
-
# begin
|
106
|
-
# ips = @client.get_ips
|
107
|
-
# @client.post_ip_to_pool(TEST_POOL, ips[0].ip)
|
108
|
-
# @client.delete_ip_from_pool(TEST_POOL, ips[0].ip)
|
109
|
-
# rescue => e
|
110
|
-
# puts e.inspect
|
111
|
-
# raise e
|
112
|
-
# end
|
113
|
-
# end
|
114
|
-
# end
|
115
208
|
end
|
116
209
|
end
|
data/spec/ips/pools_spec.rb
CHANGED
@@ -1,43 +1,199 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require File.dirname(__FILE__) + '/../spec_helper'
|
3
3
|
|
4
|
-
describe
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
4
|
+
describe SendGrid4r::REST::Ips::Pools do
|
5
|
+
describe 'integration test' do
|
6
|
+
before do
|
7
|
+
begin
|
8
|
+
Dotenv.load
|
9
|
+
@client = SendGrid4r::Client.new(
|
10
|
+
username: ENV['SILVER_SENDGRID_USERNAME'],
|
11
|
+
password: ENV['SILVER_SENDGRID_PASSWORD'])
|
12
|
+
|
13
|
+
@pool_name1 = 'pool_test1'
|
14
|
+
@pool_name2 = 'pool_test2'
|
15
|
+
@pool_edit1 = 'pool_edit1'
|
16
|
+
|
17
|
+
# clean up test env
|
18
|
+
pools = @client.get_pools
|
19
|
+
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
|
23
|
+
end
|
24
|
+
# post a pool
|
25
|
+
@client.post_pool(@pool_name1)
|
26
|
+
rescue => e
|
27
|
+
puts e.inspect
|
28
|
+
raise e
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context 'account is silver' do
|
33
|
+
context 'without block call' do
|
34
|
+
it '#post_pool' do
|
35
|
+
begin
|
36
|
+
new_pool = @client.post_pool(@pool_name2)
|
37
|
+
expect(new_pool.name).to eq(@pool_name2)
|
38
|
+
rescue => e
|
39
|
+
puts e.inspect
|
40
|
+
raise e
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
it '#get_pools' do
|
45
|
+
begin
|
46
|
+
pools = @client.get_pools
|
47
|
+
expect(pools.length).to be > 0
|
48
|
+
pools.each do |pool|
|
49
|
+
expect(pool).to be_a(SendGrid4r::REST::Ips::Pools::Pool)
|
50
|
+
expect(pool.name).to be_a(String)
|
51
|
+
end
|
52
|
+
rescue => e
|
53
|
+
puts e.inspect
|
54
|
+
raise e
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
it '#get_pool' do
|
59
|
+
begin
|
60
|
+
pool = @client.get_pool(@pool_name1)
|
61
|
+
expect(pool).to be_a(SendGrid4r::REST::Ips::Pools::Pool)
|
62
|
+
expect(pool.pool_name).to eq(@pool_name1)
|
63
|
+
expect(pool.ips).to be_a(Array)
|
64
|
+
rescue => e
|
65
|
+
puts e.inspect
|
66
|
+
raise e
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
it '#put_pool' do
|
71
|
+
begin
|
72
|
+
edit_pool = @client.put_pool(@pool_name1, @pool_edit1)
|
73
|
+
expect(edit_pool.name).to eq(@pool_edit1)
|
74
|
+
rescue => e
|
75
|
+
puts e.inspect
|
76
|
+
raise e
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
it '#delete_pool' do
|
81
|
+
begin
|
82
|
+
@client.delete_pool(@pool_name1)
|
83
|
+
rescue => e
|
84
|
+
puts e.inspect
|
85
|
+
raise e
|
86
|
+
end
|
87
|
+
end
|
88
|
+
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
|
+
end
|
148
|
+
|
149
|
+
describe 'unit test' do
|
150
|
+
it 'creates pool instance' do
|
151
|
+
json = '{"name":"marketing"}'
|
152
|
+
hash = JSON.parse(json)
|
153
|
+
actual = SendGrid4r::REST::Ips::Pools.create_pool(hash)
|
154
|
+
expect(actual).to be_a(SendGrid4r::REST::Ips::Pools::Pool)
|
155
|
+
expect(actual.name).to eq('marketing')
|
156
|
+
end
|
157
|
+
|
158
|
+
it 'creates pool instance with ips' do
|
159
|
+
json =
|
160
|
+
'{'\
|
161
|
+
'"ips":["167.89.21.3"],'\
|
162
|
+
'"name":"new_test5"'\
|
163
|
+
'}'
|
164
|
+
hash = JSON.parse(json)
|
165
|
+
actual = SendGrid4r::REST::Ips::Pools.create_pool(hash)
|
166
|
+
expect(actual).to be_a(SendGrid4r::REST::Ips::Pools::Pool)
|
167
|
+
expect(actual.ips).to be_a(Array)
|
168
|
+
actual.ips.each do |ip|
|
169
|
+
expect(ip).to eq('167.89.21.3')
|
170
|
+
end
|
171
|
+
expect(actual.name).to eq('new_test5')
|
172
|
+
end
|
12
173
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
174
|
+
it 'creates pool instances' do
|
175
|
+
json =
|
176
|
+
'['\
|
177
|
+
'{'\
|
178
|
+
'"name": "test1"'\
|
179
|
+
'},'\
|
180
|
+
'{'\
|
181
|
+
'"name": "test2"'\
|
182
|
+
'},'\
|
183
|
+
'{'\
|
184
|
+
'"name": "test3"'\
|
185
|
+
'},'\
|
186
|
+
'{'\
|
187
|
+
'"name": "new_test3"'\
|
188
|
+
'}'\
|
189
|
+
']'
|
190
|
+
hash = JSON.parse(json)
|
191
|
+
actual = SendGrid4r::REST::Ips::Pools.create_pools(hash)
|
192
|
+
expect(actual).to be_a(Array)
|
193
|
+
actual.each do |pool|
|
194
|
+
expect(pool).to be_a(SendGrid4r::REST::Ips::Pools::Pool)
|
21
195
|
end
|
22
196
|
end
|
23
|
-
# post a pool
|
24
|
-
new_pool = @client.post_pool(@pool_name)
|
25
|
-
expect(@pool_name).to eq(new_pool.name)
|
26
|
-
# put the pool
|
27
|
-
edit_pool = @client.put_pool(@pool_name, @pool_edit)
|
28
|
-
expect(@pool_edit).to eq(edit_pool.name)
|
29
|
-
# get the pool
|
30
|
-
pool = @client.get_pool(@pool_edit)
|
31
|
-
expect(SendGrid4r::REST::Ips::Pools::Pool).to be(pool.class)
|
32
|
-
# delete the pool
|
33
|
-
@client.delete_pool(pool.pool_name)
|
34
|
-
expect { @client.get_pool(pool.name) }
|
35
|
-
ips = @client.get_ips
|
36
|
-
expect(ips.length).to be(1)
|
37
|
-
expect(ips[0].class).to be(SendGrid4r::REST::Ips::Addresses::Address)
|
38
|
-
expect(
|
39
|
-
@client.get_ip(ips[0].ip).class
|
40
|
-
).to be(SendGrid4r::REST::Ips::Addresses::Address)
|
41
197
|
end
|
42
198
|
end
|
43
199
|
end
|
data/spec/ips/warmup_spec.rb
CHANGED
@@ -1,52 +1,120 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require File.dirname(__FILE__) + '/../spec_helper'
|
3
3
|
|
4
|
-
describe
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
describe SendGrid4r::REST::Ips::Warmup do
|
5
|
+
describe 'integration test' do
|
6
|
+
before do
|
7
|
+
Dotenv.load
|
8
|
+
@client = SendGrid4r::Client.new(
|
9
|
+
username: ENV['SILVER_SENDGRID_USERNAME'],
|
10
|
+
password: ENV['SILVER_SENDGRID_PASSWORD'])
|
11
|
+
end
|
8
12
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
warmup_ips.each do |warmup_ip|
|
19
|
-
client.delete_warmup_ip(warmup_ip.ip)
|
13
|
+
context 'account is silver' do
|
14
|
+
before do
|
15
|
+
begin
|
16
|
+
# celan up test env
|
17
|
+
warmup_ips = @client.get_warmup_ips
|
18
|
+
if warmup_ips.length > 0
|
19
|
+
warmup_ips.each do |warmup_ip|
|
20
|
+
@client.delete_warmup_ip(warmup_ip.ip)
|
21
|
+
end
|
20
22
|
end
|
23
|
+
rescue => e
|
24
|
+
puts e.inspect
|
25
|
+
raise e
|
21
26
|
end
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
27
|
+
end
|
28
|
+
|
29
|
+
context 'without block call' do
|
30
|
+
it 'warmup_ip spec' do
|
31
|
+
begin
|
32
|
+
# get warmup ip
|
33
|
+
warmup_ips = @client.get_warmup_ips
|
34
|
+
expect(warmup_ips.length).to eq(0)
|
35
|
+
# post warmup ip
|
36
|
+
ips = @client.get_ips
|
37
|
+
expect(ips.length).to be > 0
|
38
|
+
warmup_ip = @client.post_warmup_ip(ips[0].ip)
|
39
|
+
expect(warmup_ip.ip).to eq(ips[0].ip)
|
40
|
+
warmup_ip = @client.get_warmup_ip(warmup_ip.ip)
|
41
|
+
expect(warmup_ip.ip).to eq(ips[0].ip)
|
42
|
+
# delete the warmup ip
|
43
|
+
@client.delete_warmup_ip(warmup_ip.ip)
|
44
|
+
expect do
|
45
|
+
@client.get_warmup_ip(warmup_ip.ip)
|
46
|
+
end.to raise_error(RestClient::ResourceNotFound)
|
47
|
+
rescue => ex
|
48
|
+
puts ex.inspect
|
49
|
+
raise ex
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
context 'with block call' do
|
55
|
+
it 'warmup_ip spec' do
|
56
|
+
# get warmup ips
|
57
|
+
@client.get_warmup_ips do |resp, req, res|
|
58
|
+
resp =
|
59
|
+
SendGrid4r::REST::Ips::Warmup.create_warmup_ips(
|
60
|
+
JSON.parse(resp)
|
61
|
+
)
|
62
|
+
expect(resp).to be_a(Array)
|
63
|
+
expect(req).to be_a(RestClient::Request)
|
64
|
+
expect(res).to be_a(Net::HTTPOK)
|
65
|
+
end
|
66
|
+
# post warmup ip
|
67
|
+
warmup_ip = nil
|
68
|
+
ips = @client.get_ips
|
69
|
+
expect(ips.length).to be > 0
|
70
|
+
@client.post_warmup_ip(ips[0].ip) do |resp, req, res|
|
71
|
+
resp =
|
72
|
+
SendGrid4r::REST::Ips::Warmup.create_warmup_ip(
|
73
|
+
JSON.parse(resp)
|
74
|
+
)
|
75
|
+
warmup_ip = resp
|
76
|
+
expect(resp).to be_a(SendGrid4r::REST::Ips::Warmup::WarmupIp)
|
77
|
+
expect(req).to be_a(RestClient::Request)
|
78
|
+
expect(res).to be_a(Net::HTTPCreated)
|
79
|
+
end
|
80
|
+
# get warmup ip
|
81
|
+
@client.get_warmup_ip(warmup_ip.ip) do |resp, req, res|
|
82
|
+
resp =
|
83
|
+
SendGrid4r::REST::Ips::Warmup.create_warmup_ip(
|
84
|
+
JSON.parse(resp)
|
85
|
+
)
|
86
|
+
expect(resp).to be_a(SendGrid4r::REST::Ips::Warmup::WarmupIp)
|
87
|
+
expect(req).to be_a(RestClient::Request)
|
88
|
+
expect(res).to be_a(Net::HTTPOK)
|
89
|
+
end
|
90
|
+
# delete the warmup ip
|
91
|
+
@client.delete_warmup_ip(warmup_ip.ip) do |resp, req, res|
|
92
|
+
expect(resp).to eq('')
|
93
|
+
expect(req).to be_a(RestClient::Request)
|
94
|
+
expect(res).to be_a(Net::HTTPNoContent)
|
95
|
+
end
|
30
96
|
end
|
31
|
-
warmup_ip = client.get_warmup_ip(warmup_ip.ip)
|
32
|
-
expect(warmup_ip.ip).to eq(ips[0].ip)
|
33
|
-
# delete the warmup ip
|
34
|
-
client.delete_warmup_ip(warmup_ip.ip)
|
35
|
-
expect do
|
36
|
-
client.get_warmup_ip(warmup_ip.ip)
|
37
|
-
end.to raise_error(RestClient::ResourceNotFound)
|
38
|
-
rescue => ex
|
39
|
-
puts ex.inspect
|
40
|
-
raise ex
|
41
97
|
end
|
42
98
|
end
|
43
99
|
end
|
44
100
|
|
45
|
-
|
46
|
-
it '
|
47
|
-
|
48
|
-
|
49
|
-
|
101
|
+
describe 'unit test' do
|
102
|
+
it 'creates warmup_ip instance' do
|
103
|
+
json =
|
104
|
+
'['\
|
105
|
+
'{'\
|
106
|
+
'"ip": "0.0.0.0",'\
|
107
|
+
'"start_date": 1409616000'\
|
108
|
+
'}'\
|
109
|
+
']'
|
110
|
+
hash = JSON.parse(json)
|
111
|
+
actual = SendGrid4r::REST::Ips::Warmup.create_warmup_ips(hash)
|
112
|
+
expect(actual).to be_a(Array)
|
113
|
+
actual.each do |warmup_ip|
|
114
|
+
expect(warmup_ip).to be_a(SendGrid4r::REST::Ips::Warmup::WarmupIp)
|
115
|
+
expect(warmup_ip.ip).to eq('0.0.0.0')
|
116
|
+
expect(warmup_ip.start_date).to eq(Time.at(1409616000))
|
117
|
+
end
|
50
118
|
end
|
51
119
|
end
|
52
120
|
end
|