sendgrid-ruby 5.3.0 → 6.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/.github/PULL_REQUEST_TEMPLATE +3 -1
  3. data/CHANGELOG.md +25 -0
  4. data/CODE_OF_CONDUCT.md +11 -11
  5. data/CONTRIBUTING.md +17 -22
  6. data/LICENSE.txt +1 -1
  7. data/README.md +25 -12
  8. data/Rakefile +1 -1
  9. data/TROUBLESHOOTING.md +21 -15
  10. data/UPGRADE.md +5 -0
  11. data/USAGE.md +1103 -1101
  12. data/USE_CASES.md +248 -18
  13. data/examples/helpers/mail/example.rb +7 -7
  14. data/examples/ips/ips.rb +13 -0
  15. data/examples/mail/mail.rb +2 -2
  16. data/examples/scopes/scopes.rb +49 -3
  17. data/examples/{whitelabel/whitelabel.rb → senderauthentication/senderauthentication.rb} +27 -27
  18. data/examples/suppression/suppression.rb +10 -10
  19. data/lib/sendgrid-ruby.rb +2 -0
  20. data/lib/sendgrid/client.rb +12 -9
  21. data/lib/sendgrid/helpers/inbound/README.md +22 -5
  22. data/lib/sendgrid/helpers/inbound/app.rb +13 -1
  23. data/lib/sendgrid/helpers/inbound/public/index.html +1 -1
  24. data/lib/sendgrid/helpers/inbound/sample_data/default_data.txt +2 -2
  25. data/lib/sendgrid/helpers/inbound/sample_data/raw_data.txt +2 -2
  26. data/lib/sendgrid/helpers/inbound/sample_data/raw_data_with_attachments.txt +2 -2
  27. data/lib/sendgrid/helpers/inbound/send.rb +2 -2
  28. data/lib/sendgrid/helpers/ip_management/ip_management.rb +17 -0
  29. data/lib/sendgrid/helpers/mail/README.md +1 -1
  30. data/lib/sendgrid/helpers/mail/attachment.rb +24 -1
  31. data/lib/sendgrid/helpers/mail/category.rb +0 -8
  32. data/lib/sendgrid/helpers/mail/content.rb +3 -16
  33. data/lib/sendgrid/helpers/mail/email.rb +3 -16
  34. data/lib/sendgrid/helpers/mail/mail.rb +8 -40
  35. data/lib/sendgrid/helpers/permissions/scope.rb +28 -0
  36. data/lib/sendgrid/helpers/permissions/scopes.yml +309 -0
  37. data/lib/sendgrid/helpers/settings/README.md +1 -1
  38. data/lib/sendgrid/helpers/stats/stats_response.rb +1 -1
  39. data/lib/sendgrid/version.rb +1 -1
  40. data/mail_helper_v3.md +9 -9
  41. data/sendgrid-ruby.gemspec +3 -3
  42. data/spec/sendgrid/helpers/ip_management/ip_management_spec.rb +12 -0
  43. data/test/sendgrid/helpers/mail/test_attachment.rb +35 -0
  44. data/test/sendgrid/helpers/mail/test_mail.rb +29 -21
  45. data/test/sendgrid/permissions/test_scopes.rb +38 -0
  46. data/test/sendgrid/test_sendgrid-ruby.rb +15 -7
  47. metadata +17 -6
@@ -19,13 +19,13 @@ Content-Type: multipart/alternative; boundary=001a1140ffb6f4fc5f053a2257e0
19
19
  --001a1140ffb6f4fc5f053a2257e0
20
20
  Content-Type: text/plain; charset=UTF-8
21
21
 
22
- Hello SendGrid!
22
+ Hello Twilio SendGrid!
23
23
 
24
24
  --001a1140ffb6f4fc5f053a2257e0
25
25
  Content-Type: text/html; charset=UTF-8
26
26
  Content-Transfer-Encoding: quoted-printable
27
27
 
28
- <html><body><strong>Hello SendGrid!</body></html>
28
+ <html><body><strong>Hello Twilio SendGrid!</body></html>
29
29
 
30
30
  --001a1140ffb6f4fc5f053a2257e0--
31
31
 
@@ -1,4 +1,4 @@
1
- # A module for sending test SendGrid Inbound Parse messages
1
+ # A module for sending test Twilio SendGrid Inbound Parse messages
2
2
  # Usage: ruby ./send.rb [path to file containing test data]
3
3
  require 'ruby_http_client'
4
4
  require 'yaml'
@@ -14,7 +14,7 @@ client = SendGrid::Client.new(host: host)
14
14
  File.open(argv[0]) do |file|
15
15
  data = file.read
16
16
  headers = {
17
- 'User-Agent' => 'SendGrid-Test',
17
+ 'User-Agent' => 'Twilio-SendGrid-Test',
18
18
  'Content-Type' => 'multipart/form-data; boundary=xYzZY'
19
19
  }
20
20
  response = client.post(
@@ -0,0 +1,17 @@
1
+ require 'json'
2
+
3
+ module SendGrid
4
+ class IpManagement
5
+ attr_accessor :sendgrid_client
6
+
7
+ def initialize(sendgrid_client:)
8
+ @sendgrid_client = sendgrid_client
9
+ end
10
+
11
+ def unassigned
12
+ response = @sendgrid_client.ips.get
13
+ ips = JSON.parse(response.body)
14
+ ips.select {|ip| ip.subusers.empty?}
15
+ end
16
+ end
17
+ end
@@ -1,4 +1,4 @@
1
- **This helper allows you to quickly and easily build a Mail object for sending email through SendGrid.**
1
+ **This helper allows you to quickly and easily build a Mail object for sending email through Twilio SendGrid.**
2
2
 
3
3
  # Quick Start
4
4
 
@@ -1,4 +1,5 @@
1
1
  require 'json'
2
+ require 'base64'
2
3
 
3
4
  module SendGrid
4
5
  class Attachment
@@ -11,11 +12,18 @@ module SendGrid
11
12
  end
12
13
 
13
14
  def content=(content)
15
+ @encoded_content = nil
14
16
  @content = content
15
17
  end
16
18
 
17
19
  def content
18
- @content
20
+ return @encoded_content if @encoded_content
21
+
22
+ if @content.respond_to?(:read)
23
+ @encoded_content = encode @content
24
+ else
25
+ @encoded_content = @content
26
+ end
19
27
  end
20
28
 
21
29
  def type=(type)
@@ -59,5 +67,20 @@ module SendGrid
59
67
  'content_id' => self.content_id
60
68
  }.delete_if { |_, value| value.to_s.strip == '' }
61
69
  end
70
+
71
+ private
72
+
73
+ def encode(io)
74
+ str = io.read
75
+ # Since the API expects UTF-8, we need to ensure that we're
76
+ # converting other formats to it so (byte-wise) Base64 encoding
77
+ # will come through properly on the other side.
78
+ #
79
+ # Not much to be done to try to handle encoding for files opened
80
+ # in binary mode, but at least we can faithfully convey the
81
+ # bytes.
82
+ str = str.encode('UTF-8') unless io.respond_to?(:binmode?) && io.binmode?
83
+ Base64.encode64 str
84
+ end
62
85
  end
63
86
  end
@@ -8,14 +8,6 @@ module SendGrid
8
8
  @name = name
9
9
  end
10
10
 
11
- def name=(name)
12
- @name = name
13
- end
14
-
15
- def name
16
- @name
17
- end
18
-
19
11
  def to_json(*)
20
12
  {
21
13
  'category' => name
@@ -2,27 +2,14 @@ require 'json'
2
2
 
3
3
  module SendGrid
4
4
  class Content
5
- def initialize(type: nil, value: nil)
6
- @type = type
7
- @value = value
8
- end
9
-
10
- def type=(type)
11
- @type = type
12
- end
13
5
 
14
- def type
15
- @type
16
- end
6
+ attr_accessor :type, :value
17
7
 
18
- def value=(value)
8
+ def initialize(type: nil, value: nil)
9
+ @type = type
19
10
  @value = value
20
11
  end
21
12
 
22
- def value
23
- @value
24
- end
25
-
26
13
  def to_json(*)
27
14
  {
28
15
  'type' => self.type,
@@ -2,6 +2,9 @@ require 'json'
2
2
 
3
3
  module SendGrid
4
4
  class Email
5
+
6
+ attr_accessor :email, :name
7
+
5
8
  def initialize(email: nil, name: nil)
6
9
  if name
7
10
  @email = email
@@ -11,22 +14,6 @@ module SendGrid
11
14
  end
12
15
  end
13
16
 
14
- def email=(email)
15
- @email = email
16
- end
17
-
18
- def email
19
- @email
20
- end
21
-
22
- def name=(name)
23
- @name = name
24
- end
25
-
26
- def name
27
- @name
28
- end
29
-
30
17
  def split_email(email)
31
18
  split = /(?:(?<address>.+)\s)?<?(?<email>.+@[^>]+)>?/.match(email)
32
19
  return split[:email], split[:address]
@@ -5,6 +5,7 @@ require 'json'
5
5
  module SendGrid
6
6
  class Mail
7
7
 
8
+ attr_accessor :subject, :ip_pool_name, :template_id, :send_at, :batch_id
8
9
  attr_reader :personalizations, :contents, :attachments, :categories, :sections, :headers, :custom_args
9
10
 
10
11
  def initialize(from_email=nil, subj=nil, to_email=nil, cont=nil)
@@ -44,14 +45,6 @@ module SendGrid
44
45
  @from.nil? ? nil : @from.to_json
45
46
  end
46
47
 
47
- def subject=(subject)
48
- @subject = subject
49
- end
50
-
51
- def subject
52
- @subject
53
- end
54
-
55
48
  def add_personalization(personalization)
56
49
  @personalizations << personalization.to_json
57
50
  end
@@ -60,6 +53,13 @@ module SendGrid
60
53
  @contents << content.to_json
61
54
  end
62
55
 
56
+ def check_for_secrets(patterns)
57
+ contents = @contents.map { |content| content['value'] }.join(' ')
58
+ patterns.each do |pattern|
59
+ raise SecurityError.new('Content contains sensitive information.') if contents.match(pattern)
60
+ end
61
+ end
62
+
63
63
  def add_attachment(attachment)
64
64
  @attachments << attachment.to_json
65
65
  end
@@ -68,14 +68,6 @@ module SendGrid
68
68
  @categories << category.name
69
69
  end
70
70
 
71
- def template_id=(template_id)
72
- @template_id = template_id
73
- end
74
-
75
- def template_id
76
- @template_id
77
- end
78
-
79
71
  def add_section(section)
80
72
  section = section.to_json
81
73
  @sections = @sections.merge(section['section'])
@@ -91,22 +83,6 @@ module SendGrid
91
83
  @custom_args = @custom_args.merge(custom_arg['custom_arg'])
92
84
  end
93
85
 
94
- def send_at=(send_at)
95
- @send_at = send_at
96
- end
97
-
98
- def send_at
99
- @send_at
100
- end
101
-
102
- def batch_id=(batch_id)
103
- @batch_id = batch_id
104
- end
105
-
106
- def batch_id
107
- @batch_id
108
- end
109
-
110
86
  def asm=(asm)
111
87
  @asm = asm
112
88
  end
@@ -115,14 +91,6 @@ module SendGrid
115
91
  @asm.nil? ? nil : @asm.to_json
116
92
  end
117
93
 
118
- def ip_pool_name=(ip_pool_name)
119
- @ip_pool_name = ip_pool_name
120
- end
121
-
122
- def ip_pool_name
123
- @ip_pool_name
124
- end
125
-
126
94
  def mail_settings=(mail_settings)
127
95
  @mail_settings = mail_settings
128
96
  end
@@ -0,0 +1,28 @@
1
+ # This is used for getting scopes
2
+ require 'yaml'
3
+
4
+ module SendGrid
5
+ class Scope
6
+ SCOPES = YAML.load_file(File.dirname(__FILE__) + '/scopes.yml').freeze
7
+
8
+ class << self
9
+ def admin_permissions
10
+ SCOPES.values.map(&:values).flatten
11
+ end
12
+
13
+ def read_only_permissions
14
+ SCOPES.map { |_, v| v[:read] }.flatten
15
+ end
16
+
17
+ SCOPES.each_key do |endpoint|
18
+ define_method "#{endpoint}_read_only_permissions" do
19
+ SCOPES[endpoint][:read]
20
+ end
21
+
22
+ define_method "#{endpoint}_full_access_permissions" do
23
+ SCOPES[endpoint].values.flatten
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,309 @@
1
+ ---
2
+ :alerts:
3
+ :create:
4
+ - alerts.create
5
+ :delete:
6
+ - alerts.delete
7
+ :read:
8
+ - alerts.read
9
+ :update:
10
+ - alerts.update
11
+ :api_keys:
12
+ :create:
13
+ - api_keys.create
14
+ :delete:
15
+ - api_keys.delete
16
+ :read:
17
+ - api_keys.read
18
+ :update:
19
+ - api_keys.update
20
+ :asm_groups:
21
+ :create:
22
+ - asm.groups.create
23
+ :delete:
24
+ - asm.groups.delete
25
+ :read:
26
+ - asm.groups.read
27
+ :update:
28
+ - asm.groups.update
29
+ :billing:
30
+ :create:
31
+ - billing.create
32
+ :delete:
33
+ - billing.delete
34
+ :read:
35
+ - billing.read
36
+ :update:
37
+ - billing.update
38
+ :categories:
39
+ :create:
40
+ - categories.create
41
+ :delete:
42
+ - categories.delete
43
+ :read:
44
+ - categories.read
45
+ - categories.stats.read
46
+ - categories.stats.sums.read
47
+ :update:
48
+ - categories.update
49
+ :credentials:
50
+ :create:
51
+ - credentials.create
52
+ :delete:
53
+ - credentials.delete
54
+ :read:
55
+ - credentials.read
56
+ :update:
57
+ - credentials.update
58
+ :stats:
59
+ :create: []
60
+ :delete: []
61
+ :read:
62
+ - email_activity.read
63
+ - stats.read
64
+ - stats.global.read
65
+ - browsers.stats.read
66
+ - devices.stats.read
67
+ - geo.stats.read
68
+ - mailbox_providers.stats.read
69
+ - clients.desktop.stats.read
70
+ - clients.phone.stats.read
71
+ - clients.stats.read
72
+ - clients.tablet.stats.read
73
+ - clients.webmail.stats.read
74
+ :update: []
75
+ :ips:
76
+ :create:
77
+ - ips.pools.create
78
+ - ips.pools.ips.create
79
+ - ips.warmup.create
80
+ :delete:
81
+ - ips.pools.delete
82
+ - ips.pools.ips.delete
83
+ - ips.warmup.delete
84
+ :read:
85
+ - ips.assigned.read
86
+ - ips.read
87
+ - ips.pools.read
88
+ - ips.pools.ips.read
89
+ - ips.warmup.read
90
+ :update:
91
+ - ips.pools.update
92
+ - ips.pools.ips.update
93
+ - ips.warmup.update
94
+ :mail_settings:
95
+ :create: []
96
+ :delete: []
97
+ :read:
98
+ - mail_settings.address_whitelist.read
99
+ - mail_settings.bcc.read
100
+ - mail_settings.bounce_purge.read
101
+ - mail_settings.footer.read
102
+ - mail_settings.forward_bounce.read
103
+ - mail_settings.forward_spam.read
104
+ - mail_settings.plain_content.read
105
+ - mail_settings.read
106
+ - mail_settings.spam_check.read
107
+ - mail_settings.template.read
108
+ :update:
109
+ - mail_settings.address_whitelist.update
110
+ - mail_settings.bcc.update
111
+ - mail_settings.bounce_purge.update
112
+ - mail_settings.footer.update
113
+ - mail_settings.forward_bounce.update
114
+ - mail_settings.forward_spam.update
115
+ - mail_settings.plain_content.update
116
+ - mail_settings.spam_check.update
117
+ - mail_settings.template.update
118
+ :mail:
119
+ :create:
120
+ - mail.send
121
+ - mail.batch.create
122
+ :delete:
123
+ - mail.batch.delete
124
+ :read:
125
+ - mail.batch.read
126
+ :update:
127
+ - mail.batch.update
128
+ :marketing_campaigns:
129
+ :create:
130
+ - marketing_campaigns.create
131
+ :delete:
132
+ - marketing_campaigns.delete
133
+ :read:
134
+ - marketing_campaigns.read
135
+ :update:
136
+ - marketing_campaigns.update
137
+ :partner_settings:
138
+ :create: []
139
+ :delete: []
140
+ :read:
141
+ - partner_settings.new_relic.read
142
+ - partner_settings.read
143
+ - partner_settings.sendwithus.read
144
+ :update:
145
+ - partner_settings.new_relic.update
146
+ - partner_settings.sendwithus.update
147
+ :scheduled_sends:
148
+ :create:
149
+ - user.scheduled_sends.create
150
+ :delete:
151
+ - user.scheduled_sends.delete
152
+ :read:
153
+ - user.scheduled_sends.read
154
+ :update:
155
+ - user.scheduled_sends.update
156
+ :subusers:
157
+ :create:
158
+ - subusers.create
159
+ - subusers.credits.create
160
+ - subusers.credits.remaining.create
161
+ - subusers.monitor.create
162
+ :delete:
163
+ - subusers.delete
164
+ - subusers.credits.delete
165
+ - subusers.credits.remaining.delete
166
+ - subusers.monitor.delete
167
+ :read:
168
+ - subusers.read
169
+ - subusers.credits.read
170
+ - subusers.stats.read
171
+ - subusers.credits.remaining.read
172
+ - subusers.monitor.read
173
+ - subusers.reputations.read
174
+ - subusers.stats.monthly.read
175
+ - subusers.stats.sums.read
176
+ - subusers.summary.read
177
+ :update:
178
+ - subusers.update
179
+ - subusers.credits.update
180
+ - subusers.credits.remaining.update
181
+ - subusers.monitor.update
182
+ :suppression:
183
+ :create:
184
+ - suppression.create
185
+ - suppression.bounces.create
186
+ - suppression.blocks.create
187
+ - suppression.invalid_emails.create
188
+ - suppression.spam_reports.create
189
+ - suppression.unsubscribes.create
190
+ :delete:
191
+ - suppression.delete
192
+ - suppression.bounces.delete
193
+ - suppression.blocks.delete
194
+ - suppression.invalid_emails.delete
195
+ - suppression.spam_reports.delete
196
+ - suppression.unsubscribes.delete
197
+ :read:
198
+ - suppression.read
199
+ - suppression.bounces.read
200
+ - suppression.blocks.read
201
+ - suppression.invalid_emails.read
202
+ - suppression.spam_reports.read
203
+ - suppression.unsubscribes.read
204
+ :update:
205
+ - suppression.update
206
+ - suppression.bounces.update
207
+ - suppression.blocks.update
208
+ - suppression.invalid_emails.update
209
+ - suppression.spam_reports.update
210
+ - suppression.unsubscribes.update
211
+ :teammates:
212
+ :create:
213
+ - teammates.create
214
+ :delete:
215
+ - teammates.delete
216
+ :read:
217
+ - teammates.read
218
+ :update:
219
+ - teammates.update
220
+ :templates:
221
+ :create:
222
+ - templates.create
223
+ - templates.versions.activate.create
224
+ - templates.versions.create
225
+ :delete:
226
+ - templates.delete
227
+ - templates.versions.activate.delete
228
+ - templates.versions.delete
229
+ :read:
230
+ - templates.read
231
+ - templates.versions.activate.read
232
+ - templates.versions.read
233
+ :update:
234
+ - templates.update
235
+ - templates.versions.activate.update
236
+ - templates.versions.update
237
+ :tracking_settings:
238
+ :create: []
239
+ :delete: []
240
+ :read:
241
+ - tracking_settings.click.read
242
+ - tracking_settings.google_analytics.read
243
+ - tracking_settings.open.read
244
+ - tracking_settings.read
245
+ - tracking_settings.subscription.read
246
+ :update:
247
+ - tracking_settings.click.update
248
+ - tracking_settings.google_analytics.update
249
+ - tracking_settings.open.update
250
+ - tracking_settings.subscription.update
251
+ :user_settings:
252
+ :create:
253
+ - user.email.create
254
+ - user.multifactor_authentication.create
255
+ :delete:
256
+ - user.email.delete
257
+ - user.multifactor_authentication.delete
258
+ :read:
259
+ - user.account.read
260
+ - user.credits.read
261
+ - user.email.read
262
+ - user.multifactor_authentication.read
263
+ - user.password.read
264
+ - user.profile.read
265
+ - user.timezone.read
266
+ - user.settings.enforced_tls.read
267
+ - user.username.read
268
+ :update:
269
+ - user.email.update
270
+ - user.multifactor_authentication.update
271
+ - user.password.update
272
+ - user.profile.update
273
+ - user.settings.enforced_tls.update
274
+ - user.timezone.update
275
+ - user.username.update
276
+ :webhooks:
277
+ :create:
278
+ - user.webhooks.event.test.create
279
+ - user.webhooks.parse.settings.create
280
+ :delete:
281
+ - user.webhooks.parse.settings.delete
282
+ :read:
283
+ - user.webhooks.event.settings.read
284
+ - user.webhooks.event.test.read
285
+ - user.webhooks.parse.settings.read
286
+ - user.webhooks.parse.stats.read
287
+ :update:
288
+ - user.webhooks.event.settings.update
289
+ - user.webhooks.event.test.update
290
+ - user.webhooks.parse.settings.update
291
+ :whitelabel:
292
+ :create:
293
+ - whitelabel.create
294
+ :delete:
295
+ - whitelabel.delete
296
+ :read:
297
+ - whitelabel.read
298
+ :update:
299
+ - whitelabel.update
300
+ :access_settings:
301
+ :create:
302
+ - access_settings.whitelist.create
303
+ :delete:
304
+ - access_settings.whitelist.delete
305
+ :read:
306
+ - access_settings.activity.read
307
+ - access_settings.whitelist.read
308
+ :update:
309
+ - access_settings.whitelist.update