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,81 +1,71 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
|
3
|
-
module SendGrid4r
|
4
|
-
|
3
|
+
module SendGrid4r::REST
|
4
|
+
#
|
5
|
+
# SendGrid Web API v3 Stats
|
6
|
+
#
|
7
|
+
module Stats
|
5
8
|
#
|
6
|
-
# SendGrid Web API v3 Stats
|
9
|
+
# [DEPRECATED] SendGrid Web API v3 Stats - AggregatedBy
|
7
10
|
#
|
8
|
-
module
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
DAY = 'day'
|
14
|
-
WEEK = 'week'
|
15
|
-
MONTH = 'month'
|
16
|
-
end
|
11
|
+
module AggregatedBy
|
12
|
+
DAY = 'day'
|
13
|
+
WEEK = 'week'
|
14
|
+
MONTH = 'month'
|
15
|
+
end
|
17
16
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
17
|
+
TopStat = Struct.new(:date, :stats)
|
18
|
+
Stat = Struct.new(:metrics, :name, :type)
|
19
|
+
Metric = Struct.new(
|
20
|
+
:blocks,
|
21
|
+
:bounce_drops,
|
22
|
+
:bounces,
|
23
|
+
:clicks,
|
24
|
+
:deferred,
|
25
|
+
:delivered,
|
26
|
+
:drops,
|
27
|
+
:invalid_emails,
|
28
|
+
:opens,
|
29
|
+
:processed,
|
30
|
+
:requests,
|
31
|
+
:spam_report_drops,
|
32
|
+
:spam_reports,
|
33
|
+
:unique_clicks,
|
34
|
+
:unique_opens,
|
35
|
+
:unsubscribe_drops,
|
36
|
+
:unsubscribes,
|
37
|
+
:received
|
38
|
+
)
|
40
39
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
end
|
47
|
-
TopStat.new(resp['date'], stats)
|
48
|
-
end
|
40
|
+
def self.create_top_stat(resp)
|
41
|
+
return resp if resp.nil?
|
42
|
+
stats = resp['stats'].map { |stat| Stats.create_stat(stat) }
|
43
|
+
TopStat.new(resp['date'], stats)
|
44
|
+
end
|
49
45
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
end
|
46
|
+
def self.create_stat(resp)
|
47
|
+
return resp if resp.nil?
|
48
|
+
Stat.new(Stats.create_metric(resp['metrics']), resp['name'], resp['type'])
|
49
|
+
end
|
55
50
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
51
|
+
def self.create_metric(resp)
|
52
|
+
return resp if resp.nil?
|
53
|
+
Metric.new(
|
54
|
+
resp['blocks'], resp['bounce_drops'],
|
55
|
+
resp['bounces'], resp['clicks'],
|
56
|
+
resp['deferred'], resp['delivered'],
|
57
|
+
resp['drops'], resp['invalid_emails'],
|
58
|
+
resp['opens'], resp['processed'],
|
59
|
+
resp['requests'], resp['spam_report_drops'],
|
60
|
+
resp['spam_reports'], resp['unique_clicks'],
|
61
|
+
resp['unique_opens'], resp['unsubscribe_drops'],
|
62
|
+
resp['unsubscribes'], resp['received']
|
63
|
+
)
|
64
|
+
end
|
70
65
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
resp_a.each do |resp|
|
75
|
-
top_stats.push(SendGrid4r::REST::Stats.create_top_stat(resp))
|
76
|
-
end
|
77
|
-
top_stats
|
78
|
-
end
|
66
|
+
def self.create_top_stats(resp_a)
|
67
|
+
return resp_a if resp_a.nil?
|
68
|
+
resp_a.map { |resp| Stats.create_top_stat(resp) }
|
79
69
|
end
|
80
70
|
end
|
81
71
|
end
|
@@ -1,40 +1,78 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
|
3
|
-
module SendGrid4r
|
4
|
-
module
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
include SendGrid4r::REST::Request
|
3
|
+
module SendGrid4r::REST
|
4
|
+
module Stats
|
5
|
+
#
|
6
|
+
# SendGrid Web API v3 Stats - Subuser
|
7
|
+
#
|
8
|
+
module Subuser
|
9
|
+
include Request
|
11
10
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
subusers: subusers
|
19
|
-
}
|
20
|
-
resp = get(@auth, "#{BASE_URL}/subusers/stats", params, &block)
|
21
|
-
SendGrid4r::REST::Stats.create_top_stats(resp)
|
11
|
+
def self.url(subuser_name = nil, aggregate = nil)
|
12
|
+
url = "#{BASE_URL}/subusers"
|
13
|
+
if subuser_name.nil?
|
14
|
+
url = "#{url}/stats"
|
15
|
+
else
|
16
|
+
url = "#{url}/#{subuser_name}/stats"
|
22
17
|
end
|
18
|
+
url = "#{url}/#{aggregate}" unless aggregate.nil?
|
19
|
+
url
|
20
|
+
end
|
23
21
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
22
|
+
def get_subusers_stats(
|
23
|
+
start_date:, end_date: nil, aggregated_by: nil, subusers:, &block)
|
24
|
+
params = {
|
25
|
+
start_date: start_date,
|
26
|
+
end_date: end_date,
|
27
|
+
aggregated_by: aggregated_by,
|
28
|
+
subusers: subusers
|
29
|
+
}
|
30
|
+
resp = get(@auth, Subuser.url, params, &block)
|
31
|
+
Stats.create_top_stats(resp)
|
32
|
+
end
|
33
|
+
|
34
|
+
def get_subusers_stats_sums(
|
35
|
+
start_date:, end_date: nil, sort_by_metric: nil,
|
36
|
+
sort_by_direction: nil, limit: nil, offset: nil, &block)
|
37
|
+
params = {
|
38
|
+
start_date: start_date,
|
39
|
+
end_date: end_date,
|
40
|
+
sort_by_metric: sort_by_metric,
|
41
|
+
sort_by_direction: sort_by_direction,
|
42
|
+
limit: limit,
|
43
|
+
offset: offset
|
44
|
+
}
|
45
|
+
resp = get(@auth, Subuser.url(nil, :sums), params, &block)
|
46
|
+
Stats.create_top_stat(resp)
|
47
|
+
end
|
48
|
+
|
49
|
+
def get_subusers_stats_monthly(
|
50
|
+
date:, subuser: nil, sort_by_metric: nil, sort_by_direction: nil,
|
51
|
+
limit: nil, offset: nil, &block)
|
52
|
+
params = {
|
53
|
+
date: date,
|
54
|
+
subuser: subuser,
|
55
|
+
sort_by_metric: sort_by_metric,
|
56
|
+
sort_by_direction: sort_by_direction,
|
57
|
+
limit: limit,
|
58
|
+
offset: offset
|
59
|
+
}
|
60
|
+
resp = get(@auth, Subuser.url(nil, :monthly), params, &block)
|
61
|
+
Stats.create_top_stat(resp)
|
62
|
+
end
|
63
|
+
|
64
|
+
def get_subuser_stats_monthly(
|
65
|
+
subuser_name:, date:, sort_by_metric: nil, sort_by_direction: nil,
|
66
|
+
limit: nil, offset: nil, &block)
|
67
|
+
params = {
|
68
|
+
date: date,
|
69
|
+
sort_by_metric: sort_by_metric,
|
70
|
+
sort_by_direction: sort_by_direction,
|
71
|
+
limit: limit,
|
72
|
+
offset: offset
|
73
|
+
}
|
74
|
+
resp = get(@auth, Subuser.url(subuser_name, :monthly), params, &block)
|
75
|
+
Stats.create_top_stat(resp)
|
38
76
|
end
|
39
77
|
end
|
40
78
|
end
|
@@ -1,140 +1,112 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
|
3
|
-
module SendGrid4r
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
3
|
+
module SendGrid4r::REST
|
4
|
+
#
|
5
|
+
# SendGrid Web API v3 Subusers
|
6
|
+
#
|
7
|
+
module Subusers
|
8
|
+
include Request
|
9
|
+
|
10
|
+
Subuser = Struct.new(
|
11
|
+
:id, :username, :email, :password, :ips, :reputation, :disabled
|
12
|
+
)
|
13
|
+
Ips = Struct.new(:ips)
|
14
|
+
|
15
|
+
def self.url(subuser_name = nil)
|
16
|
+
url = "#{BASE_URL}/subusers"
|
17
|
+
url = "#{url}/#{subuser_name}" unless subuser_name.nil?
|
18
|
+
url
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.url_monitor(username)
|
22
|
+
"#{Subusers.url(username)}/monitor"
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.create_subusers(resp)
|
26
|
+
return resp if resp.nil?
|
27
|
+
resp.map { |subuser| Subusers.create_subuser(subuser) }
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.create_subuser(resp)
|
31
|
+
return resp if resp.nil?
|
32
|
+
Subuser.new(
|
33
|
+
resp['id'],
|
34
|
+
resp['username'],
|
35
|
+
resp['email'],
|
36
|
+
resp['password'],
|
37
|
+
resp['ips'],
|
38
|
+
resp['reputation'],
|
39
|
+
resp['disabled']
|
13
40
|
)
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
delete(@auth, endpoint, &block)
|
84
|
-
end
|
85
|
-
|
86
|
-
def get_subuser_monitor(username:, email:, frequency:, &block)
|
87
|
-
endpoint = SendGrid4r::REST::Subusers.url(username)
|
88
|
-
endpoint = "#{endpoint}/monitor"
|
89
|
-
payload = {}
|
90
|
-
payload['email'] = email
|
91
|
-
payload['frequency'] = frequency
|
92
|
-
resp = post(@auth, endpoint, payload, &block)
|
93
|
-
SendGrid4r::REST::Subusers.create_monitor(resp)
|
94
|
-
end
|
95
|
-
|
96
|
-
def post_subuser_monitor(username:, email:, frequency:, &block)
|
97
|
-
endpoint = SendGrid4r::REST::Subusers.url(username)
|
98
|
-
endpoint = "#{endpoint}/monitor"
|
99
|
-
payload = {}
|
100
|
-
payload['email'] = email
|
101
|
-
payload['frequency'] = frequency
|
102
|
-
resp = post(@auth, endpoint, payload, &block)
|
103
|
-
SendGrid4r::REST::Subusers.create_monitor(resp)
|
104
|
-
end
|
105
|
-
|
106
|
-
def put_subuser_monitor(username:, email:, frequency:, &block)
|
107
|
-
endpoint = SendGrid4r::REST::Subusers.url(username)
|
108
|
-
endpoint = "#{endpoint}/monitor"
|
109
|
-
payload = {}
|
110
|
-
payload['email'] = email
|
111
|
-
payload['frequency'] = frequency
|
112
|
-
resp = put(@auth, endpoint, payload, &block)
|
113
|
-
SendGrid4r::REST::Subusers.create_monitor(resp)
|
114
|
-
end
|
115
|
-
|
116
|
-
def delete_subuser_monitor(username:, &block)
|
117
|
-
endpoint = SendGrid4r::REST::Subusers.url(username)
|
118
|
-
endpoint = "#{endpoint}/monitor"
|
119
|
-
delete(@auth, endpoint, &block)
|
120
|
-
end
|
121
|
-
|
122
|
-
def get_subuser_reputation(usernames:, &block)
|
123
|
-
params = ''
|
124
|
-
usernames.each do |username|
|
125
|
-
params += "usernames=#{username}&"
|
126
|
-
end
|
127
|
-
endpoint = SendGrid4r::REST::Subusers.url
|
128
|
-
endpoint = "#{endpoint}/reputations?#{params}"
|
129
|
-
resp = get(@auth, endpoint, usernames, &block)
|
130
|
-
SendGrid4r::REST::Subusers.create_subusers(resp)
|
131
|
-
end
|
132
|
-
|
133
|
-
def put_subuser_assigned_ips(username:, ips:, &block)
|
134
|
-
endpoint = "#{SendGrid4r::REST::Subusers.url(username)}/ips"
|
135
|
-
resp = put(@auth, endpoint, ips, &block)
|
136
|
-
SendGrid4r::REST::Subusers.create_subuser(resp)
|
137
|
-
end
|
41
|
+
end
|
42
|
+
|
43
|
+
Monitor = Struct.new(:email, :frequency)
|
44
|
+
|
45
|
+
def self.create_monitor(resp)
|
46
|
+
return resp if resp.nil?
|
47
|
+
Monitor.new(resp['email'], resp['frequency'])
|
48
|
+
end
|
49
|
+
|
50
|
+
def get_subusers(limit: nil, offset: nil, username: nil, &block)
|
51
|
+
params = {}
|
52
|
+
params[:limit] = limit unless limit.nil?
|
53
|
+
params[:offset] = offset unless offset.nil?
|
54
|
+
params[:username] = username unless username.nil?
|
55
|
+
Subusers.create_subusers(get(@auth, Subusers.url, params, &block))
|
56
|
+
end
|
57
|
+
|
58
|
+
def post_subuser(username:, email:, password:, ips:, &block)
|
59
|
+
params = {
|
60
|
+
username: username,
|
61
|
+
email: email,
|
62
|
+
password: password,
|
63
|
+
ips: ips
|
64
|
+
}
|
65
|
+
Subusers.create_subuser(post(@auth, Subusers.url, params, &block))
|
66
|
+
end
|
67
|
+
|
68
|
+
def patch_subuser(username:, disabled:, &block)
|
69
|
+
payload = { disabled: disabled }
|
70
|
+
resp = patch(@auth, Subusers.url(username), payload, &block)
|
71
|
+
Subusers.create_subuser(resp)
|
72
|
+
end
|
73
|
+
|
74
|
+
def delete_subuser(username:, &block)
|
75
|
+
delete(@auth, Subusers.url(username), &block)
|
76
|
+
end
|
77
|
+
|
78
|
+
def get_subuser_monitor(username:, email:, frequency:, &block)
|
79
|
+
endpoint = Subusers.url_monitor(username)
|
80
|
+
payload = { email: email, frequency: frequency }
|
81
|
+
Subusers.create_monitor(post(@auth, endpoint, payload, &block))
|
82
|
+
end
|
83
|
+
|
84
|
+
def post_subuser_monitor(username:, email:, frequency:, &block)
|
85
|
+
endpoint = Subusers.url_monitor(username)
|
86
|
+
payload = { email: email, frequency: frequency }
|
87
|
+
Subusers.create_monitor(post(@auth, endpoint, payload, &block))
|
88
|
+
end
|
89
|
+
|
90
|
+
def put_subuser_monitor(username:, email:, frequency:, &block)
|
91
|
+
endpoint = Subusers.url_monitor(username)
|
92
|
+
payload = { email: email, frequency: frequency }
|
93
|
+
Subusers.create_monitor(put(@auth, endpoint, payload, &block))
|
94
|
+
end
|
95
|
+
|
96
|
+
def delete_subuser_monitor(username:, &block)
|
97
|
+
delete(@auth, Subusers.url_monitor(username), &block)
|
98
|
+
end
|
99
|
+
|
100
|
+
def get_subuser_reputation(usernames:, &block)
|
101
|
+
params = ''
|
102
|
+
usernames.each { |username| params += "usernames=#{username}&" }
|
103
|
+
endpoint = "#{Subusers.url}/reputations?#{params}"
|
104
|
+
Subusers.create_subusers(get(@auth, endpoint, usernames, &block))
|
105
|
+
end
|
106
|
+
|
107
|
+
def put_subuser_assigned_ips(username:, ips:, &block)
|
108
|
+
resp = put(@auth, "#{Subusers.url(username)}/ips", ips, &block)
|
109
|
+
Subusers.create_subuser(resp)
|
138
110
|
end
|
139
111
|
end
|
140
112
|
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
module SendGrid4r::REST
|
4
|
+
#
|
5
|
+
# SendGrid Web API v3 Template Engine - Templates
|
6
|
+
#
|
7
|
+
module TransactionalTemplates
|
8
|
+
include Request
|
9
|
+
|
10
|
+
Templates = Struct.new(:templates)
|
11
|
+
Template = Struct.new(:id, :name, :versions)
|
12
|
+
|
13
|
+
def self.url(temp_id = nil)
|
14
|
+
url = "#{BASE_URL}/templates"
|
15
|
+
url = "#{url}/#{temp_id}" unless temp_id.nil?
|
16
|
+
url
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.create_templates(resp)
|
20
|
+
return resp if resp.nil?
|
21
|
+
tmps = resp['templates'].map do |template|
|
22
|
+
TransactionalTemplates.create_template(template)
|
23
|
+
end
|
24
|
+
Templates.new(tmps)
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.create_template(resp)
|
28
|
+
return resp if resp.nil?
|
29
|
+
vers = resp['versions'].map do |ver|
|
30
|
+
TransactionalTemplates::Versions.create_version(ver)
|
31
|
+
end
|
32
|
+
Template.new(resp['id'], resp['name'], vers)
|
33
|
+
end
|
34
|
+
|
35
|
+
def post_template(name:, &block)
|
36
|
+
endpoint = TransactionalTemplates.url
|
37
|
+
resp = post(@auth, endpoint, name: name, &block)
|
38
|
+
TransactionalTemplates.create_template(resp)
|
39
|
+
end
|
40
|
+
|
41
|
+
def get_templates(&block)
|
42
|
+
resp = get(@auth, TransactionalTemplates.url, &block)
|
43
|
+
TransactionalTemplates.create_templates(resp)
|
44
|
+
end
|
45
|
+
|
46
|
+
def get_template(template_id:, &block)
|
47
|
+
endpoint = TransactionalTemplates.url(template_id)
|
48
|
+
resp = get(@auth, endpoint, &block)
|
49
|
+
TransactionalTemplates.create_template(resp)
|
50
|
+
end
|
51
|
+
|
52
|
+
def patch_template(template_id:, name:, &block)
|
53
|
+
endpoint = TransactionalTemplates.url(template_id)
|
54
|
+
resp = patch(@auth, endpoint, name: name, &block)
|
55
|
+
TransactionalTemplates.create_template(resp)
|
56
|
+
end
|
57
|
+
|
58
|
+
def delete_template(template_id:, &block)
|
59
|
+
endpoint = TransactionalTemplates.url(template_id)
|
60
|
+
delete(@auth, endpoint, &block)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
module SendGrid4r::REST
|
4
|
+
#
|
5
|
+
# SendGrid Web API v3 Template Engine - Templates
|
6
|
+
#
|
7
|
+
module TransactionalTemplates
|
8
|
+
#
|
9
|
+
# SendGrid Web API v3 Template Engine - Versions
|
10
|
+
#
|
11
|
+
module Versions
|
12
|
+
include Request
|
13
|
+
|
14
|
+
Version = Struct.new(
|
15
|
+
:id, :user_id, :template_id, :active, :name, :html_content,
|
16
|
+
:plain_content, :subject, :updated_at)
|
17
|
+
|
18
|
+
def self.create_version(resp)
|
19
|
+
return resp if resp.nil?
|
20
|
+
Version.new(
|
21
|
+
resp['id'],
|
22
|
+
resp['user_id'],
|
23
|
+
resp['template_id'],
|
24
|
+
resp['active'],
|
25
|
+
resp['name'],
|
26
|
+
resp['html_content'],
|
27
|
+
resp['plain_content'],
|
28
|
+
resp['subject'],
|
29
|
+
resp['updated_at'])
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.url(temp_id, ver_id = nil)
|
33
|
+
url = "#{BASE_URL}/templates/#{temp_id}/versions"
|
34
|
+
url = "#{url}/#{ver_id}" unless ver_id.nil?
|
35
|
+
url
|
36
|
+
end
|
37
|
+
|
38
|
+
def post_version(template_id:, version:, &block)
|
39
|
+
resp = post(
|
40
|
+
@auth,
|
41
|
+
Versions.url(template_id),
|
42
|
+
remove_uneditable_keys(version.to_h),
|
43
|
+
&block
|
44
|
+
)
|
45
|
+
Versions.create_version(resp)
|
46
|
+
end
|
47
|
+
|
48
|
+
def activate_version(template_id:, version_id:, &block)
|
49
|
+
url = Versions.url(template_id, version_id)
|
50
|
+
resp = post(@auth, "#{url}/activate", &block)
|
51
|
+
Versions.create_version(resp)
|
52
|
+
end
|
53
|
+
|
54
|
+
def get_version(template_id:, version_id:, &block)
|
55
|
+
resp = get(
|
56
|
+
@auth,
|
57
|
+
Versions.url(template_id, version_id),
|
58
|
+
&block
|
59
|
+
)
|
60
|
+
Versions.create_version(resp)
|
61
|
+
end
|
62
|
+
|
63
|
+
def patch_version(template_id:, version_id:, version:, &block)
|
64
|
+
resp = patch(
|
65
|
+
@auth,
|
66
|
+
Versions.url(template_id, version_id),
|
67
|
+
remove_uneditable_keys(version.to_h),
|
68
|
+
&block
|
69
|
+
)
|
70
|
+
Versions.create_version(resp)
|
71
|
+
end
|
72
|
+
|
73
|
+
def delete_version(template_id:, version_id:, &block)
|
74
|
+
delete(
|
75
|
+
@auth,
|
76
|
+
Versions.url(template_id, version_id),
|
77
|
+
&block
|
78
|
+
)
|
79
|
+
end
|
80
|
+
|
81
|
+
private
|
82
|
+
|
83
|
+
def remove_uneditable_keys(hash_value)
|
84
|
+
hash_value.delete(:id) if hash_value.key?(:id)
|
85
|
+
hash_value.delete(:template_id) if hash_value.key?(:template_id)
|
86
|
+
hash_value
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|