sendgrid4r 1.8.1 → 1.10.0

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -4,80 +4,78 @@ require 'rest-client'
4
4
  require 'uri'
5
5
  require 'json'
6
6
 
7
- module SendGrid4r
8
- module REST
9
- #
10
- # SendGrid Web API v3 Request
11
- #
12
- module Request
13
- BASE_URL = 'https://api.sendgrid.com/v3'
7
+ module SendGrid4r::REST
8
+ #
9
+ # SendGrid Web API v3 Request
10
+ #
11
+ module Request
12
+ BASE_URL = 'https://api.sendgrid.com/v3'
14
13
 
15
- def get(auth, endpoint, params = nil, payload = nil, &block)
16
- execute(:get, auth, endpoint, params, payload, &block)
17
- end
14
+ def get(auth, endpoint, params = nil, payload = nil, &block)
15
+ execute(:get, auth, endpoint, params, payload, &block)
16
+ end
18
17
 
19
- def post(auth, endpoint, payload = nil, &block)
20
- execute(:post, auth, endpoint, nil, payload, &block)
21
- end
18
+ def post(auth, endpoint, payload = nil, &block)
19
+ execute(:post, auth, endpoint, nil, payload, &block)
20
+ end
22
21
 
23
- def patch(auth, endpoint, payload, &block)
24
- execute(:patch, auth, endpoint, nil, payload, &block)
25
- end
22
+ def patch(auth, endpoint, payload, &block)
23
+ execute(:patch, auth, endpoint, nil, payload, &block)
24
+ end
26
25
 
27
- def put(auth, endpoint, payload, &block)
28
- execute(:put, auth, endpoint, nil, payload, &block)
29
- end
26
+ def put(auth, endpoint, payload, &block)
27
+ execute(:put, auth, endpoint, nil, payload, &block)
28
+ end
30
29
 
31
- def delete(auth, endpoint, params = nil, payload = nil, &block)
32
- execute(:delete, auth, endpoint, params, payload, &block)
33
- end
30
+ def delete(auth, endpoint, params = nil, payload = nil, &block)
31
+ execute(:delete, auth, endpoint, params, payload, &block)
32
+ end
34
33
 
35
- def execute(method, auth, endpoint, params, payload, &block)
36
- args = create_args(method, auth, endpoint, params, payload)
37
- body = RestClient::Request.execute(args, &block)
38
- return nil if block_given?
39
- return JSON.parse(body) unless body.nil? || body.length < 2
40
- body
41
- rescue RestClient::TooManyRequests => e
42
- duration = e.response.headers[:x_ratelimit_remaining].to_i
43
- sleep duration if duration > 0
44
- retry
45
- end
34
+ def execute(method, auth, endpoint, params, payload, &block)
35
+ args = create_args(method, auth, endpoint, params, payload)
36
+ body = RestClient::Request.execute(args, &block)
37
+ return nil if block_given?
38
+ return JSON.parse(body) unless body.nil? || body.length < 2
39
+ body
40
+ rescue RestClient::TooManyRequests => e
41
+ duration = e.response.headers[:x_ratelimit_remaining].to_i
42
+ sleep duration if duration > 0
43
+ retry
44
+ end
46
45
 
47
- def create_args(method, auth, endpoint, params, payload)
48
- args = {}
49
- args[:method] = method
50
- args[:url] = process_url_params(endpoint, params)
51
- headers = {}
52
- headers[:content_type] = :json
53
- # Added for Campaign API
54
- headers['Accept-Encoding'] = 'plain'
55
- #
56
- if !auth.api_key.nil?
57
- headers[:authorization] = "Bearer #{auth.api_key}"
58
- else
59
- args[:user] = auth.username
60
- args[:password] = auth.password
61
- end
62
- args[:headers] = headers
63
- args[:payload] = payload.to_json unless payload.nil?
64
- args
46
+ def create_args(method, auth, endpoint, params, payload)
47
+ args = {}
48
+ args[:method] = method
49
+ args[:url] = process_url_params(endpoint, params)
50
+ headers = {}
51
+ headers[:content_type] = :json
52
+ # Added for Campaign API
53
+ headers['Accept-Encoding'] = 'plain'
54
+ #
55
+ if !auth.api_key.nil?
56
+ headers[:authorization] = "Bearer #{auth.api_key}"
57
+ else
58
+ args[:user] = auth.username
59
+ args[:password] = auth.password
65
60
  end
61
+ args[:headers] = headers
62
+ args[:payload] = payload.to_json unless payload.nil?
63
+ args
64
+ end
66
65
 
67
- def process_url_params(endpoint, params)
68
- if params.nil? || params.empty?
69
- endpoint
70
- else
71
- query_string = params.collect do |k, v|
72
- "#{k}=#{CGI.escape(process_array_params(v))}"
73
- end.join('&')
74
- endpoint + "?#{query_string}"
75
- end
66
+ def process_url_params(endpoint, params)
67
+ if params.nil? || params.empty?
68
+ endpoint
69
+ else
70
+ query_string = params.collect do |k, v|
71
+ "#{k}=#{CGI.escape(process_array_params(v))}"
72
+ end.join('&')
73
+ endpoint + "?#{query_string}"
76
74
  end
75
+ end
77
76
 
78
- def process_array_params(v)
79
- v.is_a?(Array) ? v.join(',') : v.to_s
80
- end
77
+ def process_array_params(v)
78
+ v.is_a?(Array) ? v.join(',') : v.to_s
81
79
  end
82
80
  end
83
81
  end
@@ -1,35 +1,32 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
 
3
- module SendGrid4r
4
- module REST
5
- module Settings
6
- #
7
- # SendGrid Web API v3 Settings - EnforcedTls
8
- #
9
- module EnforcedTls
10
- include SendGrid4r::REST::Request
11
- EnforcedTls = Struct.new(:require_tls, :require_valid_cert)
3
+ module SendGrid4r::REST
4
+ module Settings
5
+ #
6
+ # SendGrid Web API v3 Settings - EnforcedTls
7
+ #
8
+ module EnforcedTls
9
+ include Request
12
10
 
13
- def self.create_enforced_tls(resp)
14
- return resp if resp.nil?
15
- EnforcedTls.new(resp['require_tls'], resp['require_valid_cert'])
16
- end
11
+ EnforcedTls = Struct.new(:require_tls, :require_valid_cert)
17
12
 
18
- def self.url
19
- "#{BASE_URL}/user/settings/enforced_tls"
20
- end
13
+ def self.create_enforced_tls(resp)
14
+ return resp if resp.nil?
15
+ EnforcedTls.new(resp['require_tls'], resp['require_valid_cert'])
16
+ end
17
+
18
+ def self.url
19
+ "#{BASE_URL}/user/settings/enforced_tls"
20
+ end
21
21
 
22
- def get_enforced_tls(&block)
23
- endpoint = SendGrid4r::REST::Settings::EnforcedTls.url
24
- resp = get(@auth, endpoint, &block)
25
- SendGrid4r::REST::Settings::EnforcedTls.create_enforced_tls(resp)
26
- end
22
+ def get_enforced_tls(&block)
23
+ resp = get(@auth, Settings::EnforcedTls.url, &block)
24
+ Settings::EnforcedTls.create_enforced_tls(resp)
25
+ end
27
26
 
28
- def patch_enforced_tls(params:, &block)
29
- endpoint = SendGrid4r::REST::Settings::EnforcedTls.url
30
- resp = patch(@auth, endpoint, params.to_h, &block)
31
- SendGrid4r::REST::Settings::EnforcedTls.create_enforced_tls(resp)
32
- end
27
+ def patch_enforced_tls(params:, &block)
28
+ resp = patch(@auth, Settings::EnforcedTls.url, params.to_h, &block)
29
+ Settings::EnforcedTls.create_enforced_tls(resp)
33
30
  end
34
31
  end
35
32
  end
@@ -1,188 +1,172 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
 
3
- module SendGrid4r
4
- module REST
5
- module Settings
6
- #
7
- # SendGrid Web API v3 Settings - Mail
8
- #
9
- module Mail
10
- include SendGrid4r::REST::Request
11
-
12
- AddressWhitelist = Struct.new(:enabled, :list)
13
-
14
- def self.create_address_whitelist(resp)
15
- return resp if resp.nil?
16
- list = []
17
- resp['list'].each do |address|
18
- list.push(address)
19
- end
20
- AddressWhitelist.new(resp['enabled'], list)
21
- end
22
-
23
- Bcc = Struct.new(:enabled, :email)
24
-
25
- def self.create_bcc(resp)
26
- return resp if resp.nil?
27
- Bcc.new(resp['enabled'], resp['email'])
28
- end
29
-
30
- BouncePurge = Struct.new(:enabled, :hard_bounces, :soft_bounces)
31
-
32
- def self.create_bounce_purge(resp)
33
- return resp if resp.nil?
34
- BouncePurge.new(
35
- resp['enabled'], resp['hard_bounces'], resp['soft_bounces']
36
- )
37
- end
38
-
39
- Footer = Struct.new(:enabled, :html_content, :plain_content)
40
-
41
- def self.create_footer(resp)
42
- return resp if resp.nil?
43
- Footer.new(
44
- resp['enabled'], resp['html_content'], resp['plain_content']
45
- )
46
- end
47
-
48
- ForwardBounce = Struct.new(:enabled, :email)
49
-
50
- def self.create_forward_bounce(resp)
51
- return resp if resp.nil?
52
- ForwardBounce.new(resp['enabled'], resp['email'])
53
- end
54
-
55
- ForwardSpam = Struct.new(:enabled, :email)
56
-
57
- def self.create_forward_spam(resp)
58
- return resp if resp.nil?
59
- ForwardSpam.new(resp['enabled'], resp['email'])
60
- end
61
-
62
- Template = Struct.new(:enabled, :html_content)
63
-
64
- def self.create_template(resp)
65
- return resp if resp.nil?
66
- Template.new(resp['enabled'], resp['html_content'])
67
- end
68
-
69
- PlainContent = Struct.new(:enabled)
70
-
71
- def self.create_plain_content(resp)
72
- return resp if resp.nil?
73
- PlainContent.new(resp['enabled'])
74
- end
75
-
76
- def self.url(name = nil)
77
- url = "#{BASE_URL}/mail_settings"
78
- url = "#{url}/#{name}" unless name.nil?
79
- url
80
- end
81
-
82
- def get_mail_settings(limit: nil, offset: nil, &block)
83
- params = {}
84
- params['limit'] = limit unless limit.nil?
85
- params['offset'] = offset unless offset.nil?
86
- endpoint = SendGrid4r::REST::Settings::Mail.url
87
- resp = get(@auth, endpoint, params, &block)
88
- SendGrid4r::REST::Settings.create_results(resp)
89
- end
90
-
91
- def get_settings_address_whitelist(&block)
92
- endpoint = SendGrid4r::REST::Settings::Mail.url('address_whitelist')
93
- resp = get(@auth, endpoint, &block)
94
- SendGrid4r::REST::Settings::Mail.create_address_whitelist(resp)
95
- end
96
-
97
- def patch_settings_address_whitelist(params:, &block)
98
- endpoint = SendGrid4r::REST::Settings::Mail.url('address_whitelist')
99
- resp = patch(@auth, endpoint, params.to_h, &block)
100
- SendGrid4r::REST::Settings::Mail.create_address_whitelist(resp)
101
- end
102
-
103
- def get_settings_bcc(&block)
104
- endpoint = SendGrid4r::REST::Settings::Mail.url('bcc')
105
- resp = get(@auth, endpoint, &block)
106
- SendGrid4r::REST::Settings::Mail.create_bcc(resp)
107
- end
108
-
109
- def patch_settings_bcc(params:, &block)
110
- endpoint = SendGrid4r::REST::Settings::Mail.url('bcc')
111
- resp = patch(@auth, endpoint, params.to_h, &block)
112
- SendGrid4r::REST::Settings::Mail.create_bcc(resp)
113
- end
114
-
115
- def get_settings_bounce_purge(&block)
116
- endpoint = SendGrid4r::REST::Settings::Mail.url('bounce_purge')
117
- resp = get(@auth, endpoint, &block)
118
- SendGrid4r::REST::Settings::Mail.create_bounce_purge(resp)
119
- end
120
-
121
- def patch_settings_bounce_purge(params:, &block)
122
- endpoint = SendGrid4r::REST::Settings::Mail.url('bounce_purge')
123
- resp = patch(@auth, endpoint, params.to_h, &block)
124
- SendGrid4r::REST::Settings::Mail.create_bounce_purge(resp)
125
- end
126
-
127
- def get_settings_footer(&block)
128
- endpoint = SendGrid4r::REST::Settings::Mail.url('footer')
129
- resp = get(@auth, endpoint, &block)
130
- SendGrid4r::REST::Settings::Mail.create_footer(resp)
131
- end
132
-
133
- def patch_settings_footer(params:, &block)
134
- endpoint = SendGrid4r::REST::Settings::Mail.url('footer')
135
- resp = patch(@auth, endpoint, params.to_h, &block)
136
- SendGrid4r::REST::Settings::Mail.create_footer(resp)
137
- end
138
-
139
- def get_settings_forward_bounce(&block)
140
- endpoint = SendGrid4r::REST::Settings::Mail.url('forward_bounce')
141
- resp = get(@auth, endpoint, &block)
142
- SendGrid4r::REST::Settings::Mail.create_forward_bounce(resp)
143
- end
144
-
145
- def patch_settings_forward_bounce(params:, &block)
146
- endpoint = SendGrid4r::REST::Settings::Mail.url('forward_bounce')
147
- resp = patch(@auth, endpoint, params.to_h, &block)
148
- SendGrid4r::REST::Settings::Mail.create_forward_bounce(resp)
149
- end
150
-
151
- def get_settings_forward_spam(&block)
152
- endpoint = SendGrid4r::REST::Settings::Mail.url('forward_spam')
153
- resp = get(@auth, endpoint, &block)
154
- SendGrid4r::REST::Settings::Mail.create_forward_spam(resp)
155
- end
156
-
157
- def patch_settings_forward_spam(params:, &block)
158
- endpoint = SendGrid4r::REST::Settings::Mail.url('forward_spam')
159
- resp = patch(@auth, endpoint, params.to_h, &block)
160
- SendGrid4r::REST::Settings::Mail.create_forward_spam(resp)
161
- end
162
-
163
- def get_settings_template(&block)
164
- endpoint = SendGrid4r::REST::Settings::Mail.url('template')
165
- resp = get(@auth, endpoint, &block)
166
- SendGrid4r::REST::Settings::Mail.create_template(resp)
167
- end
168
-
169
- def patch_settings_template(params:, &block)
170
- endpoint = SendGrid4r::REST::Settings::Mail.url('template')
171
- resp = patch(@auth, endpoint, params.to_h, &block)
172
- SendGrid4r::REST::Settings::Mail.create_template(resp)
173
- end
174
-
175
- def get_settings_plain_content(&block)
176
- endpoint = SendGrid4r::REST::Settings::Mail.url('plain_content')
177
- resp = get(@auth, endpoint, &block)
178
- SendGrid4r::REST::Settings::Mail.create_plain_content(resp)
179
- end
180
-
181
- def patch_settings_plain_content(params:, &block)
182
- endpoint = SendGrid4r::REST::Settings::Mail.url('plain_content')
183
- resp = patch(@auth, endpoint, params.to_h, &block)
184
- SendGrid4r::REST::Settings::Mail.create_plain_content(resp)
185
- end
3
+ module SendGrid4r::REST
4
+ module Settings
5
+ #
6
+ # SendGrid Web API v3 Settings - Mail
7
+ #
8
+ module Mail
9
+ include Request
10
+
11
+ AddressWhitelist = Struct.new(:enabled, :list)
12
+
13
+ def self.create_address_whitelist(resp)
14
+ return resp if resp.nil?
15
+ AddressWhitelist.new(resp['enabled'], resp['list'])
16
+ end
17
+
18
+ Bcc = Struct.new(:enabled, :email)
19
+
20
+ def self.create_bcc(resp)
21
+ return resp if resp.nil?
22
+ Bcc.new(resp['enabled'], resp['email'])
23
+ end
24
+
25
+ BouncePurge = Struct.new(:enabled, :hard_bounces, :soft_bounces)
26
+
27
+ def self.create_bounce_purge(resp)
28
+ return resp if resp.nil?
29
+ BouncePurge.new(
30
+ resp['enabled'], resp['hard_bounces'], resp['soft_bounces']
31
+ )
32
+ end
33
+
34
+ Footer = Struct.new(:enabled, :html_content, :plain_content)
35
+
36
+ def self.create_footer(resp)
37
+ return resp if resp.nil?
38
+ Footer.new(
39
+ resp['enabled'], resp['html_content'], resp['plain_content']
40
+ )
41
+ end
42
+
43
+ ForwardBounce = Struct.new(:enabled, :email)
44
+
45
+ def self.create_forward_bounce(resp)
46
+ return resp if resp.nil?
47
+ ForwardBounce.new(resp['enabled'], resp['email'])
48
+ end
49
+
50
+ ForwardSpam = Struct.new(:enabled, :email)
51
+
52
+ def self.create_forward_spam(resp)
53
+ return resp if resp.nil?
54
+ ForwardSpam.new(resp['enabled'], resp['email'])
55
+ end
56
+
57
+ Template = Struct.new(:enabled, :html_content)
58
+
59
+ def self.create_template(resp)
60
+ return resp if resp.nil?
61
+ Template.new(resp['enabled'], resp['html_content'])
62
+ end
63
+
64
+ PlainContent = Struct.new(:enabled)
65
+
66
+ def self.create_plain_content(resp)
67
+ return resp if resp.nil?
68
+ PlainContent.new(resp['enabled'])
69
+ end
70
+
71
+ def self.url(name = nil)
72
+ url = "#{BASE_URL}/mail_settings"
73
+ url = "#{url}/#{name}" unless name.nil?
74
+ url
75
+ end
76
+
77
+ def get_mail_settings(limit: nil, offset: nil, &block)
78
+ params = {}
79
+ params[:limit] = limit unless limit.nil?
80
+ params[:offset] = offset unless offset.nil?
81
+ resp = get(@auth, Settings::Mail.url, params, &block)
82
+ Settings.create_results(resp)
83
+ end
84
+
85
+ def get_settings_address_whitelist(&block)
86
+ resp = get(@auth, Settings::Mail.url(:address_whitelist), &block)
87
+ Settings::Mail.create_address_whitelist(resp)
88
+ end
89
+
90
+ def patch_settings_address_whitelist(params:, &block)
91
+ endpoint = Settings::Mail.url(:address_whitelist)
92
+ resp = patch(@auth, endpoint, params.to_h, &block)
93
+ Settings::Mail.create_address_whitelist(resp)
94
+ end
95
+
96
+ def get_settings_bcc(&block)
97
+ resp = get(@auth, Settings::Mail.url(:bcc), &block)
98
+ Settings::Mail.create_bcc(resp)
99
+ end
100
+
101
+ def patch_settings_bcc(params:, &block)
102
+ endpoint = Settings::Mail.url(:bcc)
103
+ resp = patch(@auth, endpoint, params.to_h, &block)
104
+ Settings::Mail.create_bcc(resp)
105
+ end
106
+
107
+ def get_settings_bounce_purge(&block)
108
+ resp = get(@auth, Settings::Mail.url(:bounce_purge), &block)
109
+ Settings::Mail.create_bounce_purge(resp)
110
+ end
111
+
112
+ def patch_settings_bounce_purge(params:, &block)
113
+ endpoint = Settings::Mail.url(:bounce_purge)
114
+ resp = patch(@auth, endpoint, params.to_h, &block)
115
+ Settings::Mail.create_bounce_purge(resp)
116
+ end
117
+
118
+ def get_settings_footer(&block)
119
+ resp = get(@auth, Settings::Mail.url(:footer), &block)
120
+ Settings::Mail.create_footer(resp)
121
+ end
122
+
123
+ def patch_settings_footer(params:, &block)
124
+ resp = patch(@auth, Settings::Mail.url(:footer), params.to_h, &block)
125
+ Settings::Mail.create_footer(resp)
126
+ end
127
+
128
+ def get_settings_forward_bounce(&block)
129
+ resp = get(@auth, Settings::Mail.url(:forward_bounce), &block)
130
+ Settings::Mail.create_forward_bounce(resp)
131
+ end
132
+
133
+ def patch_settings_forward_bounce(params:, &block)
134
+ endpoint = Settings::Mail.url(:forward_bounce)
135
+ resp = patch(@auth, endpoint, params.to_h, &block)
136
+ Settings::Mail.create_forward_bounce(resp)
137
+ end
138
+
139
+ def get_settings_forward_spam(&block)
140
+ resp = get(@auth, Settings::Mail.url(:forward_spam), &block)
141
+ Settings::Mail.create_forward_spam(resp)
142
+ end
143
+
144
+ def patch_settings_forward_spam(params:, &block)
145
+ endpoint = Settings::Mail.url(:forward_spam)
146
+ resp = patch(@auth, endpoint, params.to_h, &block)
147
+ Settings::Mail.create_forward_spam(resp)
148
+ end
149
+
150
+ def get_settings_template(&block)
151
+ resp = get(@auth, Settings::Mail.url(:template), &block)
152
+ Settings::Mail.create_template(resp)
153
+ end
154
+
155
+ def patch_settings_template(params:, &block)
156
+ endpoint = Settings::Mail.url(:template)
157
+ resp = patch(@auth, endpoint, params.to_h, &block)
158
+ Settings::Mail.create_template(resp)
159
+ end
160
+
161
+ def get_settings_plain_content(&block)
162
+ resp = get(@auth, Settings::Mail.url(:plain_content), &block)
163
+ Settings::Mail.create_plain_content(resp)
164
+ end
165
+
166
+ def patch_settings_plain_content(params:, &block)
167
+ endpoint = Settings::Mail.url(:plain_content)
168
+ resp = patch(@auth, endpoint, params.to_h, &block)
169
+ Settings::Mail.create_plain_content(resp)
186
170
  end
187
171
  end
188
172
  end
@@ -1,46 +1,43 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
 
3
- module SendGrid4r
4
- module REST
5
- module Settings
6
- #
7
- # SendGrid Web API v3 Settings - Partner
8
- #
9
- module Partner
10
- include SendGrid4r::REST::Request
11
- Partner = Struct.new(:enabled, :license_key)
3
+ module SendGrid4r::REST
4
+ module Settings
5
+ #
6
+ # SendGrid Web API v3 Settings - Partner
7
+ #
8
+ module Partner
9
+ include Request
12
10
 
13
- def self.create_partner(resp)
14
- return resp if resp.nil?
15
- Partner.new(resp['enabled'], resp['license_key'])
16
- end
11
+ Partner = Struct.new(:enabled, :license_key)
17
12
 
18
- def self.url(name = nil)
19
- url = "#{BASE_URL}/partner_settings"
20
- url = "#{url}/#{name}" unless name.nil?
21
- url
22
- end
13
+ def self.create_partner(resp)
14
+ return resp if resp.nil?
15
+ Partner.new(resp['enabled'], resp['license_key'])
16
+ end
23
17
 
24
- def get_partner_settings(limit: nil, offset: nil, &block)
25
- params = {}
26
- params['limit'] = limit unless limit.nil?
27
- params['offset'] = offset unless offset.nil?
28
- endpoint = SendGrid4r::REST::Settings::Partner.url
29
- resp = get(@auth, endpoint, params, &block)
30
- SendGrid4r::REST::Settings.create_results(resp)
31
- end
18
+ def self.url(name = nil)
19
+ url = "#{BASE_URL}/partner_settings"
20
+ url = "#{url}/#{name}" unless name.nil?
21
+ url
22
+ end
32
23
 
33
- def get_settings_new_relic(&block)
34
- endpoint = SendGrid4r::REST::Settings::Partner.url('new_relic')
35
- resp = get(@auth, endpoint, &block)
36
- SendGrid4r::REST::Settings::Partner.create_partner(resp)
37
- end
24
+ def get_partner_settings(limit: nil, offset: nil, &block)
25
+ params = {}
26
+ params[:limit] = limit unless limit.nil?
27
+ params[:offset] = offset unless offset.nil?
28
+ resp = get(@auth, Settings::Partner.url, params, &block)
29
+ Settings.create_results(resp)
30
+ end
31
+
32
+ def get_settings_new_relic(&block)
33
+ resp = get(@auth, Settings::Partner.url(:new_relic), &block)
34
+ Settings::Partner.create_partner(resp)
35
+ end
38
36
 
39
- def patch_settings_new_relic(params:, &block)
40
- endpoint = SendGrid4r::REST::Settings::Partner.url('new_relic')
41
- resp = patch(@auth, endpoint, params.to_h, &block)
42
- SendGrid4r::REST::Settings::Partner.create_partner(resp)
43
- end
37
+ def patch_settings_new_relic(params:, &block)
38
+ endpoint = Settings::Partner.url(:new_relic)
39
+ resp = patch(@auth, endpoint, params.to_h, &block)
40
+ Settings::Partner.create_partner(resp)
44
41
  end
45
42
  end
46
43
  end