sendgrid4r 1.8.1 → 1.10.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/.rubocop.yml +6 -2
- data/README.md +1 -0
- data/lib/sendgrid4r/factory/campaign_factory.rb +18 -5
- data/lib/sendgrid4r/factory/condition_factory.rb +1 -1
- data/lib/sendgrid4r/factory/mail_factory.rb +57 -0
- data/lib/sendgrid4r/factory/segment_factory.rb +2 -5
- data/lib/sendgrid4r/factory/version_factory.rb +1 -1
- data/lib/sendgrid4r/rest/api.rb +48 -49
- data/lib/sendgrid4r/rest/api_keys_management/api_keys.rb +75 -0
- data/lib/sendgrid4r/rest/api_keys_management/permissions.rb +31 -0
- data/lib/sendgrid4r/rest/blocks.rb +49 -68
- data/lib/sendgrid4r/rest/bounces.rb +45 -64
- data/lib/sendgrid4r/rest/cancel_scheduled_sends.rb +53 -72
- data/lib/sendgrid4r/rest/categories.rb +31 -0
- data/lib/sendgrid4r/rest/email_activity.rb +72 -0
- data/lib/sendgrid4r/rest/invalid_emails.rb +50 -68
- data/lib/sendgrid4r/rest/ip_access_management.rb +86 -111
- data/lib/sendgrid4r/rest/ips/addresses.rb +50 -59
- data/lib/sendgrid4r/rest/ips/pools.rb +42 -53
- data/lib/sendgrid4r/rest/ips/warmup.rb +46 -55
- data/lib/sendgrid4r/rest/mail/address.rb +14 -0
- data/lib/sendgrid4r/rest/mail/attachment.rb +22 -0
- data/lib/sendgrid4r/rest/mail/content.rb +10 -0
- data/lib/sendgrid4r/rest/mail/mail.rb +28 -0
- data/lib/sendgrid4r/rest/mail/mail_settings.rb +62 -0
- data/lib/sendgrid4r/rest/mail/params.rb +64 -0
- data/lib/sendgrid4r/rest/mail/personalization.rb +33 -0
- data/lib/sendgrid4r/rest/mail/tracking_settings.rb +74 -0
- data/lib/sendgrid4r/rest/{contacts → marketing_campaigns/contacts}/custom_fields.rb +12 -27
- data/lib/sendgrid4r/rest/{contacts → marketing_campaigns/contacts}/lists.rb +20 -34
- data/lib/sendgrid4r/rest/marketing_campaigns/contacts/recipients.rb +134 -0
- data/lib/sendgrid4r/rest/{contacts → marketing_campaigns/contacts}/reserved_fields.rb +6 -9
- data/lib/sendgrid4r/rest/marketing_campaigns/contacts/segments.rb +86 -0
- data/lib/sendgrid4r/rest/marketing_campaigns/marketing_campaigns.rb +119 -0
- data/lib/sendgrid4r/rest/marketing_campaigns/senders.rb +101 -0
- data/lib/sendgrid4r/rest/request.rb +61 -63
- data/lib/sendgrid4r/rest/settings/enforced_tls.rb +23 -26
- data/lib/sendgrid4r/rest/settings/mail.rb +167 -183
- data/lib/sendgrid4r/rest/settings/partner.rb +33 -36
- data/lib/sendgrid4r/rest/settings/settings.rb +17 -22
- data/lib/sendgrid4r/rest/settings/tracking.rb +97 -107
- data/lib/sendgrid4r/rest/sm/global_unsubscribes.rb +52 -60
- data/lib/sendgrid4r/rest/sm/groups.rb +52 -58
- data/lib/sendgrid4r/rest/sm/sm.rb +15 -17
- data/lib/sendgrid4r/rest/sm/suppressions.rb +50 -67
- data/lib/sendgrid4r/rest/spam_reports.rb +49 -69
- data/lib/sendgrid4r/rest/stats/advanced.rb +100 -102
- data/lib/sendgrid4r/rest/stats/category.rb +31 -33
- data/lib/sendgrid4r/rest/stats/global.rb +17 -19
- data/lib/sendgrid4r/rest/stats/parse.rb +18 -20
- data/lib/sendgrid4r/rest/stats/stats.rb +59 -69
- data/lib/sendgrid4r/rest/stats/subuser.rb +70 -32
- data/lib/sendgrid4r/rest/subusers.rb +106 -134
- data/lib/sendgrid4r/rest/transactional_templates/templates.rb +63 -0
- data/lib/sendgrid4r/rest/transactional_templates/versions.rb +90 -0
- data/lib/sendgrid4r/rest/users.rb +125 -57
- data/lib/sendgrid4r/rest/webhooks/event.rb +36 -42
- data/lib/sendgrid4r/rest/webhooks/parse.rb +28 -37
- data/lib/sendgrid4r/rest/whitelabel/domains.rb +176 -222
- data/lib/sendgrid4r/rest/whitelabel/ips.rb +107 -128
- data/lib/sendgrid4r/rest/whitelabel/links.rb +131 -167
- data/lib/sendgrid4r/version.rb +1 -1
- data/lib/sendgrid4r.rb +23 -13
- data/sendgrid4r.gemspec +1 -1
- data/spec/client_spec.rb +12 -1
- data/spec/factory/campaign_factory_spec.rb +75 -35
- data/spec/factory/condition_factory_spec.rb +19 -18
- data/spec/factory/segment_factory_spec.rb +28 -21
- data/spec/factory/version_factory_spec.rb +28 -27
- data/spec/photo.jpg +0 -0
- data/spec/rest/api_keys_management/api_keys_spec.rb +174 -0
- data/spec/rest/api_keys_management/permissions_spec.rb +54 -0
- data/spec/rest/blocks_spec.rb +78 -106
- data/spec/rest/bounces_spec.rb +91 -118
- data/spec/rest/cancel_scheduled_sends_spec.rb +94 -149
- data/spec/rest/categories_spec.rb +77 -0
- data/spec/rest/email_activity_spec.rb +151 -0
- data/spec/rest/invalid_emails_spec.rb +85 -119
- data/spec/rest/ip_access_management_spec.rb +157 -195
- data/spec/rest/ips/addresses_spec.rb +94 -122
- data/spec/rest/ips/pools_spec.rb +84 -112
- data/spec/rest/ips/warmup_spec.rb +63 -71
- data/spec/rest/mail/address_spec.rb +28 -0
- data/spec/rest/mail/attachment_spec.rb +48 -0
- data/spec/rest/mail/content_spec.rb +32 -0
- data/spec/rest/mail/mail_settings_spec.rb +51 -0
- data/spec/rest/mail/mail_spec.rb +136 -0
- data/spec/rest/mail/params_spec.rb +152 -0
- data/spec/rest/mail/personalization_spec.rb +66 -0
- data/spec/rest/mail/tracking_settings_spec.rb +63 -0
- data/spec/rest/marketing_campaigns/contacts/custom_fields_spec.rb +146 -0
- data/spec/rest/marketing_campaigns/contacts/lists_spec.rb +307 -0
- data/spec/rest/marketing_campaigns/contacts/recipients_spec.rb +331 -0
- data/spec/rest/marketing_campaigns/contacts/reserved_fields_spec.rb +119 -0
- data/spec/rest/marketing_campaigns/contacts/segments_spec.rb +268 -0
- data/spec/rest/marketing_campaigns/marketing_campaigns_spec.rb +427 -0
- data/spec/rest/marketing_campaigns/senders_spec.rb +230 -0
- data/spec/rest/settings/enforced_tls_spec.rb +38 -54
- data/spec/rest/settings/mail_spec.rb +227 -330
- data/spec/rest/settings/partner_spec.rb +40 -59
- data/spec/rest/settings/settings_spec.rb +44 -42
- data/spec/rest/settings/tracking_spec.rb +130 -189
- data/spec/rest/sm/global_unsubscribes_spec.rb +47 -72
- data/spec/rest/sm/groups_spec.rb +88 -123
- data/spec/rest/sm/sm_spec.rb +32 -30
- data/spec/rest/sm/suppressions_spec.rb +105 -140
- data/spec/rest/spam_reports_spec.rb +81 -109
- data/spec/rest/stats/advanced_spec.rb +67 -125
- data/spec/rest/stats/category_spec.rb +27 -45
- data/spec/rest/stats/global_spec.rb +34 -42
- data/spec/rest/stats/parse_spec.rb +32 -30
- data/spec/rest/stats/stats_spec.rb +174 -172
- data/spec/rest/stats/subuser_spec.rb +97 -57
- data/spec/rest/subusers_spec.rb +156 -209
- data/spec/rest/transactional_templates/templates_spec.rb +199 -0
- data/spec/rest/transactional_templates/versions_spec.rb +228 -0
- data/spec/rest/users_spec.rb +176 -91
- data/spec/rest/webhooks/event_spec.rb +59 -85
- data/spec/rest/webhooks/parse_spec.rb +51 -71
- data/spec/rest/whitelabel/domains_spec.rb +333 -513
- data/spec/rest/whitelabel/ips_spec.rb +109 -147
- data/spec/rest/whitelabel/links_spec.rb +181 -265
- metadata +70 -40
- data/lib/sendgrid4r/rest/api_keys/api_keys.rb +0 -80
- data/lib/sendgrid4r/rest/api_keys/permissions.rb +0 -33
- data/lib/sendgrid4r/rest/campaigns/campaigns.rb +0 -126
- data/lib/sendgrid4r/rest/categories/categories.rb +0 -43
- data/lib/sendgrid4r/rest/contacts/recipients.rb +0 -150
- data/lib/sendgrid4r/rest/contacts/segments.rb +0 -97
- data/lib/sendgrid4r/rest/email_activity/email_activity.rb +0 -81
- data/lib/sendgrid4r/rest/templates/templates.rb +0 -69
- data/lib/sendgrid4r/rest/templates/versions.rb +0 -95
- data/spec/rest/api_keys/api_keys_spec.rb +0 -210
- data/spec/rest/api_keys/permissions_spec.rb +0 -65
- data/spec/rest/campaigns/campaigns_spec.rb +0 -492
- data/spec/rest/categories/categories_spec.rb +0 -96
- data/spec/rest/contacts/custom_fields_spec.rb +0 -174
- data/spec/rest/contacts/lists_spec.rb +0 -372
- data/spec/rest/contacts/recipients_spec.rb +0 -343
- data/spec/rest/contacts/reserved_fields_spec.rb +0 -146
- data/spec/rest/contacts/segments_spec.rb +0 -307
- data/spec/rest/email_activity/email_activity_spec.rb +0 -179
- data/spec/rest/templates/templates_spec.rb +0 -222
- data/spec/rest/templates/versions_spec.rb +0 -252
data/spec/rest/subusers_spec.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require File.dirname(__FILE__) + '/../spec_helper'
|
3
3
|
|
4
|
-
|
5
|
-
describe
|
6
|
-
|
7
|
-
|
4
|
+
module SendGrid4r::REST
|
5
|
+
describe Subusers do
|
6
|
+
describe 'integration test', :it do
|
7
|
+
before do
|
8
8
|
Dotenv.load
|
9
9
|
@client = SendGrid4r::Client.new(api_key: ENV['SILVER_API_KEY'])
|
10
10
|
@username1 = ENV['SUBUSER1']
|
@@ -28,124 +28,74 @@ describe SendGrid4r::REST::Subusers do
|
|
28
28
|
password: @password1,
|
29
29
|
ips: [@ip]
|
30
30
|
)
|
31
|
-
rescue RestClient::ExceptionWithResponse => e
|
32
|
-
puts e.inspect
|
33
|
-
raise e
|
34
31
|
end
|
35
|
-
end
|
36
32
|
|
37
|
-
|
38
|
-
|
39
|
-
begin
|
33
|
+
context 'without block call' do
|
34
|
+
it '#get_subusers' do
|
40
35
|
subusers = @client.get_subusers(limit: 100, offset: 0)
|
41
36
|
expect(subusers).to be_a(Array)
|
42
37
|
subusers.each do |subuser|
|
43
|
-
expect(subuser).to be_a(
|
38
|
+
expect(subuser).to be_a(Subusers::Subuser)
|
44
39
|
end
|
45
|
-
rescue RestClient::ExceptionWithResponse => e
|
46
|
-
puts e.inspect
|
47
|
-
raise e
|
48
40
|
end
|
49
|
-
end
|
50
41
|
|
51
|
-
|
52
|
-
|
53
|
-
expect(@subuser3).to be_a(SendGrid4r::REST::Subusers::Subuser)
|
42
|
+
it '#post_subuser' do
|
43
|
+
expect(@subuser3).to be_a(Subusers::Subuser)
|
54
44
|
expect(@subuser3.username).to eq(@username3)
|
55
45
|
expect(@subuser3.email).to eq(@email1)
|
56
|
-
rescue RestClient::ExceptionWithResponse => e
|
57
|
-
puts e.inspect
|
58
|
-
raise e
|
59
46
|
end
|
60
|
-
end
|
61
47
|
|
62
|
-
|
63
|
-
begin
|
48
|
+
it '#patch_subuser' do
|
64
49
|
@client.patch_subuser(username: @username3, disabled: true)
|
65
50
|
@client.patch_subuser(username: @username3, disabled: false)
|
66
|
-
rescue RestClient::ExceptionWithResponse => e
|
67
|
-
puts e.inspect
|
68
|
-
raise e
|
69
51
|
end
|
70
|
-
end
|
71
52
|
|
72
|
-
|
73
|
-
begin
|
53
|
+
it '#delete_subuser' do
|
74
54
|
@client.delete_subuser(username: @username3)
|
75
|
-
rescue RestClient::ExceptionWithResponse => e
|
76
|
-
puts e.inspect
|
77
|
-
raise e
|
78
55
|
end
|
79
|
-
end
|
80
56
|
|
81
|
-
|
82
|
-
begin
|
57
|
+
it '#get_subuser_monitor' do
|
83
58
|
monitor = @client.get_subuser_monitor(
|
84
59
|
username: @username3, email: @email1, frequency: 10
|
85
60
|
)
|
86
|
-
expect(monitor).to be_a(
|
87
|
-
rescue RestClient::ExceptionWithResponse => e
|
88
|
-
puts e.inspect
|
89
|
-
raise e
|
61
|
+
expect(monitor).to be_a(Subusers::Monitor)
|
90
62
|
end
|
91
|
-
end
|
92
63
|
|
93
|
-
|
94
|
-
begin
|
64
|
+
it '#post_subuser_monitor' do
|
95
65
|
monitor = @client.post_subuser_monitor(
|
96
66
|
username: @username3, email: @email1, frequency: 10
|
97
67
|
)
|
98
|
-
expect(monitor).to be_a(
|
99
|
-
rescue RestClient::ExceptionWithResponse => e
|
100
|
-
puts e.inspect
|
101
|
-
raise e
|
68
|
+
expect(monitor).to be_a(Subusers::Monitor)
|
102
69
|
end
|
103
|
-
end
|
104
70
|
|
105
|
-
|
106
|
-
begin
|
71
|
+
it '#put_subuser_monitor' do
|
107
72
|
@client.post_subuser_monitor(
|
108
73
|
username: @username3, email: @email1, frequency: 10
|
109
74
|
)
|
110
75
|
monitor = @client.put_subuser_monitor(
|
111
76
|
username: @username3, email: @email1, frequency: 10
|
112
77
|
)
|
113
|
-
expect(monitor).to be_a(
|
114
|
-
rescue RestClient::ExceptionWithResponse => e
|
115
|
-
puts e.inspect
|
116
|
-
raise e
|
78
|
+
expect(monitor).to be_a(Subusers::Monitor)
|
117
79
|
end
|
118
|
-
end
|
119
80
|
|
120
|
-
|
121
|
-
begin
|
81
|
+
it '#delete_subuser_monitor' do
|
122
82
|
@client.post_subuser_monitor(
|
123
83
|
username: @username3, email: @email1, frequency: 10
|
124
84
|
)
|
125
85
|
@client.delete_subuser_monitor(username: @username3)
|
126
|
-
rescue RestClient::ExceptionWithResponse => e
|
127
|
-
puts e.inspect
|
128
|
-
raise e
|
129
86
|
end
|
130
|
-
end
|
131
87
|
|
132
|
-
|
133
|
-
begin
|
88
|
+
it '#get_subuser_reputation' do
|
134
89
|
params = []
|
135
90
|
params.push(@username3)
|
136
91
|
subusers = @client.get_subuser_reputation(usernames: params)
|
137
92
|
expect(subusers).to be_a(Array)
|
138
93
|
subusers.each do |subuser|
|
139
|
-
expect(subuser).to be_a(
|
94
|
+
expect(subuser).to be_a(Subusers::Subuser)
|
140
95
|
end
|
141
|
-
rescue RestClient::ExceptionWithResponse => e
|
142
|
-
puts e.inspect
|
143
|
-
raise e
|
144
96
|
end
|
145
|
-
end
|
146
97
|
|
147
|
-
|
148
|
-
begin
|
98
|
+
it '#put_subuser_assigned_ips' do
|
149
99
|
subuser = @client.put_subuser_assigned_ips(
|
150
100
|
username: @username3, ips: [@ip]
|
151
101
|
)
|
@@ -153,170 +103,167 @@ describe SendGrid4r::REST::Subusers do
|
|
153
103
|
subuser.ips.each do |ip|
|
154
104
|
expect(ip).to be_a(String)
|
155
105
|
end
|
156
|
-
rescue RestClient::ExceptionWithResponse => e
|
157
|
-
puts e.inspect
|
158
|
-
raise e
|
159
106
|
end
|
160
107
|
end
|
161
108
|
end
|
162
|
-
end
|
163
109
|
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
110
|
+
describe 'unit test', :ut do
|
111
|
+
let(:client) do
|
112
|
+
SendGrid4r::Client.new(api_key: '')
|
113
|
+
end
|
168
114
|
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
115
|
+
let(:subusers) do
|
116
|
+
JSON.parse(
|
117
|
+
'['\
|
118
|
+
'{'\
|
119
|
+
'"id": 1,'\
|
120
|
+
'"username": "Test@example.com",'\
|
121
|
+
'"email": "Test@example.com"'\
|
122
|
+
'},'\
|
123
|
+
'{'\
|
124
|
+
'"id": 2,'\
|
125
|
+
'"username": "John@example.com",'\
|
126
|
+
'"email": "John@example.com"'\
|
127
|
+
'}'\
|
128
|
+
']'
|
129
|
+
)
|
130
|
+
end
|
131
|
+
|
132
|
+
let(:subuser) do
|
133
|
+
JSON.parse(
|
177
134
|
'{'\
|
178
|
-
'"id": 2,'\
|
179
135
|
'"username": "John@example.com",'\
|
180
|
-
'"email": "John@example.com"'\
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
'"email": "John@example.com",'\
|
191
|
-
'"password": "johns_password",'\
|
192
|
-
'"ips": ['\
|
193
|
-
'"1.1.1.1",'\
|
194
|
-
'"2.2.2.2"'\
|
195
|
-
'],'\
|
196
|
-
'"disabled": false'\
|
197
|
-
'}'
|
198
|
-
)
|
199
|
-
end
|
136
|
+
'"email": "John@example.com",'\
|
137
|
+
'"password": "johns_password",'\
|
138
|
+
'"ips": ['\
|
139
|
+
'"1.1.1.1",'\
|
140
|
+
'"2.2.2.2"'\
|
141
|
+
'],'\
|
142
|
+
'"disabled": false'\
|
143
|
+
'}'
|
144
|
+
)
|
145
|
+
end
|
200
146
|
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
147
|
+
let(:ips) do
|
148
|
+
JSON.parse(
|
149
|
+
'{'\
|
150
|
+
'"ips": ['\
|
151
|
+
'"127.0.0.1",'\
|
152
|
+
'"127.0.0.2"'\
|
153
|
+
']'\
|
154
|
+
'}'
|
155
|
+
)
|
156
|
+
end
|
211
157
|
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
158
|
+
let(:monitor) do
|
159
|
+
JSON.parse(
|
160
|
+
'{'\
|
161
|
+
'"email": "test@example.com",'\
|
162
|
+
'"frequency": 500'\
|
163
|
+
'}'
|
164
|
+
)
|
165
|
+
end
|
220
166
|
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
167
|
+
it '#get_subusers' do
|
168
|
+
allow(client).to receive(:execute).and_return(subusers)
|
169
|
+
actual = client.get_subusers(limit: 0, offset: 0, username: 'aaa')
|
170
|
+
expect(actual).to be_a(Array)
|
171
|
+
actual.each do |subuser|
|
172
|
+
expect(subuser).to be_a(Subusers::Subuser)
|
173
|
+
end
|
227
174
|
end
|
228
|
-
end
|
229
175
|
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
176
|
+
it '#post_subuser' do
|
177
|
+
allow(client).to receive(:execute).and_return(subuser)
|
178
|
+
actual = client.post_subuser(
|
179
|
+
username: '', email: '', password: '', ips: []
|
180
|
+
)
|
181
|
+
expect(actual).to be_a(Subusers::Subuser)
|
182
|
+
end
|
237
183
|
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
184
|
+
it '#patch_subuser' do
|
185
|
+
allow(client).to receive(:execute).and_return(subuser)
|
186
|
+
actual = client.patch_subuser(username: '', disabled: true)
|
187
|
+
expect(actual).to be_a(Subusers::Subuser)
|
188
|
+
end
|
243
189
|
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
190
|
+
it '#delete_subuser' do
|
191
|
+
allow(client).to receive(:execute).and_return('')
|
192
|
+
actual = client.delete_subuser(username: '')
|
193
|
+
expect(actual).to eq('')
|
194
|
+
end
|
249
195
|
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
196
|
+
it '#get_subuser_monitor' do
|
197
|
+
allow(client).to receive(:execute).and_return(monitor)
|
198
|
+
actual = client.get_subuser_monitor(
|
199
|
+
username: '', email: '', frequency: 1
|
200
|
+
)
|
201
|
+
expect(actual).to be_a(Subusers::Monitor)
|
202
|
+
end
|
257
203
|
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
204
|
+
it '#post_subuser_monitor' do
|
205
|
+
allow(client).to receive(:execute).and_return(monitor)
|
206
|
+
actual = client.post_subuser_monitor(
|
207
|
+
username: '', email: '', frequency: 1
|
208
|
+
)
|
209
|
+
expect(actual).to be_a(Subusers::Monitor)
|
210
|
+
end
|
265
211
|
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
212
|
+
it '#put_subuser_monitor' do
|
213
|
+
allow(client).to receive(:execute).and_return(monitor)
|
214
|
+
actual = client.put_subuser_monitor(
|
215
|
+
username: '', email: '', frequency: 1
|
216
|
+
)
|
217
|
+
expect(actual).to be_a(Subusers::Monitor)
|
218
|
+
end
|
273
219
|
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
220
|
+
it '#delete_subuser_monitor' do
|
221
|
+
allow(client).to receive(:execute).and_return('')
|
222
|
+
actual = client.delete_subuser_monitor(username: '')
|
223
|
+
expect(actual).to eq('')
|
224
|
+
end
|
279
225
|
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
226
|
+
it '#get_subuser_reputation' do
|
227
|
+
allow(client).to receive(:execute).and_return(subusers)
|
228
|
+
actual = client.get_subuser_reputation(usernames: [])
|
229
|
+
expect(actual).to be_a(Array)
|
230
|
+
actual.each do |subuser|
|
231
|
+
expect(subuser).to be_a(Subusers::Subuser)
|
232
|
+
end
|
286
233
|
end
|
287
|
-
end
|
288
234
|
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
235
|
+
it '#put_subuser_assigned_ips' do
|
236
|
+
allow(client).to receive(:execute).and_return(subuser)
|
237
|
+
actual = client.put_subuser_assigned_ips(username: '', ips: [])
|
238
|
+
expect(actual).to be_a(Subusers::Subuser)
|
239
|
+
end
|
294
240
|
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
241
|
+
it 'creates subusers instance' do
|
242
|
+
actual = Subusers.create_subusers(subusers)
|
243
|
+
expect(actual).to be_a(Array)
|
244
|
+
actual.each do |subuser|
|
245
|
+
expect(subuser).to be_a(Subusers::Subuser)
|
246
|
+
end
|
300
247
|
end
|
301
|
-
end
|
302
248
|
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
249
|
+
it 'creates subuser instance' do
|
250
|
+
actual = Subusers.create_subuser(subuser)
|
251
|
+
expect(actual).to be_a(Subusers::Subuser)
|
252
|
+
expect(actual.username).to eq('John@example.com')
|
253
|
+
expect(actual.email).to eq('John@example.com')
|
254
|
+
expect(actual.password).to eq('johns_password')
|
255
|
+
actual.ips do |ip|
|
256
|
+
expect(ip).to be_a(String)
|
257
|
+
end
|
258
|
+
expect(actual.disabled).to eq(false)
|
311
259
|
end
|
312
|
-
expect(actual.disabled).to eq(false)
|
313
|
-
end
|
314
260
|
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
261
|
+
it 'creates monitor instance' do
|
262
|
+
actual = Subusers.create_monitor(monitor)
|
263
|
+
expect(actual).to be_a(Subusers::Monitor)
|
264
|
+
expect(actual.email).to eq('test@example.com')
|
265
|
+
expect(actual.frequency).to eq(500)
|
266
|
+
end
|
320
267
|
end
|
321
268
|
end
|
322
269
|
end
|
@@ -0,0 +1,199 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
3
|
+
|
4
|
+
module SendGrid4r::REST::TransactionalTemplates
|
5
|
+
describe SendGrid4r::REST::TransactionalTemplates do
|
6
|
+
describe 'integration test', :it do
|
7
|
+
before do
|
8
|
+
Dotenv.load
|
9
|
+
@client = SendGrid4r::Client.new(api_key: ENV['SILVER_API_KEY'])
|
10
|
+
@template_name1 = 'template_test1'
|
11
|
+
@template_name2 = 'template_test2'
|
12
|
+
@template_edit1 = 'template_edit1'
|
13
|
+
@version_name1 = 'version_test1'
|
14
|
+
@factory = SendGrid4r::Factory::VersionFactory.new
|
15
|
+
|
16
|
+
# celan up test env
|
17
|
+
tmps = @client.get_templates
|
18
|
+
tmps.templates.each do |tmp|
|
19
|
+
delete_template(tmp) if tmp.name == @template_name1
|
20
|
+
delete_template(tmp) if tmp.name == @template_name2
|
21
|
+
delete_template(tmp) if tmp.name == @template_edit1
|
22
|
+
end
|
23
|
+
# post a template
|
24
|
+
@template1 = @client.post_template(name: @template_name1)
|
25
|
+
end
|
26
|
+
|
27
|
+
def delete_template(tmp)
|
28
|
+
tmp.versions.each do |ver|
|
29
|
+
@client.delete_version(template_id: tmp.id, version_id: ver.id)
|
30
|
+
end
|
31
|
+
@client.delete_template(template_id: tmp.id)
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'without block call' do
|
35
|
+
it '#post_template' do
|
36
|
+
new_template = @client.post_template(name: @template_name2)
|
37
|
+
expect(new_template.id).to be_a(String)
|
38
|
+
expect(new_template.name).to eq(@template_name2)
|
39
|
+
expect(new_template.versions).to be_a(Array)
|
40
|
+
end
|
41
|
+
|
42
|
+
it '#get_templates' do
|
43
|
+
tmps = @client.get_templates
|
44
|
+
tmps.templates.each do |tmp|
|
45
|
+
expect(tmp.id).to be_a(String)
|
46
|
+
expect(tmp.name).to be_a(String)
|
47
|
+
expect(tmp.versions).to be_a(Array)
|
48
|
+
tmp.versions.each do |ver|
|
49
|
+
expect(ver.id).to be_a(String)
|
50
|
+
expect(ver.template_id).to be_a(String)
|
51
|
+
expect(ver.active).to be_a(Fixnum)
|
52
|
+
expect(ver.name).to be_a(String)
|
53
|
+
expect(ver.updated_at).to be_a(String)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
it '#patch_template' do
|
59
|
+
version = @factory.create(name: @version_name1)
|
60
|
+
@client.post_version(template_id: @template1.id, version: version)
|
61
|
+
tmp = @client.patch_template(
|
62
|
+
template_id: @template1.id, name: @template_edit1
|
63
|
+
)
|
64
|
+
expect(tmp.id).to be_a(String)
|
65
|
+
expect(tmp.name).to be_a(String)
|
66
|
+
expect(tmp.versions).to be_a(Array)
|
67
|
+
tmp.versions.each do |ver|
|
68
|
+
expect(ver.id).to be_a(String)
|
69
|
+
expect(ver.template_id).to be_a(String)
|
70
|
+
expect(ver.active).to be_a(Fixnum)
|
71
|
+
expect(ver.name).to be_a(String)
|
72
|
+
expect(ver.updated_at).to be_a(String)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
it '#get_template' do
|
77
|
+
tmp = @client.get_template(template_id: @template1.id)
|
78
|
+
expect(tmp.id).to eq(@template1.id)
|
79
|
+
expect(tmp.versions).to eq(@template1.versions)
|
80
|
+
end
|
81
|
+
|
82
|
+
it '#delete_template' do
|
83
|
+
@client.delete_template(template_id: @template1.id)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
describe 'unit test', :ut do
|
89
|
+
let(:client) do
|
90
|
+
SendGrid4r::Client.new(api_key: '')
|
91
|
+
end
|
92
|
+
|
93
|
+
let(:template) do
|
94
|
+
JSON.parse(
|
95
|
+
'{'\
|
96
|
+
'"id": "733ba07f-ead1-41fc-933a-3976baa23716",'\
|
97
|
+
'"name": "example_name",'\
|
98
|
+
'"versions": []'\
|
99
|
+
'}'
|
100
|
+
)
|
101
|
+
end
|
102
|
+
|
103
|
+
let(:templates) do
|
104
|
+
JSON.parse(
|
105
|
+
'{'\
|
106
|
+
'"templates": ['\
|
107
|
+
'{'\
|
108
|
+
'"id": "e8ac01d5-a07a-4a71-b14c-4721136fe6aa",'\
|
109
|
+
'"name": "example template name",'\
|
110
|
+
'"versions": ['\
|
111
|
+
'{'\
|
112
|
+
'"id": "de37d11b-082a-42c0-9884-c0c143015a47",'\
|
113
|
+
'"user_id": 1234,'\
|
114
|
+
'"template_id": "d51480ba-ca3f-465c-bc3e-ceb71d73c38d",'\
|
115
|
+
'"active": 1,'\
|
116
|
+
'"name": "example version",'\
|
117
|
+
'"html_content": "<%body%><strong>Click '\
|
118
|
+
'to Reset</strong>",'\
|
119
|
+
'"plain_content": "Click to Reset<%body%>",'\
|
120
|
+
'"subject": "<%subject%>",'\
|
121
|
+
'"updated_at": "2014-05-22 20:05:21"'\
|
122
|
+
'}'\
|
123
|
+
']'\
|
124
|
+
'}'\
|
125
|
+
']'\
|
126
|
+
'}'
|
127
|
+
)
|
128
|
+
end
|
129
|
+
|
130
|
+
it '#post_template' do
|
131
|
+
allow(client).to receive(:execute).and_return(template)
|
132
|
+
actual = client.post_template(name: '')
|
133
|
+
expect(actual).to be_a(Template)
|
134
|
+
end
|
135
|
+
|
136
|
+
it '#get_templates' do
|
137
|
+
allow(client).to receive(:execute).and_return(templates)
|
138
|
+
actual = client.get_templates
|
139
|
+
expect(actual).to be_a(Templates)
|
140
|
+
end
|
141
|
+
|
142
|
+
it '#patch_template' do
|
143
|
+
allow(client).to receive(:execute).and_return(template)
|
144
|
+
actual = client.patch_template(template_id: '', name: '')
|
145
|
+
expect(actual).to be_a(Template)
|
146
|
+
end
|
147
|
+
|
148
|
+
it '#get_template' do
|
149
|
+
allow(client).to receive(:execute).and_return(template)
|
150
|
+
actual = client.get_template(template_id: '')
|
151
|
+
expect(actual).to be_a(Template)
|
152
|
+
end
|
153
|
+
|
154
|
+
it '#delete_template' do
|
155
|
+
allow(client).to receive(:execute).and_return('')
|
156
|
+
actual = client.delete_template(template_id: '')
|
157
|
+
expect(actual).to eq('')
|
158
|
+
end
|
159
|
+
|
160
|
+
it 'creates template instance' do
|
161
|
+
actual = SendGrid4r::REST::TransactionalTemplates.create_template(
|
162
|
+
template
|
163
|
+
)
|
164
|
+
expect(actual).to be_a(Template)
|
165
|
+
expect(actual.id).to eq('733ba07f-ead1-41fc-933a-3976baa23716')
|
166
|
+
expect(actual.name).to eq('example_name')
|
167
|
+
expect(actual.versions).to be_a(Array)
|
168
|
+
end
|
169
|
+
|
170
|
+
it 'creates templates instance' do
|
171
|
+
actual = SendGrid4r::REST::TransactionalTemplates.create_templates(
|
172
|
+
templates
|
173
|
+
)
|
174
|
+
expect(actual).to be_a(Templates)
|
175
|
+
expect(actual.templates).to be_a(Array)
|
176
|
+
actual.templates.each do |template|
|
177
|
+
expect(template.id).to eq('e8ac01d5-a07a-4a71-b14c-4721136fe6aa')
|
178
|
+
expect(template.name).to eq('example template name')
|
179
|
+
expect(template.versions).to be_a(Array)
|
180
|
+
template.versions do |version|
|
181
|
+
expect(version.id).to eq('de37d11b-082a-42c0-9884-c0c143015a47')
|
182
|
+
expect(version.user_id).to eq(1234)
|
183
|
+
expect(version.template_id).to eq(
|
184
|
+
'd51480ba-ca3f-465c-bc3e-ceb71d73c38d'
|
185
|
+
)
|
186
|
+
expect(version.active).to eq(1)
|
187
|
+
expect(version.name).to eq('example version')
|
188
|
+
expect(version.html_content).to eq(
|
189
|
+
'<%body%><strong>Click to Reset</strong>'
|
190
|
+
)
|
191
|
+
expect(version.plain_content).to eq('Click to Reset<%body%>')
|
192
|
+
expect(version.subject).to eq('<%subject%>')
|
193
|
+
expect(version.updated_at).to eq('2014-05-22 20:05:21')
|
194
|
+
end
|
195
|
+
end
|
196
|
+
end
|
197
|
+
end
|
198
|
+
end
|
199
|
+
end
|