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,174 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require File.dirname(__FILE__) + '/../../spec_helper'
|
3
|
-
|
4
|
-
describe SendGrid4r::REST::Contacts::CustomFields 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
|
-
@name1 = 'birthday'
|
11
|
-
@type1 = 'text'
|
12
|
-
@name2 = 'born_at'
|
13
|
-
@type2 = 'date'
|
14
|
-
|
15
|
-
# celan up test env
|
16
|
-
fields = @client.get_custom_fields
|
17
|
-
fields.custom_fields.each do |field|
|
18
|
-
next if field.name != @name1 && field.name != @name2
|
19
|
-
@client.delete_custom_field(custom_field_id: field.id)
|
20
|
-
end
|
21
|
-
# post a custom field
|
22
|
-
@new_field = @client.post_custom_field(name: @name1, type: @type1)
|
23
|
-
rescue RestClient::ExceptionWithResponse => e
|
24
|
-
puts e.inspect
|
25
|
-
raise e
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
context 'without block call' do
|
30
|
-
it '#post_custom_field' do
|
31
|
-
begin
|
32
|
-
new_field = @client.post_custom_field(name: @name2, type: @type2)
|
33
|
-
expect(new_field.id).to be_a(Fixnum)
|
34
|
-
expect(new_field.name).to eq(@name2)
|
35
|
-
expect(new_field.type).to eq(@type2)
|
36
|
-
rescue RestClient::ExceptionWithResponse => e
|
37
|
-
puts e.inspect
|
38
|
-
raise e
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
it '#post_custom_field for same key' do
|
43
|
-
begin
|
44
|
-
expect do
|
45
|
-
@client.post_custom_field(name: @name1, type: @type1)
|
46
|
-
end.to raise_error(RestClient::BadRequest)
|
47
|
-
rescue RestClient::ExceptionWithResponse => e
|
48
|
-
puts e.inspect
|
49
|
-
raise e
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
it '#get_custom_fields' do
|
54
|
-
begin
|
55
|
-
fields = @client.get_custom_fields
|
56
|
-
expect(fields.length).to be >= 1
|
57
|
-
fields.custom_fields.each do |field|
|
58
|
-
next if field.name != @name1
|
59
|
-
expect(field.id).to eq(@new_field.id)
|
60
|
-
expect(field.name).to eq(@new_field.name)
|
61
|
-
expect(field.type).to eq(@new_field.type)
|
62
|
-
end
|
63
|
-
rescue RestClient::ExceptionWithResponse => e
|
64
|
-
puts e.inspect
|
65
|
-
raise e
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
it '#get_custom_field' do
|
70
|
-
begin
|
71
|
-
actual_field = @client.get_custom_field(
|
72
|
-
custom_field_id: @new_field.id
|
73
|
-
)
|
74
|
-
expect(actual_field.id).to eq(@new_field.id)
|
75
|
-
expect(actual_field.name).to eq(@new_field.name)
|
76
|
-
expect(actual_field.type).to eq(@new_field.type)
|
77
|
-
rescue RestClient::ExceptionWithResponse => e
|
78
|
-
puts e.inspect
|
79
|
-
raise e
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
it '#delete_custom_field' do
|
84
|
-
begin
|
85
|
-
@client.delete_custom_field(custom_field_id: @new_field.id)
|
86
|
-
rescue RestClient::ExceptionWithResponse => e
|
87
|
-
puts e.inspect
|
88
|
-
raise e
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
describe 'unit test', :ut do
|
95
|
-
let(:client) do
|
96
|
-
SendGrid4r::Client.new(api_key: '')
|
97
|
-
end
|
98
|
-
|
99
|
-
let(:field) do
|
100
|
-
JSON.parse(
|
101
|
-
'{'\
|
102
|
-
'"id": 1,'\
|
103
|
-
'"name": "pet",'\
|
104
|
-
'"type": "text"'\
|
105
|
-
'}'
|
106
|
-
)
|
107
|
-
end
|
108
|
-
|
109
|
-
let(:fields) do
|
110
|
-
JSON.parse(
|
111
|
-
'{'\
|
112
|
-
'"custom_fields": ['\
|
113
|
-
'{'\
|
114
|
-
'"id": 1,'\
|
115
|
-
'"name": "birthday",'\
|
116
|
-
'"type": "date"'\
|
117
|
-
'},'\
|
118
|
-
'{'\
|
119
|
-
'"id": 2,'\
|
120
|
-
'"name": "middle_name",'\
|
121
|
-
'"type": "text"'\
|
122
|
-
'},'\
|
123
|
-
'{'\
|
124
|
-
'"id": 3,'\
|
125
|
-
'"name": "favorite_number",'\
|
126
|
-
'"type": "number"'\
|
127
|
-
'}'\
|
128
|
-
']'\
|
129
|
-
'}'
|
130
|
-
)
|
131
|
-
end
|
132
|
-
|
133
|
-
it '#post_custom_field' do
|
134
|
-
allow(client).to receive(:execute).and_return(field)
|
135
|
-
actual = client.post_custom_field(name: '', type: '')
|
136
|
-
expect(actual).to be_a(SendGrid4r::REST::Contacts::CustomFields::Field)
|
137
|
-
end
|
138
|
-
|
139
|
-
it '#get_custom_fields' do
|
140
|
-
allow(client).to receive(:execute).and_return(fields)
|
141
|
-
actual = client.get_custom_fields
|
142
|
-
expect(actual).to be_a(SendGrid4r::REST::Contacts::CustomFields::Fields)
|
143
|
-
end
|
144
|
-
|
145
|
-
it '#get_custom_field' do
|
146
|
-
allow(client).to receive(:execute).and_return(field)
|
147
|
-
actual = client.get_custom_field(custom_field_id: 0)
|
148
|
-
expect(actual).to be_a(SendGrid4r::REST::Contacts::CustomFields::Field)
|
149
|
-
end
|
150
|
-
|
151
|
-
it '#delete_custom_field' do
|
152
|
-
allow(client).to receive(:execute).and_return('')
|
153
|
-
actual = client.delete_custom_field(custom_field_id: 0)
|
154
|
-
expect(actual).to eq('')
|
155
|
-
end
|
156
|
-
|
157
|
-
it 'creates field instance' do
|
158
|
-
actual = SendGrid4r::REST::Contacts::CustomFields.create_field(field)
|
159
|
-
expect(actual).to be_a(SendGrid4r::REST::Contacts::CustomFields::Field)
|
160
|
-
expect(actual.id).to eq(1)
|
161
|
-
expect(actual.name).to eq('pet')
|
162
|
-
expect(actual.type).to eq('text')
|
163
|
-
end
|
164
|
-
|
165
|
-
it 'creates fields instance' do
|
166
|
-
actual = SendGrid4r::REST::Contacts::CustomFields.create_fields(fields)
|
167
|
-
expect(actual).to be_a(SendGrid4r::REST::Contacts::CustomFields::Fields)
|
168
|
-
expect(actual.custom_fields).to be_a(Array)
|
169
|
-
actual.custom_fields.each do |field|
|
170
|
-
expect(field).to be_a(SendGrid4r::REST::Contacts::CustomFields::Field)
|
171
|
-
end
|
172
|
-
end
|
173
|
-
end
|
174
|
-
end
|
@@ -1,372 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require File.dirname(__FILE__) + '/../../spec_helper'
|
3
|
-
|
4
|
-
describe SendGrid4r::REST::Contacts::Lists 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
|
-
@list_name1 = 'test_list1'
|
11
|
-
@edit_name1 = 'test_list1_edit'
|
12
|
-
@list_name2 = 'test_list2'
|
13
|
-
@email1 = 'jones@example.com'
|
14
|
-
@email2 = 'miller@example.com'
|
15
|
-
@last_name1 = 'Jones'
|
16
|
-
@last_name2 = 'Miller'
|
17
|
-
@pet1 = 'Fluffy'
|
18
|
-
@pet2 = 'FrouFrou'
|
19
|
-
|
20
|
-
# celan up test env(lists)
|
21
|
-
lists = @client.get_lists
|
22
|
-
lists.lists.each do |list|
|
23
|
-
@client.delete_list(list_id: list.id) if list.name == @list_name1
|
24
|
-
@client.delete_list(list_id: list.id) if list.name == @edit_name1
|
25
|
-
@client.delete_list(list_id: list.id) if list.name == @list_name2
|
26
|
-
end
|
27
|
-
# celan up test env(recipients)
|
28
|
-
recipients = @client.get_recipients
|
29
|
-
recipients.recipients.each do |recipient|
|
30
|
-
@client.delete_recipient(
|
31
|
-
recipient_id: recipient.id
|
32
|
-
) if recipient.email == @email1
|
33
|
-
@client.delete_recipient(
|
34
|
-
recipient_id: recipient.id
|
35
|
-
) if recipient.email == @email2
|
36
|
-
end
|
37
|
-
# post a first list
|
38
|
-
@list1 = @client.post_list(name: @list_name1)
|
39
|
-
# add multiple recipients
|
40
|
-
recipient1 = {}
|
41
|
-
recipient1['email'] = @email1
|
42
|
-
recipient1['last_name'] = @last_name1
|
43
|
-
recipient2 = {}
|
44
|
-
recipient2['email'] = @email2
|
45
|
-
recipient2['last_name'] = @last_name2
|
46
|
-
result = @client.post_recipients(params: [recipient1, recipient2])
|
47
|
-
@recipients = result.persisted_recipients
|
48
|
-
@client.post_recipient_to_list(
|
49
|
-
list_id: @list1.id, recipient_id: result.persisted_recipients[0]
|
50
|
-
)
|
51
|
-
@client.post_recipient_to_list(
|
52
|
-
list_id: @list1.id, recipient_id: result.persisted_recipients[1]
|
53
|
-
)
|
54
|
-
rescue RestClient::ExceptionWithResponse => e
|
55
|
-
puts e.inspect
|
56
|
-
raise e
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
context 'without block call' do
|
61
|
-
it '#post_list' do
|
62
|
-
begin
|
63
|
-
list2 = @client.post_list(name: @list_name2)
|
64
|
-
expect(list2.id).to be_a(Fixnum)
|
65
|
-
expect(list2.name).to eq(@list_name2)
|
66
|
-
expect(list2.recipient_count).to eq(0)
|
67
|
-
@client.delete_list(list_id: list2.id)
|
68
|
-
rescue RestClient::ExceptionWithResponse => e
|
69
|
-
puts e.inspect
|
70
|
-
raise e
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
it '#post_list for same key' do
|
75
|
-
begin
|
76
|
-
expect do
|
77
|
-
@client.post_list(name: @list_name1)
|
78
|
-
end.to raise_error(RestClient::BadRequest)
|
79
|
-
rescue RestClient::ExceptionWithResponse => e
|
80
|
-
puts e.inspect
|
81
|
-
raise e
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
it '#get_lists' do
|
86
|
-
begin
|
87
|
-
lists = @client.get_lists
|
88
|
-
expect(lists.length).to be >= 1
|
89
|
-
lists.lists.each do |list|
|
90
|
-
next if list.name != @list_name1
|
91
|
-
expect(list.id).to eq(@list1.id)
|
92
|
-
expect(list.name).to eq(@list1.name)
|
93
|
-
expect(list.recipient_count).to be_a(Fixnum)
|
94
|
-
end
|
95
|
-
rescue RestClient::ExceptionWithResponse => e
|
96
|
-
puts e.inspect
|
97
|
-
raise e
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
it '#get_list' do
|
102
|
-
begin
|
103
|
-
actual_list = @client.get_list(list_id: @list1.id)
|
104
|
-
expect(actual_list.id).to eq(@list1.id)
|
105
|
-
expect(actual_list.name).to eq(@list1.name)
|
106
|
-
expect(actual_list.recipient_count).to be_a(Fixnum)
|
107
|
-
rescue RestClient::ExceptionWithResponse => e
|
108
|
-
puts e.inspect
|
109
|
-
raise e
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
it '#patch_list' do
|
114
|
-
begin
|
115
|
-
edit_list = @client.patch_list(list_id: @list1.id, name: @edit_name1)
|
116
|
-
expect(edit_list.id).to eq(@list1.id)
|
117
|
-
expect(edit_list.name).to eq(@edit_name1)
|
118
|
-
rescue RestClient::ExceptionWithResponse => e
|
119
|
-
puts e.inspect
|
120
|
-
raise e
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
|
-
it '#get_recipients_from_list' do
|
125
|
-
begin
|
126
|
-
recipients = @client.get_recipients_from_list(list_id: @list1.id)
|
127
|
-
recipients.recipients.each do |recipient|
|
128
|
-
expect(
|
129
|
-
recipient
|
130
|
-
).to be_a(SendGrid4r::REST::Contacts::Recipients::Recipient)
|
131
|
-
end
|
132
|
-
rescue RestClient::ExceptionWithResponse => e
|
133
|
-
puts e.inspect
|
134
|
-
raise e
|
135
|
-
end
|
136
|
-
end
|
137
|
-
|
138
|
-
it '#get_recipients_from_list with offset & limit' do
|
139
|
-
begin
|
140
|
-
recipients = @client.get_recipients_from_list(
|
141
|
-
list_id: @list1.id, page: 1, page_size: 10
|
142
|
-
)
|
143
|
-
recipients.recipients.each do |recipient|
|
144
|
-
expect(
|
145
|
-
recipient
|
146
|
-
).to be_a(SendGrid4r::REST::Contacts::Recipients::Recipient)
|
147
|
-
end
|
148
|
-
rescue RestClient::ExceptionWithResponse => e
|
149
|
-
puts e.inspect
|
150
|
-
raise e
|
151
|
-
end
|
152
|
-
end
|
153
|
-
|
154
|
-
it '#delete_recipient_from_list' do
|
155
|
-
begin
|
156
|
-
@client.delete_recipient_from_list(
|
157
|
-
list_id: @list1.id, recipient_id: @recipients[0]
|
158
|
-
)
|
159
|
-
rescue RestClient::ExceptionWithResponse => e
|
160
|
-
puts e.inspect
|
161
|
-
raise e
|
162
|
-
end
|
163
|
-
end
|
164
|
-
|
165
|
-
it '#delete_list' do
|
166
|
-
begin
|
167
|
-
@client.delete_list(list_id: @list1.id)
|
168
|
-
expect do
|
169
|
-
@client.get_list(list_id: @list1.id)
|
170
|
-
end.to raise_error(RestClient::ResourceNotFound)
|
171
|
-
rescue RestClient::ExceptionWithResponse => e
|
172
|
-
puts e.inspect
|
173
|
-
raise e
|
174
|
-
end
|
175
|
-
end
|
176
|
-
|
177
|
-
it '#delete_lists' do
|
178
|
-
begin
|
179
|
-
list2 = @client.post_list(name: @list_name2)
|
180
|
-
@client.delete_lists(list_ids: [@list1.id, list2.id])
|
181
|
-
rescue RestClient::ExceptionWithResponse => e
|
182
|
-
puts e.inspect
|
183
|
-
raise e
|
184
|
-
end
|
185
|
-
end
|
186
|
-
|
187
|
-
it '#post_recipients_to_list' do
|
188
|
-
begin
|
189
|
-
@client.post_recipients_to_list(
|
190
|
-
list_id: @list1.id, recipients: @recipients
|
191
|
-
)
|
192
|
-
rescue RestClient::ExceptionWithResponse => e
|
193
|
-
puts e.inspect
|
194
|
-
raise e
|
195
|
-
end
|
196
|
-
end
|
197
|
-
|
198
|
-
it '#post_recipient_to_list' do
|
199
|
-
begin
|
200
|
-
recipient1 = {}
|
201
|
-
recipient1['email'] = @email1
|
202
|
-
recipient1['last_name'] = @last_name1
|
203
|
-
result = @client.post_recipients(params: [recipient1])
|
204
|
-
@client.post_recipient_to_list(
|
205
|
-
list_id: @list1.id, recipient_id: result.persisted_recipients[0]
|
206
|
-
)
|
207
|
-
rescue RestClient::ExceptionWithResponse => e
|
208
|
-
puts e.inspect
|
209
|
-
raise e
|
210
|
-
end
|
211
|
-
end
|
212
|
-
end
|
213
|
-
end
|
214
|
-
|
215
|
-
describe 'unit test', :ut do
|
216
|
-
let(:client) do
|
217
|
-
SendGrid4r::Client.new(api_key: '')
|
218
|
-
end
|
219
|
-
|
220
|
-
let(:list) do
|
221
|
-
JSON.parse(
|
222
|
-
'{'\
|
223
|
-
'"id": 1,'\
|
224
|
-
'"name": "listname",'\
|
225
|
-
'"recipient_count": 0'\
|
226
|
-
'}'
|
227
|
-
)
|
228
|
-
end
|
229
|
-
|
230
|
-
let(:lists) do
|
231
|
-
JSON.parse(
|
232
|
-
'{'\
|
233
|
-
'"lists": ['\
|
234
|
-
'{'\
|
235
|
-
'"id": 1,'\
|
236
|
-
'"name": "the jones",'\
|
237
|
-
'"recipient_count": 1'\
|
238
|
-
'}'\
|
239
|
-
']'\
|
240
|
-
'}'
|
241
|
-
)
|
242
|
-
end
|
243
|
-
|
244
|
-
let(:recipient) do
|
245
|
-
JSON.parse(
|
246
|
-
'{'\
|
247
|
-
'"created_at": 1422313607,'\
|
248
|
-
'"email": "jones@example.com",'\
|
249
|
-
'"first_name": null,'\
|
250
|
-
'"id": "jones@example.com",'\
|
251
|
-
'"last_clicked": null,'\
|
252
|
-
'"last_emailed": null,'\
|
253
|
-
'"last_name": "Jones",'\
|
254
|
-
'"last_opened": null,'\
|
255
|
-
'"updated_at": 1422313790,'\
|
256
|
-
'"custom_fields": ['\
|
257
|
-
'{'\
|
258
|
-
'"id": 23,'\
|
259
|
-
'"name": "pet",'\
|
260
|
-
'"value": "Fluffy",'\
|
261
|
-
'"type": "text"'\
|
262
|
-
'}'\
|
263
|
-
']'\
|
264
|
-
'}'
|
265
|
-
)
|
266
|
-
end
|
267
|
-
|
268
|
-
let(:recipients) do
|
269
|
-
JSON.parse(
|
270
|
-
'{'\
|
271
|
-
'"recipients": ['\
|
272
|
-
'{'\
|
273
|
-
'"created_at": 1422313607,'\
|
274
|
-
'"email": "jones@example.com",'\
|
275
|
-
'"first_name": null,'\
|
276
|
-
'"id": "jones@example.com",'\
|
277
|
-
'"last_clicked": null,'\
|
278
|
-
'"last_emailed": null,'\
|
279
|
-
'"last_name": "Jones",'\
|
280
|
-
'"last_opened": null,'\
|
281
|
-
'"updated_at": 1422313790,'\
|
282
|
-
'"custom_fields": ['\
|
283
|
-
'{'\
|
284
|
-
'"id": 23,'\
|
285
|
-
'"name": "pet",'\
|
286
|
-
'"value": "Fluffy",'\
|
287
|
-
'"type": "text"'\
|
288
|
-
'}'\
|
289
|
-
']'\
|
290
|
-
'}'\
|
291
|
-
']'\
|
292
|
-
'}'
|
293
|
-
)
|
294
|
-
end
|
295
|
-
|
296
|
-
it '#post_list' do
|
297
|
-
allow(client).to receive(:execute).and_return(list)
|
298
|
-
actual = client.post_list(name: '')
|
299
|
-
expect(actual).to be_a(SendGrid4r::REST::Contacts::Lists::List)
|
300
|
-
end
|
301
|
-
|
302
|
-
it '#get_lists' do
|
303
|
-
allow(client).to receive(:execute).and_return(lists)
|
304
|
-
actual = client.get_lists
|
305
|
-
expect(actual).to be_a(SendGrid4r::REST::Contacts::Lists::Lists)
|
306
|
-
end
|
307
|
-
|
308
|
-
it '#get_list' do
|
309
|
-
allow(client).to receive(:execute).and_return(list)
|
310
|
-
actual = client.get_list(list_id: 0)
|
311
|
-
expect(actual).to be_a(SendGrid4r::REST::Contacts::Lists::List)
|
312
|
-
end
|
313
|
-
|
314
|
-
it '#patch_list' do
|
315
|
-
allow(client).to receive(:execute).and_return(list)
|
316
|
-
actual = client.patch_list(list_id: 0, name: '')
|
317
|
-
expect(actual).to be_a(SendGrid4r::REST::Contacts::Lists::List)
|
318
|
-
end
|
319
|
-
|
320
|
-
it '#get_recipients_from_list' do
|
321
|
-
allow(client).to receive(:execute).and_return(recipients)
|
322
|
-
actual = client.get_recipients_from_list(list_id: 0)
|
323
|
-
expect(actual).to be_a(SendGrid4r::REST::Contacts::Recipients::Recipients)
|
324
|
-
end
|
325
|
-
|
326
|
-
it '#delete_recipient_from_list' do
|
327
|
-
allow(client).to receive(:execute).and_return('')
|
328
|
-
actual = client.delete_recipient_from_list(list_id: 0, recipient_id: '')
|
329
|
-
expect(actual).to eq('')
|
330
|
-
end
|
331
|
-
|
332
|
-
it '#delete_list' do
|
333
|
-
allow(client).to receive(:execute).and_return('')
|
334
|
-
actual = client.delete_list(list_id: 0)
|
335
|
-
expect(actual).to eq('')
|
336
|
-
end
|
337
|
-
|
338
|
-
it '#delete_lists' do
|
339
|
-
allow(client).to receive(:execute).and_return('')
|
340
|
-
actual = client.delete_lists(list_ids: [0, 1])
|
341
|
-
expect(actual).to eq('')
|
342
|
-
end
|
343
|
-
|
344
|
-
it '#post_recipients_to_list' do
|
345
|
-
allow(client).to receive(:execute).and_return('')
|
346
|
-
actual = client.post_recipients_to_list(list_id: 0, recipients: ['', ''])
|
347
|
-
expect(actual).to eq('')
|
348
|
-
end
|
349
|
-
|
350
|
-
it '#post_recipient_to_list' do
|
351
|
-
allow(client).to receive(:execute).and_return('')
|
352
|
-
actual = client.post_recipient_to_list(list_id: 0, recipient_id: 0)
|
353
|
-
expect(actual).to eq('')
|
354
|
-
end
|
355
|
-
|
356
|
-
it 'creates list instance' do
|
357
|
-
actual = SendGrid4r::REST::Contacts::Lists.create_list(list)
|
358
|
-
expect(actual).to be_a(SendGrid4r::REST::Contacts::Lists::List)
|
359
|
-
expect(actual.id).to eq(1)
|
360
|
-
expect(actual.name).to eq('listname')
|
361
|
-
expect(actual.recipient_count).to eq(0)
|
362
|
-
end
|
363
|
-
|
364
|
-
it 'creates lists instance' do
|
365
|
-
actual = SendGrid4r::REST::Contacts::Lists.create_lists(lists)
|
366
|
-
expect(actual.lists).to be_a(Array)
|
367
|
-
actual.lists.each do |list|
|
368
|
-
expect(list).to be_a(SendGrid4r::REST::Contacts::Lists::List)
|
369
|
-
end
|
370
|
-
end
|
371
|
-
end
|
372
|
-
end
|