sendgrid-ruby 6.2.0 → 6.3.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.codeclimate.yml +1 -1
- data/.gitignore +2 -0
- data/.rubocop.yml +6 -0
- data/.travis.yml +12 -21
- data/CHANGELOG.md +57 -8
- data/CONTRIBUTING.md +10 -17
- data/Dockerfile +14 -0
- data/FIRST_TIMERS.md +79 -0
- data/Gemfile +0 -1
- data/ISSUE_TEMPLATE.md +5 -1
- data/Makefile +9 -2
- data/PULL_REQUEST_TEMPLATE.md +1 -1
- data/README.md +22 -21
- data/TROUBLESHOOTING.md +5 -5
- data/USAGE.md +35 -36
- data/examples/helpers/eventwebhook/example.rb +16 -0
- data/examples/helpers/mail/example.rb +11 -4
- data/examples/mail/mail.rb +1 -1
- data/lib/rack/sendgrid_webhook_verification.rb +52 -0
- data/lib/sendgrid-ruby.rb +2 -0
- data/lib/sendgrid/helpers/eventwebhook/eventwebhook.rb +52 -0
- data/lib/sendgrid/helpers/inbound/README.md +5 -5
- data/lib/sendgrid/helpers/inbound/public/index.html +1 -1
- data/lib/sendgrid/helpers/mail/README.md +3 -3
- data/lib/sendgrid/helpers/settings/README.md +2 -2
- data/lib/sendgrid/version.rb +1 -1
- data/mail_helper_v3.md +9 -9
- data/sendgrid-ruby.gemspec +2 -0
- data/spec/fixtures/event_webhook.rb +16 -0
- data/spec/rack/sendgrid_webhook_verification_spec.rb +116 -0
- data/spec/sendgrid/helpers/eventwebhook/eventwebhook_spec.rb +103 -0
- data/spec/spec_helper.rb +2 -0
- data/static/img/github-fork.png +0 -0
- data/static/img/github-sign-up.png +0 -0
- data/test/sendgrid/helpers/mail/test_mail.rb +1 -1
- data/test/sendgrid/test_sendgrid-ruby.rb +24 -59
- data/twilio_sendgrid_logo.png +0 -0
- data/use-cases/README.md +16 -0
- data/use-cases/domain-authentication.md +5 -0
- data/use-cases/email-statistics.md +52 -0
- data/use-cases/legacy-templates.md +98 -0
- data/use-cases/sms.md +39 -0
- data/use-cases/transactional-templates.md +111 -0
- data/use-cases/twilio-email.md +13 -0
- data/use-cases/twilio-setup.md +54 -0
- metadata +54 -8
- data/USE_CASES.md +0 -405
- data/docker/Dockerfile +0 -12
- data/docker/README.md +0 -30
- data/test/prism.sh +0 -42
data/TROUBLESHOOTING.md
CHANGED
@@ -28,7 +28,7 @@ Please review [our guide](https://sendgrid.com/docs/Classroom/Send/v3_Mail_Send/
|
|
28
28
|
|
29
29
|
[Here](https://github.com/sendgrid/sendgrid-ruby/tree/0fbf579c0f7ed1dff87adc4957c4dc5a6b257068) is the last working version with v2 support.
|
30
30
|
|
31
|
-
Using
|
31
|
+
Using RubyGems:
|
32
32
|
|
33
33
|
Add this line to your application's Gemfile:
|
34
34
|
|
@@ -73,7 +73,7 @@ end
|
|
73
73
|
<a name="versioning"></a>
|
74
74
|
## Versioning
|
75
75
|
|
76
|
-
We follow the MAJOR.MINOR.PATCH versioning scheme as described by [SemVer.org](http://semver.org). Therefore, we recommend that you always pin (or vendor) the particular version you are working with
|
76
|
+
We follow the MAJOR.MINOR.PATCH versioning scheme as described by [SemVer.org](http://semver.org). Therefore, we recommend that you always pin (or vendor) the particular version you are working with your code and never auto-update to the latest version. Especially when there is a MAJOR point release since that is guaranteed to be a breaking change. Changes are documented in the [CHANGELOG](CHANGELOG.md) and [releases](https://github.com/sendgrid/sendgrid-ruby/releases) section.
|
77
77
|
|
78
78
|
<a name="environment"></a>
|
79
79
|
## Environment Variables and Your Twilio SendGrid API Key
|
@@ -88,7 +88,7 @@ becomes
|
|
88
88
|
|
89
89
|
`sg = SendGrid::API.new(api_key: 'SENDGRID_API_KEY')`
|
90
90
|
|
91
|
-
In the first case SENDGRID_API_KEY is in reference to the name of the environment variable, while the second case references the actual Twilio SendGrid API Key.
|
91
|
+
In the first case, SENDGRID_API_KEY is in reference to the name of the environment variable, while the second case references the actual Twilio SendGrid API Key.
|
92
92
|
|
93
93
|
<a name="package-manager"></a>
|
94
94
|
## Using the Package Manager
|
@@ -118,9 +118,9 @@ gem install sendgrid-ruby -v X.X.X
|
|
118
118
|
<a name="rails-specifics"></a>
|
119
119
|
## Rails Specifics
|
120
120
|
|
121
|
-
- Namespace collision between Rails own `Mail` class and sendgrid class `Mail`. To avoid that issues please use `SendGrid::Mail` instead.
|
121
|
+
- Namespace collision between Rails own `Mail` class and sendgrid class `Mail`. To avoid that issues please use `SendGrid:: Mail` instead.
|
122
122
|
|
123
|
-
-
|
123
|
+
- The possibility of a namespace collision between the sendgrid class `Email` and your own defined `Email` class. To avoid these issues, you can skip the `include SendGrid` line and use the `SendGrid::` prefix for Email. Please see this [SO answer](https://stackoverflow.com/questions/41508464/rails-model-name-conflict-with-included-gem?noredirect=1#comment70223099_41508464) for specifics.
|
124
124
|
|
125
125
|
<a name="ruby-versions"></a>
|
126
126
|
## Ruby Versions
|
data/USAGE.md
CHANGED
@@ -290,7 +290,7 @@ puts response.headers
|
|
290
290
|
|
291
291
|
**This endpoint allows you to create a new random API Key for the user.**
|
292
292
|
|
293
|
-
A JSON request body containing a "name" property is required. If number of maximum keys is reached, HTTP 403 will be returned.
|
293
|
+
A JSON request body containing a "name" property is required. If the number of maximum keys is reached, HTTP 403 will be returned.
|
294
294
|
|
295
295
|
There is a limit of 100 API Keys on your account.
|
296
296
|
|
@@ -406,7 +406,7 @@ puts response.headers
|
|
406
406
|
|
407
407
|
**This endpoint allows you to revoke an existing API Key**
|
408
408
|
|
409
|
-
Authentications using this API Key will fail after this request is made, with some small propagation delay.If the API Key ID does not exist an HTTP 404 will be returned.
|
409
|
+
Authentications using this API Key will fail after this request is made, with some small propagation delay. If the API Key ID does not exist an HTTP 404 will be returned.
|
410
410
|
|
411
411
|
The API Keys feature allows customers to be able to generate an API Key credential which can be used for authentication with the Twilio SendGrid v3 Web API or the [Mail API Endpoint](https://sendgrid.com/docs/API_Reference/Web_API/mail.html).
|
412
412
|
|
@@ -967,7 +967,7 @@ puts response.headers
|
|
967
967
|
|
968
968
|
**This endpoint allows you to send a test campaign.**
|
969
969
|
|
970
|
-
To send to multiple addresses, use an array for the JSON "to" value ["one@address","two@address"]
|
970
|
+
To send to multiple addresses, use an array for the JSON "to" value ["one@address", "two@address"]
|
971
971
|
|
972
972
|
For more information:
|
973
973
|
|
@@ -1417,7 +1417,7 @@ puts response.headers
|
|
1417
1417
|
```
|
1418
1418
|
## Delete Recipient
|
1419
1419
|
|
1420
|
-
**This endpoint allows you to
|
1420
|
+
**This endpoint allows you to delete one or more recipients.**
|
1421
1421
|
|
1422
1422
|
The body of an API call to this endpoint must include an array of recipient IDs of the recipients you want to delete.
|
1423
1423
|
|
@@ -1529,7 +1529,7 @@ puts response.headers
|
|
1529
1529
|
|
1530
1530
|
**This endpoint allows you to retrieve the lists that a given recipient belongs to.**
|
1531
1531
|
|
1532
|
-
Each recipient can be on many lists. This endpoint gives you all of the lists that
|
1532
|
+
Each recipient can be on many lists. This endpoint gives you all of the lists that anyone recipient has been added to.
|
1533
1533
|
|
1534
1534
|
The Contacts API helps you manage your [Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html) recipients.
|
1535
1535
|
|
@@ -1686,7 +1686,7 @@ puts response.headers
|
|
1686
1686
|
```
|
1687
1687
|
## Delete a segment
|
1688
1688
|
|
1689
|
-
**This endpoint allows you to delete a segment from your
|
1689
|
+
**This endpoint allows you to delete a segment from your recipient's database.**
|
1690
1690
|
|
1691
1691
|
You also have the option to delete all the contacts from your Marketing Campaigns recipient database who were in this segment.
|
1692
1692
|
|
@@ -1736,10 +1736,10 @@ puts response.headers
|
|
1736
1736
|
## Available Device Types
|
1737
1737
|
| **Device** | **Description** | **Example** |
|
1738
1738
|
|---|---|---|
|
1739
|
-
| Desktop | Email software on desktop computer. | I.E., Outlook, Sparrow, or Apple Mail. |
|
1740
|
-
| Webmail |
|
1741
|
-
| Phone | A
|
1742
|
-
| Tablet | A tablet computer. | iPad,
|
1739
|
+
| Desktop | Email software on a desktop computer. | I.E., Outlook, Sparrow, or Apple Mail. |
|
1740
|
+
| Webmail | A web-based email client. | I.E., Yahoo, Google, AOL, or Outlook.com. |
|
1741
|
+
| Phone | A smartphone. | iPhone, Android, Blackberry, etc.
|
1742
|
+
| Tablet | A tablet computer. | iPad, Android-based tablet, etc. |
|
1743
1743
|
| Other | An unrecognized device. |
|
1744
1744
|
|
1745
1745
|
Advanced Stats provide a more in-depth view of your email statistics and the actions taken by your recipients. You can segment these statistics by geographic location, device type, client type, browser, and mailbox provider. For more information about statistics, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Statistics/index.html).
|
@@ -1782,7 +1782,7 @@ puts response.headers
|
|
1782
1782
|
|
1783
1783
|
**This endpoint allows you to retrieve a list of all assigned and unassigned IPs.**
|
1784
1784
|
|
1785
|
-
|
1785
|
+
The response includes warm up status, pools, assigned sub users, and authentication info. The start_date field corresponds to when warmup started for that IP.
|
1786
1786
|
|
1787
1787
|
A single IP address or a range of IP addresses may be dedicated to an account in order to send email for multiple domains. The reputation of this IP is based on the aggregate performance of all the senders who use it.
|
1788
1788
|
|
@@ -2055,7 +2055,7 @@ puts response.headers
|
|
2055
2055
|
|
2056
2056
|
**This endpoint allows you to generate a new batch ID. This batch ID can be associated with scheduled sends via the mail/send endpoint.**
|
2057
2057
|
|
2058
|
-
If you set the SMTPAPI header `batch_id`, it allows you to then associate multiple scheduled mail/send requests together with the same ID. Then at
|
2058
|
+
If you set the SMTPAPI header `batch_id`, it allows you to then associate multiple scheduled mail/send requests together with the same ID. Then at any time up to 10 minutes before the scheduled date, you can cancel all of the mail/send requests that have this batch ID by calling the Cancel Scheduled Send endpoint.
|
2059
2059
|
|
2060
2060
|
More Information:
|
2061
2061
|
|
@@ -2074,7 +2074,7 @@ puts response.headers
|
|
2074
2074
|
|
2075
2075
|
**This endpoint allows you to validate a batch ID.**
|
2076
2076
|
|
2077
|
-
If you set the SMTPAPI header `batch_id`, it allows you to then associate multiple scheduled mail/send requests together with the same ID. Then at
|
2077
|
+
If you set the SMTPAPI header `batch_id`, it allows you to then associate multiple scheduled mail/send requests together with the same ID. Then at any time up to 10 minutes before the scheduled date, you can cancel all of the mail/send requests that have this batch ID by calling the Cancel Scheduled Send endpoint.
|
2078
2078
|
|
2079
2079
|
More Information:
|
2080
2080
|
|
@@ -2092,7 +2092,7 @@ puts response.headers
|
|
2092
2092
|
```
|
2093
2093
|
## v3 Mail Send
|
2094
2094
|
|
2095
|
-
This endpoint allows you to send email over Twilio SendGrid's v3 Web API, the most recent version of our API. If you are looking for documentation about the v2 Mail Send endpoint, please see our [v2 API Reference](https://sendgrid.com/docs/API_Reference/Web_API/mail.html).
|
2095
|
+
This endpoint allows you to send an email over Twilio SendGrid's v3 Web API, the most recent version of our API. If you are looking for documentation about the v2 Mail Send endpoint, please see our [v2 API Reference](https://sendgrid.com/docs/API_Reference/Web_API/mail.html).
|
2096
2096
|
|
2097
2097
|
* Top level parameters are referred to as "global".
|
2098
2098
|
* Individual fields within the personalizations array will override any other global, or message level, parameters that are defined outside of personalizations.
|
@@ -2103,7 +2103,7 @@ For more detailed information about how to use the v3 Mail Send endpoint, please
|
|
2103
2103
|
|
2104
2104
|
### POST /mail/send
|
2105
2105
|
|
2106
|
-
This endpoint has a helper, check it out [here](
|
2106
|
+
This endpoint has a helper, check it out [here](lib/sendgrid/helpers/mail/README.md).
|
2107
2107
|
|
2108
2108
|
```ruby
|
2109
2109
|
data = JSON.parse('{
|
@@ -2313,7 +2313,7 @@ puts response.headers
|
|
2313
2313
|
|
2314
2314
|
**This endpoint allows you to update your current BCC mail settings.**
|
2315
2315
|
|
2316
|
-
When the BCC mail setting is enabled, Twilio SendGrid will automatically send a blind carbon copy (BCC) to an address for every email sent without adding that address to the header. Please note that only one email address may be entered in this field
|
2316
|
+
When the BCC mail setting is enabled, Twilio SendGrid will automatically send a blind carbon copy (BCC) to an address for every email sent without adding that address to the header. Please note that only one email address may be entered in this field if you wish to distribute BCCs to multiple addresses you will need to create a distribution group or use forwarding rules.
|
2317
2317
|
|
2318
2318
|
Mail settings allow you to tell Twilio SendGrid specific things to do to every email that you send to your recipients over Twilio SendGrid's [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html).
|
2319
2319
|
|
@@ -2334,7 +2334,7 @@ puts response.headers
|
|
2334
2334
|
|
2335
2335
|
**This endpoint allows you to retrieve your current BCC mail settings.**
|
2336
2336
|
|
2337
|
-
When the BCC mail setting is enabled, Twilio SendGrid will automatically send a blind carbon copy (BCC) to an address for every email sent without adding that address to the header. Please note that only one email address may be entered in this field
|
2337
|
+
When the BCC mail setting is enabled, Twilio SendGrid will automatically send a blind carbon copy (BCC) to an address for every email sent without adding that address to the header. Please note that only one email address may be entered in this field if you wish to distribute BCCs to multiple addresses you will need to create a distribution group or use forwarding rules.
|
2338
2338
|
|
2339
2339
|
Mail settings allow you to tell Twilio SendGrid specific things to do to every email that you send to your recipients over Twilio SendGrid's [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html).
|
2340
2340
|
|
@@ -2725,7 +2725,7 @@ puts response.headers
|
|
2725
2725
|
|
2726
2726
|
*You may create up to 100 unique sender identities.*
|
2727
2727
|
|
2728
|
-
Sender Identities are required to be verified before use. If your domain has been authenticated, it will auto verify on creation. Otherwise an email will be sent to the `from.email`.
|
2728
|
+
Sender Identities are required to be verified before use. If your domain has been authenticated, it will auto verify on creation. Otherwise, an email will be sent to the `from.email`.
|
2729
2729
|
|
2730
2730
|
### POST /senders
|
2731
2731
|
|
@@ -2757,7 +2757,7 @@ puts response.headers
|
|
2757
2757
|
|
2758
2758
|
**This endpoint allows you to retrieve a list of all sender identities that have been created for your account.**
|
2759
2759
|
|
2760
|
-
Sender Identities are required to be verified before use. If your domain has been authenticated, it will auto verify on creation. Otherwise an email will be sent to the `from.email`.
|
2760
|
+
Sender Identities are required to be verified before use. If your domain has been authenticated, it will auto verify on creation. Otherwise, an email will be sent to the `from.email`.
|
2761
2761
|
|
2762
2762
|
### GET /senders
|
2763
2763
|
|
@@ -2772,7 +2772,7 @@ puts response.headers
|
|
2772
2772
|
|
2773
2773
|
**This endpoint allows you to update a sender identity.**
|
2774
2774
|
|
2775
|
-
Updates to `from.email` require re-verification. If your domain has been authenticated, it will auto verify on creation. Otherwise an email will be sent to the `from.email`.
|
2775
|
+
Updates to `from.email` require re-verification. If your domain has been authenticated, it will auto verify on creation. Otherwise, an email will be sent to the `from.email`.
|
2776
2776
|
|
2777
2777
|
Partial updates are allowed, but fields that are marked as "required" in the POST (create) endpoint must not be nil if that field is included in the PATCH request.
|
2778
2778
|
|
@@ -2807,7 +2807,7 @@ puts response.headers
|
|
2807
2807
|
|
2808
2808
|
**This endpoint allows you to retrieve a specific sender identity.**
|
2809
2809
|
|
2810
|
-
Sender Identities are required to be verified before use. If your domain has been authenticated, it will auto verify on creation. Otherwise an email will be sent to the `from.email`.
|
2810
|
+
Sender Identities are required to be verified before use. If your domain has been authenticated, it will auto verify on creation. Otherwise, an email will be sent to the `from.email`.
|
2811
2811
|
|
2812
2812
|
### GET /senders/{sender_id}
|
2813
2813
|
|
@@ -2823,7 +2823,7 @@ puts response.headers
|
|
2823
2823
|
|
2824
2824
|
**This endpoint allows you to delete one of your sender identities.**
|
2825
2825
|
|
2826
|
-
Sender Identities are required to be verified before use. If your domain has been authenticated, it will auto verify on creation. Otherwise an email will be sent to the `from.email`.
|
2826
|
+
Sender Identities are required to be verified before use. If your domain has been authenticated, it will auto verify on creation. Otherwise, an email will be sent to the `from.email`.
|
2827
2827
|
|
2828
2828
|
### DELETE /senders/{sender_id}
|
2829
2829
|
|
@@ -2839,7 +2839,7 @@ puts response.headers
|
|
2839
2839
|
|
2840
2840
|
**This endpoint allows you to resend a sender identity verification email.**
|
2841
2841
|
|
2842
|
-
Sender Identities are required to be verified before use. If your domain has been authenticated, it will auto verify on creation. Otherwise an email will be sent to the `from.email`.
|
2842
|
+
Sender Identities are required to be verified before use. If your domain has been authenticated, it will auto verify on creation. Otherwise, an email will be sent to the `from.email`.
|
2843
2843
|
|
2844
2844
|
### POST /senders/{sender_id}/resend_verification
|
2845
2845
|
|
@@ -3517,7 +3517,7 @@ puts response.headers
|
|
3517
3517
|
```
|
3518
3518
|
## Retrieve Subuser Reputations
|
3519
3519
|
|
3520
|
-
Subuser sender reputations give a good idea how well a sender is doing with regards to how recipients and recipient servers react to the mail that is being received. When a bounce, spam report, or other negative action happens on a sent email, it will
|
3520
|
+
Subuser sender reputations give a good idea how well a sender is doing with regards to how recipients and recipient servers react to the mail that is being received. When a bounce, spam report, or other negative action happens on a sent email, it will affect your sender rating.
|
3521
3521
|
|
3522
3522
|
This endpoint allows you to request the reputations for your subusers.
|
3523
3523
|
|
@@ -3594,7 +3594,6 @@ puts response.headers
|
|
3594
3594
|
## Enable/disable a subuser
|
3595
3595
|
|
3596
3596
|
This endpoint allows you to enable or disable a subuser.
|
3597
|
-
|
3598
3597
|
For more information about Subusers:
|
3599
3598
|
|
3600
3599
|
* [User Guide > Subusers](https://sendgrid.com/docs/User_Guide/Settings/Subusers/index.html)
|
@@ -3903,7 +3902,7 @@ puts response.headers
|
|
3903
3902
|
|
3904
3903
|
**This endpoint allows you to remove an email address from your bounce list.**
|
3905
3904
|
|
3906
|
-
Bounces are messages that are returned to the server that sent it. This endpoint allows you to delete a single email
|
3905
|
+
Bounces are messages that are returned to the server that sent it. This endpoint allows you to delete a single email address from your bounce list.
|
3907
3906
|
|
3908
3907
|
For more information see:
|
3909
3908
|
|
@@ -3926,7 +3925,7 @@ puts response.headers
|
|
3926
3925
|
|
3927
3926
|
**This endpoint allows you to retrieve a list of all invalid email addresses.**
|
3928
3927
|
|
3929
|
-
An invalid email occurs when you attempt to send email to an address that is formatted in a manner that does not meet internet email format standards or the email does not exist at the
|
3928
|
+
An invalid email occurs when you attempt to send email to an address that is formatted in a manner that does not meet internet email format standards or the email does not exist at the recipient's mail server.
|
3930
3929
|
|
3931
3930
|
Examples include addresses without the @ sign or addresses that include certain special characters and/or spaces. This response can come from our own server or the recipient mail server.
|
3932
3931
|
|
@@ -3951,7 +3950,7 @@ There are two options for deleting invalid email addresses:
|
|
3951
3950
|
1) You can delete all invalid email addresses by setting `delete_all` to true in the request body.
|
3952
3951
|
2) You can delete some invalid email addresses by specifying certain addresses in an array in the request body.
|
3953
3952
|
|
3954
|
-
An invalid email occurs when you attempt to send email to an address that is formatted in a manner that does not meet internet email format standards or the email does not exist at the
|
3953
|
+
An invalid email occurs when you attempt to send email to an address that is formatted in a manner that does not meet internet email format standards or the email does not exist at the recipient's mail server.
|
3955
3954
|
|
3956
3955
|
Examples include addresses without the @ sign or addresses that include certain special characters and/or spaces. This response can come from our own server or the recipient mail server.
|
3957
3956
|
|
@@ -3975,9 +3974,9 @@ puts response.headers
|
|
3975
3974
|
```
|
3976
3975
|
## Retrieve a specific invalid email
|
3977
3976
|
|
3978
|
-
**This endpoint allows you to retrieve a specific invalid email
|
3977
|
+
**This endpoint allows you to retrieve a specific invalid email address.**
|
3979
3978
|
|
3980
|
-
An invalid email occurs when you attempt to send email to an address that is formatted in a manner that does not meet internet email format standards or the email does not exist at the
|
3979
|
+
An invalid email occurs when you attempt to send email to an address that is formatted in a manner that does not meet internet email format standards or the email does not exist at the recipient's mail server.
|
3981
3980
|
|
3982
3981
|
Examples include addresses without the @ sign or addresses that include certain special characters and/or spaces. This response can come from our own server or the recipient mail server.
|
3983
3982
|
|
@@ -3997,7 +3996,7 @@ puts response.headers
|
|
3997
3996
|
|
3998
3997
|
**This endpoint allows you to remove a specific email address from the invalid email address list.**
|
3999
3998
|
|
4000
|
-
An invalid email occurs when you attempt to send email to an address that is formatted in a manner that does not meet internet email format standards or the email does not exist at the
|
3999
|
+
An invalid email occurs when you attempt to send email to an address that is formatted in a manner that does not meet internet email format standards or the email does not exist at the recipient's mail server.
|
4001
4000
|
|
4002
4001
|
Examples include addresses without the @ sign or addresses that include certain special characters and/or spaces. This response can come from our own server or the recipient mail server.
|
4003
4002
|
|
@@ -4695,7 +4694,7 @@ puts response.headers
|
|
4695
4694
|
If the maximum number of cancellations/pauses are added, HTTP 400 will
|
4696
4695
|
be returned.
|
4697
4696
|
|
4698
|
-
The Cancel Scheduled Sends feature allows the customer to cancel a scheduled send based on a Batch ID included in the SMTPAPI header.Scheduled sends
|
4697
|
+
The Cancel Scheduled Sends feature allows the customer to cancel a scheduled send based on a Batch ID included in the SMTPAPI header. Scheduled sends canceled less than 10 minutes before the scheduled time are not guaranteed to be canceled.
|
4699
4698
|
|
4700
4699
|
### POST /user/scheduled_sends
|
4701
4700
|
|
@@ -4714,7 +4713,7 @@ puts response.headers
|
|
4714
4713
|
|
4715
4714
|
**This endpoint allows you to retrieve all cancel/paused scheduled send information.**
|
4716
4715
|
|
4717
|
-
The Cancel Scheduled Sends feature allows the customer to cancel a scheduled send based on a Batch ID included in the SMTPAPI header.Scheduled sends
|
4716
|
+
The Cancel Scheduled Sends feature allows the customer to cancel a scheduled send based on a Batch ID included in the SMTPAPI header. Scheduled sends canceled less than 10 minutes before the scheduled time are not guaranteed to be canceled.
|
4718
4717
|
|
4719
4718
|
### GET /user/scheduled_sends
|
4720
4719
|
|
@@ -4729,7 +4728,7 @@ puts response.headers
|
|
4729
4728
|
|
4730
4729
|
**This endpoint allows you to update the status of a scheduled send for the given `batch_id`.**
|
4731
4730
|
|
4732
|
-
The Cancel Scheduled Sends feature allows the customer to cancel a scheduled send based on a Batch ID included in the SMTPAPI header.Scheduled sends
|
4731
|
+
The Cancel Scheduled Sends feature allows the customer to cancel a scheduled send based on a Batch ID included in the SMTPAPI header. Scheduled sends canceled less than 10 minutes before the scheduled time are not guaranteed to be canceled.
|
4733
4732
|
|
4734
4733
|
### PATCH /user/scheduled_sends/{batch_id}
|
4735
4734
|
|
@@ -4748,7 +4747,7 @@ puts response.headers
|
|
4748
4747
|
|
4749
4748
|
**This endpoint allows you to retrieve the cancel/paused scheduled send information for a specific `batch_id`.**
|
4750
4749
|
|
4751
|
-
The Cancel Scheduled Sends feature allows the customer to cancel a scheduled send based on a Batch ID included in the SMTPAPI header.Scheduled sends
|
4750
|
+
The Cancel Scheduled Sends feature allows the customer to cancel a scheduled send based on a Batch ID included in the SMTPAPI header. Scheduled sends canceled less than 10 minutes before the scheduled time are not guaranteed to be canceled.
|
4752
4751
|
|
4753
4752
|
### GET /user/scheduled_sends/{batch_id}
|
4754
4753
|
|
@@ -4764,7 +4763,7 @@ puts response.headers
|
|
4764
4763
|
|
4765
4764
|
**This endpoint allows you to delete the cancellation/pause of a scheduled send.**
|
4766
4765
|
|
4767
|
-
The Cancel Scheduled Sends feature allows the customer to cancel a scheduled send based on a Batch ID included in the SMTPAPI header.Scheduled sends
|
4766
|
+
The Cancel Scheduled Sends feature allows the customer to cancel a scheduled send based on a Batch ID included in the SMTPAPI header. Scheduled sends canceled less than 10 minutes before the scheduled time are not guaranteed to be canceled.
|
4768
4767
|
|
4769
4768
|
### DELETE /user/scheduled_sends/{batch_id}
|
4770
4769
|
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'sengrid-ruby'
|
2
|
+
include SendGrid
|
3
|
+
|
4
|
+
def is_valid_signature(request)
|
5
|
+
public_key = 'base64-encoded public key'
|
6
|
+
|
7
|
+
event_webhook = SendGrid::EventWebhook.new
|
8
|
+
ec_public_key = event_webhook.convert_public_key_to_ecdsa(public_key)
|
9
|
+
|
10
|
+
event_webhook.verify_signature(
|
11
|
+
ec_public_key,
|
12
|
+
request.body.read,
|
13
|
+
request.env[SendGrid::EventWebhookHeader::SIGNATURE],
|
14
|
+
request.env[SendGrid::EventWebhookHeader::TIMESTAMP]
|
15
|
+
)
|
16
|
+
end
|
@@ -11,7 +11,7 @@ def hello_world
|
|
11
11
|
# puts JSON.pretty_generate(mail.to_json)
|
12
12
|
puts mail.to_json
|
13
13
|
|
14
|
-
sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY']
|
14
|
+
sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
|
15
15
|
response = sg.client.mail._('send').post(request_body: mail.to_json)
|
16
16
|
puts response.status_code
|
17
17
|
puts response.body
|
@@ -118,7 +118,7 @@ def kitchen_sink
|
|
118
118
|
# puts JSON.pretty_generate(mail.to_json)
|
119
119
|
puts mail.to_json
|
120
120
|
|
121
|
-
sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY']
|
121
|
+
sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
|
122
122
|
response = sg.client.mail._('send').post(request_body: mail.to_json)
|
123
123
|
puts response.status_code
|
124
124
|
puts response.body
|
@@ -129,8 +129,6 @@ def dynamic_template_data_hello_world
|
|
129
129
|
mail = Mail.new
|
130
130
|
mail.template_id = '' # a non-legacy template id
|
131
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
132
|
personalization = Personalization.new
|
135
133
|
personalization.add_to(Email.new(email: 'test1@example.com', name: 'Example User'))
|
136
134
|
personalization.add_dynamic_template_data({
|
@@ -139,6 +137,15 @@ def dynamic_template_data_hello_world
|
|
139
137
|
]
|
140
138
|
})
|
141
139
|
mail.add_personalization(personalization)
|
140
|
+
|
141
|
+
# puts JSON.pretty_generate(mail.to_json)
|
142
|
+
puts mail.to_json
|
143
|
+
|
144
|
+
sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
|
145
|
+
response = sg.client.mail._('send').post(request_body: mail.to_json)
|
146
|
+
puts response.status_code
|
147
|
+
puts response.body
|
148
|
+
puts response.headers
|
142
149
|
end
|
143
150
|
|
144
151
|
hello_world
|
data/examples/mail/mail.rb
CHANGED
@@ -26,7 +26,7 @@ puts response.headers
|
|
26
26
|
##################################################
|
27
27
|
# v3 Mail Send #
|
28
28
|
# POST /mail/send #
|
29
|
-
# This endpoint has a helper, check it out [here](https://github.com/sendgrid/sendgrid-ruby/blob/
|
29
|
+
# This endpoint has a helper, check it out [here](https://github.com/sendgrid/sendgrid-ruby/blob/HEAD/lib/helpers/mail/README.md).
|
30
30
|
|
31
31
|
data = JSON.parse('{
|
32
32
|
"asm": {
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Rack
|
4
|
+
# Middleware that verifies webhooks from SendGrid using the EventWebhook
|
5
|
+
# verifier.
|
6
|
+
#
|
7
|
+
# The middleware takes a public key with which to set up the request
|
8
|
+
# validator and any number of paths. When a path matches the incoming request
|
9
|
+
# path, the request will be verified using the signature and timestamp of the
|
10
|
+
# request.
|
11
|
+
#
|
12
|
+
# Example:
|
13
|
+
#
|
14
|
+
# require 'rack'
|
15
|
+
# use Rack::SendGridWebhookVerification, ENV['PUBLIC_KEY'], /\/emails/
|
16
|
+
#
|
17
|
+
# The above appends this middleware to the stack, using a public key saved in
|
18
|
+
# the ENV and only against paths that match /\/emails/. If the request
|
19
|
+
# validates then it gets passed on to the action as normal. If the request
|
20
|
+
# doesn't validate then the middleware responds immediately with a 403 status.
|
21
|
+
class SendGridWebhookVerification
|
22
|
+
def initialize(app, public_key, *paths)
|
23
|
+
@app = app
|
24
|
+
@public_key = public_key
|
25
|
+
@path_regex = Regexp.union(paths)
|
26
|
+
end
|
27
|
+
|
28
|
+
def call(env)
|
29
|
+
return @app.call(env) unless env['PATH_INFO'].match(@path_regex)
|
30
|
+
request = Rack::Request.new(env)
|
31
|
+
|
32
|
+
event_webhook = SendGrid::EventWebhook.new
|
33
|
+
ec_public_key = event_webhook.convert_public_key_to_ecdsa(@public_key)
|
34
|
+
verified = event_webhook.verify_signature(
|
35
|
+
ec_public_key,
|
36
|
+
request.body.read,
|
37
|
+
request.env[SendGrid::EventWebhookHeader::SIGNATURE],
|
38
|
+
request.env[SendGrid::EventWebhookHeader::TIMESTAMP]
|
39
|
+
)
|
40
|
+
|
41
|
+
if verified
|
42
|
+
return @app.call(env)
|
43
|
+
else
|
44
|
+
return [
|
45
|
+
403,
|
46
|
+
{ 'Content-Type' => 'text/plain' },
|
47
|
+
['SendGrid Request Verification Failed.']
|
48
|
+
]
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
data/lib/sendgrid-ruby.rb
CHANGED
@@ -2,6 +2,7 @@ require_relative 'sendgrid/base_interface'
|
|
2
2
|
require_relative 'sendgrid/sendgrid'
|
3
3
|
require_relative 'sendgrid/twilio_email'
|
4
4
|
require_relative 'sendgrid/version'
|
5
|
+
require_relative 'sendgrid/helpers/eventwebhook/eventwebhook'
|
5
6
|
require_relative 'sendgrid/helpers/ip_management/ip_management'
|
6
7
|
require_relative 'sendgrid/helpers/mail/asm'
|
7
8
|
require_relative 'sendgrid/helpers/mail/attachment'
|
@@ -29,3 +30,4 @@ require_relative 'sendgrid/helpers/stats/email_stats'
|
|
29
30
|
require_relative 'sendgrid/helpers/stats/stats_response'
|
30
31
|
require_relative 'sendgrid/helpers/stats/metrics'
|
31
32
|
require_relative 'sendgrid/helpers/permissions/scope'
|
33
|
+
require_relative 'rack/sendgrid_webhook_verification'
|