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
@@ -1,343 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require File.dirname(__FILE__) + '/../../spec_helper'
|
3
|
-
|
4
|
-
describe SendGrid4r::REST::Contacts::Recipients do
|
5
|
-
describe 'integration test', :it do
|
6
|
-
before do
|
7
|
-
begin
|
8
|
-
Dotenv.load
|
9
|
-
@client = SendGrid4r::Client.new(api_key: ENV['API_KEY'])
|
10
|
-
@email1 = 'jones@example.com'
|
11
|
-
@email2 = 'miller@example.com'
|
12
|
-
@last_name1 = 'Jones'
|
13
|
-
@last_name2 = 'Miller'
|
14
|
-
@pet1 = 'Fluffy'
|
15
|
-
@pet2 = 'FrouFrou'
|
16
|
-
|
17
|
-
# celan up test env
|
18
|
-
recipients = @client.get_recipients
|
19
|
-
recipients.recipients.each do |recipient|
|
20
|
-
next if recipient.email != @email1 && recipient.email != @email2
|
21
|
-
@client.delete_recipient(recipient_id: recipient.id)
|
22
|
-
end
|
23
|
-
# post a recipient
|
24
|
-
params = {}
|
25
|
-
params['email'] = @email1
|
26
|
-
params['last_name'] = @last_name1
|
27
|
-
@result = @client.post_recipients(params: [params])
|
28
|
-
rescue RestClient::ExceptionWithResponse => e
|
29
|
-
puts e.inspect
|
30
|
-
raise e
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
context 'without block call' do
|
35
|
-
it '#post_recipients' do
|
36
|
-
begin
|
37
|
-
params = {}
|
38
|
-
params['email'] = @email2
|
39
|
-
params['last_name'] = @last_name2
|
40
|
-
result = @client.post_recipients(params: [params])
|
41
|
-
expect(result.error_count).to eq(0)
|
42
|
-
expect(result.error_indices).to eq([])
|
43
|
-
expect(result.new_count).to eq(1)
|
44
|
-
expect(result.persisted_recipients).to be_a(Array)
|
45
|
-
expect(result.updated_count).to eq(0)
|
46
|
-
rescue RestClient::ExceptionWithResponse => e
|
47
|
-
puts e.inspect
|
48
|
-
raise e
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
it '#patch_recipients' do
|
53
|
-
begin
|
54
|
-
params = {}
|
55
|
-
params['email'] = @email1
|
56
|
-
params['last_name'] = 'JonesEdit'
|
57
|
-
result = @client.patch_recipients(params: [params])
|
58
|
-
expect(result.error_count).to eq(0)
|
59
|
-
expect(result.error_indices).to eq([])
|
60
|
-
expect(result.new_count).to eq(0)
|
61
|
-
expect(result.persisted_recipients).to be_a(Array)
|
62
|
-
expect(result.updated_count).to eq(1)
|
63
|
-
rescue RestClient::ExceptionWithResponse => e
|
64
|
-
puts e.inspect
|
65
|
-
raise e
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
it '#delete_recipients' do
|
70
|
-
begin
|
71
|
-
@client.delete_recipients(recipient_ids: @result.persisted_recipients)
|
72
|
-
rescue RestClient::ExceptionWithResponse => e
|
73
|
-
puts e.inspect
|
74
|
-
raise e
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
it '#get_recipients' do
|
79
|
-
begin
|
80
|
-
recipients = @client.get_recipients(page: 1, page_size: 100)
|
81
|
-
expect(recipients.recipients.length).to be > 0
|
82
|
-
recipients.recipients.each do |recipient|
|
83
|
-
expect(
|
84
|
-
recipient
|
85
|
-
).to be_a(SendGrid4r::REST::Contacts::Recipients::Recipient)
|
86
|
-
end
|
87
|
-
rescue RestClient::ExceptionWithResponse => e
|
88
|
-
puts e.inspect
|
89
|
-
raise e
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
it '#get_recipient' do
|
94
|
-
begin
|
95
|
-
recipient = @client.get_recipient(
|
96
|
-
recipient_id: @result.persisted_recipients[0]
|
97
|
-
)
|
98
|
-
expect(
|
99
|
-
recipient
|
100
|
-
).to be_a(SendGrid4r::REST::Contacts::Recipients::Recipient)
|
101
|
-
rescue RestClient::ExceptionWithResponse => e
|
102
|
-
puts e.inspect
|
103
|
-
raise e
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
it '#delete_recipient' do
|
108
|
-
begin
|
109
|
-
@client.delete_recipient(
|
110
|
-
recipient_id: @result.persisted_recipients[0]
|
111
|
-
)
|
112
|
-
expect do
|
113
|
-
@client.get_recipient(recipient_id: @result.persisted_recipients[0])
|
114
|
-
end.to raise_error(RestClient::ResourceNotFound)
|
115
|
-
rescue RestClient::ExceptionWithResponse => e
|
116
|
-
puts e.inspect
|
117
|
-
raise e
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
it '#get_lists_recipient_belong' do
|
122
|
-
begin
|
123
|
-
lists = @client.get_lists_recipient_belong(
|
124
|
-
recipient_id: @result.persisted_recipients[0]
|
125
|
-
)
|
126
|
-
lists.lists.each do |list|
|
127
|
-
expect(
|
128
|
-
list.is_a?(SendGrid4r::REST::Contacts::Lists::List)
|
129
|
-
).to eq(true)
|
130
|
-
end
|
131
|
-
rescue RestClient::ExceptionWithResponse => e
|
132
|
-
puts e.inspect
|
133
|
-
raise e
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
it '#get_recipient_count' do
|
138
|
-
begin
|
139
|
-
actual_count = @client.get_recipients_count
|
140
|
-
expect(actual_count).to be >= 0
|
141
|
-
rescue RestClient::ExceptionWithResponse => e
|
142
|
-
puts e.inspect
|
143
|
-
raise e
|
144
|
-
end
|
145
|
-
end
|
146
|
-
|
147
|
-
it '#search_recipients' do
|
148
|
-
begin
|
149
|
-
params = {}
|
150
|
-
params['email'] = @email1
|
151
|
-
recipients = @client.search_recipients(params: params)
|
152
|
-
expect(recipients.recipients).to be_a(Array)
|
153
|
-
rescue RestClient::ExceptionWithResponse => e
|
154
|
-
puts e.inspect
|
155
|
-
raise e
|
156
|
-
end
|
157
|
-
end
|
158
|
-
end
|
159
|
-
end
|
160
|
-
|
161
|
-
describe 'unit test', :ut do
|
162
|
-
let(:client) do
|
163
|
-
SendGrid4r::Client.new(api_key: '')
|
164
|
-
end
|
165
|
-
|
166
|
-
let(:recipient) do
|
167
|
-
JSON.parse(
|
168
|
-
'{'\
|
169
|
-
'"created_at": 1422313607,'\
|
170
|
-
'"email": "jones@example.com",'\
|
171
|
-
'"first_name": null,'\
|
172
|
-
'"id": "YUBh",'\
|
173
|
-
'"last_clicked": null,'\
|
174
|
-
'"last_emailed": null,'\
|
175
|
-
'"last_name": "Jones",'\
|
176
|
-
'"last_opened": null,'\
|
177
|
-
'"updated_at": 1422313790,'\
|
178
|
-
'"custom_fields": ['\
|
179
|
-
'{'\
|
180
|
-
'"id": 23,'\
|
181
|
-
'"name": "pet",'\
|
182
|
-
'"value": "Fluffy",'\
|
183
|
-
'"type": "text"'\
|
184
|
-
'}'\
|
185
|
-
']'\
|
186
|
-
'}'
|
187
|
-
)
|
188
|
-
end
|
189
|
-
|
190
|
-
let(:recipients) do
|
191
|
-
JSON.parse(
|
192
|
-
'{'\
|
193
|
-
'"recipients": ['\
|
194
|
-
'{'\
|
195
|
-
'"created_at": 1422313607,'\
|
196
|
-
'"email": "jones@example.com",'\
|
197
|
-
'"first_name": null,'\
|
198
|
-
'"id": "YUBh",'\
|
199
|
-
'"last_clicked": null,'\
|
200
|
-
'"last_emailed": null,'\
|
201
|
-
'"last_name": "Jones",'\
|
202
|
-
'"last_opened": null,'\
|
203
|
-
'"updated_at": 1422313790,'\
|
204
|
-
'"custom_fields": ['\
|
205
|
-
'{'\
|
206
|
-
'"id": 23,'\
|
207
|
-
'"name": "pet",'\
|
208
|
-
'"value": "Fluffy",'\
|
209
|
-
'"type": "text"'\
|
210
|
-
'}'\
|
211
|
-
']'\
|
212
|
-
'}'\
|
213
|
-
']'\
|
214
|
-
'}'
|
215
|
-
)
|
216
|
-
end
|
217
|
-
|
218
|
-
let(:recipient_count) do
|
219
|
-
JSON.parse(
|
220
|
-
'{'\
|
221
|
-
'"recipient_count": 2'\
|
222
|
-
'}'
|
223
|
-
)
|
224
|
-
end
|
225
|
-
|
226
|
-
let(:lists) do
|
227
|
-
JSON.parse(
|
228
|
-
'{'\
|
229
|
-
'"lists": ['\
|
230
|
-
'{'\
|
231
|
-
'"id": 1,'\
|
232
|
-
'"name": "the jones",'\
|
233
|
-
'"recipient_count": 1'\
|
234
|
-
'}'\
|
235
|
-
']'\
|
236
|
-
'}'
|
237
|
-
)
|
238
|
-
end
|
239
|
-
|
240
|
-
let(:result) do
|
241
|
-
JSON.parse(
|
242
|
-
'{'\
|
243
|
-
'"error_count": 0,'\
|
244
|
-
'"error_indices": ['\
|
245
|
-
'],'\
|
246
|
-
'"new_count": 2,'\
|
247
|
-
'"persisted_recipients": ['\
|
248
|
-
'"jones@example.com",'\
|
249
|
-
'"miller@example.com"'\
|
250
|
-
'],'\
|
251
|
-
'"updated_count": 0'\
|
252
|
-
'}'
|
253
|
-
)
|
254
|
-
end
|
255
|
-
|
256
|
-
it '#post_recipients' do
|
257
|
-
allow(client).to receive(:execute).and_return(result)
|
258
|
-
actual = client.post_recipients(params: {})
|
259
|
-
expect(actual).to be_a(SendGrid4r::REST::Contacts::Recipients::Result)
|
260
|
-
end
|
261
|
-
|
262
|
-
it '#patch_recipients' do
|
263
|
-
allow(client).to receive(:execute).and_return(result)
|
264
|
-
actual = client.patch_recipients(params: {})
|
265
|
-
expect(actual).to be_a(SendGrid4r::REST::Contacts::Recipients::Result)
|
266
|
-
end
|
267
|
-
|
268
|
-
it '#delete_recipients' do
|
269
|
-
allow(client).to receive(:execute).and_return('')
|
270
|
-
actual = client.delete_recipients(recipient_ids: ['', ''])
|
271
|
-
expect(actual).to eq('')
|
272
|
-
end
|
273
|
-
|
274
|
-
it '#get_recipients' do
|
275
|
-
allow(client).to receive(:execute).and_return(recipients)
|
276
|
-
actual = client.get_recipients(page: 0, page_size: 0)
|
277
|
-
expect(actual).to be_a(SendGrid4r::REST::Contacts::Recipients::Recipients)
|
278
|
-
end
|
279
|
-
|
280
|
-
it '#get_recipient' do
|
281
|
-
allow(client).to receive(:execute).and_return(recipient)
|
282
|
-
actual = client.get_recipient(recipient_id: '')
|
283
|
-
expect(actual).to be_a(SendGrid4r::REST::Contacts::Recipients::Recipient)
|
284
|
-
end
|
285
|
-
|
286
|
-
it '#delete_recipient' do
|
287
|
-
allow(client).to receive(:execute).and_return('')
|
288
|
-
actual = client.delete_recipient(recipient_id: '')
|
289
|
-
expect(actual).to eq('')
|
290
|
-
end
|
291
|
-
|
292
|
-
it '#get_lists_recipient_belong' do
|
293
|
-
allow(client).to receive(:execute).and_return(lists)
|
294
|
-
actual = client.get_lists_recipient_belong(recipient_id: '')
|
295
|
-
expect(actual).to be_a(SendGrid4r::REST::Contacts::Lists::Lists)
|
296
|
-
end
|
297
|
-
|
298
|
-
it '#get_recipient_count' do
|
299
|
-
allow(client).to receive(:execute).and_return(recipient_count)
|
300
|
-
actual = client.get_recipients_count
|
301
|
-
expect(actual).to be_a(Fixnum)
|
302
|
-
end
|
303
|
-
|
304
|
-
it '#search_recipients' do
|
305
|
-
allow(client).to receive(:execute).and_return(recipients)
|
306
|
-
actual = client.search_recipients(params: {})
|
307
|
-
expect(actual).to be_a(SendGrid4r::REST::Contacts::Recipients::Recipients)
|
308
|
-
end
|
309
|
-
|
310
|
-
it 'creates recipient instance' do
|
311
|
-
actual = SendGrid4r::REST::Contacts::Recipients.create_recipient(
|
312
|
-
recipient
|
313
|
-
)
|
314
|
-
expect(actual).to be_a(SendGrid4r::REST::Contacts::Recipients::Recipient)
|
315
|
-
expect(actual.created_at).to eq(Time.at(1422313607))
|
316
|
-
expect(actual.email).to eq('jones@example.com')
|
317
|
-
expect(actual.first_name).to eq(nil)
|
318
|
-
expect(actual.id).to eq('YUBh')
|
319
|
-
expect(actual.last_clicked).to eq(nil)
|
320
|
-
expect(actual.last_emailed).to eq(nil)
|
321
|
-
expect(actual.last_name).to eq('Jones')
|
322
|
-
expect(actual.last_opened).to eq(nil)
|
323
|
-
expect(actual.updated_at).to eq(Time.at(1422313790))
|
324
|
-
custom_field = actual.custom_fields[0]
|
325
|
-
expect(custom_field.id).to eq(23)
|
326
|
-
expect(custom_field.name).to eq('pet')
|
327
|
-
expect(custom_field.value).to eq('Fluffy')
|
328
|
-
expect(custom_field.type).to eq('text')
|
329
|
-
end
|
330
|
-
|
331
|
-
it 'creates recipients instance' do
|
332
|
-
actual = SendGrid4r::REST::Contacts::Recipients.create_recipients(
|
333
|
-
recipients
|
334
|
-
)
|
335
|
-
expect(actual.recipients).to be_a(Array)
|
336
|
-
actual.recipients.each do |recipient|
|
337
|
-
expect(
|
338
|
-
recipient
|
339
|
-
).to be_a(SendGrid4r::REST::Contacts::Recipients::Recipient)
|
340
|
-
end
|
341
|
-
end
|
342
|
-
end
|
343
|
-
end
|
@@ -1,146 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require File.dirname(__FILE__) + '/../../spec_helper'
|
3
|
-
|
4
|
-
describe SendGrid4r::REST::Contacts::ReservedFields do
|
5
|
-
describe 'integration test', :it do
|
6
|
-
before do
|
7
|
-
Dotenv.load
|
8
|
-
@client = SendGrid4r::Client.new(api_key: ENV['API_KEY'])
|
9
|
-
@first_name =
|
10
|
-
SendGrid4r::REST::Contacts::ReservedFields::Field.new(
|
11
|
-
'first_name', 'text'
|
12
|
-
)
|
13
|
-
@last_name =
|
14
|
-
SendGrid4r::REST::Contacts::ReservedFields::Field.new(
|
15
|
-
'last_name', 'text'
|
16
|
-
)
|
17
|
-
@email =
|
18
|
-
SendGrid4r::REST::Contacts::ReservedFields::Field.new(
|
19
|
-
'email', 'text'
|
20
|
-
)
|
21
|
-
@created_at =
|
22
|
-
SendGrid4r::REST::Contacts::ReservedFields::Field.new(
|
23
|
-
'created_at', 'date'
|
24
|
-
)
|
25
|
-
@updated_at =
|
26
|
-
SendGrid4r::REST::Contacts::ReservedFields::Field.new(
|
27
|
-
'updated_at', 'date'
|
28
|
-
)
|
29
|
-
@last_emailed =
|
30
|
-
SendGrid4r::REST::Contacts::ReservedFields::Field.new(
|
31
|
-
'last_emailed', 'date'
|
32
|
-
)
|
33
|
-
@last_clicked =
|
34
|
-
SendGrid4r::REST::Contacts::ReservedFields::Field.new(
|
35
|
-
'last_clicked', 'date'
|
36
|
-
)
|
37
|
-
@last_opened =
|
38
|
-
SendGrid4r::REST::Contacts::ReservedFields::Field.new(
|
39
|
-
'last_opened', 'date'
|
40
|
-
)
|
41
|
-
end
|
42
|
-
|
43
|
-
context 'without block call' do
|
44
|
-
it '#get_reserved_fields' do
|
45
|
-
begin
|
46
|
-
# get the reserved fields
|
47
|
-
fields = @client.get_reserved_fields
|
48
|
-
expect(fields.reserved_fields.length).to eq(8)
|
49
|
-
set = Set.new(fields.reserved_fields)
|
50
|
-
expect(set.include?(@first_name)).to eq(true)
|
51
|
-
expect(set.include?(@last_name)).to eq(true)
|
52
|
-
expect(set.include?(@email)).to eq(true)
|
53
|
-
expect(set.include?(@created_at)).to eq(true)
|
54
|
-
expect(set.include?(@updated_at)).to eq(true)
|
55
|
-
expect(set.include?(@last_emailed)).to eq(true)
|
56
|
-
expect(set.include?(@last_clicked)).to eq(true)
|
57
|
-
expect(set.include?(@last_opened)).to eq(true)
|
58
|
-
rescue RestClient::ExceptionWithResponse => e
|
59
|
-
puts e.inspect
|
60
|
-
raise e
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
describe 'unit test', :ut do
|
67
|
-
let(:client) do
|
68
|
-
SendGrid4r::Client.new(api_key: '')
|
69
|
-
end
|
70
|
-
|
71
|
-
let(:field) do
|
72
|
-
JSON.parse(
|
73
|
-
'{'\
|
74
|
-
'"name": "first_name",'\
|
75
|
-
'"type": "text"'\
|
76
|
-
'}'
|
77
|
-
)
|
78
|
-
end
|
79
|
-
|
80
|
-
let(:fields) do
|
81
|
-
JSON.parse(
|
82
|
-
'{'\
|
83
|
-
'"reserved_fields": ['\
|
84
|
-
'{'\
|
85
|
-
'"name": "first_name",'\
|
86
|
-
'"type": "text"'\
|
87
|
-
'},'\
|
88
|
-
'{'\
|
89
|
-
'"name": "last_name",'\
|
90
|
-
'"type": "text"'\
|
91
|
-
'},'\
|
92
|
-
'{'\
|
93
|
-
'"name": "email",'\
|
94
|
-
'"type": "text"'\
|
95
|
-
'},'\
|
96
|
-
'{'\
|
97
|
-
'"name": "created_at",'\
|
98
|
-
'"type": "date"'\
|
99
|
-
'},'\
|
100
|
-
'{'\
|
101
|
-
'"name": "updated_at",'\
|
102
|
-
'"type": "date"'\
|
103
|
-
'},'\
|
104
|
-
'{'\
|
105
|
-
'"name": "last_emailed",'\
|
106
|
-
'"type": "date"'\
|
107
|
-
'},'\
|
108
|
-
'{'\
|
109
|
-
'"name": "last_clicked",'\
|
110
|
-
'"type": "date"'\
|
111
|
-
'},'\
|
112
|
-
'{'\
|
113
|
-
'"name": "last_opened",'\
|
114
|
-
'"type": "date"'\
|
115
|
-
'},'\
|
116
|
-
'{'\
|
117
|
-
'"name": "my_custom_field",'\
|
118
|
-
'"type": "text"'\
|
119
|
-
'}'\
|
120
|
-
']'\
|
121
|
-
'}'
|
122
|
-
)
|
123
|
-
end
|
124
|
-
|
125
|
-
it '#get_reserved_fields' do
|
126
|
-
allow(client).to receive(:execute).and_return(fields)
|
127
|
-
actual = client.get_reserved_fields
|
128
|
-
expect(actual).to be_a(SendGrid4r::REST::Contacts::ReservedFields::Fields)
|
129
|
-
end
|
130
|
-
|
131
|
-
it 'creates field instance' do
|
132
|
-
actual = SendGrid4r::REST::Contacts::CustomFields.create_field(field)
|
133
|
-
expect(actual.name).to eq('first_name')
|
134
|
-
expect(actual.type).to eq('text')
|
135
|
-
end
|
136
|
-
|
137
|
-
it 'creates fields instance' do
|
138
|
-
actual = SendGrid4r::REST::Contacts::ReservedFields.create_fields(fields)
|
139
|
-
expect(actual).to be_a(SendGrid4r::REST::Contacts::ReservedFields::Fields)
|
140
|
-
expect(actual.reserved_fields).to be_a(Array)
|
141
|
-
actual.reserved_fields.each do |field|
|
142
|
-
expect(field).to be_a(SendGrid4r::REST::Contacts::ReservedFields::Field)
|
143
|
-
end
|
144
|
-
end
|
145
|
-
end
|
146
|
-
end
|