sendgrid-ruby 1.1.6 → 6.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.codeclimate.yml +21 -0
- data/.env_sample +1 -3
- data/.gitignore +1 -0
- data/.travis.yml +28 -17
- data/CHANGELOG.md +231 -1
- data/CODE_OF_CONDUCT.md +73 -0
- data/CONTRIBUTING.md +214 -0
- data/Gemfile +5 -4
- data/ISSUE_TEMPLATE.md +26 -0
- data/LICENSE.md +21 -0
- data/Makefile +7 -0
- data/PULL_REQUEST_TEMPLATE.md +31 -0
- data/README.md +161 -225
- data/Rakefile +9 -2
- data/TROUBLESHOOTING.md +137 -0
- data/UPGRADE.md +5 -0
- data/USAGE.md +5037 -0
- data/USE_CASES.md +377 -0
- data/config.ru +4 -0
- data/docker/Dockerfile +12 -0
- data/docker/README.md +30 -0
- data/examples/accesssettings/accesssettings.rb +83 -0
- data/examples/alerts/alerts.rb +62 -0
- data/examples/apikeys/apikeys.rb +84 -0
- data/examples/asm/asm.rb +173 -0
- data/examples/browsers/browsers.rb +16 -0
- data/examples/campaigns/campaigns.rb +153 -0
- data/examples/categories/categories.rb +36 -0
- data/examples/clients/clients.rb +27 -0
- data/examples/contactdb/contactdb.rb +395 -0
- data/examples/devices/devices.rb +16 -0
- data/examples/geo/geo.rb +16 -0
- data/examples/helpers/mail/example.rb +147 -0
- data/examples/helpers/settings/example.rb +23 -0
- data/examples/helpers/stats/example.rb +42 -0
- data/examples/ips/ips.rb +167 -0
- data/examples/mail/mail.rb +173 -0
- data/examples/mailboxproviders/mailboxproviders.rb +16 -0
- data/examples/mailsettings/mailsettings.rb +219 -0
- data/examples/partnersettings/partnersettings.rb +39 -0
- data/examples/scopes/scopes.rb +61 -0
- data/examples/senderauthentication/senderauthentication.rb +310 -0
- data/examples/senders/senders.rb +98 -0
- data/examples/stats/stats.rb +16 -0
- data/examples/subusers/subusers.rb +169 -0
- data/examples/suppression/suppression.rb +201 -0
- data/examples/templates/templates.rb +129 -0
- data/examples/trackingsettings/trackingsettings.rb +110 -0
- data/examples/user/user.rb +293 -0
- data/gemfiles/Sinatra_1.gemfile +6 -0
- data/gemfiles/Sinatra_2.gemfile +6 -0
- data/lib/sendgrid/client.rb +33 -57
- 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 +14 -0
- 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 +140 -0
- 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 +1 -1
- data/lib/sendgrid-ruby.rb +27 -6
- data/mail_helper_v3.md +390 -0
- data/sendgrid-ruby.gemspec +13 -17
- 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 -1
- data/test/prism.sh +42 -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 +261 -0
- 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 +2751 -0
- metadata +149 -115
- data/.rspec +0 -2
- data/.rubocop.yml +0 -30
- data/FETCH_HEAD +0 -0
- data/Guardfile +0 -10
- data/LICENSE.txt +0 -22
- data/example.rb +0 -41
- data/lib/sendgrid/exceptions.rb +0 -7
- data/lib/sendgrid/mail.rb +0 -182
- data/lib/sendgrid/recipient.rb +0 -29
- data/lib/sendgrid/response.rb +0 -14
- data/lib/sendgrid/template.rb +0 -26
- data/lib/sendgrid/template_mailer.rb +0 -59
- data/spec/lib/sendgrid/client_spec.rb +0 -87
- data/spec/lib/sendgrid/mail_spec.rb +0 -151
- data/spec/lib/sendgrid/recipient_spec.rb +0 -91
- data/spec/lib/sendgrid/template_mailer_spec.rb +0 -86
- data/spec/lib/sendgrid/template_spec.rb +0 -61
- data/spec/lib/sendgrid_spec.rb +0 -7
data/LICENSE.md
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (C) 2020, Twilio SendGrid, Inc. <help@twilio.com>
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
7
|
+
the Software without restriction, including without limitation the rights to
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
9
|
+
of the Software, and to permit persons to whom the Software is furnished to do
|
10
|
+
so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/Makefile
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
<!--
|
2
|
+
We appreciate the effort for this pull request but before that please make sure you read the contribution guidelines, then fill out the blanks below.
|
3
|
+
|
4
|
+
Please format the PR title appropriately based on the type of change:
|
5
|
+
<type>[!]: <description>
|
6
|
+
Where <type> is one of: docs, chore, feat, fix, test.
|
7
|
+
Add a '!' after the type for breaking changes (e.g. feat!: new breaking feature).
|
8
|
+
|
9
|
+
**All third-party contributors acknowledge that any contributions they provide will be made under the same open-source license that the open-source project is provided under.**
|
10
|
+
|
11
|
+
Please enter each Issue number you are resolving in your PR after one of the following words [Fixes, Closes, Resolves]. This will auto-link these issues and close them when this PR is merged!
|
12
|
+
e.g.
|
13
|
+
Fixes #1
|
14
|
+
Closes #2
|
15
|
+
-->
|
16
|
+
|
17
|
+
# Fixes #
|
18
|
+
|
19
|
+
A short description of what this PR does.
|
20
|
+
|
21
|
+
### Checklist
|
22
|
+
- [ ] I acknowledge that all my contributions will be made under the project's license
|
23
|
+
- [ ] I have made a material change to the repo (functionality, testing, spelling, grammar)
|
24
|
+
- [ ] I have read the [Contribution Guidelines](CONTRIBUTING.md) and my PR follows them
|
25
|
+
- [ ] I have titled the PR appropriately
|
26
|
+
- [ ] I have updated my branch with the master branch
|
27
|
+
- [ ] I have added tests that prove my fix is effective or that my feature works
|
28
|
+
- [ ] I have added necessary documentation about the functionality in the appropriate .md file
|
29
|
+
- [ ] I have added inline documentation to the code I modified
|
30
|
+
|
31
|
+
If you have questions, please file a [support ticket](https://twilio.com/help/contact), or create a GitHub Issue in this repository.
|
data/README.md
CHANGED
@@ -1,296 +1,232 @@
|
|
1
|
-
|
1
|
+

|
2
2
|
|
3
|
-
|
3
|
+
[](https://travis-ci.org/sendgrid/sendgrid-ruby)
|
4
|
+
[](https://badge.fury.io/rb/sendgrid-ruby)
|
5
|
+
[](https://dx.sendgrid.com/newsletter/ruby)
|
6
|
+
[](./LICENSE.md)
|
7
|
+
[](https://twitter.com/sendgrid)
|
8
|
+
[](https://github.com/sendgrid/sendgrid-ruby/graphs/contributors)
|
9
|
+
[](https://www.codetriage.com/sendgrid/sendgrid-ruby)
|
4
10
|
|
5
|
-
|
11
|
+
**NEW:** Subscribe to email [notifications](https://dx.sendgrid.com/newsletter/ruby) for releases and breaking changes.
|
6
12
|
|
7
|
-
|
13
|
+
**This library allows you to quickly and easily use the Twilio SendGrid Web API v3 via Ruby.**
|
8
14
|
|
15
|
+
Version 3.X.X+ of this library provides full support for all Twilio SendGrid [Web API v3](https://sendgrid.com/docs/API_Reference/Web_API_v3/index.html) endpoints, including the new [v3 /mail/send](https://sendgrid.com/blog/introducing-v3mailsend-sendgrids-new-mail-endpoint).
|
9
16
|
|
10
|
-
|
17
|
+
This library represents the beginning of a new path for Twilio SendGrid. We want this library to be community driven and Twilio SendGrid led. We need your help to realize this goal. To help make sure we are building the right things in the right order, we ask that you create [issues](https://github.com/sendgrid/sendgrid-ruby/issues) and [pull requests](https://github.com/sendgrid/sendgrid-ruby/blob/master/CONTRIBUTING.md) or simply upvote or comment on existing issues or pull requests.
|
11
18
|
|
12
|
-
|
19
|
+
Please browse the rest of this README for further details.
|
13
20
|
|
14
|
-
|
21
|
+
We appreciate your continued support, thank you!
|
15
22
|
|
16
|
-
|
23
|
+
# Table of Contents
|
17
24
|
|
18
|
-
|
25
|
+
* [Announcements](#announcements)
|
26
|
+
* [Installation](#installation)
|
27
|
+
* [Quick Start](#quick-start)
|
28
|
+
* [Processing Inbound Email](#inbound)
|
29
|
+
* [Usage](#usage)
|
30
|
+
* [Use Cases](#use_cases)
|
31
|
+
* [Announcements](#announcements)
|
32
|
+
* [Roadmap](#roadmap)
|
33
|
+
* [How to Contribute](#contribute)
|
34
|
+
* [Troubleshooting](#troubleshooting)
|
35
|
+
* [About](#about)
|
36
|
+
* [License](#license)
|
19
37
|
|
20
|
-
|
38
|
+
<a name="announcements"></a>
|
39
|
+
# Announcements
|
21
40
|
|
22
|
-
|
41
|
+
**NEW:** If you're a software engineer who is passionate about #DeveloperExperience and/or #OpenSource, [this is an incredible opportunity to join our #DX team](https://sendgrid.com/careers/role/1421152/?gh_jid=1421152) as a Developer Experience Engineer and work with [@thinkingserious](https://github.com/thinkingserious) and [@aroach](https://github.com/aroach)! Tell your friends :)
|
23
42
|
|
24
|
-
## Usage
|
25
43
|
|
26
|
-
|
44
|
+
<a name="installation"></a>
|
45
|
+
# Installation
|
27
46
|
|
28
|
-
|
29
|
-
require 'sendgrid-ruby'
|
30
|
-
|
31
|
-
# As a hash
|
32
|
-
client = SendGrid::Client.new(api_user: 'SENDGRID_USERNAME', api_key: 'SENDGRID_PASSWORD')
|
47
|
+
## Prerequisites
|
33
48
|
|
34
|
-
|
35
|
-
|
36
|
-
c.api_user = 'SENDGRID_USERNAME'
|
37
|
-
c.api_key = 'SENDGRID_PASSWORD'
|
38
|
-
end
|
49
|
+
- Ruby version >= 2.2 (except version [2.6.0](https://github.com/sendgrid/sendgrid-ruby/blob/master/TROUBLESHOOTING.md#ruby-versions))
|
50
|
+
- The Twilio SendGrid service, starting at the [free level](https://sendgrid.com/free?source=sendgrid-ruby)
|
39
51
|
|
40
|
-
|
41
|
-
client = SendGrid::Client.new do |c|
|
42
|
-
c.api_key = 'SENDGRID_APIKEY'
|
43
|
-
end
|
44
|
-
```
|
52
|
+
## Setup Environment Variables
|
45
53
|
|
46
|
-
|
47
|
-
```ruby
|
48
|
-
mail = SendGrid::Mail.new do |m|
|
49
|
-
m.to = 'test@sendgrid.com'
|
50
|
-
m.from = 'taco@cat.limo'
|
51
|
-
m.subject = 'Hello world!'
|
52
|
-
m.text = 'I heard you like pineapple.'
|
53
|
-
end
|
54
|
-
|
55
|
-
res = client.send(mail)
|
56
|
-
puts res.code
|
57
|
-
puts res.body
|
58
|
-
# 200
|
59
|
-
# {"message"=>"success"}
|
60
|
-
```
|
54
|
+
Update the development environment with your [SENDGRID_API_KEY](https://app.sendgrid.com/settings/api_keys), for example:
|
61
55
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
puts res.body
|
67
|
-
# 200
|
68
|
-
# {"message"=>"success"}
|
56
|
+
```bash
|
57
|
+
echo "export SENDGRID_API_KEY='YOUR_API_KEY'" > sendgrid.env
|
58
|
+
echo "sendgrid.env" >> .gitignore
|
59
|
+
source ./sendgrid.env
|
69
60
|
```
|
61
|
+
## Install Package
|
70
62
|
|
71
|
-
|
63
|
+
Add this line to your application's Gemfile:
|
72
64
|
|
73
|
-
|
74
|
-
|
75
|
-
mail.add_attachment('/tmp/report.pdf', 'july_report.pdf')
|
65
|
+
```bash
|
66
|
+
gem 'sendgrid-ruby'
|
76
67
|
```
|
77
68
|
|
78
|
-
|
69
|
+
And then execute:
|
79
70
|
|
80
|
-
|
81
|
-
|
82
|
-
mail = SendGrid::Mail.new do |m|
|
83
|
-
m.to = 'test@sendgrid.com'
|
84
|
-
m.from = 'taco@cat.limo'
|
85
|
-
m.subject = 'Hello world!'
|
86
|
-
m.text = 'I heard you like the beach.'
|
87
|
-
m.html = 'I heard you like the beach <div><img src="cid:beach"></div>'
|
88
|
-
end
|
89
|
-
mail.add_content('/tmp/beach.jpg', 'beach')
|
90
|
-
result = client.send(mail)
|
71
|
+
```bash
|
72
|
+
bundle
|
91
73
|
```
|
92
74
|
|
93
|
-
|
75
|
+
Or install it yourself using:
|
94
76
|
|
95
|
-
```
|
96
|
-
|
97
|
-
:to,
|
98
|
-
:to_name,
|
99
|
-
:from,
|
100
|
-
:from_name,
|
101
|
-
:subject,
|
102
|
-
:text,
|
103
|
-
:html,
|
104
|
-
:cc,
|
105
|
-
:cc_name,
|
106
|
-
:bcc,
|
107
|
-
:bcc_name,
|
108
|
-
:reply_to,
|
109
|
-
:date,
|
110
|
-
:smtpapi,
|
111
|
-
:attachments,
|
112
|
-
:template
|
113
|
-
}
|
77
|
+
```bash
|
78
|
+
gem install sendgrid-ruby
|
114
79
|
```
|
115
80
|
|
116
|
-
|
117
|
-
|
118
|
-
Params can be set in the usual Ruby ways, including a block or a hash.
|
119
|
-
|
120
|
-
````ruby
|
121
|
-
mail = SendGrid::Mail.new do |m|
|
122
|
-
m.to = 'rbin@sendgrid.com'
|
123
|
-
m.from = 'taco@rbin.codes'
|
124
|
-
end
|
125
|
-
|
126
|
-
client.send(SendGrid::Mail.new(to: 'rbin@sendgrid.com', from: 'taco@cat.limo'))
|
127
|
-
````
|
128
|
-
|
129
|
-
#### :to
|
130
|
-
|
131
|
-
Using the **:to** param, we can pass a single email address as a string, or an array of email address strings.
|
81
|
+
## Dependencies
|
132
82
|
|
133
|
-
|
134
|
-
mail = SendGrid::Mail.new
|
135
|
-
mail.to = 'taco@rbin.codes'
|
136
|
-
# or
|
137
|
-
mail.to = ['Example Dude <example@email.com>', 'john@email.com']
|
138
|
-
# or
|
139
|
-
mail.to = ['rbin@sendgrid.com', 'taco@cat.limo']
|
140
|
-
````
|
83
|
+
- [Ruby-HTTP-Client](https://github.com/sendgrid/ruby-http-client)
|
141
84
|
|
142
|
-
|
85
|
+
<a name="quick-start"></a>
|
86
|
+
# Quick Start
|
143
87
|
|
144
|
-
|
145
|
-
mail = SendGrid::Mail.new
|
146
|
-
mail.from = 'me@sendgrid.com'
|
147
|
-
```
|
148
|
-
|
149
|
-
#### :cc
|
150
|
-
|
151
|
-
As with **:to**, **:cc** can take a single string or an array of strings.
|
152
|
-
|
153
|
-
```ruby
|
154
|
-
mail = SendGrid::Mail.new
|
155
|
-
mail.cc = ['robin@sendgrid.com', 'taco@cat.limo']
|
156
|
-
```
|
88
|
+
## Hello Email
|
157
89
|
|
158
|
-
|
90
|
+
The following is the minimum needed code to send an email with the [/mail/send Helper](https://github.com/sendgrid/sendgrid-ruby/tree/master/lib/sendgrid/helpers/mail) ([here](https://github.com/sendgrid/sendgrid-ruby/blob/master/examples/helpers/mail/example.rb#L21) is a full example):
|
159
91
|
|
160
|
-
|
92
|
+
### With Mail Helper Class
|
161
93
|
|
162
94
|
```ruby
|
163
|
-
|
164
|
-
|
165
|
-
```
|
95
|
+
require 'sendgrid-ruby'
|
96
|
+
include SendGrid
|
166
97
|
|
167
|
-
|
98
|
+
from = SendGrid::Email.new(email: 'test@example.com')
|
99
|
+
to = SendGrid::Email.new(email: 'test@example.com')
|
100
|
+
subject = 'Sending with Twilio SendGrid is Fun'
|
101
|
+
content = SendGrid::Content.new(type: 'text/plain', value: 'and easy to do anywhere, even with Ruby')
|
102
|
+
mail = SendGrid::Mail.new(from, subject, to, content)
|
168
103
|
|
169
|
-
|
170
|
-
|
171
|
-
|
104
|
+
sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
|
105
|
+
response = sg.client.mail._('send').post(request_body: mail.to_json)
|
106
|
+
puts response.status_code
|
107
|
+
puts response.body
|
108
|
+
puts response.parsed_body
|
109
|
+
puts response.headers
|
172
110
|
```
|
173
111
|
|
174
|
-
|
175
|
-
#### :text
|
112
|
+
For more complex scenarios, please do not use the above constructor and instead build your own personalization object as [demonstrated here](https://github.com/sendgrid/sendgrid-ruby/blob/master/examples/helpers/mail/example.rb#L21).
|
176
113
|
|
177
|
-
|
114
|
+
### Without Mail Helper Class
|
178
115
|
|
179
|
-
|
180
|
-
mail = SendGrid::Mail.new
|
181
|
-
mail.text = 'WHATTUP KITTY CAT!?'
|
182
|
-
```
|
183
|
-
|
184
|
-
#### :html
|
116
|
+
The following is the minimum needed code to send an email without the /mail/send Helper ([here](https://github.com/sendgrid/sendgrid-ruby/blob/master/examples/mail/mail.rb#L26) is a full example):
|
185
117
|
|
186
|
-
Using the **:html** param allows us to add html content to our email body.
|
187
118
|
```ruby
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
119
|
+
require 'sendgrid-ruby'
|
120
|
+
include SendGrid
|
121
|
+
|
122
|
+
data = JSON.parse('{
|
123
|
+
"personalizations": [
|
124
|
+
{
|
125
|
+
"to": [
|
126
|
+
{
|
127
|
+
"email": "test@example.com"
|
128
|
+
}
|
129
|
+
],
|
130
|
+
"subject": "Sending with Twilio SendGrid is Fun"
|
131
|
+
}
|
132
|
+
],
|
133
|
+
"from": {
|
134
|
+
"email": "test@example.com"
|
135
|
+
},
|
136
|
+
"content": [
|
137
|
+
{
|
138
|
+
"type": "text/plain",
|
139
|
+
"value": "and easy to do anywhere, even with Ruby"
|
140
|
+
}
|
141
|
+
]
|
142
|
+
}')
|
143
|
+
sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
|
144
|
+
response = sg.client.mail._("send").post(request_body: data)
|
145
|
+
puts response.status_code
|
146
|
+
puts response.body
|
147
|
+
puts response.parsed_body
|
148
|
+
puts response.headers
|
149
|
+
```
|
150
|
+
|
151
|
+
## General v3 Web API Usage (With Fluent Interface)
|
195
152
|
|
196
153
|
```ruby
|
197
|
-
|
198
|
-
|
154
|
+
require 'sendgrid-ruby'
|
155
|
+
sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
|
156
|
+
response = sg.client.suppression.bounces.get()
|
157
|
+
puts response.status_code
|
158
|
+
puts response.body
|
159
|
+
puts response.parsed_body
|
160
|
+
puts response.headers
|
199
161
|
```
|
200
162
|
|
201
|
-
##
|
202
|
-
|
203
|
-
Another easy way to use the [SendGrid Templating](https://sendgrid.com/docs/API_Reference/Web_API_v3/Template_Engine/index.html) system is with the `Recipient`, `Mail`, `Template`, and `TemplateMailer` objects.
|
204
|
-
|
205
|
-
Create some `Recipients`
|
163
|
+
## General v3 Web API Usage (Without Fluent Interface)
|
206
164
|
|
207
165
|
```ruby
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
recipient.add_substitution('city', user.city)
|
216
|
-
|
217
|
-
recipients << recipient
|
218
|
-
end
|
166
|
+
require 'sendgrid-ruby'
|
167
|
+
sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
|
168
|
+
response = sg.client._("suppression/bounces").get()
|
169
|
+
puts response.status_code
|
170
|
+
puts response.body
|
171
|
+
puts response.parsed_body
|
172
|
+
puts response.headers
|
219
173
|
```
|
220
174
|
|
221
|
-
|
175
|
+
<a name="inbound"></a>
|
176
|
+
# Processing Inbound Email
|
222
177
|
|
223
|
-
|
224
|
-
template = SendGrid::Template.new('MY_TEMPLATE_ID')
|
225
|
-
```
|
178
|
+
Please see [our helper](https://github.com/sendgrid/sendgrid-ruby/tree/master/lib/sendgrid/helpers/inbound) for utilizing our Inbound Parse webhook.
|
226
179
|
|
227
|
-
|
180
|
+
<a name="usage"></a>
|
181
|
+
# Usage
|
228
182
|
|
229
|
-
|
230
|
-
|
231
|
-
|
183
|
+
- [Twilio SendGrid Docs](https://sendgrid.com/docs/API_Reference/index.html)
|
184
|
+
- [Library Usage Docs](https://github.com/sendgrid/sendgrid-ruby/tree/master/USAGE.md)
|
185
|
+
- [Example Code](https://github.com/sendgrid/sendgrid-ruby/tree/master/examples)
|
186
|
+
- [How-to: Migration from v2 to v3](https://sendgrid.com/docs/Classroom/Send/v3_Mail_Send/how_to_migrate_from_v2_to_v3_mail_send.html)
|
187
|
+
- [v3 Web API Mail Send Helper](https://github.com/sendgrid/sendgrid-ruby/tree/master/lib/sendgrid/helpers/mail) - build a request object payload for a v3 /mail/send API call.
|
188
|
+
- [Settings Helper](https://github.com/sendgrid/sendgrid-ruby/tree/master/lib/sendgrid/helpers/settings)
|
232
189
|
|
233
|
-
|
190
|
+
<a name="use_cases"></a>
|
191
|
+
# Use Cases
|
234
192
|
|
235
|
-
|
236
|
-
mail_defaults = {
|
237
|
-
from: 'admin@email.com',
|
238
|
-
html: '<h1>I like email</h1>',
|
239
|
-
text: 'I like email',
|
240
|
-
subject: 'Email is great',
|
241
|
-
}
|
242
|
-
|
243
|
-
mailer = SendGrid::TemplateMailer.new(client, template, recipients)
|
244
|
-
```
|
193
|
+
[Examples of common API use cases](https://github.com/sendgrid/sendgrid-ruby/blob/master/USE_CASES.md), such as how to send an email with a transactional template.
|
245
194
|
|
246
|
-
|
195
|
+
<a name="announcements"></a>
|
196
|
+
# Announcements
|
247
197
|
|
248
|
-
|
249
|
-
mailer.mail(mail_defaults)
|
250
|
-
```
|
198
|
+
Please see our announcement regarding [breaking changes](https://github.com/sendgrid/sendgrid-ruby/issues/94). Your support is appreciated!
|
251
199
|
|
252
|
-
|
200
|
+
All updates to this library are documented in our [CHANGELOG](https://github.com/sendgrid/sendgrid-ruby/blob/master/CHANGELOG.md) and [releases](https://github.com/sendgrid/sendgrid-ruby/releases). You may also subscribe to email [release notifications](https://dx.sendgrid.com/newsletter/ruby) for releases and breaking changes.
|
253
201
|
|
254
|
-
<
|
255
|
-
|
256
|
-
For more information, view our <a href=https://sendgrid.com/docs/API_Reference/SMTP_API/index.html>SMTPAPI docs page</a>.
|
257
|
-
</blockquote>
|
202
|
+
<a name="roadmap"></a>
|
203
|
+
# Roadmap
|
258
204
|
|
259
|
-
|
205
|
+
If you are interested in the future direction of this project, please take a look at our open [issues](https://github.com/sendgrid/sendgrid-ruby/issues) and [pull requests](https://github.com/sendgrid/sendgrid-ruby/pulls). We would love to hear your feedback.
|
260
206
|
|
261
|
-
|
262
|
-
|
263
|
-
header.add_substitution('keep', ['secret']) # sub = {keep: ['secret']}
|
264
|
-
header.add_substitution('other', ['one', 'two']) # sub = {keep: ['secret'], other: ['one', 'two']}
|
265
|
-
header.add_unique_arg("unique_code", "8675309")
|
266
|
-
header.add_category("Newsletter")
|
267
|
-
header.add_filter('templates', 'enable', 1) # necessary for each time the template engine is used
|
268
|
-
header.add_filter('templates', 'template_id', '1234-5678-9100-abcd')
|
269
|
-
header.set_ip_pool("marketing_ip_pool")
|
270
|
-
mail.smtpapi = header
|
207
|
+
<a name="contribute"></a>
|
208
|
+
# How to Contribute
|
271
209
|
|
272
|
-
|
273
|
-
## Testing ##
|
210
|
+
We encourage contribution to our libraries (you might even score some nifty swag), please see our [CONTRIBUTING](https://github.com/sendgrid/sendgrid-ruby/tree/master/CONTRIBUTING.md) guide for details.
|
274
211
|
|
275
|
-
|
212
|
+
- [Feature Request](https://github.com/sendgrid/sendgrid-ruby/tree/master/CONTRIBUTING.md#feature_request)
|
213
|
+
- [Bug Reports](https://github.com/sendgrid/sendgrid-ruby/tree/master/CONTRIBUTING.md#submit_a_bug_report)
|
214
|
+
- [Sign the CLA to Create a Pull Request](https://github.com/sendgrid/sendgrid-ruby/tree/master/CONTRIBUTING.md#cla)
|
215
|
+
- [Improvements to the Codebase](https://github.com/sendgrid/sendgrid-ruby/tree/master/CONTRIBUTING.md#improvements_to_the_codebase)
|
216
|
+
- [Review Pull Requests](https://github.com/sendgrid/sendgrid-ruby/blob/master/CONTRIBUTING.md#code-reviews)
|
276
217
|
|
277
|
-
|
218
|
+
<a name="troubleshooting"></a>
|
219
|
+
# Troubleshooting
|
278
220
|
|
279
|
-
|
280
|
-
2. Bump the version in `lib/sendgrid/version.rb` and `spec/lib/sendgrid_spec.rb`
|
281
|
-
3. Update CHANGELOG.md
|
282
|
-
4. Commit Version bump vX.X.X
|
283
|
-
5. `rake release`
|
284
|
-
6. Push changes to GitHub
|
285
|
-
7. Release tag on GitHub vX.X.X
|
221
|
+
Please see our [troubleshooting guide](https://github.com/sendgrid/sendgrid-ruby/blob/master/TROUBLESHOOTING.md) for common library issues.
|
286
222
|
|
287
|
-
|
223
|
+
<a name="about"></a>
|
224
|
+
# About
|
288
225
|
|
289
|
-
|
290
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
291
|
-
3. Commit your changes (`git commit -am 'Add some feature'`)
|
292
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
293
|
-
5. Create a new Pull Request
|
226
|
+
sendgrid-ruby is guided and supported by the [Developer Experience Team](mailto:dx@sendgrid.com).
|
294
227
|
|
295
|
-
|
228
|
+
sendgrid-ruby is maintained and funded by SendGrid, Inc. The names and logos for sendgrid-ruby are trademarks of SendGrid, Inc.
|
296
229
|
|
230
|
+
<a name="license"></a>
|
231
|
+
# License
|
232
|
+
[The MIT License (MIT)](LICENSE.md)
|
data/Rakefile
CHANGED
@@ -1,8 +1,15 @@
|
|
1
|
+
require 'rake/testtask'
|
1
2
|
require 'bundler/gem_tasks'
|
2
3
|
require 'rspec/core/rake_task'
|
3
4
|
|
5
|
+
Rake::TestTask.new do |t|
|
6
|
+
t.libs << 'test'
|
7
|
+
t.test_files = FileList['test/sendgrid/test*.rb', 'test/sendgrid/helpers/mail/test*.rb', 'test/sendgrid/helpers/permissions/test*.rb']
|
8
|
+
t.verbose = true
|
9
|
+
end
|
10
|
+
|
4
11
|
RSpec::Core::RakeTask.new(:spec)
|
5
12
|
|
6
|
-
|
13
|
+
desc "Run tests"
|
14
|
+
task default: [:spec, :test]
|
7
15
|
|
8
|
-
task default: :test
|