sendgrid4r 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -1
- data/.travis.yml +1 -0
- data/lib/client.rb +1 -0
- data/lib/sendgrid4r/factory/campaign_factory.rb +25 -0
- data/lib/sendgrid4r/factory/segment_factory.rb +8 -4
- data/lib/sendgrid4r/rest/api.rb +2 -0
- data/lib/sendgrid4r/rest/campaigns/campaigns.rb +128 -0
- data/lib/sendgrid4r/rest/contacts/lists.rb +7 -5
- data/lib/sendgrid4r/rest/contacts/recipients.rb +25 -31
- data/lib/sendgrid4r/rest/contacts/segments.rb +4 -9
- data/lib/sendgrid4r/rest/request.rb +3 -0
- data/lib/sendgrid4r/version.rb +1 -1
- data/spec/client_spec.rb +21 -8
- data/spec/factory/campaign_factory_spec.rb +38 -0
- data/spec/factory/segment_factory_spec.rb +0 -2
- data/spec/rest/campaigns/campaigns_spec.rb +454 -0
- data/spec/rest/contacts/lists_spec.rb +10 -12
- data/spec/rest/contacts/recipients_spec.rb +80 -133
- data/spec/rest/contacts/segments_spec.rb +24 -109
- metadata +8 -2
@@ -0,0 +1,454 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
3
|
+
|
4
|
+
describe SendGrid4r::REST::Campaigns::Campaigns 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
|
+
@title1 = 'Test Title1'
|
11
|
+
@title2 = 'Test Title2'
|
12
|
+
@title1_edit = 'Edit Title1'
|
13
|
+
@subject1 = 'Subject1'
|
14
|
+
@subject2 = 'Subject2'
|
15
|
+
|
16
|
+
@email1 = 'test@example.com'
|
17
|
+
@last_name1 = 'Last Name1'
|
18
|
+
@list_name1 = 'List Name1'
|
19
|
+
@group_name1 = 'Group Name1'
|
20
|
+
|
21
|
+
# celan up test env
|
22
|
+
# delete campaigns
|
23
|
+
campaigns = @client.get_campaigns
|
24
|
+
campaigns.result.each do |campaign|
|
25
|
+
@client.delete_campaign(
|
26
|
+
campaign_id: campaign.id
|
27
|
+
) if campaign.title == @title1
|
28
|
+
@client.delete_campaign(
|
29
|
+
campaign_id: campaign.id
|
30
|
+
) if campaign.title == @title2
|
31
|
+
@client.delete_campaign(
|
32
|
+
campaign_id: campaign.id
|
33
|
+
) if campaign.title == @title1_edit
|
34
|
+
end
|
35
|
+
# delete recipients
|
36
|
+
recipients = @client.get_recipients
|
37
|
+
recipients.recipients.each do |recipient|
|
38
|
+
next if recipient.email != @email1
|
39
|
+
@client.delete_recipient(recipient_id: recipient.id)
|
40
|
+
end
|
41
|
+
# delete lists
|
42
|
+
lists = @client.get_lists
|
43
|
+
lists.lists.each do |list|
|
44
|
+
next if list.name != @list_name1
|
45
|
+
@client.delete_list(list_id: list.id)
|
46
|
+
end
|
47
|
+
# delete suppression groups
|
48
|
+
grps = @client.get_groups
|
49
|
+
grps.each do |grp|
|
50
|
+
next if grp.name != @group_name1
|
51
|
+
@client.delete_group(group_id: grp.id)
|
52
|
+
end
|
53
|
+
# post a recipient
|
54
|
+
recipient1 = {}
|
55
|
+
recipient1['email'] = @email1
|
56
|
+
recipient1['last_name'] = @last_name1
|
57
|
+
@result = @client.post_recipients(params: [recipient1])
|
58
|
+
# post a list
|
59
|
+
@list1 = @client.post_list(name: @list_name1)
|
60
|
+
# add a recipient to the list
|
61
|
+
@client.post_recipient_to_list(
|
62
|
+
list_id: @list1.id, recipient_id: @result.persisted_recipients[0]
|
63
|
+
)
|
64
|
+
# add agroup
|
65
|
+
@group1 = @client.post_group(name: @group_name1, description: 'test')
|
66
|
+
# add a campaign
|
67
|
+
@campaign_factory = SendGrid4r::Factory::CampaignFactory.new
|
68
|
+
@params = @campaign_factory.create(
|
69
|
+
title: @title1, subject: @subject1, sender_id: 493,
|
70
|
+
list_ids: [@list1.id], categories: ['cat1'],
|
71
|
+
suppression_group_id: @group1.id, html_content: 'html',
|
72
|
+
plain_content: 'plain')
|
73
|
+
@campaign1 = @client.post_campaign(params: @params)
|
74
|
+
rescue RestClient::ExceptionWithResponse => e
|
75
|
+
puts e.inspect
|
76
|
+
raise e
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
context 'without block call' do
|
81
|
+
it '#post_campaign' do
|
82
|
+
begin
|
83
|
+
params = @campaign_factory.create(
|
84
|
+
title: @title2, subject: @subject2, sender_id: 493,
|
85
|
+
list_ids: [@list1.id], categories: ['cat1'],
|
86
|
+
suppression_group_id: @group1.id, html_content: 'html',
|
87
|
+
plain_content: 'plain')
|
88
|
+
campaign2 = @client.post_campaign(params: params)
|
89
|
+
expect(campaign2.title).to eq(@title2)
|
90
|
+
expect(campaign2.subject).to eq(@subject2)
|
91
|
+
expect(campaign2.sender_id).to eq(493)
|
92
|
+
expect(campaign2.list_ids).to eq([@list1.id])
|
93
|
+
expect(campaign2.categories).to eq(['cat1'])
|
94
|
+
expect(campaign2.suppression_group_id).to eq(@group1.id)
|
95
|
+
expect(campaign2.html_content).to eq('html')
|
96
|
+
expect(campaign2.plain_content).to eq('plain')
|
97
|
+
rescue RestClient::ExceptionWithResponse => e
|
98
|
+
puts e.inspect
|
99
|
+
raise e
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
it '#get_campaigns' do
|
104
|
+
begin
|
105
|
+
campaigns = @client.get_campaigns
|
106
|
+
expect(campaigns.length).to be >= 1
|
107
|
+
campaigns.result.each do |campaign|
|
108
|
+
next if campaign.title != @title1
|
109
|
+
expect(campaign.title).to eq(@title1)
|
110
|
+
end
|
111
|
+
rescue RestClient::ExceptionWithResponse => e
|
112
|
+
puts e.inspect
|
113
|
+
raise e
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
it '#get_campaign' do
|
118
|
+
begin
|
119
|
+
campaign = @client.get_campaign(campaign_id: @campaign1.id)
|
120
|
+
expect(campaign).to eq(@campaign1)
|
121
|
+
rescue RestClient::ExceptionWithResponse => e
|
122
|
+
puts e.inspect
|
123
|
+
raise e
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
it '#delete_campaign' do
|
128
|
+
begin
|
129
|
+
@client.delete_campaign(campaign_id: @campaign1.id)
|
130
|
+
expect do
|
131
|
+
@client.delete_campaign(campaign_id: @campaign1.id)
|
132
|
+
end.to raise_error(RestClient::ResourceNotFound)
|
133
|
+
rescue RestClient::ExceptionWithResponse => e
|
134
|
+
puts e.inspect
|
135
|
+
raise e
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
it '#patch_campaign' do
|
140
|
+
begin
|
141
|
+
@campaign1.title = @title1_edit
|
142
|
+
actual = @client.patch_campaign(
|
143
|
+
campaign_id: @campaign1.id, params: @campaign1
|
144
|
+
)
|
145
|
+
expect(actual.title).to eq(@title1_edit)
|
146
|
+
rescue RestClient::ExceptionWithResponse => e
|
147
|
+
puts e.inspect
|
148
|
+
raise e
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
it '#send_campaign' do
|
153
|
+
begin
|
154
|
+
actual = @client.send_campaign(campaign_id: @campaign1.id)
|
155
|
+
expect(actual.id).to eq(@campaign1.id)
|
156
|
+
expect(actual.status).to eq('Scheduled')
|
157
|
+
rescue RestClient::ExceptionWithResponse => e
|
158
|
+
puts e.inspect
|
159
|
+
raise e
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
it '#schedule_campaign' do
|
164
|
+
begin
|
165
|
+
send_at = Time.new(2015, 12, 12, 12, 34, 56)
|
166
|
+
actual = @client.schedule_campaign(
|
167
|
+
campaign_id: @campaign1.id,
|
168
|
+
send_at: send_at
|
169
|
+
)
|
170
|
+
expect(actual.id).to eq(@campaign1.id)
|
171
|
+
expect(actual.status).to eq('Scheduled')
|
172
|
+
expect(actual.send_at).to eq(send_at)
|
173
|
+
rescue RestClient::ExceptionWithResponse => e
|
174
|
+
puts e.inspect
|
175
|
+
raise e
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
it '#reschedule_campaign' do
|
180
|
+
begin
|
181
|
+
send_at = Time.new(2015, 12, 12, 12, 34, 56)
|
182
|
+
@client.schedule_campaign(
|
183
|
+
campaign_id: @campaign1.id,
|
184
|
+
send_at: send_at
|
185
|
+
)
|
186
|
+
send_at = Time.new(2015, 11, 11, 11, 11, 11)
|
187
|
+
actual = @client.reschedule_campaign(
|
188
|
+
campaign_id: @campaign1.id,
|
189
|
+
send_at: send_at
|
190
|
+
)
|
191
|
+
expect(actual.id).to eq(@campaign1.id)
|
192
|
+
expect(actual.status).to eq('Scheduled')
|
193
|
+
expect(actual.send_at).to eq(send_at)
|
194
|
+
rescue RestClient::ExceptionWithResponse => e
|
195
|
+
puts e.inspect
|
196
|
+
raise e
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
it '#get_schedule_time_campaign' do
|
201
|
+
begin
|
202
|
+
send_at = Time.new(2015, 12, 12, 12, 34, 56)
|
203
|
+
@client.schedule_campaign(
|
204
|
+
campaign_id: @campaign1.id,
|
205
|
+
send_at: send_at
|
206
|
+
)
|
207
|
+
actual = @client.get_schedule_time_campaign(
|
208
|
+
campaign_id: @campaign1.id
|
209
|
+
)
|
210
|
+
expect(actual.send_at).to eq(send_at)
|
211
|
+
rescue RestClient::ExceptionWithResponse => e
|
212
|
+
puts e.inspect
|
213
|
+
raise e
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
217
|
+
it '#unschedule_campaign' do
|
218
|
+
begin
|
219
|
+
send_at = Time.new(2015, 12, 12, 12, 34, 56)
|
220
|
+
@client.schedule_campaign(
|
221
|
+
campaign_id: @campaign1.id, send_at: send_at
|
222
|
+
)
|
223
|
+
@client.unschedule_campaign(campaign_id: @campaign1.id)
|
224
|
+
rescue RestClient::ExceptionWithResponse => e
|
225
|
+
puts e.inspect
|
226
|
+
raise e
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
230
|
+
it '#test_campaign' do
|
231
|
+
begin
|
232
|
+
@client.test_campaign(campaign_id: @campaign1.id, to: ENV['MAIL'])
|
233
|
+
rescue RestClient::ExceptionWithResponse => e
|
234
|
+
puts e.inspect
|
235
|
+
raise e
|
236
|
+
end
|
237
|
+
end
|
238
|
+
end
|
239
|
+
end
|
240
|
+
|
241
|
+
describe 'unit test', :ut do
|
242
|
+
let(:client) do
|
243
|
+
SendGrid4r::Client.new(api_key: '')
|
244
|
+
end
|
245
|
+
|
246
|
+
let(:campaign) do
|
247
|
+
JSON.parse(
|
248
|
+
'{'\
|
249
|
+
'"id": 986724,'\
|
250
|
+
'"title": "March Newsletter",'\
|
251
|
+
'"subject": "New Products for Spring!",'\
|
252
|
+
'"sender_id": 124451,'\
|
253
|
+
'"list_ids": ['\
|
254
|
+
'110,'\
|
255
|
+
'124'\
|
256
|
+
'],'\
|
257
|
+
'"segment_ids": ['\
|
258
|
+
'110'\
|
259
|
+
'],'\
|
260
|
+
'"categories": ['\
|
261
|
+
'"spring line"'\
|
262
|
+
'],'\
|
263
|
+
'"suppression_group_id": 42,'\
|
264
|
+
'"html_content": "<html><head><title></title></head><body>'\
|
265
|
+
'<p>Check out our spring line!</p></body></html>",'\
|
266
|
+
'"plain_content": "Check out our spring line!",'\
|
267
|
+
'"status": "Draft"'\
|
268
|
+
'}'
|
269
|
+
)
|
270
|
+
end
|
271
|
+
|
272
|
+
let(:campaigns) do
|
273
|
+
JSON.parse(
|
274
|
+
'{'\
|
275
|
+
'"result": ['\
|
276
|
+
'{'\
|
277
|
+
'"id": 986724,'\
|
278
|
+
'"title": "March Newsletter",'\
|
279
|
+
'"subject": "New Products for Spring!",'\
|
280
|
+
'"sender_id": 124451,'\
|
281
|
+
'"list_ids": ['\
|
282
|
+
'110,'\
|
283
|
+
'124'\
|
284
|
+
'],'\
|
285
|
+
'"segment_ids": ['\
|
286
|
+
'110'\
|
287
|
+
'],'\
|
288
|
+
'"categories": ['\
|
289
|
+
'"spring line"'\
|
290
|
+
'],'\
|
291
|
+
'"suppression_group_id": 42,'\
|
292
|
+
'"html_content": "<html><head><title></title></head><body>'\
|
293
|
+
'<p>Check out our spring line!</p></body></html>",'\
|
294
|
+
'"plain_content": "Check out our spring line!",'\
|
295
|
+
'"status": "Draft"'\
|
296
|
+
'},'\
|
297
|
+
'{'\
|
298
|
+
'"id": 986723,'\
|
299
|
+
'"title": "February Newsletter",'\
|
300
|
+
'"subject": "Final Winter Product Sale!",'\
|
301
|
+
'"sender_id": 124451,'\
|
302
|
+
'"list_ids": ['\
|
303
|
+
'110,'\
|
304
|
+
'124'\
|
305
|
+
'],'\
|
306
|
+
'"segment_ids": ['\
|
307
|
+
'110'\
|
308
|
+
'],'\
|
309
|
+
'"categories": ['\
|
310
|
+
'"winter line"'\
|
311
|
+
'],'\
|
312
|
+
'"suppression_group_id": 42,'\
|
313
|
+
'"html_content": "<html><head><title></title></head><body>'\
|
314
|
+
'<p>Last call for winter clothes!</p></body></html>",'\
|
315
|
+
'"plain_content": "Last call for winter clothes!",'\
|
316
|
+
'"status": "Sent"'\
|
317
|
+
'}'\
|
318
|
+
']'\
|
319
|
+
'}'
|
320
|
+
)
|
321
|
+
end
|
322
|
+
|
323
|
+
let(:sent) do
|
324
|
+
JSON.parse(
|
325
|
+
'{'\
|
326
|
+
'"id": 986724,'\
|
327
|
+
'"status": "Scheduled"'\
|
328
|
+
'}'
|
329
|
+
)
|
330
|
+
end
|
331
|
+
|
332
|
+
let(:schedule) do
|
333
|
+
JSON.parse(
|
334
|
+
'{'\
|
335
|
+
'"id": 986724,'\
|
336
|
+
'"send_at": 1489771528,'\
|
337
|
+
'"status": "Scheduled"'\
|
338
|
+
'}'
|
339
|
+
)
|
340
|
+
end
|
341
|
+
|
342
|
+
it '#post_campaign' do
|
343
|
+
allow(client).to receive(:execute).and_return(campaign)
|
344
|
+
actual = client.post_campaign(params: nil)
|
345
|
+
expect(actual).to be_a(SendGrid4r::REST::Campaigns::Campaigns::Campaign)
|
346
|
+
end
|
347
|
+
|
348
|
+
it '#get_campaigns' do
|
349
|
+
allow(client).to receive(:execute).and_return(campaigns)
|
350
|
+
actual = client.get_campaigns
|
351
|
+
expect(actual).to be_a(
|
352
|
+
SendGrid4r::REST::Campaigns::Campaigns::Campaigns
|
353
|
+
)
|
354
|
+
end
|
355
|
+
|
356
|
+
it '#get_campaign' do
|
357
|
+
allow(client).to receive(:execute).and_return(campaign)
|
358
|
+
actual = client.get_campaign(campaign_id: 0)
|
359
|
+
expect(actual).to be_a(SendGrid4r::REST::Campaigns::Campaigns::Campaign)
|
360
|
+
end
|
361
|
+
|
362
|
+
it '#delete_campaign' do
|
363
|
+
allow(client).to receive(:execute).and_return('')
|
364
|
+
client.delete_campaign(campaign_id: 0)
|
365
|
+
end
|
366
|
+
|
367
|
+
it '#patch_campaign' do
|
368
|
+
allow(client).to receive(:execute).and_return(campaign)
|
369
|
+
actual = client.patch_campaign(campaign_id: 0, params: nil)
|
370
|
+
expect(actual).to be_a(SendGrid4r::REST::Campaigns::Campaigns::Campaign)
|
371
|
+
end
|
372
|
+
|
373
|
+
it '#send_campaign' do
|
374
|
+
allow(client).to receive(:execute).and_return(sent)
|
375
|
+
actual = client.send_campaign(campaign_id: 0)
|
376
|
+
expect(actual).to be_a(SendGrid4r::REST::Campaigns::Campaigns::Campaign)
|
377
|
+
end
|
378
|
+
|
379
|
+
it '#schedule_campaign' do
|
380
|
+
allow(client).to receive(:execute).and_return(schedule)
|
381
|
+
actual = client.schedule_campaign(campaign_id: 0, send_at: nil)
|
382
|
+
expect(actual).to be_a(SendGrid4r::REST::Campaigns::Campaigns::Campaign)
|
383
|
+
end
|
384
|
+
|
385
|
+
it '#reschedule_campaign' do
|
386
|
+
allow(client).to receive(:execute).and_return(schedule)
|
387
|
+
actual = client.reschedule_campaign(campaign_id: 0, send_at: nil)
|
388
|
+
expect(actual).to be_a(SendGrid4r::REST::Campaigns::Campaigns::Campaign)
|
389
|
+
end
|
390
|
+
|
391
|
+
it '#get_schedule_time_campaign' do
|
392
|
+
allow(client).to receive(:execute).and_return(schedule)
|
393
|
+
actual = client.get_schedule_time_campaign(campaign_id: 0)
|
394
|
+
expect(actual).to be_a(SendGrid4r::REST::Campaigns::Campaigns::Campaign)
|
395
|
+
end
|
396
|
+
|
397
|
+
it '#unschedule_campaign' do
|
398
|
+
allow(client).to receive(:execute).and_return('')
|
399
|
+
actual = client.unschedule_campaign(campaign_id: 0)
|
400
|
+
expect(actual).to eq('')
|
401
|
+
end
|
402
|
+
|
403
|
+
it '#test_campaign' do
|
404
|
+
allow(client).to receive(:execute).and_return('')
|
405
|
+
actual = client.test_campaign(campaign_id: 0, to: '')
|
406
|
+
expect(actual).to eq('')
|
407
|
+
end
|
408
|
+
|
409
|
+
it 'creates campaign instance' do
|
410
|
+
actual = SendGrid4r::REST::Campaigns::Campaigns.create_campaign(campaign)
|
411
|
+
expect(actual).to be_a(SendGrid4r::REST::Campaigns::Campaigns::Campaign)
|
412
|
+
expect(actual.id).to eq(986724)
|
413
|
+
expect(actual.title).to eq('March Newsletter')
|
414
|
+
expect(actual.subject).to eq('New Products for Spring!')
|
415
|
+
expect(actual.sender_id).to eq(124451)
|
416
|
+
expect(actual.list_ids).to eq([110, 124])
|
417
|
+
expect(actual.segment_ids).to eq([110])
|
418
|
+
expect(actual.categories).to eq(['spring line'])
|
419
|
+
expect(actual.suppression_group_id).to eq(42)
|
420
|
+
expect(actual.html_content).to eq(
|
421
|
+
'<html><head><title></title></head><body>'\
|
422
|
+
'<p>Check out our spring line!</p></body></html>')
|
423
|
+
expect(actual.plain_content).to eq('Check out our spring line!')
|
424
|
+
expect(actual.status).to eq('Draft')
|
425
|
+
end
|
426
|
+
|
427
|
+
it 'creates campaigns instance' do
|
428
|
+
actual = SendGrid4r::REST::Campaigns::Campaigns.create_campaigns(
|
429
|
+
campaigns
|
430
|
+
)
|
431
|
+
expect(actual).to be_a(SendGrid4r::REST::Campaigns::Campaigns::Campaigns)
|
432
|
+
actual.result.each do |campaign|
|
433
|
+
expect(campaign).to be_a(
|
434
|
+
SendGrid4r::REST::Campaigns::Campaigns::Campaign
|
435
|
+
)
|
436
|
+
end
|
437
|
+
end
|
438
|
+
|
439
|
+
it 'creates sent instance' do
|
440
|
+
actual = SendGrid4r::REST::Campaigns::Campaigns.create_campaign(sent)
|
441
|
+
expect(actual).to be_a(SendGrid4r::REST::Campaigns::Campaigns::Campaign)
|
442
|
+
expect(actual.id).to eq(986724)
|
443
|
+
expect(actual.status).to eq('Scheduled')
|
444
|
+
end
|
445
|
+
|
446
|
+
it 'creates schedule instance' do
|
447
|
+
actual = SendGrid4r::REST::Campaigns::Campaigns.create_campaign(schedule)
|
448
|
+
expect(actual).to be_a(SendGrid4r::REST::Campaigns::Campaigns::Campaign)
|
449
|
+
expect(actual.id).to eq(986724)
|
450
|
+
expect(actual.send_at).to eq(Time.at(1489771528))
|
451
|
+
expect(actual.status).to eq('Scheduled')
|
452
|
+
end
|
453
|
+
end
|
454
|
+
end
|
@@ -5,7 +5,6 @@ describe SendGrid4r::REST::Contacts::Lists do
|
|
5
5
|
describe 'integration test', :it do
|
6
6
|
before do
|
7
7
|
begin
|
8
|
-
pending 'waiting sendgrid documentation update'
|
9
8
|
Dotenv.load
|
10
9
|
@client = SendGrid4r::Client.new(api_key: ENV['API_KEY'])
|
11
10
|
@list_name1 = 'test_list1'
|
@@ -18,7 +17,6 @@ describe SendGrid4r::REST::Contacts::Lists do
|
|
18
17
|
@pet1 = 'Fluffy'
|
19
18
|
@pet2 = 'FrouFrou'
|
20
19
|
@custom_field_name = 'pet'
|
21
|
-
@recipients = [@email1, @email2]
|
22
20
|
|
23
21
|
# celan up test env(lists)
|
24
22
|
lists = @client.get_lists
|
@@ -44,17 +42,17 @@ describe SendGrid4r::REST::Contacts::Lists do
|
|
44
42
|
recipient1['email'] = @email1
|
45
43
|
recipient1['last_name'] = @last_name1
|
46
44
|
recipient1[@custom_field_name] = @pet1
|
47
|
-
recipient1 = @client.post_recipient(params: recipient1)
|
48
|
-
@client.post_recipient_to_list(
|
49
|
-
list_id: @list1.id, recipient_id: recipient1.id
|
50
|
-
)
|
51
45
|
recipient2 = {}
|
52
46
|
recipient2['email'] = @email2
|
53
47
|
recipient2['last_name'] = @last_name2
|
54
48
|
recipient2[@custom_field_name] = @pet2
|
55
|
-
|
49
|
+
result = @client.post_recipients(params: [recipient1, recipient2])
|
50
|
+
@recipients = result.persisted_recipients
|
51
|
+
@client.post_recipient_to_list(
|
52
|
+
list_id: @list1.id, recipient_id: result.persisted_recipients[0]
|
53
|
+
)
|
56
54
|
@client.post_recipient_to_list(
|
57
|
-
list_id: @list1.id, recipient_id:
|
55
|
+
list_id: @list1.id, recipient_id: result.persisted_recipients[1]
|
58
56
|
)
|
59
57
|
# # Add multiple recipients to a single list
|
60
58
|
# @client.post_recipients_to_list(@list1.id, @recipients)
|
@@ -145,7 +143,7 @@ describe SendGrid4r::REST::Contacts::Lists do
|
|
145
143
|
it '#get_recipients_from_list with offset & limit' do
|
146
144
|
begin
|
147
145
|
recipients = @client.get_recipients_from_list(
|
148
|
-
list_id: @list1.id,
|
146
|
+
list_id: @list1.id, page: 1, page_size: 10
|
149
147
|
)
|
150
148
|
recipients.recipients.each do |recipient|
|
151
149
|
expect(
|
@@ -161,7 +159,7 @@ describe SendGrid4r::REST::Contacts::Lists do
|
|
161
159
|
it '#delete_recipient_from_list' do
|
162
160
|
begin
|
163
161
|
@client.delete_recipient_from_list(
|
164
|
-
list_id: @list1.id, recipient_id: @
|
162
|
+
list_id: @list1.id, recipient_id: @recipients[0]
|
165
163
|
)
|
166
164
|
rescue RestClient::ExceptionWithResponse => e
|
167
165
|
puts e.inspect
|
@@ -208,9 +206,9 @@ describe SendGrid4r::REST::Contacts::Lists do
|
|
208
206
|
recipient1['email'] = @email1
|
209
207
|
recipient1['last_name'] = @last_name1
|
210
208
|
recipient1[@custom_field_name] = @pet1
|
211
|
-
|
209
|
+
result = @client.post_recipients(params: [recipient1])
|
212
210
|
@client.post_recipient_to_list(
|
213
|
-
list_id: @list1.id, recipient_id:
|
211
|
+
list_id: @list1.id, recipient_id: result.persisted_recipients[0]
|
214
212
|
)
|
215
213
|
rescue RestClient::ExceptionWithResponse => e
|
216
214
|
puts e.inspect
|