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.
Files changed (136) hide show
  1. checksums.yaml +5 -5
  2. data/.codeclimate.yml +21 -0
  3. data/.env_sample +1 -3
  4. data/.gitignore +1 -0
  5. data/.travis.yml +28 -17
  6. data/CHANGELOG.md +231 -1
  7. data/CODE_OF_CONDUCT.md +73 -0
  8. data/CONTRIBUTING.md +214 -0
  9. data/Gemfile +5 -4
  10. data/ISSUE_TEMPLATE.md +26 -0
  11. data/LICENSE.md +21 -0
  12. data/Makefile +7 -0
  13. data/PULL_REQUEST_TEMPLATE.md +31 -0
  14. data/README.md +161 -225
  15. data/Rakefile +9 -2
  16. data/TROUBLESHOOTING.md +137 -0
  17. data/UPGRADE.md +5 -0
  18. data/USAGE.md +5037 -0
  19. data/USE_CASES.md +377 -0
  20. data/config.ru +4 -0
  21. data/docker/Dockerfile +12 -0
  22. data/docker/README.md +30 -0
  23. data/examples/accesssettings/accesssettings.rb +83 -0
  24. data/examples/alerts/alerts.rb +62 -0
  25. data/examples/apikeys/apikeys.rb +84 -0
  26. data/examples/asm/asm.rb +173 -0
  27. data/examples/browsers/browsers.rb +16 -0
  28. data/examples/campaigns/campaigns.rb +153 -0
  29. data/examples/categories/categories.rb +36 -0
  30. data/examples/clients/clients.rb +27 -0
  31. data/examples/contactdb/contactdb.rb +395 -0
  32. data/examples/devices/devices.rb +16 -0
  33. data/examples/geo/geo.rb +16 -0
  34. data/examples/helpers/mail/example.rb +147 -0
  35. data/examples/helpers/settings/example.rb +23 -0
  36. data/examples/helpers/stats/example.rb +42 -0
  37. data/examples/ips/ips.rb +167 -0
  38. data/examples/mail/mail.rb +173 -0
  39. data/examples/mailboxproviders/mailboxproviders.rb +16 -0
  40. data/examples/mailsettings/mailsettings.rb +219 -0
  41. data/examples/partnersettings/partnersettings.rb +39 -0
  42. data/examples/scopes/scopes.rb +61 -0
  43. data/examples/senderauthentication/senderauthentication.rb +310 -0
  44. data/examples/senders/senders.rb +98 -0
  45. data/examples/stats/stats.rb +16 -0
  46. data/examples/subusers/subusers.rb +169 -0
  47. data/examples/suppression/suppression.rb +201 -0
  48. data/examples/templates/templates.rb +129 -0
  49. data/examples/trackingsettings/trackingsettings.rb +110 -0
  50. data/examples/user/user.rb +293 -0
  51. data/gemfiles/Sinatra_1.gemfile +6 -0
  52. data/gemfiles/Sinatra_2.gemfile +6 -0
  53. data/lib/sendgrid/client.rb +33 -57
  54. data/lib/sendgrid/helpers/inbound/README.md +98 -0
  55. data/lib/sendgrid/helpers/inbound/app.rb +32 -0
  56. data/lib/sendgrid/helpers/inbound/config.yml +26 -0
  57. data/lib/sendgrid/helpers/inbound/public/index.html +10 -0
  58. data/lib/sendgrid/helpers/inbound/sample_data/default_data.txt +58 -0
  59. data/lib/sendgrid/helpers/inbound/sample_data/raw_data.txt +57 -0
  60. data/lib/sendgrid/helpers/inbound/sample_data/raw_data_with_attachments.txt +298 -0
  61. data/lib/sendgrid/helpers/inbound/send.rb +26 -0
  62. data/lib/sendgrid/helpers/ip_management/ip_management.rb +17 -0
  63. data/lib/sendgrid/helpers/mail/README.md +14 -0
  64. data/lib/sendgrid/helpers/mail/asm.rb +33 -0
  65. data/lib/sendgrid/helpers/mail/attachment.rb +86 -0
  66. data/lib/sendgrid/helpers/mail/bcc_settings.rb +33 -0
  67. data/lib/sendgrid/helpers/mail/bypass_list_management.rb +43 -0
  68. data/lib/sendgrid/helpers/mail/category.rb +20 -0
  69. data/lib/sendgrid/helpers/mail/click_tracking.rb +33 -0
  70. data/lib/sendgrid/helpers/mail/content.rb +20 -0
  71. data/lib/sendgrid/helpers/mail/custom_arg.rb +24 -0
  72. data/lib/sendgrid/helpers/mail/email.rb +29 -0
  73. data/lib/sendgrid/helpers/mail/footer.rb +43 -0
  74. data/lib/sendgrid/helpers/mail/ganalytics.rb +74 -0
  75. data/lib/sendgrid/helpers/mail/header.rb +24 -0
  76. data/lib/sendgrid/helpers/mail/mail.rb +140 -0
  77. data/lib/sendgrid/helpers/mail/mail_settings.rb +63 -0
  78. data/lib/sendgrid/helpers/mail/open_tracking.rb +33 -0
  79. data/lib/sendgrid/helpers/mail/personalization.rb +82 -0
  80. data/lib/sendgrid/helpers/mail/section.rb +24 -0
  81. data/lib/sendgrid/helpers/mail/spam_check.rb +43 -0
  82. data/lib/sendgrid/helpers/mail/subscription_tracking.rb +53 -0
  83. data/lib/sendgrid/helpers/mail/substitution.rb +24 -0
  84. data/lib/sendgrid/helpers/mail/tracking_settings.rb +53 -0
  85. data/lib/sendgrid/helpers/permissions/scope.rb +28 -0
  86. data/lib/sendgrid/helpers/permissions/scopes.yml +309 -0
  87. data/lib/sendgrid/helpers/settings/README.md +14 -0
  88. data/lib/sendgrid/helpers/settings/mail_settings_dto.rb +13 -0
  89. data/lib/sendgrid/helpers/settings/partner_settings_dto.rb +13 -0
  90. data/lib/sendgrid/helpers/settings/settings.rb +28 -0
  91. data/lib/sendgrid/helpers/settings/tracking_settings_dto.rb +24 -0
  92. data/lib/sendgrid/helpers/settings/user_settings_dto.rb +13 -0
  93. data/lib/sendgrid/helpers/stats/email_stats.rb +46 -0
  94. data/lib/sendgrid/helpers/stats/metrics.rb +35 -0
  95. data/lib/sendgrid/helpers/stats/stats_response.rb +31 -0
  96. data/lib/sendgrid/version.rb +1 -1
  97. data/lib/sendgrid-ruby.rb +27 -6
  98. data/mail_helper_v3.md +390 -0
  99. data/sendgrid-ruby.gemspec +13 -17
  100. data/spec/sendgrid/helpers/ip_management/ip_management_spec.rb +12 -0
  101. data/spec/sendgrid/helpers/settings/mail_settings_dto_spec.rb +32 -0
  102. data/spec/sendgrid/helpers/settings/partner_settings_dto_spec.rb +24 -0
  103. data/spec/sendgrid/helpers/settings/settings_spec.rb +25 -0
  104. data/spec/sendgrid/helpers/settings/tracking_settings_dto_spec.rb +27 -0
  105. data/spec/sendgrid/helpers/settings/user_settings_dto_spec.rb +24 -0
  106. data/spec/sendgrid/helpers/stats/email_stats_spec.rb +112 -0
  107. data/spec/sendgrid/helpers/stats/metrics_spec.rb +46 -0
  108. data/spec/sendgrid/helpers/stats/stats_response_spec.rb +76 -0
  109. data/spec/spec_helper.rb +10 -1
  110. data/test/prism.sh +42 -0
  111. data/test/sendgrid/helpers/mail/test_attachment.rb +35 -0
  112. data/test/sendgrid/helpers/mail/test_category.rb +27 -0
  113. data/test/sendgrid/helpers/mail/test_email.rb +34 -0
  114. data/test/sendgrid/helpers/mail/test_mail.rb +261 -0
  115. data/test/sendgrid/helpers/mail/test_personalizations.rb +161 -0
  116. data/test/sendgrid/permissions/test_scopes.rb +38 -0
  117. data/test/sendgrid/test_sendgrid-ruby.rb +2751 -0
  118. metadata +149 -115
  119. data/.rspec +0 -2
  120. data/.rubocop.yml +0 -30
  121. data/FETCH_HEAD +0 -0
  122. data/Guardfile +0 -10
  123. data/LICENSE.txt +0 -22
  124. data/example.rb +0 -41
  125. data/lib/sendgrid/exceptions.rb +0 -7
  126. data/lib/sendgrid/mail.rb +0 -182
  127. data/lib/sendgrid/recipient.rb +0 -29
  128. data/lib/sendgrid/response.rb +0 -14
  129. data/lib/sendgrid/template.rb +0 -26
  130. data/lib/sendgrid/template_mailer.rb +0 -59
  131. data/spec/lib/sendgrid/client_spec.rb +0 -87
  132. data/spec/lib/sendgrid/mail_spec.rb +0 -151
  133. data/spec/lib/sendgrid/recipient_spec.rb +0 -91
  134. data/spec/lib/sendgrid/template_mailer_spec.rb +0 -86
  135. data/spec/lib/sendgrid/template_spec.rb +0 -61
  136. 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,7 @@
1
+ .PHONY: install test
2
+
3
+ install:
4
+ gem install bundler:1.14.6; bundle install
5
+
6
+ test:
7
+ bundle exec rake spec
@@ -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
- # SendGrid::Ruby
1
+ ![Twilio SendGrid Logo](https://github.com/sendgrid/sendgrid-python/raw/master/twilio_sendgrid_logo.png)
2
2
 
3
- This Gem allows you to quickly and easily send emails through SendGrid's Web API using native Ruby.
3
+ [![Travis Badge](https://travis-ci.org/sendgrid/sendgrid-ruby.svg?branch=master)](https://travis-ci.org/sendgrid/sendgrid-ruby)
4
+ [![Gem Version](https://badge.fury.io/rb/sendgrid-ruby.svg)](https://badge.fury.io/rb/sendgrid-ruby)
5
+ [![Email Notifications Badge](https://dx.sendgrid.com/badge/ruby)](https://dx.sendgrid.com/newsletter/ruby)
6
+ [![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](./LICENSE.md)
7
+ [![Twitter Follow](https://img.shields.io/twitter/follow/sendgrid.svg?style=social&label=Follow)](https://twitter.com/sendgrid)
8
+ [![GitHub contributors](https://img.shields.io/github/contributors/sendgrid/sendgrid-ruby.svg)](https://github.com/sendgrid/sendgrid-ruby/graphs/contributors)
9
+ [![Open Source Helpers](https://www.codetriage.com/sendgrid/sendgrid-ruby/badges/users.svg)](https://www.codetriage.com/sendgrid/sendgrid-ruby)
4
10
 
5
- You can read our official documentation on the Web API's Mail feature [here](https://sendgrid.com/docs/API_Reference/Web_API/mail.html).
11
+ **NEW:** Subscribe to email [notifications](https://dx.sendgrid.com/newsletter/ruby) for releases and breaking changes.
6
12
 
7
- [![BuildStatus](https://travis-ci.org/sendgrid/sendgrid-ruby.svg?branch=master)](https://travis-ci.org/sendgrid/sendgrid-ruby)
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
- ## Installation
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
- Add this line to your application's Gemfile:
19
+ Please browse the rest of this README for further details.
13
20
 
14
- gem 'sendgrid-ruby'
21
+ We appreciate your continued support, thank you!
15
22
 
16
- And then execute:
23
+ # Table of Contents
17
24
 
18
- $ bundle
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
- Or install it yourself using:
38
+ <a name="announcements"></a>
39
+ # Announcements
21
40
 
22
- $ gem install sendgrid-ruby
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
- Create a new client with your SendGrid Username and Password.
44
+ <a name="installation"></a>
45
+ # Installation
27
46
 
28
- ```ruby
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
- # Or as a block
35
- client = SendGrid::Client.new do |c|
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
- # or as a block with the API key only #
41
- client = SendGrid::Client.new do |c|
42
- c.api_key = 'SENDGRID_APIKEY'
43
- end
44
- ```
52
+ ## Setup Environment Variables
45
53
 
46
- Create a new Mail object and send:
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
- You can also create a Mail object with a hash:
63
- ```ruby
64
- res = client.send(SendGrid::Mail.new(to: 'example@example.com', from: 'taco@cat.limo', subject: 'Hello world!', text: 'Hi there!', html: '<b>Hi there!</b>'))
65
- puts res.code
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
- #### Attachments
63
+ Add this line to your application's Gemfile:
72
64
 
73
- Attachments can be added to a Mail object with the `add_attachment` method. The first parameter is the path to the file, the second (optional) parameter is the desired name of the file. If a file name is not provided, it will use the original filename.
74
- ```ruby
75
- mail.add_attachment('/tmp/report.pdf', 'july_report.pdf')
65
+ ```bash
66
+ gem 'sendgrid-ruby'
76
67
  ```
77
68
 
78
- #### Inline Content
69
+ And then execute:
79
70
 
80
- Inline content can be added to a Mail object with the `add_content` method. The first parameter is the path to the file, the second parameter is the cid to be referenced in the html.
81
- ```ruby
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
- #### Available Params
75
+ Or install it yourself using:
94
76
 
95
- ```ruby
96
- params = {
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
- #### Setting Params
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
- ````ruby
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
- #### :from
85
+ <a name="quick-start"></a>
86
+ # Quick Start
143
87
 
144
- ```ruby
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
- #### :bcc
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
- As with **:to** and **:cc**, **:bcc** can take a single string or an array of strings.
92
+ ### With Mail Helper Class
161
93
 
162
94
  ```ruby
163
- mail = SendGrid::Mail.new
164
- mail.bcc = ['robin@sendgrid.com', 'taco@cat.limo']
165
- ```
95
+ require 'sendgrid-ruby'
96
+ include SendGrid
166
97
 
167
- #### :subject
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
- ```ruby
170
- mail = SendGrid::Mail.new
171
- mail.subject = 'This is a subject string'
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
- ### Email Bodies:
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
- Using the **:text** param allows us to add plain text to our email body.
114
+ ### Without Mail Helper Class
178
115
 
179
- ```ruby
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
- mail = SendGrid::Mail.new
189
- mail.html = '<html><body>Stuff in here, yo!</body></html>'
190
- ```
191
-
192
- #### :template
193
-
194
- The **:template** param allows us to specify a template object for this email to use. The initialized `Template` will automatically be included in the `smtpapi` header and passed to SendGrid.
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
- template = SendGrid::Template.new('MY_TEMPLATE_ID')
198
- mail.template = template
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
- ## Working with Templates
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
- users = User.where(email: ['first@gmail.com', 'second@gmail.com'])
209
-
210
- recipients = []
211
-
212
- users.each do |user|
213
- recipient = SendGrid::Recipient.new(user.email)
214
- recipient.add_substitution('first_name', user.first_name)
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
- Create a `Template`
175
+ <a name="inbound"></a>
176
+ # Processing Inbound Email
222
177
 
223
- ```ruby
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
- Create a `Client`
180
+ <a name="usage"></a>
181
+ # Usage
228
182
 
229
- ```ruby
230
- client = SendGrid::Client.new(api_user: my_user, api_key: my_key)
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
- Initialize mail defaults and create the `TemplateMailer`
190
+ <a name="use_cases"></a>
191
+ # Use Cases
234
192
 
235
- ```ruby
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
- Mail it!
195
+ <a name="announcements"></a>
196
+ # Announcements
247
197
 
248
- ```ruby
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
- ## Using SendGrid's X-SMTPAPI Header
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
- <blockquote>
255
- To utilize the X-SMTPAPI header, we have directly integrated the <a href="https://github.com/SendGridJP/smtpapi-ruby">SendGridJP/smtpapi-ruby</a> gem.
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
- ```ruby
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
- header = Smtpapi::Header.new
262
- header.add_to(['john.doe@example.com', 'jane.doe@example.com'])
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
- `bundle exec rake test`
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
- ## Deploying ##
218
+ <a name="troubleshooting"></a>
219
+ # Troubleshooting
278
220
 
279
- 1. Confirm tests pass `bundle exec rake test`
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
- ## Contributing ##
223
+ <a name="about"></a>
224
+ # About
288
225
 
289
- 1. Fork it ( https://github.com/[my-github-username]/sendgrid-ruby/fork )
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
- ***Hit up [@rbin](http://twitter.com/rbin) or [@sendgrid](http://twitter.com/sendgrid) on Twitter with any issues.***
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
- task test: :spec
13
+ desc "Run tests"
14
+ task default: [:spec, :test]
7
15
 
8
- task default: :test