sendgrid-ruby 4.0.8 → 6.0.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/.codeclimate.yml +21 -0
- data/.env_sample +1 -0
- data/.github/PULL_REQUEST_TEMPLATE +26 -0
- data/.gitignore +1 -0
- data/.travis.yml +11 -2
- data/CHANGELOG.md +119 -3
- data/CODE_OF_CONDUCT.md +41 -0
- data/CONTRIBUTING.md +34 -30
- data/Gemfile +4 -1
- data/LICENSE.txt +1 -1
- data/README.md +53 -24
- data/Rakefile +7 -2
- data/TROUBLESHOOTING.md +41 -15
- data/UPGRADE.md +5 -0
- data/USAGE.md +1130 -1129
- data/USE_CASES.md +280 -16
- data/config.ru +4 -0
- data/docker/Dockerfile +12 -0
- data/docker/README.md +30 -0
- data/examples/helpers/mail/example.rb +62 -45
- data/examples/helpers/settings/example.rb +23 -0
- data/examples/helpers/stats/example.rb +42 -0
- data/examples/ips/ips.rb +13 -0
- data/examples/mail/mail.rb +2 -2
- data/examples/scopes/scopes.rb +49 -3
- data/examples/{whitelabel/whitelabel.rb → senderauthentication/senderauthentication.rb} +27 -27
- data/examples/suppression/suppression.rb +10 -10
- data/gemfiles/Sinatra_1.gemfile +6 -0
- data/gemfiles/Sinatra_2.gemfile +6 -0
- data/lib/sendgrid-ruby.rb +27 -1
- data/lib/sendgrid/client.rb +12 -9
- data/lib/sendgrid/helpers/inbound/README.md +98 -0
- data/lib/sendgrid/helpers/inbound/app.rb +32 -0
- data/lib/sendgrid/helpers/inbound/config.yml +26 -0
- data/lib/sendgrid/helpers/inbound/public/index.html +10 -0
- data/lib/sendgrid/helpers/inbound/sample_data/default_data.txt +58 -0
- data/lib/sendgrid/helpers/inbound/sample_data/raw_data.txt +57 -0
- data/lib/sendgrid/helpers/inbound/sample_data/raw_data_with_attachments.txt +298 -0
- data/lib/sendgrid/helpers/inbound/send.rb +26 -0
- data/lib/sendgrid/helpers/ip_management/ip_management.rb +17 -0
- data/lib/sendgrid/helpers/mail/README.md +1 -1
- data/lib/sendgrid/helpers/mail/asm.rb +33 -0
- data/lib/sendgrid/helpers/mail/attachment.rb +86 -0
- data/lib/sendgrid/helpers/mail/bcc_settings.rb +33 -0
- data/lib/sendgrid/helpers/mail/bypass_list_management.rb +43 -0
- data/lib/sendgrid/helpers/mail/category.rb +20 -0
- data/lib/sendgrid/helpers/mail/click_tracking.rb +33 -0
- data/lib/sendgrid/helpers/mail/content.rb +20 -0
- data/lib/sendgrid/helpers/mail/custom_arg.rb +24 -0
- data/lib/sendgrid/helpers/mail/email.rb +29 -0
- data/lib/sendgrid/helpers/mail/footer.rb +43 -0
- data/lib/sendgrid/helpers/mail/ganalytics.rb +74 -0
- data/lib/sendgrid/helpers/mail/header.rb +24 -0
- data/lib/sendgrid/helpers/mail/mail.rb +36 -895
- data/lib/sendgrid/helpers/mail/mail_settings.rb +63 -0
- data/lib/sendgrid/helpers/mail/open_tracking.rb +33 -0
- data/lib/sendgrid/helpers/mail/personalization.rb +82 -0
- data/lib/sendgrid/helpers/mail/section.rb +24 -0
- data/lib/sendgrid/helpers/mail/spam_check.rb +43 -0
- data/lib/sendgrid/helpers/mail/subscription_tracking.rb +53 -0
- data/lib/sendgrid/helpers/mail/substitution.rb +24 -0
- data/lib/sendgrid/helpers/mail/tracking_settings.rb +53 -0
- data/lib/sendgrid/helpers/permissions/scope.rb +28 -0
- data/lib/sendgrid/helpers/permissions/scopes.yml +309 -0
- data/lib/sendgrid/helpers/settings/README.md +14 -0
- data/lib/sendgrid/helpers/settings/mail_settings_dto.rb +13 -0
- data/lib/sendgrid/helpers/settings/partner_settings_dto.rb +13 -0
- data/lib/sendgrid/helpers/settings/settings.rb +28 -0
- data/lib/sendgrid/helpers/settings/tracking_settings_dto.rb +24 -0
- data/lib/sendgrid/helpers/settings/user_settings_dto.rb +13 -0
- data/lib/sendgrid/helpers/stats/email_stats.rb +46 -0
- data/lib/sendgrid/helpers/stats/metrics.rb +35 -0
- data/lib/sendgrid/helpers/stats/stats_response.rb +31 -0
- data/lib/sendgrid/version.rb +2 -2
- data/mail_helper_v3.md +390 -0
- data/sendgrid-ruby.gemspec +12 -5
- data/spec/sendgrid/helpers/ip_management/ip_management_spec.rb +12 -0
- data/spec/sendgrid/helpers/settings/mail_settings_dto_spec.rb +32 -0
- data/spec/sendgrid/helpers/settings/partner_settings_dto_spec.rb +24 -0
- data/spec/sendgrid/helpers/settings/settings_spec.rb +25 -0
- data/spec/sendgrid/helpers/settings/tracking_settings_dto_spec.rb +27 -0
- data/spec/sendgrid/helpers/settings/user_settings_dto_spec.rb +24 -0
- data/spec/sendgrid/helpers/stats/email_stats_spec.rb +112 -0
- data/spec/sendgrid/helpers/stats/metrics_spec.rb +46 -0
- data/spec/sendgrid/helpers/stats/stats_response_spec.rb +76 -0
- data/spec/spec_helper.rb +10 -0
- data/test/sendgrid/helpers/mail/test_attachment.rb +35 -0
- data/test/sendgrid/helpers/mail/test_category.rb +27 -0
- data/test/sendgrid/helpers/mail/test_email.rb +34 -0
- data/test/sendgrid/helpers/mail/test_mail.rb +198 -59
- data/test/sendgrid/helpers/mail/test_personalizations.rb +161 -0
- data/test/sendgrid/permissions/test_scopes.rb +38 -0
- data/test/sendgrid/test_sendgrid-ruby.rb +90 -9
- metadata +170 -10
data/USE_CASES.md
CHANGED
|
@@ -2,12 +2,128 @@ This documentation provides examples for specific use cases. Please [open an iss
|
|
|
2
2
|
|
|
3
3
|
# Table of Contents
|
|
4
4
|
|
|
5
|
-
* [Transactional Templates](#
|
|
5
|
+
* [Transactional Templates](#transactional-templates)
|
|
6
|
+
* [With Mail Helper Class](#with-mail-helper-class)
|
|
7
|
+
* [Without Mail Helper Class](#without-mail-helper-class)
|
|
8
|
+
* [Legacy Templates](#legacy-templates)
|
|
9
|
+
* [With Mail Helper Class](#with-mail-helper-class-1)
|
|
10
|
+
* [Without Mail Helper Class](#without-mail-helper-class-1)
|
|
11
|
+
* [Adding Attachments](#adding-attachments)
|
|
12
|
+
* [How to Setup a Domain Authentication](#how-to-setup-a-domain-authentication)
|
|
13
|
+
* [How to View Email Statistics](#how-to-view-email-statistics)
|
|
14
|
+
* [Send a SMS Message](#send-a-sms-message)
|
|
15
|
+
* [1. Obtain a Free Twilio Account](#1-obtain-a-free-twilio-account)
|
|
16
|
+
* [2. Update Your Environment Variables](#2-update-your-environment-variables)
|
|
17
|
+
* [Mac](#mac)
|
|
18
|
+
* [Windows](#windows)
|
|
19
|
+
* [3. Install the Twilio Helper Library](#3-install-the-twilio-helper-library)
|
|
20
|
+
* [4. Setup Work](#4-setup-work)
|
|
21
|
+
* [5. Send an SMS](#5-send-an-sms)
|
|
6
22
|
|
|
7
|
-
<a name="
|
|
23
|
+
<a name="transactional-templates"></a>
|
|
8
24
|
# Transactional Templates
|
|
9
25
|
|
|
10
|
-
For this example, we assume you have created a [transactional template](https://sendgrid.com/docs/User_Guide/Transactional_Templates/index.html). Following is the template content we used for testing.
|
|
26
|
+
For this example, we assume you have created a [transactional template](https://sendgrid.com/docs/User_Guide/Transactional_Templates/index.html) in the UI or via the API. Following is the template content we used for testing.
|
|
27
|
+
|
|
28
|
+
Template ID (replace with your own):
|
|
29
|
+
|
|
30
|
+
```text
|
|
31
|
+
d-2c214ac919e84170b21855cc129b4a5f
|
|
32
|
+
```
|
|
33
|
+
Email Subject:
|
|
34
|
+
```text
|
|
35
|
+
{{subject}}
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Template Body:
|
|
39
|
+
|
|
40
|
+
```html
|
|
41
|
+
<html>
|
|
42
|
+
<head>
|
|
43
|
+
<title></title>
|
|
44
|
+
</head>
|
|
45
|
+
<body>
|
|
46
|
+
Hello {{name}},
|
|
47
|
+
<br/><br/>
|
|
48
|
+
I'm glad you are trying out the template feature!
|
|
49
|
+
<br/><br/>
|
|
50
|
+
I hope you are having a great day in {{city}} :)
|
|
51
|
+
<br/><br/>
|
|
52
|
+
</body>
|
|
53
|
+
</html>
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## With Mail Helper Class
|
|
57
|
+
```ruby
|
|
58
|
+
require 'sendgrid-ruby'
|
|
59
|
+
include SendGrid
|
|
60
|
+
|
|
61
|
+
mail = Mail.new
|
|
62
|
+
mail.from = Email.new(email: 'test@example.com')
|
|
63
|
+
personalization = Personalization.new
|
|
64
|
+
personalization.add_to(Email.new(email: 'test@example.com'))
|
|
65
|
+
personalization.add_dynamic_template_data({
|
|
66
|
+
"subject" => "Testing Templates",
|
|
67
|
+
"name" => "Example User",
|
|
68
|
+
"city" => "Denver"
|
|
69
|
+
})
|
|
70
|
+
mail.add_personalization(personalization)
|
|
71
|
+
mail.template_id = 'd-2c214ac919e84170b21855cc129b4a5f'
|
|
72
|
+
|
|
73
|
+
sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
|
|
74
|
+
begin
|
|
75
|
+
response = sg.client.mail._("send").post(request_body: mail.to_json)
|
|
76
|
+
rescue Exception => e
|
|
77
|
+
puts e.message
|
|
78
|
+
end
|
|
79
|
+
puts response.status_code
|
|
80
|
+
puts response.body
|
|
81
|
+
puts response.parsed_body
|
|
82
|
+
puts response.headers
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## Without Mail Helper Class
|
|
86
|
+
|
|
87
|
+
```ruby
|
|
88
|
+
require 'sendgrid-ruby'
|
|
89
|
+
include SendGrid
|
|
90
|
+
|
|
91
|
+
data = JSON.parse('{
|
|
92
|
+
"personalizations": [
|
|
93
|
+
{
|
|
94
|
+
"to": [
|
|
95
|
+
{
|
|
96
|
+
"email": "test@example.com"
|
|
97
|
+
}
|
|
98
|
+
],
|
|
99
|
+
"dynamic_template_data": {
|
|
100
|
+
"subject": "Testing Templates",
|
|
101
|
+
"name": "Example User",
|
|
102
|
+
"city": "Denver"
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
],
|
|
106
|
+
"from": {
|
|
107
|
+
"email": "test@example.com"
|
|
108
|
+
},
|
|
109
|
+
"template_id": "d-2c214ac919e84170b21855cc129b4a5f"
|
|
110
|
+
}')
|
|
111
|
+
sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
|
|
112
|
+
begin
|
|
113
|
+
response = sg.client.mail._("send").post(request_body: data)
|
|
114
|
+
rescue Exception => e
|
|
115
|
+
puts e.message
|
|
116
|
+
end
|
|
117
|
+
puts response.status_code
|
|
118
|
+
puts response.body
|
|
119
|
+
puts response.parsed_body
|
|
120
|
+
puts response.headers
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
<a name="legacy-templates"></a>
|
|
124
|
+
# Legacy Templates
|
|
125
|
+
|
|
126
|
+
For this example, we assume you have created a [legacy template](https://sendgrid.com/docs/User_Guide/Transactional_Templates/index.html). Following is the template content we used for testing.
|
|
11
127
|
|
|
12
128
|
Template ID (replace with your own):
|
|
13
129
|
|
|
@@ -47,15 +163,14 @@ I hope you are having a great day in -city- :)
|
|
|
47
163
|
require 'sendgrid-ruby'
|
|
48
164
|
include SendGrid
|
|
49
165
|
|
|
50
|
-
mail = Mail.new
|
|
166
|
+
mail = SendGrid::Mail.new
|
|
51
167
|
mail.from = Email.new(email: 'test@example.com')
|
|
52
168
|
mail.subject = 'I\'m replacing the subject tag'
|
|
53
169
|
personalization = Personalization.new
|
|
54
|
-
personalization.
|
|
55
|
-
personalization.
|
|
56
|
-
personalization.
|
|
57
|
-
mail.
|
|
58
|
-
mail.contents = Content.new(type: 'text/html', value: 'I\'m replacing the <strong>body tag</strong>')
|
|
170
|
+
personalization.add_to(Email.new(email: 'test@example.com'))
|
|
171
|
+
personalization.add_substitution(Substitution.new(key: '-name-', value: 'Example User'))
|
|
172
|
+
personalization.add_substitution(Substitution.new(key: '-city-', value: 'Denver'))
|
|
173
|
+
mail.add_personalization(personalization)
|
|
59
174
|
mail.template_id = '13b8f94f-bcae-4ec6-b752-70d6cb59f932'
|
|
60
175
|
|
|
61
176
|
sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
|
|
@@ -66,6 +181,7 @@ rescue Exception => e
|
|
|
66
181
|
end
|
|
67
182
|
puts response.status_code
|
|
68
183
|
puts response.body
|
|
184
|
+
puts response.parsed_body
|
|
69
185
|
puts response.headers
|
|
70
186
|
```
|
|
71
187
|
|
|
@@ -93,12 +209,6 @@ data = JSON.parse('{
|
|
|
93
209
|
"from": {
|
|
94
210
|
"email": "test@example.com"
|
|
95
211
|
},
|
|
96
|
-
"content": [
|
|
97
|
-
{
|
|
98
|
-
"type": "text/html",
|
|
99
|
-
"value": "I\'m replacing the <strong>body tag</strong>"
|
|
100
|
-
}
|
|
101
|
-
],
|
|
102
212
|
"template_id": "13b8f94f-bcae-4ec6-b752-70d6cb59f932"
|
|
103
213
|
}')
|
|
104
214
|
sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
|
|
@@ -109,5 +219,159 @@ rescue Exception => e
|
|
|
109
219
|
end
|
|
110
220
|
puts response.status_code
|
|
111
221
|
puts response.body
|
|
222
|
+
puts response.parsed_body
|
|
112
223
|
puts response.headers
|
|
113
|
-
```
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
## Adding Attachments
|
|
227
|
+
|
|
228
|
+
```ruby
|
|
229
|
+
attachment = Attachment.new
|
|
230
|
+
attachment.content = Base64.strict_encode64(File.open(fpath, 'rb').read)
|
|
231
|
+
attachment.type = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
|
|
232
|
+
attachment.filename = fname
|
|
233
|
+
attachment.disposition = 'attachment'
|
|
234
|
+
attachment.content_id = 'Reports Sheet'
|
|
235
|
+
mail.add_attachment(attachment)
|
|
236
|
+
|
|
237
|
+
```
|
|
238
|
+
Attachments must be base64 encoded, using Base64's strict_encode64 where no line feeds are added.
|
|
239
|
+
|
|
240
|
+
<a name="domain-authentication"></a>
|
|
241
|
+
# How to Setup a Domain Authentication
|
|
242
|
+
|
|
243
|
+
You can find documentation for how to setup a domain authentication via the UI [here](https://sendgrid.com/docs/ui/account-and-settings/how-to-set-up-domain-authentication/) and via API [here](https://github.com/sendgrid/sendgrid-nodejs/blob/master/packages/client/USAGE.md#sender-authentication).
|
|
244
|
+
|
|
245
|
+
Find more information about all of SendGrid's authentication related documentation [here](https://sendgrid.com/docs/ui/account-and-settings/).
|
|
246
|
+
|
|
247
|
+
<a name="email-statistics"></a>
|
|
248
|
+
# How to View Email Statistics
|
|
249
|
+
|
|
250
|
+
You can find documentation for how to view your email statistics via the UI [here](https://app.sendgrid.com/statistics) and via API [here](https://github.com/sendgrid/sendgrid-ruby/blob/master/USAGE.md#stats).
|
|
251
|
+
|
|
252
|
+
Alternatively, we can post events to a URL of your choice via our [Event Webhook](https://sendgrid.com/docs/API_Reference/Webhooks/event.html) about events that occur as Twilio SendGrid processes your email.
|
|
253
|
+
|
|
254
|
+
You can also use the email statistics helper to make it easier to interact with the API.
|
|
255
|
+
|
|
256
|
+
```ruby
|
|
257
|
+
require 'sendgrid-ruby'
|
|
258
|
+
require 'date'
|
|
259
|
+
|
|
260
|
+
include SendGrid
|
|
261
|
+
|
|
262
|
+
sg_client = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY']).client
|
|
263
|
+
stats = SendGrid::EmailStats.new(sendgrid_client: sg_client)
|
|
264
|
+
|
|
265
|
+
# Fetch stats by day, between 2 dates
|
|
266
|
+
from = Date.new(2017, 10, 01)
|
|
267
|
+
to = Date.new(2017, 10, 12)
|
|
268
|
+
|
|
269
|
+
email_stats = stats.by_day(from, to)
|
|
270
|
+
|
|
271
|
+
email_stats.metrics
|
|
272
|
+
|
|
273
|
+
if !email_stats.error?
|
|
274
|
+
email_stats.metrics.each do |metric|
|
|
275
|
+
puts "Date - #{metric.date}"
|
|
276
|
+
puts "Number of Requests - #{metric.requests}"
|
|
277
|
+
puts "Bounces - #{metric.bounces}"
|
|
278
|
+
puts "Opens - #{metric.opens}"
|
|
279
|
+
puts "Clicks - #{metric.clicks}"
|
|
280
|
+
end
|
|
281
|
+
end
|
|
282
|
+
|
|
283
|
+
# Fetch stats by week, between 2 dates for a category
|
|
284
|
+
from = Date.new(2017, 10, 01)
|
|
285
|
+
to = Date.new(2017, 10, 12)
|
|
286
|
+
category = 'abcd'
|
|
287
|
+
|
|
288
|
+
email_stats = stats.by_week(from, to, category)
|
|
289
|
+
|
|
290
|
+
if !email_stats.error?
|
|
291
|
+
email_stats.metrics.each do |metric|
|
|
292
|
+
puts "Date - #{metric.date}"
|
|
293
|
+
puts "Number of Requests - #{metric.requests}"
|
|
294
|
+
puts "Bounces - #{metric.bounces}"
|
|
295
|
+
puts "Opens - #{metric.opens}"
|
|
296
|
+
puts "Clicks - #{metric.clicks}"
|
|
297
|
+
end
|
|
298
|
+
end
|
|
299
|
+
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
<a name="sms"></a>
|
|
303
|
+
# Send a SMS Message
|
|
304
|
+
|
|
305
|
+
Following are the steps to add Twilio SMS to your app:
|
|
306
|
+
|
|
307
|
+
## 1. Obtain a Free Twilio Account
|
|
308
|
+
|
|
309
|
+
Sign up for a free Twilio account [here](https://www.twilio.com/try-twilio?source=sendgrid-ruby).
|
|
310
|
+
|
|
311
|
+
## 2. Update Your Environment Variables
|
|
312
|
+
|
|
313
|
+
You can obtain your Account Sid and Auth Token from [twilio.com/console](https://twilio.com/console).
|
|
314
|
+
|
|
315
|
+
### Mac
|
|
316
|
+
|
|
317
|
+
```bash
|
|
318
|
+
echo "export TWILIO_ACCOUNT_SID='YOUR_TWILIO_ACCOUNT_SID'" > twilio.env
|
|
319
|
+
echo "export TWILIO_AUTH_TOKEN='YOUR_TWILIO_AUTH_TOKEN'" >> twilio.env
|
|
320
|
+
echo "twilio.env" >> .gitignore
|
|
321
|
+
source ./twilio.env
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
### Windows
|
|
325
|
+
|
|
326
|
+
Temporarily set the environment variable (accessible only during the current CLI session):
|
|
327
|
+
|
|
328
|
+
```bash
|
|
329
|
+
set TWILIO_ACCOUNT_SID=YOUR_TWILIO_ACCOUNT_SID
|
|
330
|
+
set TWILIO_AUTH_TOKEN=YOUR_TWILIO_AUTH_TOKEN
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
Permanently set the environment variable (accessible in all subsequent CLI sessions):
|
|
334
|
+
|
|
335
|
+
```bash
|
|
336
|
+
setx TWILIO_ACCOUNT_SID "YOUR_TWILIO_ACCOUNT_SID"
|
|
337
|
+
setx TWILIO_AUTH_TOKEN "YOUR_TWILIO_AUTH_TOKEN"
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
## 3. Install the Twilio Helper Library
|
|
341
|
+
|
|
342
|
+
To install using [Bundler][bundler] grab the latest stable version:
|
|
343
|
+
|
|
344
|
+
```ruby
|
|
345
|
+
gem 'twilio-ruby', '~> 5.23.1'
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
To manually install `twilio-ruby` via [Rubygems][rubygems] simply gem install:
|
|
349
|
+
|
|
350
|
+
```bash
|
|
351
|
+
gem install twilio-ruby -v 5.23.1
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
## 4. Setup Work
|
|
355
|
+
|
|
356
|
+
```ruby
|
|
357
|
+
require 'twilio-ruby'
|
|
358
|
+
|
|
359
|
+
# put your own credentials here
|
|
360
|
+
account_sid = ENV['TWILIO_ACCOUNT_SID']
|
|
361
|
+
auth_token = ENV['TWILIO_AUTH_TOKEN']
|
|
362
|
+
|
|
363
|
+
# set up a client to talk to the Twilio REST API
|
|
364
|
+
@client = Twilio::REST::Client.new account_sid, auth_token
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
## 5. Send an SMS
|
|
368
|
+
|
|
369
|
+
```ruby
|
|
370
|
+
@client.api.account.messages.create(
|
|
371
|
+
from: '+14159341234',
|
|
372
|
+
to: '+16105557069',
|
|
373
|
+
body: 'Hey there!'
|
|
374
|
+
)
|
|
375
|
+
```
|
|
376
|
+
|
|
377
|
+
For more information, please visit the [Twilio SMS Ruby documentation](https://www.twilio.com/docs/sms/quickstart/ruby).
|
data/config.ru
ADDED
data/docker/Dockerfile
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
FROM ruby:2.4.2-jessie
|
|
2
|
+
|
|
3
|
+
# Clone sendgrid-ruby
|
|
4
|
+
WORKDIR /sources
|
|
5
|
+
RUN git clone https://github.com/sendgrid/sendgrid-ruby.git
|
|
6
|
+
|
|
7
|
+
# Bundle
|
|
8
|
+
WORKDIR /sources/sendgrid-ruby
|
|
9
|
+
RUN bundle install
|
|
10
|
+
|
|
11
|
+
# Install prism
|
|
12
|
+
RUN curl https://raw.githubusercontent.com/stoplightio/prism/master/install.sh | sh
|
data/docker/README.md
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# Docker image for sendgrid-ruby
|
|
2
|
+
|
|
3
|
+
## Quickstart
|
|
4
|
+
1. [Install Docker](https://docs.docker.com/engine/installation/) on your machine.
|
|
5
|
+
2. Run `docker run --rm -it sendgrid/sendgrid-ruby irb`.
|
|
6
|
+
3. Run `require './lib/sendgrid-ruby.rb'`.
|
|
7
|
+
|
|
8
|
+
## Poke around
|
|
9
|
+
|
|
10
|
+
If you would like to just poke around in the image and check some examples:
|
|
11
|
+
```sh
|
|
12
|
+
docker run --rm -it sendgrid/sendgrid-ruby bash
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
If you want to mount your fork or specific version of the gem:
|
|
16
|
+
```sh
|
|
17
|
+
docker run --rm -v /path/to/local/sendgrid-ruby:/sources/sendgrid-ruby -it sendgrid/sendgrid-ruby bash
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Running tests
|
|
21
|
+
|
|
22
|
+
If you would like to run the tests present in the image:
|
|
23
|
+
```sh
|
|
24
|
+
docker run --rm sendgrid/sendgrid-ruby rake
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
If you want to run tests on your fork or a specific version, mount the codebase onto the image:
|
|
28
|
+
```sh
|
|
29
|
+
docker run --rm -v /path/to/local/sendgrid-ruby:/sources/sendgrid-ruby sendgrid/sendgrid-ruby rake
|
|
30
|
+
```
|
|
@@ -4,10 +4,10 @@ require 'json'
|
|
|
4
4
|
|
|
5
5
|
def hello_world
|
|
6
6
|
from = Email.new(email: 'test@example.com')
|
|
7
|
-
subject = 'Hello World from the SendGrid Ruby Library'
|
|
7
|
+
subject = 'Hello World from the Twilio SendGrid Ruby Library'
|
|
8
8
|
to = Email.new(email: 'test@example.com')
|
|
9
9
|
content = Content.new(type: 'text/plain', value: 'some text here')
|
|
10
|
-
mail = Mail.new(from, subject, to, content)
|
|
10
|
+
mail = SendGrid::Mail.new(from, subject, to, content)
|
|
11
11
|
# puts JSON.pretty_generate(mail.to_json)
|
|
12
12
|
puts mail.to_json
|
|
13
13
|
|
|
@@ -19,45 +19,45 @@ def hello_world
|
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
def kitchen_sink
|
|
22
|
-
mail = Mail.new
|
|
22
|
+
mail = SendGrid::Mail.new
|
|
23
23
|
mail.from = Email.new(email: 'test@example.com')
|
|
24
|
-
mail.subject = 'Hello World from the SendGrid Ruby Library'
|
|
24
|
+
mail.subject = 'Hello World from the Twilio SendGrid Ruby Library'
|
|
25
25
|
personalization = Personalization.new
|
|
26
|
-
personalization.
|
|
27
|
-
personalization.
|
|
28
|
-
personalization.
|
|
29
|
-
personalization.
|
|
30
|
-
personalization.
|
|
31
|
-
personalization.
|
|
32
|
-
personalization.subject = 'Hello World from the Personalized SendGrid Ruby Library'
|
|
33
|
-
personalization.
|
|
34
|
-
personalization.
|
|
35
|
-
personalization.
|
|
36
|
-
personalization.
|
|
37
|
-
personalization.
|
|
38
|
-
personalization.
|
|
26
|
+
personalization.add_to(Email.new(email: 'test1@example.com', name: 'Example User'))
|
|
27
|
+
personalization.add_to(Email.new(email: 'test2@example.com', name: 'Example User'))
|
|
28
|
+
personalization.add_cc(Email.new(email: 'test3@example.com', name: 'Example User'))
|
|
29
|
+
personalization.add_cc(Email.new(email: 'test4@example.com', name: 'Example User'))
|
|
30
|
+
personalization.add_bcc(Email.new(email: 'test5@example.com', name: 'Example User'))
|
|
31
|
+
personalization.add_bcc(Email.new(email: 'test6@example.com', name: 'Example User'))
|
|
32
|
+
personalization.subject = 'Hello World from the Personalized Twilio SendGrid Ruby Library'
|
|
33
|
+
personalization.add_header(Header.new(key: 'X-Test', value: 'True'))
|
|
34
|
+
personalization.add_header(Header.new(key: 'X-Mock', value: 'False'))
|
|
35
|
+
personalization.add_substitution(Substitution.new(key: '%name%', value: 'Example User'))
|
|
36
|
+
personalization.add_substitution(Substitution.new(key: '%city%', value: 'Denver'))
|
|
37
|
+
personalization.add_custom_arg(CustomArg.new(key: 'user_id', value: '343'))
|
|
38
|
+
personalization.add_custom_arg(CustomArg.new(key: 'type', value: 'marketing'))
|
|
39
39
|
personalization.send_at = 1443636843
|
|
40
|
-
mail.
|
|
40
|
+
mail.add_personalization(personalization)
|
|
41
41
|
|
|
42
42
|
personalization2 = Personalization.new
|
|
43
|
-
personalization2.
|
|
44
|
-
personalization2.
|
|
45
|
-
personalization2.
|
|
46
|
-
personalization2.
|
|
47
|
-
personalization2.
|
|
48
|
-
personalization2.
|
|
49
|
-
personalization2.subject = 'Hello World from the Personalized SendGrid Ruby Library'
|
|
50
|
-
personalization2.
|
|
51
|
-
personalization2.
|
|
52
|
-
personalization2.
|
|
53
|
-
personalization2.
|
|
54
|
-
personalization2.
|
|
55
|
-
personalization2.
|
|
43
|
+
personalization2.add_to(Email.new(email: 'test1@example.com', name: 'Example User'))
|
|
44
|
+
personalization2.add_to(Email.new(email: 'test2@example.com', name: 'Example User'))
|
|
45
|
+
personalization2.add_cc(Email.new(email: 'test3@example.com', name: 'Example User'))
|
|
46
|
+
personalization2.add_cc(Email.new(email: 'test4@example.com', name: 'Example User'))
|
|
47
|
+
personalization2.add_bcc(Email.new(email: 'test5@example.com', name: 'Example User'))
|
|
48
|
+
personalization2.add_bcc(Email.new(email: 'test6@example.com', name: 'Example User'))
|
|
49
|
+
personalization2.subject = 'Hello World from the Personalized Twilio SendGrid Ruby Library'
|
|
50
|
+
personalization2.add_header(Header.new(key: 'X-Test', value: 'True'))
|
|
51
|
+
personalization2.add_header(Header.new(key: 'X-Mock', value: 'False'))
|
|
52
|
+
personalization2.add_substitution(Substitution.new(key: '%name%', value: 'Example User'))
|
|
53
|
+
personalization2.add_substitution(Substitution.new(key: '%city%', value: 'Denver'))
|
|
54
|
+
personalization2.add_custom_arg(CustomArg.new(key: 'user_id', value: '343'))
|
|
55
|
+
personalization2.add_custom_arg(CustomArg.new(key: 'type', value: 'marketing'))
|
|
56
56
|
personalization2.send_at = 1443636843
|
|
57
|
-
mail.
|
|
57
|
+
mail.add_personalization(personalization2)
|
|
58
58
|
|
|
59
|
-
mail.
|
|
60
|
-
mail.
|
|
59
|
+
mail.add_content(Content.new(type: 'text/plain', value: 'some text here'))
|
|
60
|
+
mail.add_content(Content.new(type: 'text/html', value: '<html><body>some text here</body></html>'))
|
|
61
61
|
|
|
62
62
|
attachment = Attachment.new
|
|
63
63
|
attachment.content = 'TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2NpbmcgZWxpdC4gQ3JhcyBwdW12'
|
|
@@ -65,8 +65,7 @@ def kitchen_sink
|
|
|
65
65
|
attachment.filename = 'balance_001.pdf'
|
|
66
66
|
attachment.disposition = 'attachment'
|
|
67
67
|
attachment.content_id = 'Balance Sheet'
|
|
68
|
-
|
|
69
|
-
mail.attachments = attachment
|
|
68
|
+
mail.add_attachment(attachment)
|
|
70
69
|
|
|
71
70
|
attachment2 = Attachment.new
|
|
72
71
|
attachment2.content = 'BwdW'
|
|
@@ -74,21 +73,21 @@ def kitchen_sink
|
|
|
74
73
|
attachment2.filename = 'banner.png'
|
|
75
74
|
attachment2.disposition = 'inline'
|
|
76
75
|
attachment2.content_id = 'Banner'
|
|
77
|
-
mail.
|
|
76
|
+
mail.add_attachment(attachment2)
|
|
78
77
|
|
|
79
78
|
mail.template_id = '13b8f94f-bcae-4ec6-b752-70d6cb59f932'
|
|
80
79
|
|
|
81
|
-
mail.
|
|
82
|
-
mail.
|
|
80
|
+
mail.add_section(Section.new(key: '%section1%', value: 'Substitution Text for Section 1'))
|
|
81
|
+
mail.add_section(Section.new(key: '%section2%', value: 'Substitution Text for Section 2'))
|
|
83
82
|
|
|
84
|
-
mail.
|
|
85
|
-
mail.
|
|
83
|
+
mail.add_header(Header.new(key: 'X-Test3', value: 'test3'))
|
|
84
|
+
mail.add_header(Header.new(key: 'X-Test4', value: 'test4'))
|
|
86
85
|
|
|
87
|
-
mail.
|
|
88
|
-
mail.
|
|
86
|
+
mail.add_category(Category.new(name: 'May'))
|
|
87
|
+
mail.add_category(Category.new(name: '2016'))
|
|
89
88
|
|
|
90
|
-
mail.
|
|
91
|
-
mail.
|
|
89
|
+
mail.add_custom_arg(CustomArg.new(key: 'campaign', value: 'welcome'))
|
|
90
|
+
mail.add_custom_arg(CustomArg.new(key: 'weekday', value: 'morning'))
|
|
92
91
|
|
|
93
92
|
mail.send_at = 1443636842
|
|
94
93
|
|
|
@@ -126,5 +125,23 @@ def kitchen_sink
|
|
|
126
125
|
puts response.headers
|
|
127
126
|
end
|
|
128
127
|
|
|
128
|
+
def dynamic_template_data_hello_world
|
|
129
|
+
mail = Mail.new
|
|
130
|
+
mail.template_id = '' # a non-legacy template id
|
|
131
|
+
mail.from = Email.new(email: 'test@example.com')
|
|
132
|
+
subject = 'Dynamic Template Data Hello World from the Twilio SendGrid Ruby Library'
|
|
133
|
+
mail.subject = subject
|
|
134
|
+
personalization = Personalization.new
|
|
135
|
+
personalization.add_to(Email.new(email: 'test1@example.com', name: 'Example User'))
|
|
136
|
+
personalization.add_dynamic_template_data({
|
|
137
|
+
"variable" => [
|
|
138
|
+
{"foo" => "bar"}, {"foo" => "baz"}
|
|
139
|
+
]
|
|
140
|
+
})
|
|
141
|
+
mail.add_personalization(personalization)
|
|
142
|
+
end
|
|
143
|
+
|
|
129
144
|
hello_world
|
|
130
145
|
kitchen_sink
|
|
146
|
+
dynamic_template_data_hello_world
|
|
147
|
+
|