sendgrid4r 0.3.0 → 0.4.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 +4 -1
- data/.travis.yml +1 -1
- data/lib/client.rb +0 -2
- data/lib/sendgrid4r/rest/api.rb +4 -0
- data/lib/sendgrid4r/rest/api_keys/api_keys.rb +4 -10
- data/lib/sendgrid4r/rest/asm/global_suppressions.rb +9 -16
- data/lib/sendgrid4r/rest/asm/groups.rb +3 -7
- data/lib/sendgrid4r/rest/asm/suppressions.rb +25 -18
- data/lib/sendgrid4r/rest/categories/categories.rb +1 -3
- data/lib/sendgrid4r/rest/contacts/custom_fields.rb +1 -1
- data/lib/sendgrid4r/rest/contacts/lists.rb +15 -37
- data/lib/sendgrid4r/rest/contacts/recipients.rb +19 -44
- data/lib/sendgrid4r/rest/contacts/reserved_fields.rb +1 -5
- data/lib/sendgrid4r/rest/contacts/segments.rb +9 -16
- data/lib/sendgrid4r/rest/email_activity/email_activity.rb +84 -0
- data/lib/sendgrid4r/rest/ips/addresses.rb +9 -18
- data/lib/sendgrid4r/rest/ips/pools.rb +7 -12
- data/lib/sendgrid4r/rest/ips/warmup.rb +7 -17
- data/lib/sendgrid4r/rest/request.rb +7 -1
- data/lib/sendgrid4r/rest/settings/enforced_tls.rb +5 -12
- data/lib/sendgrid4r/rest/stats/advanced.rb +10 -32
- data/lib/sendgrid4r/rest/stats/category.rb +4 -11
- data/lib/sendgrid4r/rest/stats/global.rb +3 -2
- data/lib/sendgrid4r/rest/stats/parse.rb +4 -6
- data/lib/sendgrid4r/rest/stats/subuser.rb +4 -11
- data/lib/sendgrid4r/rest/subusers/subusers.rb +83 -0
- data/lib/sendgrid4r/rest/templates/templates.rb +1 -1
- data/lib/sendgrid4r/rest/templates/versions.rb +3 -2
- data/lib/sendgrid4r/version.rb +1 -1
- data/spec/client_spec.rb +17 -4
- data/spec/factory/condition_factory_spec.rb +1 -1
- data/spec/factory/segment_factory_spec.rb +1 -1
- data/spec/factory/version_factory_spec.rb +1 -1
- data/spec/{api_keys → rest/api_keys}/api_keys_spec.rb +52 -18
- data/spec/{asm → rest/asm}/asm_spec.rb +23 -17
- data/spec/{asm → rest/asm}/global_suppressions_spec.rb +45 -2
- data/spec/{asm → rest/asm}/groups_spec.rb +76 -7
- data/spec/{asm → rest/asm}/suppressions_spec.rb +95 -20
- data/spec/{categories → rest/categories}/categories_spec.rb +27 -7
- data/spec/{contacts → rest/contacts}/custom_fields_spec.rb +49 -15
- data/spec/{contacts → rest/contacts}/lists_spec.rb +138 -15
- data/spec/{contacts → rest/contacts}/recipients_spec.rb +141 -26
- data/spec/{contacts → rest/contacts}/reserved_fields_spec.rb +29 -13
- data/spec/{contacts → rest/contacts}/segments_spec.rb +108 -31
- data/spec/rest/email_activity/email_activity_spec.rb +192 -0
- data/spec/{ips → rest/ips}/addresses_spec.rb +58 -18
- data/spec/{ips → rest/ips}/pools_spec.rb +80 -45
- data/spec/{ips → rest/ips}/warmup_spec.rb +50 -7
- data/spec/{settings → rest/settings}/enforced_tls_spec.rb +32 -7
- data/spec/{stats → rest/stats}/advanced_spec.rb +2 -2
- data/spec/{stats → rest/stats}/category_spec.rb +2 -2
- data/spec/{stats → rest/stats}/global_spec.rb +2 -2
- data/spec/{stats → rest/stats}/parse_spec.rb +2 -2
- data/spec/{stats → rest/stats}/stats_spec.rb +2 -2
- data/spec/{stats → rest/stats}/subuser_spec.rb +2 -2
- data/spec/rest/subusers/subusers_spec.rb +246 -0
- data/spec/{templates → rest/templates}/templates_spec.rb +55 -15
- data/spec/{templates → rest/templates}/versions_spec.rb +44 -7
- metadata +54 -48
@@ -1,10 +1,11 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
require File.dirname(__FILE__) + '
|
2
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
3
3
|
|
4
4
|
describe SendGrid4r::REST::Contacts::Lists do
|
5
|
-
describe 'integration test' do
|
5
|
+
describe 'integration test', :it do
|
6
6
|
before do
|
7
7
|
begin
|
8
|
+
pending 'waiting sendgrid documentation update'
|
8
9
|
Dotenv.load
|
9
10
|
@client = SendGrid4r::Client.new(
|
10
11
|
username: ENV['SENDGRID_USERNAME'],
|
@@ -342,24 +343,23 @@ describe SendGrid4r::REST::Contacts::Lists do
|
|
342
343
|
end
|
343
344
|
end
|
344
345
|
|
345
|
-
describe 'unit test' do
|
346
|
-
|
347
|
-
|
346
|
+
describe 'unit test', :ut do
|
347
|
+
let(:client) do
|
348
|
+
SendGrid4r::Client.new(api_key: '')
|
349
|
+
end
|
350
|
+
|
351
|
+
let(:list) do
|
352
|
+
JSON.parse(
|
348
353
|
'{'\
|
349
354
|
'"id": 1,'\
|
350
355
|
'"name": "listname",'\
|
351
356
|
'"recipient_count": 0'\
|
352
357
|
'}'
|
353
|
-
|
354
|
-
actual = SendGrid4r::REST::Contacts::Lists.create_list(hash)
|
355
|
-
expect(actual).to be_a(SendGrid4r::REST::Contacts::Lists::List)
|
356
|
-
expect(actual.id).to eq(1)
|
357
|
-
expect(actual.name).to eq('listname')
|
358
|
-
expect(actual.recipient_count).to eq(0)
|
358
|
+
)
|
359
359
|
end
|
360
360
|
|
361
|
-
|
362
|
-
|
361
|
+
let(:lists) do
|
362
|
+
JSON.parse(
|
363
363
|
'{'\
|
364
364
|
'"lists": ['\
|
365
365
|
'{'\
|
@@ -369,8 +369,131 @@ describe SendGrid4r::REST::Contacts::Lists do
|
|
369
369
|
'}'\
|
370
370
|
']'\
|
371
371
|
'}'
|
372
|
-
|
373
|
-
|
372
|
+
)
|
373
|
+
end
|
374
|
+
|
375
|
+
let(:recipient) do
|
376
|
+
JSON.parse(
|
377
|
+
'{'\
|
378
|
+
'"created_at": 1422313607,'\
|
379
|
+
'"email": "jones@example.com",'\
|
380
|
+
'"first_name": null,'\
|
381
|
+
'"id": "jones@example.com",'\
|
382
|
+
'"last_clicked": null,'\
|
383
|
+
'"last_emailed": null,'\
|
384
|
+
'"last_name": "Jones",'\
|
385
|
+
'"last_opened": null,'\
|
386
|
+
'"updated_at": 1422313790,'\
|
387
|
+
'"custom_fields": ['\
|
388
|
+
'{'\
|
389
|
+
'"id": 23,'\
|
390
|
+
'"name": "pet",'\
|
391
|
+
'"value": "Fluffy",'\
|
392
|
+
'"type": "text"'\
|
393
|
+
'}'\
|
394
|
+
']'\
|
395
|
+
'}'
|
396
|
+
)
|
397
|
+
end
|
398
|
+
|
399
|
+
let(:recipients) do
|
400
|
+
JSON.parse(
|
401
|
+
'{'\
|
402
|
+
'"recipients": ['\
|
403
|
+
'{'\
|
404
|
+
'"created_at": 1422313607,'\
|
405
|
+
'"email": "jones@example.com",'\
|
406
|
+
'"first_name": null,'\
|
407
|
+
'"id": "jones@example.com",'\
|
408
|
+
'"last_clicked": null,'\
|
409
|
+
'"last_emailed": null,'\
|
410
|
+
'"last_name": "Jones",'\
|
411
|
+
'"last_opened": null,'\
|
412
|
+
'"updated_at": 1422313790,'\
|
413
|
+
'"custom_fields": ['\
|
414
|
+
'{'\
|
415
|
+
'"id": 23,'\
|
416
|
+
'"name": "pet",'\
|
417
|
+
'"value": "Fluffy",'\
|
418
|
+
'"type": "text"'\
|
419
|
+
'}'\
|
420
|
+
']'\
|
421
|
+
'}'\
|
422
|
+
']'\
|
423
|
+
'}'
|
424
|
+
)
|
425
|
+
end
|
426
|
+
|
427
|
+
it '#post_list' do
|
428
|
+
allow(client).to receive(:execute).and_return(list)
|
429
|
+
actual = client.post_list('')
|
430
|
+
expect(actual).to be_a(SendGrid4r::REST::Contacts::Lists::List)
|
431
|
+
end
|
432
|
+
|
433
|
+
it '#get_lists' do
|
434
|
+
allow(client).to receive(:execute).and_return(lists)
|
435
|
+
actual = client.get_lists
|
436
|
+
expect(actual).to be_a(SendGrid4r::REST::Contacts::Lists::Lists)
|
437
|
+
end
|
438
|
+
|
439
|
+
it '#get_list' do
|
440
|
+
allow(client).to receive(:execute).and_return(list)
|
441
|
+
actual = client.get_list(0)
|
442
|
+
expect(actual).to be_a(SendGrid4r::REST::Contacts::Lists::List)
|
443
|
+
end
|
444
|
+
|
445
|
+
it '#patch_list' do
|
446
|
+
allow(client).to receive(:execute).and_return(list)
|
447
|
+
actual = client.patch_list(0, '')
|
448
|
+
expect(actual).to be_a(SendGrid4r::REST::Contacts::Lists::List)
|
449
|
+
end
|
450
|
+
|
451
|
+
it '#get_recipients_from_list' do
|
452
|
+
allow(client).to receive(:execute).and_return(recipients)
|
453
|
+
actual = client.get_recipients_from_list(0)
|
454
|
+
expect(actual).to be_a(SendGrid4r::REST::Contacts::Recipients::Recipients)
|
455
|
+
end
|
456
|
+
|
457
|
+
it '#delete_recipient_from_list' do
|
458
|
+
allow(client).to receive(:execute).and_return('')
|
459
|
+
actual = client.delete_recipient_from_list(0, '')
|
460
|
+
expect(actual).to eq('')
|
461
|
+
end
|
462
|
+
|
463
|
+
it '#delete_list' do
|
464
|
+
allow(client).to receive(:execute).and_return('')
|
465
|
+
actual = client.delete_list(0)
|
466
|
+
expect(actual).to eq('')
|
467
|
+
end
|
468
|
+
|
469
|
+
it '#delete_lists' do
|
470
|
+
allow(client).to receive(:execute).and_return('')
|
471
|
+
actual = client.delete_lists([0, 1])
|
472
|
+
expect(actual).to eq('')
|
473
|
+
end
|
474
|
+
|
475
|
+
it '#post_recipients_to_list' do
|
476
|
+
allow(client).to receive(:execute).and_return('')
|
477
|
+
actual = client.post_recipients_to_list(0, ['', ''])
|
478
|
+
expect(actual).to eq('')
|
479
|
+
end
|
480
|
+
|
481
|
+
it '#post_recipient_to_list' do
|
482
|
+
allow(client).to receive(:execute).and_return('')
|
483
|
+
actual = client.post_recipient_to_list(0, 0)
|
484
|
+
expect(actual).to eq('')
|
485
|
+
end
|
486
|
+
|
487
|
+
it 'creates list instance' do
|
488
|
+
actual = SendGrid4r::REST::Contacts::Lists.create_list(list)
|
489
|
+
expect(actual).to be_a(SendGrid4r::REST::Contacts::Lists::List)
|
490
|
+
expect(actual.id).to eq(1)
|
491
|
+
expect(actual.name).to eq('listname')
|
492
|
+
expect(actual.recipient_count).to eq(0)
|
493
|
+
end
|
494
|
+
|
495
|
+
it 'creates lists instance' do
|
496
|
+
actual = SendGrid4r::REST::Contacts::Lists.create_lists(lists)
|
374
497
|
expect(actual.lists).to be_a(Array)
|
375
498
|
actual.lists.each do |list|
|
376
499
|
expect(list).to be_a(SendGrid4r::REST::Contacts::Lists::List)
|
@@ -1,10 +1,11 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
require File.dirname(__FILE__) + '
|
2
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
3
3
|
|
4
4
|
describe SendGrid4r::REST::Contacts::Recipients do
|
5
|
-
describe 'integration test' do
|
5
|
+
describe 'integration test', :it do
|
6
6
|
before do
|
7
7
|
begin
|
8
|
+
pending 'waiting sendgrid documentation update'
|
8
9
|
Dotenv.load
|
9
10
|
@client = SendGrid4r::Client.new(
|
10
11
|
username: ENV['SENDGRID_USERNAME'],
|
@@ -366,9 +367,13 @@ describe SendGrid4r::REST::Contacts::Recipients do
|
|
366
367
|
end
|
367
368
|
end
|
368
369
|
|
369
|
-
describe 'unit test' do
|
370
|
-
|
371
|
-
|
370
|
+
describe 'unit test', :ut do
|
371
|
+
let(:client) do
|
372
|
+
SendGrid4r::Client.new(api_key: '')
|
373
|
+
end
|
374
|
+
|
375
|
+
let(:recipient) do
|
376
|
+
JSON.parse(
|
372
377
|
'{'\
|
373
378
|
'"created_at": 1422313607,'\
|
374
379
|
'"email": "jones@example.com",'\
|
@@ -388,27 +393,11 @@ describe SendGrid4r::REST::Contacts::Recipients do
|
|
388
393
|
'}'\
|
389
394
|
']'\
|
390
395
|
'}'
|
391
|
-
|
392
|
-
actual = SendGrid4r::REST::Contacts::Recipients.create_recipient(hash)
|
393
|
-
expect(actual).to be_a(SendGrid4r::REST::Contacts::Recipients::Recipient)
|
394
|
-
expect(actual.created_at).to eq(Time.at(1422313607))
|
395
|
-
expect(actual.email).to eq('jones@example.com')
|
396
|
-
expect(actual.first_name).to eq(nil)
|
397
|
-
expect(actual.id).to eq('jones@example.com')
|
398
|
-
expect(actual.last_clicked).to eq(nil)
|
399
|
-
expect(actual.last_emailed).to eq(nil)
|
400
|
-
expect(actual.last_name).to eq('Jones')
|
401
|
-
expect(actual.last_opened).to eq(nil)
|
402
|
-
expect(actual.updated_at).to eq(Time.at(1422313790))
|
403
|
-
custom_field = actual.custom_fields[0]
|
404
|
-
expect(custom_field.id).to eq(23)
|
405
|
-
expect(custom_field.name).to eq('pet')
|
406
|
-
expect(custom_field.value).to eq('Fluffy')
|
407
|
-
expect(custom_field.type).to eq('text')
|
396
|
+
)
|
408
397
|
end
|
409
398
|
|
410
|
-
|
411
|
-
|
399
|
+
let(:recipients) do
|
400
|
+
JSON.parse(
|
412
401
|
'{'\
|
413
402
|
'"recipients": ['\
|
414
403
|
'{'\
|
@@ -432,8 +421,134 @@ describe SendGrid4r::REST::Contacts::Recipients do
|
|
432
421
|
'}'\
|
433
422
|
']'\
|
434
423
|
'}'
|
435
|
-
|
436
|
-
|
424
|
+
)
|
425
|
+
end
|
426
|
+
|
427
|
+
let(:recipient_count) do
|
428
|
+
JSON.parse(
|
429
|
+
'{'\
|
430
|
+
'"recipient_count": 2'\
|
431
|
+
'}'
|
432
|
+
)
|
433
|
+
end
|
434
|
+
|
435
|
+
let(:lists) do
|
436
|
+
JSON.parse(
|
437
|
+
'{'\
|
438
|
+
'"lists": ['\
|
439
|
+
'{'\
|
440
|
+
'"id": 1,'\
|
441
|
+
'"name": "the jones",'\
|
442
|
+
'"recipient_count": 1'\
|
443
|
+
'}'\
|
444
|
+
']'\
|
445
|
+
'}'
|
446
|
+
)
|
447
|
+
end
|
448
|
+
|
449
|
+
let(:result) do
|
450
|
+
JSON.parse(
|
451
|
+
'{'\
|
452
|
+
'"error_count": 0,'\
|
453
|
+
'"error_indices": ['\
|
454
|
+
'],'\
|
455
|
+
'"new_count": 2,'\
|
456
|
+
'"persisted_recipients": ['\
|
457
|
+
'"jones@example.com",'\
|
458
|
+
'"miller@example.com"'\
|
459
|
+
'],'\
|
460
|
+
'"updated_count": 0'\
|
461
|
+
'}'
|
462
|
+
)
|
463
|
+
end
|
464
|
+
|
465
|
+
it '#post_recipient' do
|
466
|
+
allow(client).to receive(:execute).and_return(recipient)
|
467
|
+
actual = client.post_recipient({})
|
468
|
+
expect(actual).to be_a(SendGrid4r::REST::Contacts::Recipients::Recipient)
|
469
|
+
end
|
470
|
+
|
471
|
+
it '#get_recipients' do
|
472
|
+
allow(client).to receive(:execute).and_return(recipients)
|
473
|
+
actual = client.get_recipients(0, 0)
|
474
|
+
expect(actual).to be_a(SendGrid4r::REST::Contacts::Recipients::Recipients)
|
475
|
+
end
|
476
|
+
|
477
|
+
it '#get_recipient_count' do
|
478
|
+
allow(client).to receive(:execute).and_return(recipient_count)
|
479
|
+
actual = client.get_recipients_count
|
480
|
+
expect(actual).to be_a(Fixnum)
|
481
|
+
end
|
482
|
+
|
483
|
+
it '#search_recipients' do
|
484
|
+
allow(client).to receive(:execute).and_return(recipients)
|
485
|
+
actual = client.search_recipients({})
|
486
|
+
expect(actual).to be_a(SendGrid4r::REST::Contacts::Recipients::Recipients)
|
487
|
+
end
|
488
|
+
|
489
|
+
it '#get_recipient' do
|
490
|
+
allow(client).to receive(:execute).and_return(recipient)
|
491
|
+
actual = client.get_recipient(0)
|
492
|
+
expect(actual).to be_a(SendGrid4r::REST::Contacts::Recipients::Recipient)
|
493
|
+
end
|
494
|
+
|
495
|
+
it '#get_lists_recipient_belong' do
|
496
|
+
allow(client).to receive(:execute).and_return(lists)
|
497
|
+
actual = client.get_lists_recipient_belong(0)
|
498
|
+
expect(actual).to be_a(SendGrid4r::REST::Contacts::Lists::Lists)
|
499
|
+
end
|
500
|
+
|
501
|
+
it '#post_recipients' do
|
502
|
+
allow(client).to receive(:execute).and_return(result)
|
503
|
+
actual = client.post_recipients([{}, {}])
|
504
|
+
expect(actual).to be_a(
|
505
|
+
SendGrid4r::REST::Contacts::Recipients::ResultAddMultiple
|
506
|
+
)
|
507
|
+
end
|
508
|
+
|
509
|
+
it '#get_recipients_by_id' do
|
510
|
+
allow(client).to receive(:execute).and_return(recipients)
|
511
|
+
actual = client.get_recipients_by_id(['', ''])
|
512
|
+
expect(actual).to be_a(SendGrid4r::REST::Contacts::Recipients::Recipients)
|
513
|
+
end
|
514
|
+
|
515
|
+
it '#delete_recipient' do
|
516
|
+
allow(client).to receive(:execute).and_return('')
|
517
|
+
actual = client.delete_recipient(0)
|
518
|
+
expect(actual).to eq('')
|
519
|
+
end
|
520
|
+
|
521
|
+
it '#delete_recipients' do
|
522
|
+
allow(client).to receive(:execute).and_return('')
|
523
|
+
actual = client.delete_recipients(['', ''])
|
524
|
+
expect(actual).to eq('')
|
525
|
+
end
|
526
|
+
|
527
|
+
it 'creates recipient instance' do
|
528
|
+
actual = SendGrid4r::REST::Contacts::Recipients.create_recipient(
|
529
|
+
recipient
|
530
|
+
)
|
531
|
+
expect(actual).to be_a(SendGrid4r::REST::Contacts::Recipients::Recipient)
|
532
|
+
expect(actual.created_at).to eq(Time.at(1422313607))
|
533
|
+
expect(actual.email).to eq('jones@example.com')
|
534
|
+
expect(actual.first_name).to eq(nil)
|
535
|
+
expect(actual.id).to eq('jones@example.com')
|
536
|
+
expect(actual.last_clicked).to eq(nil)
|
537
|
+
expect(actual.last_emailed).to eq(nil)
|
538
|
+
expect(actual.last_name).to eq('Jones')
|
539
|
+
expect(actual.last_opened).to eq(nil)
|
540
|
+
expect(actual.updated_at).to eq(Time.at(1422313790))
|
541
|
+
custom_field = actual.custom_fields[0]
|
542
|
+
expect(custom_field.id).to eq(23)
|
543
|
+
expect(custom_field.name).to eq('pet')
|
544
|
+
expect(custom_field.value).to eq('Fluffy')
|
545
|
+
expect(custom_field.type).to eq('text')
|
546
|
+
end
|
547
|
+
|
548
|
+
it 'creates recipients instance' do
|
549
|
+
actual = SendGrid4r::REST::Contacts::Recipients.create_recipients(
|
550
|
+
recipients
|
551
|
+
)
|
437
552
|
expect(actual.recipients).to be_a(Array)
|
438
553
|
actual.recipients.each do |recipient|
|
439
554
|
expect(
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
require File.dirname(__FILE__) + '
|
2
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
3
3
|
|
4
4
|
describe SendGrid4r::REST::Contacts::ReservedFields do
|
5
|
-
describe 'integration test' do
|
5
|
+
describe 'integration test', :it do
|
6
6
|
before do
|
7
7
|
Dotenv.load
|
8
8
|
@client = SendGrid4r::Client.new(
|
@@ -81,21 +81,22 @@ describe SendGrid4r::REST::Contacts::ReservedFields do
|
|
81
81
|
end
|
82
82
|
end
|
83
83
|
|
84
|
-
describe 'unit test' do
|
85
|
-
|
86
|
-
|
84
|
+
describe 'unit test', :ut do
|
85
|
+
let(:client) do
|
86
|
+
SendGrid4r::Client.new(api_key: '')
|
87
|
+
end
|
88
|
+
|
89
|
+
let(:field) do
|
90
|
+
JSON.parse(
|
87
91
|
'{'\
|
88
92
|
'"name": "first_name",'\
|
89
93
|
'"type": "text"'\
|
90
94
|
'}'
|
91
|
-
|
92
|
-
actual = SendGrid4r::REST::Contacts::CustomFields.create_field(hash)
|
93
|
-
expect(actual.name).to eq('first_name')
|
94
|
-
expect(actual.type).to eq('text')
|
95
|
+
)
|
95
96
|
end
|
96
97
|
|
97
|
-
|
98
|
-
|
98
|
+
let(:fields) do
|
99
|
+
JSON.parse(
|
99
100
|
'{'\
|
100
101
|
'"reserved_fields": ['\
|
101
102
|
'{'\
|
@@ -136,8 +137,23 @@ describe SendGrid4r::REST::Contacts::ReservedFields do
|
|
136
137
|
'}'\
|
137
138
|
']'\
|
138
139
|
'}'
|
139
|
-
|
140
|
-
|
140
|
+
)
|
141
|
+
end
|
142
|
+
|
143
|
+
it '#get_reserved_fields' do
|
144
|
+
allow(client).to receive(:execute).and_return(fields)
|
145
|
+
actual = client.get_reserved_fields
|
146
|
+
expect(actual).to be_a(SendGrid4r::REST::Contacts::ReservedFields::Fields)
|
147
|
+
end
|
148
|
+
|
149
|
+
it 'creates field instance' do
|
150
|
+
actual = SendGrid4r::REST::Contacts::CustomFields.create_field(field)
|
151
|
+
expect(actual.name).to eq('first_name')
|
152
|
+
expect(actual.type).to eq('text')
|
153
|
+
end
|
154
|
+
|
155
|
+
it 'creates fields instance' do
|
156
|
+
actual = SendGrid4r::REST::Contacts::ReservedFields.create_fields(fields)
|
141
157
|
expect(actual).to be_a(SendGrid4r::REST::Contacts::ReservedFields::Fields)
|
142
158
|
expect(actual.reserved_fields).to be_a(Array)
|
143
159
|
actual.reserved_fields.each do |field|
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
require File.dirname(__FILE__) + '
|
2
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
3
3
|
|
4
4
|
describe SendGrid4r::REST::Contacts::Segments do
|
5
|
-
describe 'integration test' do
|
5
|
+
describe 'integration test', :it do
|
6
6
|
before do
|
7
7
|
begin
|
8
8
|
Dotenv.load
|
@@ -220,26 +220,24 @@ describe SendGrid4r::REST::Contacts::Segments do
|
|
220
220
|
end
|
221
221
|
end
|
222
222
|
|
223
|
-
describe 'unit test' do
|
224
|
-
|
225
|
-
|
223
|
+
describe 'unit test', :ut do
|
224
|
+
let(:client) do
|
225
|
+
SendGrid4r::Client.new(api_key: '')
|
226
|
+
end
|
227
|
+
|
228
|
+
let(:condition) do
|
229
|
+
JSON.parse(
|
226
230
|
'{'\
|
227
231
|
'"field": "last_name",'\
|
228
232
|
'"value": "Miller",'\
|
229
233
|
'"operator": "eq",'\
|
230
234
|
'"and_or": ""'\
|
231
235
|
'}'
|
232
|
-
|
233
|
-
actual = SendGrid4r::REST::Contacts::Segments.create_condition(hash)
|
234
|
-
expect(actual).to be_a(SendGrid4r::REST::Contacts::Segments::Condition)
|
235
|
-
expect(actual.field).to eq('last_name')
|
236
|
-
expect(actual.value).to eq('Miller')
|
237
|
-
expect(actual.operator).to eq('eq')
|
238
|
-
expect(actual.and_or).to eq('')
|
236
|
+
)
|
239
237
|
end
|
240
238
|
|
241
|
-
|
242
|
-
|
239
|
+
let(:segment) do
|
240
|
+
JSON.parse(
|
243
241
|
'{'\
|
244
242
|
'"id": 1,'\
|
245
243
|
'"name": "Last Name Miller",'\
|
@@ -254,23 +252,11 @@ describe SendGrid4r::REST::Contacts::Segments do
|
|
254
252
|
'],'\
|
255
253
|
'"recipient_count": 1'\
|
256
254
|
'}'
|
257
|
-
|
258
|
-
actual = SendGrid4r::REST::Contacts::Segments.create_segment(hash)
|
259
|
-
expect(actual).to be_a(SendGrid4r::REST::Contacts::Segments::Segment)
|
260
|
-
expect(actual.id).to eq(1)
|
261
|
-
expect(actual.name).to eq('Last Name Miller')
|
262
|
-
expect(actual.list_id).to eq(nil)
|
263
|
-
expect(actual.conditions).to be_a(Array)
|
264
|
-
actual.conditions.each do |condition|
|
265
|
-
expect(condition).to be_a(
|
266
|
-
SendGrid4r::REST::Contacts::Segments::Condition
|
267
|
-
)
|
268
|
-
end
|
269
|
-
expect(actual.recipient_count).to be_a(Fixnum)
|
255
|
+
)
|
270
256
|
end
|
271
257
|
|
272
|
-
|
273
|
-
|
258
|
+
let(:segments) do
|
259
|
+
JSON.parse(
|
274
260
|
'{'\
|
275
261
|
'"segments": ['\
|
276
262
|
'{'\
|
@@ -289,8 +275,99 @@ describe SendGrid4r::REST::Contacts::Segments do
|
|
289
275
|
'}'\
|
290
276
|
']'\
|
291
277
|
'}'
|
292
|
-
|
293
|
-
|
278
|
+
)
|
279
|
+
end
|
280
|
+
|
281
|
+
let(:recipients) do
|
282
|
+
JSON.parse(
|
283
|
+
'{'\
|
284
|
+
'"recipients": ['\
|
285
|
+
'{'\
|
286
|
+
'"created_at": 1422313607,'\
|
287
|
+
'"email": "jones@example.com",'\
|
288
|
+
'"first_name": null,'\
|
289
|
+
'"id": "jones@example.com",'\
|
290
|
+
'"last_clicked": null,'\
|
291
|
+
'"last_emailed": null,'\
|
292
|
+
'"last_name": "Jones",'\
|
293
|
+
'"last_opened": null,'\
|
294
|
+
'"updated_at": 1422313790,'\
|
295
|
+
'"custom_fields": ['\
|
296
|
+
'{'\
|
297
|
+
'"id": 23,'\
|
298
|
+
'"name": "pet",'\
|
299
|
+
'"value": "Fluffy",'\
|
300
|
+
'"type": "text"'\
|
301
|
+
'}'\
|
302
|
+
']'\
|
303
|
+
'}'\
|
304
|
+
']'\
|
305
|
+
'}'
|
306
|
+
)
|
307
|
+
end
|
308
|
+
|
309
|
+
it '#post_segment' do
|
310
|
+
allow(client).to receive(:execute).and_return(segment)
|
311
|
+
actual = client.post_segment(nil)
|
312
|
+
expect(actual).to be_a(SendGrid4r::REST::Contacts::Segments::Segment)
|
313
|
+
end
|
314
|
+
|
315
|
+
it '#get_segments' do
|
316
|
+
allow(client).to receive(:execute).and_return(segments)
|
317
|
+
actual = client.get_segments
|
318
|
+
expect(actual).to be_a(SendGrid4r::REST::Contacts::Segments::Segments)
|
319
|
+
end
|
320
|
+
|
321
|
+
it '#get_segment' do
|
322
|
+
allow(client).to receive(:execute).and_return(segment)
|
323
|
+
actual = client.get_segment(0)
|
324
|
+
expect(actual).to be_a(SendGrid4r::REST::Contacts::Segments::Segment)
|
325
|
+
end
|
326
|
+
|
327
|
+
it '#put_segment' do
|
328
|
+
allow(client).to receive(:execute).and_return(segment)
|
329
|
+
actual = client.put_segment(0, nil)
|
330
|
+
expect(actual).to be_a(SendGrid4r::REST::Contacts::Segments::Segment)
|
331
|
+
end
|
332
|
+
|
333
|
+
it '#get_recipients_from_segment' do
|
334
|
+
allow(client).to receive(:execute).and_return(recipients)
|
335
|
+
actual = client.get_recipients_from_segment(0)
|
336
|
+
expect(actual).to be_a(SendGrid4r::REST::Contacts::Recipients::Recipients)
|
337
|
+
end
|
338
|
+
|
339
|
+
it '#delete_segment' do
|
340
|
+
allow(client).to receive(:execute).and_return('')
|
341
|
+
actual = client.delete_segment(0)
|
342
|
+
expect(actual).to eq('')
|
343
|
+
end
|
344
|
+
|
345
|
+
it 'creates condition instance' do
|
346
|
+
actual = SendGrid4r::REST::Contacts::Segments.create_condition(condition)
|
347
|
+
expect(actual).to be_a(SendGrid4r::REST::Contacts::Segments::Condition)
|
348
|
+
expect(actual.field).to eq('last_name')
|
349
|
+
expect(actual.value).to eq('Miller')
|
350
|
+
expect(actual.operator).to eq('eq')
|
351
|
+
expect(actual.and_or).to eq('')
|
352
|
+
end
|
353
|
+
|
354
|
+
it 'creates segment instance' do
|
355
|
+
actual = SendGrid4r::REST::Contacts::Segments.create_segment(segment)
|
356
|
+
expect(actual).to be_a(SendGrid4r::REST::Contacts::Segments::Segment)
|
357
|
+
expect(actual.id).to eq(1)
|
358
|
+
expect(actual.name).to eq('Last Name Miller')
|
359
|
+
expect(actual.list_id).to eq(nil)
|
360
|
+
expect(actual.conditions).to be_a(Array)
|
361
|
+
actual.conditions.each do |condition|
|
362
|
+
expect(condition).to be_a(
|
363
|
+
SendGrid4r::REST::Contacts::Segments::Condition
|
364
|
+
)
|
365
|
+
end
|
366
|
+
expect(actual.recipient_count).to be_a(Fixnum)
|
367
|
+
end
|
368
|
+
|
369
|
+
it 'creates segments instance' do
|
370
|
+
actual = SendGrid4r::REST::Contacts::Segments.create_segments(segments)
|
294
371
|
expect(actual).to be_a(SendGrid4r::REST::Contacts::Segments::Segments)
|
295
372
|
expect(actual.segments).to be_a(Array)
|
296
373
|
actual.segments.each do |segment|
|