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.
Files changed (145) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +6 -2
  3. data/README.md +1 -0
  4. data/lib/sendgrid4r/factory/campaign_factory.rb +18 -5
  5. data/lib/sendgrid4r/factory/condition_factory.rb +1 -1
  6. data/lib/sendgrid4r/factory/mail_factory.rb +57 -0
  7. data/lib/sendgrid4r/factory/segment_factory.rb +2 -5
  8. data/lib/sendgrid4r/factory/version_factory.rb +1 -1
  9. data/lib/sendgrid4r/rest/api.rb +48 -49
  10. data/lib/sendgrid4r/rest/api_keys_management/api_keys.rb +75 -0
  11. data/lib/sendgrid4r/rest/api_keys_management/permissions.rb +31 -0
  12. data/lib/sendgrid4r/rest/blocks.rb +49 -68
  13. data/lib/sendgrid4r/rest/bounces.rb +45 -64
  14. data/lib/sendgrid4r/rest/cancel_scheduled_sends.rb +53 -72
  15. data/lib/sendgrid4r/rest/categories.rb +31 -0
  16. data/lib/sendgrid4r/rest/email_activity.rb +72 -0
  17. data/lib/sendgrid4r/rest/invalid_emails.rb +50 -68
  18. data/lib/sendgrid4r/rest/ip_access_management.rb +86 -111
  19. data/lib/sendgrid4r/rest/ips/addresses.rb +50 -59
  20. data/lib/sendgrid4r/rest/ips/pools.rb +42 -53
  21. data/lib/sendgrid4r/rest/ips/warmup.rb +46 -55
  22. data/lib/sendgrid4r/rest/mail/address.rb +14 -0
  23. data/lib/sendgrid4r/rest/mail/attachment.rb +22 -0
  24. data/lib/sendgrid4r/rest/mail/content.rb +10 -0
  25. data/lib/sendgrid4r/rest/mail/mail.rb +28 -0
  26. data/lib/sendgrid4r/rest/mail/mail_settings.rb +62 -0
  27. data/lib/sendgrid4r/rest/mail/params.rb +64 -0
  28. data/lib/sendgrid4r/rest/mail/personalization.rb +33 -0
  29. data/lib/sendgrid4r/rest/mail/tracking_settings.rb +74 -0
  30. data/lib/sendgrid4r/rest/{contacts → marketing_campaigns/contacts}/custom_fields.rb +12 -27
  31. data/lib/sendgrid4r/rest/{contacts → marketing_campaigns/contacts}/lists.rb +20 -34
  32. data/lib/sendgrid4r/rest/marketing_campaigns/contacts/recipients.rb +134 -0
  33. data/lib/sendgrid4r/rest/{contacts → marketing_campaigns/contacts}/reserved_fields.rb +6 -9
  34. data/lib/sendgrid4r/rest/marketing_campaigns/contacts/segments.rb +86 -0
  35. data/lib/sendgrid4r/rest/marketing_campaigns/marketing_campaigns.rb +119 -0
  36. data/lib/sendgrid4r/rest/marketing_campaigns/senders.rb +101 -0
  37. data/lib/sendgrid4r/rest/request.rb +61 -63
  38. data/lib/sendgrid4r/rest/settings/enforced_tls.rb +23 -26
  39. data/lib/sendgrid4r/rest/settings/mail.rb +167 -183
  40. data/lib/sendgrid4r/rest/settings/partner.rb +33 -36
  41. data/lib/sendgrid4r/rest/settings/settings.rb +17 -22
  42. data/lib/sendgrid4r/rest/settings/tracking.rb +97 -107
  43. data/lib/sendgrid4r/rest/sm/global_unsubscribes.rb +52 -60
  44. data/lib/sendgrid4r/rest/sm/groups.rb +52 -58
  45. data/lib/sendgrid4r/rest/sm/sm.rb +15 -17
  46. data/lib/sendgrid4r/rest/sm/suppressions.rb +50 -67
  47. data/lib/sendgrid4r/rest/spam_reports.rb +49 -69
  48. data/lib/sendgrid4r/rest/stats/advanced.rb +100 -102
  49. data/lib/sendgrid4r/rest/stats/category.rb +31 -33
  50. data/lib/sendgrid4r/rest/stats/global.rb +17 -19
  51. data/lib/sendgrid4r/rest/stats/parse.rb +18 -20
  52. data/lib/sendgrid4r/rest/stats/stats.rb +59 -69
  53. data/lib/sendgrid4r/rest/stats/subuser.rb +70 -32
  54. data/lib/sendgrid4r/rest/subusers.rb +106 -134
  55. data/lib/sendgrid4r/rest/transactional_templates/templates.rb +63 -0
  56. data/lib/sendgrid4r/rest/transactional_templates/versions.rb +90 -0
  57. data/lib/sendgrid4r/rest/users.rb +125 -57
  58. data/lib/sendgrid4r/rest/webhooks/event.rb +36 -42
  59. data/lib/sendgrid4r/rest/webhooks/parse.rb +28 -37
  60. data/lib/sendgrid4r/rest/whitelabel/domains.rb +176 -222
  61. data/lib/sendgrid4r/rest/whitelabel/ips.rb +107 -128
  62. data/lib/sendgrid4r/rest/whitelabel/links.rb +131 -167
  63. data/lib/sendgrid4r/version.rb +1 -1
  64. data/lib/sendgrid4r.rb +23 -13
  65. data/sendgrid4r.gemspec +1 -1
  66. data/spec/client_spec.rb +12 -1
  67. data/spec/factory/campaign_factory_spec.rb +75 -35
  68. data/spec/factory/condition_factory_spec.rb +19 -18
  69. data/spec/factory/segment_factory_spec.rb +28 -21
  70. data/spec/factory/version_factory_spec.rb +28 -27
  71. data/spec/photo.jpg +0 -0
  72. data/spec/rest/api_keys_management/api_keys_spec.rb +174 -0
  73. data/spec/rest/api_keys_management/permissions_spec.rb +54 -0
  74. data/spec/rest/blocks_spec.rb +78 -106
  75. data/spec/rest/bounces_spec.rb +91 -118
  76. data/spec/rest/cancel_scheduled_sends_spec.rb +94 -149
  77. data/spec/rest/categories_spec.rb +77 -0
  78. data/spec/rest/email_activity_spec.rb +151 -0
  79. data/spec/rest/invalid_emails_spec.rb +85 -119
  80. data/spec/rest/ip_access_management_spec.rb +157 -195
  81. data/spec/rest/ips/addresses_spec.rb +94 -122
  82. data/spec/rest/ips/pools_spec.rb +84 -112
  83. data/spec/rest/ips/warmup_spec.rb +63 -71
  84. data/spec/rest/mail/address_spec.rb +28 -0
  85. data/spec/rest/mail/attachment_spec.rb +48 -0
  86. data/spec/rest/mail/content_spec.rb +32 -0
  87. data/spec/rest/mail/mail_settings_spec.rb +51 -0
  88. data/spec/rest/mail/mail_spec.rb +136 -0
  89. data/spec/rest/mail/params_spec.rb +152 -0
  90. data/spec/rest/mail/personalization_spec.rb +66 -0
  91. data/spec/rest/mail/tracking_settings_spec.rb +63 -0
  92. data/spec/rest/marketing_campaigns/contacts/custom_fields_spec.rb +146 -0
  93. data/spec/rest/marketing_campaigns/contacts/lists_spec.rb +307 -0
  94. data/spec/rest/marketing_campaigns/contacts/recipients_spec.rb +331 -0
  95. data/spec/rest/marketing_campaigns/contacts/reserved_fields_spec.rb +119 -0
  96. data/spec/rest/marketing_campaigns/contacts/segments_spec.rb +268 -0
  97. data/spec/rest/marketing_campaigns/marketing_campaigns_spec.rb +427 -0
  98. data/spec/rest/marketing_campaigns/senders_spec.rb +230 -0
  99. data/spec/rest/settings/enforced_tls_spec.rb +38 -54
  100. data/spec/rest/settings/mail_spec.rb +227 -330
  101. data/spec/rest/settings/partner_spec.rb +40 -59
  102. data/spec/rest/settings/settings_spec.rb +44 -42
  103. data/spec/rest/settings/tracking_spec.rb +130 -189
  104. data/spec/rest/sm/global_unsubscribes_spec.rb +47 -72
  105. data/spec/rest/sm/groups_spec.rb +88 -123
  106. data/spec/rest/sm/sm_spec.rb +32 -30
  107. data/spec/rest/sm/suppressions_spec.rb +105 -140
  108. data/spec/rest/spam_reports_spec.rb +81 -109
  109. data/spec/rest/stats/advanced_spec.rb +67 -125
  110. data/spec/rest/stats/category_spec.rb +27 -45
  111. data/spec/rest/stats/global_spec.rb +34 -42
  112. data/spec/rest/stats/parse_spec.rb +32 -30
  113. data/spec/rest/stats/stats_spec.rb +174 -172
  114. data/spec/rest/stats/subuser_spec.rb +97 -57
  115. data/spec/rest/subusers_spec.rb +156 -209
  116. data/spec/rest/transactional_templates/templates_spec.rb +199 -0
  117. data/spec/rest/transactional_templates/versions_spec.rb +228 -0
  118. data/spec/rest/users_spec.rb +176 -91
  119. data/spec/rest/webhooks/event_spec.rb +59 -85
  120. data/spec/rest/webhooks/parse_spec.rb +51 -71
  121. data/spec/rest/whitelabel/domains_spec.rb +333 -513
  122. data/spec/rest/whitelabel/ips_spec.rb +109 -147
  123. data/spec/rest/whitelabel/links_spec.rb +181 -265
  124. metadata +70 -40
  125. data/lib/sendgrid4r/rest/api_keys/api_keys.rb +0 -80
  126. data/lib/sendgrid4r/rest/api_keys/permissions.rb +0 -33
  127. data/lib/sendgrid4r/rest/campaigns/campaigns.rb +0 -126
  128. data/lib/sendgrid4r/rest/categories/categories.rb +0 -43
  129. data/lib/sendgrid4r/rest/contacts/recipients.rb +0 -150
  130. data/lib/sendgrid4r/rest/contacts/segments.rb +0 -97
  131. data/lib/sendgrid4r/rest/email_activity/email_activity.rb +0 -81
  132. data/lib/sendgrid4r/rest/templates/templates.rb +0 -69
  133. data/lib/sendgrid4r/rest/templates/versions.rb +0 -95
  134. data/spec/rest/api_keys/api_keys_spec.rb +0 -210
  135. data/spec/rest/api_keys/permissions_spec.rb +0 -65
  136. data/spec/rest/campaigns/campaigns_spec.rb +0 -492
  137. data/spec/rest/categories/categories_spec.rb +0 -96
  138. data/spec/rest/contacts/custom_fields_spec.rb +0 -174
  139. data/spec/rest/contacts/lists_spec.rb +0 -372
  140. data/spec/rest/contacts/recipients_spec.rb +0 -343
  141. data/spec/rest/contacts/reserved_fields_spec.rb +0 -146
  142. data/spec/rest/contacts/segments_spec.rb +0 -307
  143. data/spec/rest/email_activity/email_activity_spec.rb +0 -179
  144. data/spec/rest/templates/templates_spec.rb +0 -222
  145. data/spec/rest/templates/versions_spec.rb +0 -252
@@ -1,81 +1,71 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
 
3
- module SendGrid4r
4
- module REST
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 Stats
9
- #
10
- # SendGrid Web API v3 Stats - AggregatedBy
11
- #
12
- module AggregatedBy
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
- TopStat = Struct.new(:date, :stats)
19
- Stat = Struct.new(:metrics, :name, :type)
20
- Metric = Struct.new(
21
- :blocks,
22
- :bounce_drops,
23
- :bounces,
24
- :clicks,
25
- :deferred,
26
- :delivered,
27
- :drops,
28
- :invalid_emails,
29
- :opens,
30
- :processed,
31
- :requests,
32
- :spam_report_drops,
33
- :spam_reports,
34
- :unique_clicks,
35
- :unique_opens,
36
- :unsubscribe_drops,
37
- :unsubscribes,
38
- :received
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
- def self.create_top_stat(resp)
42
- return resp if resp.nil?
43
- stats = []
44
- resp['stats'].each do |stat|
45
- stats.push(SendGrid4r::REST::Stats.create_stat(stat))
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
- def self.create_stat(resp)
51
- return resp if resp.nil?
52
- stat = SendGrid4r::REST::Stats.create_metric(resp['metrics'])
53
- Stat.new(stat, resp['name'], resp['type'])
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
- def self.create_metric(resp)
57
- return resp if resp.nil?
58
- Metric.new(
59
- resp['blocks'], resp['bounce_drops'],
60
- resp['bounces'], resp['clicks'],
61
- resp['deferred'], resp['delivered'],
62
- resp['drops'], resp['invalid_emails'],
63
- resp['opens'], resp['processed'],
64
- resp['requests'], resp['spam_report_drops'],
65
- resp['spam_reports'], resp['unique_clicks'],
66
- resp['unique_opens'], resp['unsubscribe_drops'],
67
- resp['unsubscribes'], resp['received']
68
- )
69
- end
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
- def self.create_top_stats(resp_a)
72
- return resp_a if resp_a.nil?
73
- top_stats = []
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 REST
5
- module Stats
6
- #
7
- # SendGrid Web API v3 Stats - Subuser
8
- #
9
- module Subuser
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
- def get_subusers_stats(
13
- start_date:, end_date: nil, aggregated_by: nil, subusers:, &block)
14
- params = {
15
- start_date: start_date,
16
- end_date: end_date,
17
- aggregated_by: aggregated_by,
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
- def get_subusers_stats_sums(
25
- start_date:, end_date: nil, sort_by_metric: nil,
26
- sort_by_direction: nil, limit: nil, offset: nil, &block)
27
- params = {
28
- start_date: start_date,
29
- end_date: end_date,
30
- sort_by_metric: sort_by_metric,
31
- sort_by_direction: sort_by_direction,
32
- limit: limit,
33
- offset: offset
34
- }
35
- resp = get(@auth, "#{BASE_URL}/subusers/stats/sums", params, &block)
36
- SendGrid4r::REST::Stats.create_top_stat(resp)
37
- end
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
- module REST
5
- #
6
- # SendGrid Web API v3 Subusers
7
- #
8
- module Subusers
9
- include SendGrid4r::REST::Request
10
-
11
- Subuser = Struct.new(
12
- :id, :username, :email, :password, :ips, :reputation, :disabled
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
- Ips = Struct.new(:ips)
15
-
16
- def self.url(subuser_name = nil)
17
- url = "#{BASE_URL}/subusers"
18
- url = "#{url}/#{subuser_name}" unless subuser_name.nil?
19
- url
20
- end
21
-
22
- def self.create_subusers(resp)
23
- return resp if resp.nil?
24
- subusers = []
25
- resp.each do |subuser|
26
- subusers.push(SendGrid4r::REST::Subusers.create_subuser(subuser))
27
- end
28
- subusers
29
- end
30
-
31
- def self.create_subuser(resp)
32
- return resp if resp.nil?
33
- Subuser.new(
34
- resp['id'],
35
- resp['username'],
36
- resp['email'],
37
- resp['password'],
38
- resp['ips'],
39
- resp['reputation'],
40
- resp['disabled']
41
- )
42
- end
43
-
44
- Monitor = Struct.new(:email, :frequency)
45
-
46
- def self.create_monitor(resp)
47
- return resp if resp.nil?
48
- Monitor.new(
49
- resp['email'],
50
- resp['frequency']
51
- )
52
- end
53
-
54
- def get_subusers(limit: nil, offset: nil, username: nil, &block)
55
- params = {}
56
- params['limit'] = limit unless limit.nil?
57
- params['offset'] = offset unless offset.nil?
58
- params['username'] = username unless username.nil?
59
- resp = get(@auth, SendGrid4r::REST::Subusers.url, params, &block)
60
- SendGrid4r::REST::Subusers.create_subusers(resp)
61
- end
62
-
63
- def post_subuser(username:, email:, password:, ips:, &block)
64
- params = {}
65
- params['username'] = username
66
- params['email'] = email
67
- params['password'] = password
68
- params['ips'] = ips
69
- resp = post(@auth, SendGrid4r::REST::Subusers.url, params, &block)
70
- SendGrid4r::REST::Subusers.create_subuser(resp)
71
- end
72
-
73
- def patch_subuser(username:, disabled:, &block)
74
- endpoint = SendGrid4r::REST::Subusers.url(username)
75
- payload = {}
76
- payload['disabled'] = disabled
77
- resp = patch(@auth, endpoint, payload, &block)
78
- SendGrid4r::REST::Subusers.create_subuser(resp)
79
- end
80
-
81
- def delete_subuser(username:, &block)
82
- endpoint = SendGrid4r::REST::Subusers.url(username)
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