sendgrid4r 1.8.1 → 1.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +6 -2
- data/README.md +1 -0
- data/lib/sendgrid4r/factory/campaign_factory.rb +18 -5
- data/lib/sendgrid4r/factory/condition_factory.rb +1 -1
- data/lib/sendgrid4r/factory/mail_factory.rb +57 -0
- data/lib/sendgrid4r/factory/segment_factory.rb +2 -5
- data/lib/sendgrid4r/factory/version_factory.rb +1 -1
- data/lib/sendgrid4r/rest/api.rb +48 -49
- data/lib/sendgrid4r/rest/api_keys_management/api_keys.rb +75 -0
- data/lib/sendgrid4r/rest/api_keys_management/permissions.rb +31 -0
- data/lib/sendgrid4r/rest/blocks.rb +49 -68
- data/lib/sendgrid4r/rest/bounces.rb +45 -64
- data/lib/sendgrid4r/rest/cancel_scheduled_sends.rb +53 -72
- data/lib/sendgrid4r/rest/categories.rb +31 -0
- data/lib/sendgrid4r/rest/email_activity.rb +72 -0
- data/lib/sendgrid4r/rest/invalid_emails.rb +50 -68
- data/lib/sendgrid4r/rest/ip_access_management.rb +86 -111
- data/lib/sendgrid4r/rest/ips/addresses.rb +50 -59
- data/lib/sendgrid4r/rest/ips/pools.rb +42 -53
- data/lib/sendgrid4r/rest/ips/warmup.rb +46 -55
- data/lib/sendgrid4r/rest/mail/address.rb +14 -0
- data/lib/sendgrid4r/rest/mail/attachment.rb +22 -0
- data/lib/sendgrid4r/rest/mail/content.rb +10 -0
- data/lib/sendgrid4r/rest/mail/mail.rb +28 -0
- data/lib/sendgrid4r/rest/mail/mail_settings.rb +62 -0
- data/lib/sendgrid4r/rest/mail/params.rb +64 -0
- data/lib/sendgrid4r/rest/mail/personalization.rb +33 -0
- data/lib/sendgrid4r/rest/mail/tracking_settings.rb +74 -0
- data/lib/sendgrid4r/rest/{contacts → marketing_campaigns/contacts}/custom_fields.rb +12 -27
- data/lib/sendgrid4r/rest/{contacts → marketing_campaigns/contacts}/lists.rb +20 -34
- data/lib/sendgrid4r/rest/marketing_campaigns/contacts/recipients.rb +134 -0
- data/lib/sendgrid4r/rest/{contacts → marketing_campaigns/contacts}/reserved_fields.rb +6 -9
- data/lib/sendgrid4r/rest/marketing_campaigns/contacts/segments.rb +86 -0
- data/lib/sendgrid4r/rest/marketing_campaigns/marketing_campaigns.rb +119 -0
- data/lib/sendgrid4r/rest/marketing_campaigns/senders.rb +101 -0
- data/lib/sendgrid4r/rest/request.rb +61 -63
- data/lib/sendgrid4r/rest/settings/enforced_tls.rb +23 -26
- data/lib/sendgrid4r/rest/settings/mail.rb +167 -183
- data/lib/sendgrid4r/rest/settings/partner.rb +33 -36
- data/lib/sendgrid4r/rest/settings/settings.rb +17 -22
- data/lib/sendgrid4r/rest/settings/tracking.rb +97 -107
- data/lib/sendgrid4r/rest/sm/global_unsubscribes.rb +52 -60
- data/lib/sendgrid4r/rest/sm/groups.rb +52 -58
- data/lib/sendgrid4r/rest/sm/sm.rb +15 -17
- data/lib/sendgrid4r/rest/sm/suppressions.rb +50 -67
- data/lib/sendgrid4r/rest/spam_reports.rb +49 -69
- data/lib/sendgrid4r/rest/stats/advanced.rb +100 -102
- data/lib/sendgrid4r/rest/stats/category.rb +31 -33
- data/lib/sendgrid4r/rest/stats/global.rb +17 -19
- data/lib/sendgrid4r/rest/stats/parse.rb +18 -20
- data/lib/sendgrid4r/rest/stats/stats.rb +59 -69
- data/lib/sendgrid4r/rest/stats/subuser.rb +70 -32
- data/lib/sendgrid4r/rest/subusers.rb +106 -134
- data/lib/sendgrid4r/rest/transactional_templates/templates.rb +63 -0
- data/lib/sendgrid4r/rest/transactional_templates/versions.rb +90 -0
- data/lib/sendgrid4r/rest/users.rb +125 -57
- data/lib/sendgrid4r/rest/webhooks/event.rb +36 -42
- data/lib/sendgrid4r/rest/webhooks/parse.rb +28 -37
- data/lib/sendgrid4r/rest/whitelabel/domains.rb +176 -222
- data/lib/sendgrid4r/rest/whitelabel/ips.rb +107 -128
- data/lib/sendgrid4r/rest/whitelabel/links.rb +131 -167
- data/lib/sendgrid4r/version.rb +1 -1
- data/lib/sendgrid4r.rb +23 -13
- data/sendgrid4r.gemspec +1 -1
- data/spec/client_spec.rb +12 -1
- data/spec/factory/campaign_factory_spec.rb +75 -35
- data/spec/factory/condition_factory_spec.rb +19 -18
- data/spec/factory/segment_factory_spec.rb +28 -21
- data/spec/factory/version_factory_spec.rb +28 -27
- data/spec/photo.jpg +0 -0
- data/spec/rest/api_keys_management/api_keys_spec.rb +174 -0
- data/spec/rest/api_keys_management/permissions_spec.rb +54 -0
- data/spec/rest/blocks_spec.rb +78 -106
- data/spec/rest/bounces_spec.rb +91 -118
- data/spec/rest/cancel_scheduled_sends_spec.rb +94 -149
- data/spec/rest/categories_spec.rb +77 -0
- data/spec/rest/email_activity_spec.rb +151 -0
- data/spec/rest/invalid_emails_spec.rb +85 -119
- data/spec/rest/ip_access_management_spec.rb +157 -195
- data/spec/rest/ips/addresses_spec.rb +94 -122
- data/spec/rest/ips/pools_spec.rb +84 -112
- data/spec/rest/ips/warmup_spec.rb +63 -71
- data/spec/rest/mail/address_spec.rb +28 -0
- data/spec/rest/mail/attachment_spec.rb +48 -0
- data/spec/rest/mail/content_spec.rb +32 -0
- data/spec/rest/mail/mail_settings_spec.rb +51 -0
- data/spec/rest/mail/mail_spec.rb +136 -0
- data/spec/rest/mail/params_spec.rb +152 -0
- data/spec/rest/mail/personalization_spec.rb +66 -0
- data/spec/rest/mail/tracking_settings_spec.rb +63 -0
- data/spec/rest/marketing_campaigns/contacts/custom_fields_spec.rb +146 -0
- data/spec/rest/marketing_campaigns/contacts/lists_spec.rb +307 -0
- data/spec/rest/marketing_campaigns/contacts/recipients_spec.rb +331 -0
- data/spec/rest/marketing_campaigns/contacts/reserved_fields_spec.rb +119 -0
- data/spec/rest/marketing_campaigns/contacts/segments_spec.rb +268 -0
- data/spec/rest/marketing_campaigns/marketing_campaigns_spec.rb +427 -0
- data/spec/rest/marketing_campaigns/senders_spec.rb +230 -0
- data/spec/rest/settings/enforced_tls_spec.rb +38 -54
- data/spec/rest/settings/mail_spec.rb +227 -330
- data/spec/rest/settings/partner_spec.rb +40 -59
- data/spec/rest/settings/settings_spec.rb +44 -42
- data/spec/rest/settings/tracking_spec.rb +130 -189
- data/spec/rest/sm/global_unsubscribes_spec.rb +47 -72
- data/spec/rest/sm/groups_spec.rb +88 -123
- data/spec/rest/sm/sm_spec.rb +32 -30
- data/spec/rest/sm/suppressions_spec.rb +105 -140
- data/spec/rest/spam_reports_spec.rb +81 -109
- data/spec/rest/stats/advanced_spec.rb +67 -125
- data/spec/rest/stats/category_spec.rb +27 -45
- data/spec/rest/stats/global_spec.rb +34 -42
- data/spec/rest/stats/parse_spec.rb +32 -30
- data/spec/rest/stats/stats_spec.rb +174 -172
- data/spec/rest/stats/subuser_spec.rb +97 -57
- data/spec/rest/subusers_spec.rb +156 -209
- data/spec/rest/transactional_templates/templates_spec.rb +199 -0
- data/spec/rest/transactional_templates/versions_spec.rb +228 -0
- data/spec/rest/users_spec.rb +176 -91
- data/spec/rest/webhooks/event_spec.rb +59 -85
- data/spec/rest/webhooks/parse_spec.rb +51 -71
- data/spec/rest/whitelabel/domains_spec.rb +333 -513
- data/spec/rest/whitelabel/ips_spec.rb +109 -147
- data/spec/rest/whitelabel/links_spec.rb +181 -265
- metadata +70 -40
- data/lib/sendgrid4r/rest/api_keys/api_keys.rb +0 -80
- data/lib/sendgrid4r/rest/api_keys/permissions.rb +0 -33
- data/lib/sendgrid4r/rest/campaigns/campaigns.rb +0 -126
- data/lib/sendgrid4r/rest/categories/categories.rb +0 -43
- data/lib/sendgrid4r/rest/contacts/recipients.rb +0 -150
- data/lib/sendgrid4r/rest/contacts/segments.rb +0 -97
- data/lib/sendgrid4r/rest/email_activity/email_activity.rb +0 -81
- data/lib/sendgrid4r/rest/templates/templates.rb +0 -69
- data/lib/sendgrid4r/rest/templates/versions.rb +0 -95
- data/spec/rest/api_keys/api_keys_spec.rb +0 -210
- data/spec/rest/api_keys/permissions_spec.rb +0 -65
- data/spec/rest/campaigns/campaigns_spec.rb +0 -492
- data/spec/rest/categories/categories_spec.rb +0 -96
- data/spec/rest/contacts/custom_fields_spec.rb +0 -174
- data/spec/rest/contacts/lists_spec.rb +0 -372
- data/spec/rest/contacts/recipients_spec.rb +0 -343
- data/spec/rest/contacts/reserved_fields_spec.rb +0 -146
- data/spec/rest/contacts/segments_spec.rb +0 -307
- data/spec/rest/email_activity/email_activity_spec.rb +0 -179
- data/spec/rest/templates/templates_spec.rb +0 -222
- data/spec/rest/templates/versions_spec.rb +0 -252
data/spec/client_spec.rb
CHANGED
@@ -161,6 +161,8 @@ describe SendGrid4r::Client do
|
|
161
161
|
expect(@client.respond_to?('get_categories_stats_sums')).to eq(true)
|
162
162
|
expect(@client.respond_to?('get_subusers_stats')).to eq(true)
|
163
163
|
expect(@client.respond_to?('get_subusers_stats_sums')).to eq(true)
|
164
|
+
expect(@client.respond_to?('get_subusers_stats_monthly')).to eq(true)
|
165
|
+
expect(@client.respond_to?('get_subuser_stats_monthly')).to eq(true)
|
164
166
|
expect(@client.respond_to?('get_geo_stats')).to eq(true)
|
165
167
|
expect(@client.respond_to?('get_devices_stats')).to eq(true)
|
166
168
|
expect(@client.respond_to?('get_clients_stats')).to eq(true)
|
@@ -257,6 +259,12 @@ describe SendGrid4r::Client do
|
|
257
259
|
expect(@client.respond_to?('get_user_profile')).to eq(true)
|
258
260
|
expect(@client.respond_to?('patch_user_profile')).to eq(true)
|
259
261
|
expect(@client.respond_to?('get_user_account')).to eq(true)
|
262
|
+
expect(@client.respond_to?('get_user_email')).to eq(true)
|
263
|
+
expect(@client.respond_to?('put_user_email')).to eq(true)
|
264
|
+
expect(@client.respond_to?('get_user_username')).to eq(true)
|
265
|
+
expect(@client.respond_to?('put_user_username')).to eq(true)
|
266
|
+
expect(@client.respond_to?('get_user_credits')).to eq(true)
|
267
|
+
expect(@client.respond_to?('put_user_password')).to eq(true)
|
260
268
|
|
261
269
|
# Bounces API
|
262
270
|
expect(@client.respond_to?('get_bounces')).to eq(true)
|
@@ -308,12 +316,15 @@ describe SendGrid4r::Client do
|
|
308
316
|
expect(@client.respond_to?('delete_whitelisted_ips')).to eq(true)
|
309
317
|
expect(@client.respond_to?('get_whitelisted_ip')).to eq(true)
|
310
318
|
expect(@client.respond_to?('delete_whitelisted_ip')).to eq(true)
|
319
|
+
|
320
|
+
# Mail
|
321
|
+
expect(@client.respond_to?('send')).to eq(true)
|
311
322
|
end
|
312
323
|
end
|
313
324
|
|
314
325
|
describe 'VERSION' do
|
315
326
|
it 'returns VERSION value' do
|
316
|
-
expect(SendGrid4r::VERSION).to eq('1.
|
327
|
+
expect(SendGrid4r::VERSION).to eq('1.10.0')
|
317
328
|
end
|
318
329
|
end
|
319
330
|
end
|
@@ -1,42 +1,82 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require File.dirname(__FILE__) + '/../spec_helper'
|
3
3
|
|
4
|
-
|
5
|
-
describe
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
4
|
+
module SendGrid4r::Factory
|
5
|
+
describe CampaignFactory do
|
6
|
+
describe 'unit test', :ut do
|
7
|
+
before do
|
8
|
+
Dotenv.load
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'create with mandatory parameters' do
|
12
|
+
campaign = CampaignFactory.new.create
|
13
|
+
expect(campaign).to eq({})
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'create with full parameters' do
|
17
|
+
campaign = CampaignFactory.new.create(
|
18
|
+
title: 'March Newsletter',
|
19
|
+
subject: 'New Products for Spring!',
|
20
|
+
sender_id: 124451,
|
21
|
+
list_ids: [110, 124],
|
22
|
+
segment_ids: [110],
|
23
|
+
categories: ['spring line'],
|
24
|
+
suppression_group_id: 42,
|
25
|
+
custom_unsubscribe_url: 'https://sendgrid.com',
|
26
|
+
ip_pool: 'marketing',
|
27
|
+
html_content: '<html><head><title></title></head><body>'\
|
28
|
+
'<p>Check out our spring line!</p></body></html>',
|
29
|
+
plain_content: 'Check out our spring line!'
|
30
|
+
)
|
31
|
+
expect(campaign).to eq(
|
32
|
+
title: 'March Newsletter',
|
33
|
+
subject: 'New Products for Spring!',
|
34
|
+
sender_id: 124451,
|
35
|
+
list_ids: [110, 124],
|
36
|
+
segment_ids: [110],
|
37
|
+
categories: ['spring line'],
|
38
|
+
suppression_group_id: 42,
|
39
|
+
custom_unsubscribe_url: 'https://sendgrid.com',
|
40
|
+
ip_pool: 'marketing',
|
41
|
+
html_content: '<html><head><title></title></head><body>'\
|
42
|
+
'<p>Check out our spring line!</p></body></html>',
|
43
|
+
plain_content: 'Check out our spring line!'
|
44
|
+
)
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'create address with full parameters' do
|
48
|
+
address = CampaignFactory.new.create_address(
|
49
|
+
email: 'from@example.com', name: 'Example INC'
|
50
|
+
)
|
51
|
+
expect(address.email).to eq('from@example.com')
|
52
|
+
expect(address.name).to eq('Example INC')
|
53
|
+
end
|
10
54
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
@expect[:html_content] = '<html><head><title></title></head><body>'\
|
37
|
-
'<p>Check out our spring line!</p></body></html>'
|
38
|
-
@expect[:plain_content] = 'Check out our spring line!'
|
39
|
-
expect(campaign).to eq(@expect)
|
55
|
+
it 'create sender with full parameters' do
|
56
|
+
from = CampaignFactory.new.create_address(
|
57
|
+
email: 'from@example.com', name: 'Example INC'
|
58
|
+
)
|
59
|
+
reply_to = CampaignFactory.new.create_address(
|
60
|
+
email: 'replyto@example.com', name: 'Example INC'
|
61
|
+
)
|
62
|
+
sender = CampaignFactory.new.create_sender(
|
63
|
+
nickname: 'My Sender ID', from: from, reply_to: reply_to,
|
64
|
+
address: '123 Elm St.', address_2: 'Apt. 456',
|
65
|
+
city: 'Denver', state: 'Colorado', zip: '80202',
|
66
|
+
country: 'United States'
|
67
|
+
)
|
68
|
+
expect(sender.nickname).to eq('My Sender ID')
|
69
|
+
expect(sender.from[:email]).to eq('from@example.com')
|
70
|
+
expect(sender.from[:name]).to eq('Example INC')
|
71
|
+
expect(sender.reply_to[:email]).to eq('replyto@example.com')
|
72
|
+
expect(sender.reply_to[:name]).to eq('Example INC')
|
73
|
+
expect(sender.address).to eq('123 Elm St.')
|
74
|
+
expect(sender.address_2).to eq('Apt. 456')
|
75
|
+
expect(sender.city).to eq('Denver')
|
76
|
+
expect(sender.state).to eq('Colorado')
|
77
|
+
expect(sender.zip).to eq('80202')
|
78
|
+
expect(sender.country).to eq('United States')
|
79
|
+
end
|
40
80
|
end
|
41
81
|
end
|
42
82
|
end
|
@@ -1,25 +1,26 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require File.dirname(__FILE__) + '/../spec_helper'
|
3
3
|
|
4
|
-
|
5
|
-
describe
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
@expect[:field] = 'last_name'
|
11
|
-
@expect[:value] = 'Miller'
|
12
|
-
@expect[:operator] = 'eq'
|
13
|
-
@expect[:and_or] = ''
|
14
|
-
end
|
4
|
+
module SendGrid4r::Factory
|
5
|
+
describe ConditionFactory do
|
6
|
+
describe 'unit test', :ut do
|
7
|
+
before do
|
8
|
+
Dotenv.load
|
9
|
+
end
|
15
10
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
11
|
+
it 'create with full parameters' do
|
12
|
+
condition = ConditionFactory.new.create(
|
13
|
+
field: 'last_name',
|
14
|
+
value: 'Miller',
|
15
|
+
operator: 'eq',
|
16
|
+
and_or: '')
|
17
|
+
expect(condition).to eq(
|
18
|
+
field: 'last_name',
|
19
|
+
value: 'Miller',
|
20
|
+
operator: 'eq',
|
21
|
+
and_or: ''
|
22
|
+
)
|
23
|
+
end
|
23
24
|
end
|
24
25
|
end
|
25
26
|
end
|
@@ -1,28 +1,35 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require File.dirname(__FILE__) + '/../spec_helper'
|
3
3
|
|
4
|
-
|
5
|
-
describe
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
4
|
+
module SendGrid4r::Factory
|
5
|
+
describe SegmentFactory do
|
6
|
+
describe 'unit test', :ut do
|
7
|
+
before do
|
8
|
+
Dotenv.load
|
9
|
+
end
|
10
|
+
|
11
|
+
let(:condition) do
|
12
|
+
ConditionFactory.new.create(
|
13
|
+
field: 'last_name',
|
14
|
+
value: 'Miller',
|
15
|
+
operator: 'eq',
|
16
|
+
and_or: ''
|
17
|
+
)
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'create with mandatory parameters' do
|
21
|
+
segment = SegmentFactory.new.create(conditions: [condition])
|
22
|
+
expect(segment).to eq(conditions: [condition])
|
23
|
+
end
|
20
24
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
25
|
+
it 'create with full parameters' do
|
26
|
+
segment = SegmentFactory.new.create(
|
27
|
+
name: 'Last Name Miller', conditions: [condition]
|
28
|
+
)
|
29
|
+
expect(segment).to eq(
|
30
|
+
name: 'Last Name Miller', conditions: [condition]
|
31
|
+
)
|
32
|
+
end
|
26
33
|
end
|
27
34
|
end
|
28
35
|
end
|
@@ -1,35 +1,36 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require File.dirname(__FILE__) + '/../spec_helper'
|
3
3
|
|
4
|
-
|
5
|
-
describe
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
4
|
+
module SendGrid4r::Factory
|
5
|
+
describe VersionFactory do
|
6
|
+
describe 'unit test', :ut do
|
7
|
+
before do
|
8
|
+
Dotenv.load
|
9
|
+
end
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
11
|
+
it 'create with mandatory parameters' do
|
12
|
+
version = VersionFactory.new.create(name: 'version_name')
|
13
|
+
expect(version.name).to eq('version_name')
|
14
|
+
expect(version.subject).to eq('<%subject%>')
|
15
|
+
expect(version.html_content).to eq('<%body%>')
|
16
|
+
expect(version.plain_content).to eq('<%body%>')
|
17
|
+
expect(version.active).to eq(1)
|
18
|
+
end
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
20
|
+
it 'create with full parameters' do
|
21
|
+
version = VersionFactory.new.create(
|
22
|
+
name: 'version_name',
|
23
|
+
subject: 'This is subject <%subject%>',
|
24
|
+
html_content: 'This is html content <%body%>',
|
25
|
+
plain_content: 'This is plain content <%body%>',
|
26
|
+
active: 0
|
27
|
+
)
|
28
|
+
expect(version.name).to eq('version_name')
|
29
|
+
expect(version.subject).to eq('This is subject <%subject%>')
|
30
|
+
expect(version.html_content).to eq('This is html content <%body%>')
|
31
|
+
expect(version.plain_content).to eq('This is plain content <%body%>')
|
32
|
+
expect(version.active).to eq(0)
|
33
|
+
end
|
33
34
|
end
|
34
35
|
end
|
35
36
|
end
|
data/spec/photo.jpg
ADDED
Binary file
|
@@ -0,0 +1,174 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
3
|
+
|
4
|
+
module SendGrid4r::REST::ApiKeysManagement
|
5
|
+
describe SendGrid4r::REST::ApiKeysManagement do
|
6
|
+
describe 'integration test', :it do
|
7
|
+
before do
|
8
|
+
Dotenv.load
|
9
|
+
@client = SendGrid4r::Client.new(api_key: ENV['SILVER_API_KEY'])
|
10
|
+
@name1 = 'api_key_name1'
|
11
|
+
@name2 = 'api_key_name2'
|
12
|
+
@name1e = 'api_key_name1_edit'
|
13
|
+
|
14
|
+
# celan up test env(lists)
|
15
|
+
api_keys = @client.get_api_keys
|
16
|
+
api_keys.result.each do |api_key|
|
17
|
+
@client.delete_api_key(
|
18
|
+
api_key_id: api_key.api_key_id
|
19
|
+
) if api_key.name == @name1
|
20
|
+
@client.delete_api_key(
|
21
|
+
api_key_id: api_key.api_key_id
|
22
|
+
) if api_key.name == @name2
|
23
|
+
@client.delete_api_key(
|
24
|
+
api_key_id: api_key.api_key_id
|
25
|
+
) if api_key.name == @name1e
|
26
|
+
end
|
27
|
+
|
28
|
+
# post api_key
|
29
|
+
@api_key1 = @client.post_api_key(name: @name1, scopes: ['mail.send'])
|
30
|
+
end
|
31
|
+
|
32
|
+
context 'without block call' do
|
33
|
+
it '#get_api_keys' do
|
34
|
+
api_keys = @client.get_api_keys
|
35
|
+
expect(api_keys).to be_a(ApiKeys)
|
36
|
+
expect(api_keys.result).to be_a(Array)
|
37
|
+
end
|
38
|
+
|
39
|
+
it '#post_api_key' do
|
40
|
+
api_key2 = @client.post_api_key(name: @name2)
|
41
|
+
expect(api_key2).to be_a(ApiKey)
|
42
|
+
expect(api_key2.name).to eq(@name2)
|
43
|
+
expect(api_key2.api_key_id).to be_a(String)
|
44
|
+
expect(api_key2.api_key).to be_a(String)
|
45
|
+
end
|
46
|
+
|
47
|
+
it '#post_api_key with scopes' do
|
48
|
+
api_key2 = @client.post_api_key(name: @name2, scopes: ['mail.send'])
|
49
|
+
expect(api_key2).to be_a(ApiKey)
|
50
|
+
expect(api_key2.name).to eq(@name2)
|
51
|
+
expect(api_key2.api_key_id).to be_a(String)
|
52
|
+
expect(api_key2.api_key).to be_a(String)
|
53
|
+
expect(api_key2.scopes).to be_a(Array)
|
54
|
+
end
|
55
|
+
|
56
|
+
it '#get_api_key' do
|
57
|
+
api_key = @client.get_api_key(api_key_id: @api_key1.api_key_id)
|
58
|
+
expect(api_key).to be_a(ApiKey)
|
59
|
+
expect(api_key.api_key_id).to eq(@api_key1.api_key_id)
|
60
|
+
expect(api_key.name).to eq('api_key_name1')
|
61
|
+
expect(api_key.scopes).to be_a(Array)
|
62
|
+
end
|
63
|
+
|
64
|
+
it '#delete_api_key' do
|
65
|
+
@client.delete_api_key(api_key_id: @api_key1.api_key_id)
|
66
|
+
end
|
67
|
+
|
68
|
+
it '#patch_api_key' do
|
69
|
+
edit_api_key = @client.patch_api_key(
|
70
|
+
api_key_id: @api_key1.api_key_id, name: @name1e
|
71
|
+
)
|
72
|
+
expect(edit_api_key.api_key_id).to eq(@api_key1.api_key_id)
|
73
|
+
expect(edit_api_key.name).to eq(@name1e)
|
74
|
+
end
|
75
|
+
|
76
|
+
it '#put_api_key' do
|
77
|
+
edit_api_key = @client.put_api_key(
|
78
|
+
api_key_id: @api_key1.api_key_id,
|
79
|
+
name: @name1e,
|
80
|
+
scopes: ['mail.send']
|
81
|
+
)
|
82
|
+
expect(edit_api_key.api_key_id).to eq(@api_key1.api_key_id)
|
83
|
+
expect(edit_api_key.name).to eq(@name1e)
|
84
|
+
expect(edit_api_key.scopes).to eq(['mail.send'])
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
describe 'unit test', :ut do
|
90
|
+
let(:client) do
|
91
|
+
SendGrid4r::Client.new(api_key: '')
|
92
|
+
end
|
93
|
+
|
94
|
+
let(:api_keys) do
|
95
|
+
JSON.parse(
|
96
|
+
'{'\
|
97
|
+
'"result": ['\
|
98
|
+
'{'\
|
99
|
+
'"name": "A New Hope",'\
|
100
|
+
'"api_key_id": "xxxxxxxx"'\
|
101
|
+
'}'\
|
102
|
+
']'\
|
103
|
+
'}'
|
104
|
+
)
|
105
|
+
end
|
106
|
+
|
107
|
+
let(:api_key) do
|
108
|
+
JSON.parse(
|
109
|
+
'{'\
|
110
|
+
'"api_key": "SG.xxxxxxxx.yyyyyyyy",'\
|
111
|
+
'"api_key_id": "xxxxxxxx",'\
|
112
|
+
'"name": "My API Key",'\
|
113
|
+
'"scopes": ['\
|
114
|
+
'"mail.send",'\
|
115
|
+
'"alerts.create",'\
|
116
|
+
'"alerts.read"'\
|
117
|
+
']'\
|
118
|
+
'}'
|
119
|
+
)
|
120
|
+
end
|
121
|
+
|
122
|
+
it '#get_api_keys' do
|
123
|
+
allow(client).to receive(:execute).and_return(api_keys)
|
124
|
+
actual = client.get_api_keys
|
125
|
+
expect(actual).to be_a(ApiKeys)
|
126
|
+
end
|
127
|
+
|
128
|
+
it '#post_api_key' do
|
129
|
+
allow(client).to receive(:execute).and_return(api_key)
|
130
|
+
actual = client.post_api_key(name: '')
|
131
|
+
expect(actual).to be_a(ApiKey)
|
132
|
+
end
|
133
|
+
|
134
|
+
it '#delete_api_key' do
|
135
|
+
allow(client).to receive(:execute).and_return('')
|
136
|
+
actual = client.delete_api_key(api_key_id: '')
|
137
|
+
expect(actual).to eq('')
|
138
|
+
end
|
139
|
+
|
140
|
+
it '#patch_api_key' do
|
141
|
+
allow(client).to receive(:execute).and_return(api_key)
|
142
|
+
actual = client.patch_api_key(api_key_id: '', name: '')
|
143
|
+
expect(actual).to be_a(ApiKey)
|
144
|
+
end
|
145
|
+
|
146
|
+
it '#put_api_key' do
|
147
|
+
allow(client).to receive(:execute).and_return(api_key)
|
148
|
+
actual = client.put_api_key(api_key_id: '', name: '', scopes: [])
|
149
|
+
expect(actual).to be_a(ApiKey)
|
150
|
+
end
|
151
|
+
|
152
|
+
it 'creates api_key instance' do
|
153
|
+
actual = SendGrid4r::REST::ApiKeysManagement.create_api_key(api_key)
|
154
|
+
expect(actual).to be_a(ApiKey)
|
155
|
+
expect(actual.api_key).to eq('SG.xxxxxxxx.yyyyyyyy')
|
156
|
+
expect(actual.api_key_id).to eq('xxxxxxxx')
|
157
|
+
expect(actual.name).to eq('My API Key')
|
158
|
+
expect(actual.scopes).to eq(
|
159
|
+
['mail.send', 'alerts.create', 'alerts.read']
|
160
|
+
)
|
161
|
+
end
|
162
|
+
|
163
|
+
it 'creates api_keys instance' do
|
164
|
+
actual = SendGrid4r::REST::ApiKeysManagement.create_api_keys(api_keys)
|
165
|
+
expect(actual).to be_a(ApiKeys)
|
166
|
+
expect(actual.result).to be_a(Array)
|
167
|
+
actual.result.each do |api_key|
|
168
|
+
expect(api_key.name).to eq('A New Hope')
|
169
|
+
expect(api_key.api_key_id).to eq('xxxxxxxx')
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
3
|
+
|
4
|
+
module SendGrid4r::REST::ApiKeysManagement
|
5
|
+
describe Permissions do
|
6
|
+
describe 'integration test', :it do
|
7
|
+
before do
|
8
|
+
Dotenv.load
|
9
|
+
@client = SendGrid4r::Client.new(api_key: ENV['SILVER_API_KEY'])
|
10
|
+
end
|
11
|
+
|
12
|
+
context 'without block call' do
|
13
|
+
it '#get_permissions' do
|
14
|
+
permissions = @client.get_permissions
|
15
|
+
expect(permissions).to be_a(Permissions::Permissions)
|
16
|
+
expect(permissions.scopes).to be_a(Array)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe 'unit test', :ut do
|
22
|
+
let(:client) do
|
23
|
+
SendGrid4r::Client.new(api_key: '')
|
24
|
+
end
|
25
|
+
|
26
|
+
let(:permissions) do
|
27
|
+
JSON.parse(
|
28
|
+
'{'\
|
29
|
+
'"scopes": ['\
|
30
|
+
'"alerts.create",'\
|
31
|
+
'"alerts.read",'\
|
32
|
+
'"alerts.update"'\
|
33
|
+
']'\
|
34
|
+
'}'
|
35
|
+
)
|
36
|
+
end
|
37
|
+
|
38
|
+
it '#get_permissions' do
|
39
|
+
allow(client).to receive(:execute).and_return(permissions)
|
40
|
+
actual = client.get_permissions
|
41
|
+
expect(actual).to be_a(Permissions::Permissions)
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'creates permissions instance' do
|
45
|
+
actual = Permissions.create_permissions(permissions)
|
46
|
+
expect(actual).to be_a(Permissions::Permissions)
|
47
|
+
expect(actual.scopes).to be_a(Array)
|
48
|
+
expect(actual.scopes[0]).to eq('alerts.create')
|
49
|
+
expect(actual.scopes[1]).to eq('alerts.read')
|
50
|
+
expect(actual.scopes[2]).to eq('alerts.update')
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|