send_grid_mailer 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +8 -0
  3. data/.rspec +3 -0
  4. data/.ruby-version +1 -0
  5. data/CHANGELOG.md +7 -0
  6. data/Gemfile +15 -0
  7. data/Gemfile.lock +192 -0
  8. data/Guardfile +15 -0
  9. data/LICENSE.txt +21 -0
  10. data/README.md +209 -0
  11. data/Rakefile +10 -0
  12. data/lib/send_grid_mailer.rb +27 -0
  13. data/lib/send_grid_mailer/definition.rb +110 -0
  14. data/lib/send_grid_mailer/deliverer.rb +46 -0
  15. data/lib/send_grid_mailer/engine.rb +23 -0
  16. data/lib/send_grid_mailer/errors.rb +2 -0
  17. data/lib/send_grid_mailer/logger.rb +99 -0
  18. data/lib/send_grid_mailer/mail_message_ext.rb +7 -0
  19. data/lib/send_grid_mailer/mailer_base_ext.rb +88 -0
  20. data/lib/send_grid_mailer/version.rb +3 -0
  21. data/lib/tasks/send_grid_mailer_tasks.rake +4 -0
  22. data/send_grid_mailer.gemspec +31 -0
  23. data/spec/dummy/README.rdoc +28 -0
  24. data/spec/dummy/Rakefile +6 -0
  25. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  26. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  27. data/spec/dummy/app/controllers/application_controller.rb +5 -0
  28. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  29. data/spec/dummy/app/mailers/application_mailer.rb +4 -0
  30. data/spec/dummy/app/mailers/test_mailer.rb +86 -0
  31. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  32. data/spec/dummy/app/views/layouts/mailer.html.erb +5 -0
  33. data/spec/dummy/app/views/layouts/mailer.text.erb +1 -0
  34. data/spec/dummy/app/views/test_mailer/rails_tpl_email.html.erb +1 -0
  35. data/spec/dummy/bin/bundle +3 -0
  36. data/spec/dummy/bin/rails +4 -0
  37. data/spec/dummy/bin/rake +4 -0
  38. data/spec/dummy/bin/setup +29 -0
  39. data/spec/dummy/config.ru +4 -0
  40. data/spec/dummy/config/application.rb +32 -0
  41. data/spec/dummy/config/boot.rb +5 -0
  42. data/spec/dummy/config/database.yml +25 -0
  43. data/spec/dummy/config/environment.rb +5 -0
  44. data/spec/dummy/config/environments/development.rb +46 -0
  45. data/spec/dummy/config/environments/production.rb +79 -0
  46. data/spec/dummy/config/environments/test.rb +42 -0
  47. data/spec/dummy/config/initializers/assets.rb +11 -0
  48. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  49. data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
  50. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  51. data/spec/dummy/config/initializers/inflections.rb +16 -0
  52. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  53. data/spec/dummy/config/initializers/session_store.rb +3 -0
  54. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  55. data/spec/dummy/config/locales/en.yml +23 -0
  56. data/spec/dummy/config/routes.rb +56 -0
  57. data/spec/dummy/config/secrets.yml +22 -0
  58. data/spec/dummy/db/development.sqlite3 +0 -0
  59. data/spec/dummy/db/schema.rb +16 -0
  60. data/spec/dummy/db/test.sqlite3 +0 -0
  61. data/spec/dummy/log/development.log +1984 -0
  62. data/spec/dummy/log/test.log +58252 -0
  63. data/spec/dummy/public/404.html +67 -0
  64. data/spec/dummy/public/422.html +67 -0
  65. data/spec/dummy/public/500.html +66 -0
  66. data/spec/dummy/public/favicon.ico +0 -0
  67. data/spec/dummy/spec/assets/image.png +0 -0
  68. data/spec/dummy/spec/assets/video.mp4 +0 -0
  69. data/spec/dummy/spec/lib/send_grid_mailer/definition_spec.rb +102 -0
  70. data/spec/dummy/spec/mailers/test_mailer_spec.rb +423 -0
  71. data/spec/dummy/spec/support/test_helpers.rb +5 -0
  72. data/spec/rails_helper.rb +28 -0
  73. data/spec/spec_helper.rb +9 -0
  74. metadata +313 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4faec0a432af15b6398489de76957702d4ee324d
4
+ data.tar.gz: b7244a3bc8a5f7acf01011aff00e55db8732e68a
5
+ SHA512:
6
+ metadata.gz: f429d42dc73f6c49ef54a2418be0ab25cabf85aac100f4021a12a9bd2af77f3085e95d4fed18a3ba677fac9a8bbb7d53217296439fe93adb705f8b011be97dbc
7
+ data.tar.gz: a5a29f1551a0968142e7dd93fc31cd2e6ffd4e4e803b71cb4bb8bc6cce1cb25773e55af641eafa57b579bd0abadef3c75b7e4224248700ea405896364922c666
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ .bundle/
2
+ log/*.log
3
+ pkg/
4
+ spec/dummy/db/*.sqlite3
5
+ spec/dummy/db/*.sqlite3-journal
6
+ spec/dummy/log/*.log
7
+ spec/dummy/tmp/
8
+ spec/dummy/.sass-cache
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --require rails_helper
3
+ --format=doc
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.3
data/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ # Change Log
2
+ All notable changes to this project will be documented in this file.
3
+ This project adheres to [Semantic Versioning](http://semver.org/).
4
+
5
+ ### v0.1.0
6
+
7
+ * Initial release.
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Declare your gem's dependencies in send_grid_mailer.gemspec.
4
+ # Bundler will treat runtime dependencies like base dependencies, and
5
+ # development dependencies will be added by default to the :development group.
6
+ gemspec
7
+
8
+ # Declare any dependencies that are still in development here instead of in
9
+ # your gemspec. These might include edge Rails or gems from your path or
10
+ # Git. Remember to move these dependencies to your gemspec before releasing
11
+ # your gem to rubygems.org.
12
+
13
+ # To use a debugger
14
+ # gem 'byebug', group: [:development, :test]
15
+
data/Gemfile.lock ADDED
@@ -0,0 +1,192 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ send_grid_mailer (0.1.0)
5
+ colorize (~> 0.7, >= 0.7.7)
6
+ rails (~> 4.2, >= 4.2.0)
7
+ sendgrid-ruby (~> 4.0, >= 4.0.4)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ actionmailer (4.2.7.1)
13
+ actionpack (= 4.2.7.1)
14
+ actionview (= 4.2.7.1)
15
+ activejob (= 4.2.7.1)
16
+ mail (~> 2.5, >= 2.5.4)
17
+ rails-dom-testing (~> 1.0, >= 1.0.5)
18
+ actionpack (4.2.7.1)
19
+ actionview (= 4.2.7.1)
20
+ activesupport (= 4.2.7.1)
21
+ rack (~> 1.6)
22
+ rack-test (~> 0.6.2)
23
+ rails-dom-testing (~> 1.0, >= 1.0.5)
24
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
25
+ actionview (4.2.7.1)
26
+ activesupport (= 4.2.7.1)
27
+ builder (~> 3.1)
28
+ erubis (~> 2.7.0)
29
+ rails-dom-testing (~> 1.0, >= 1.0.5)
30
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
31
+ activejob (4.2.7.1)
32
+ activesupport (= 4.2.7.1)
33
+ globalid (>= 0.3.0)
34
+ activemodel (4.2.7.1)
35
+ activesupport (= 4.2.7.1)
36
+ builder (~> 3.1)
37
+ activerecord (4.2.7.1)
38
+ activemodel (= 4.2.7.1)
39
+ activesupport (= 4.2.7.1)
40
+ arel (~> 6.0)
41
+ activesupport (4.2.7.1)
42
+ i18n (~> 0.7)
43
+ json (~> 1.7, >= 1.7.7)
44
+ minitest (~> 5.1)
45
+ thread_safe (~> 0.3, >= 0.3.4)
46
+ tzinfo (~> 1.1)
47
+ arel (6.0.3)
48
+ builder (3.2.2)
49
+ coderay (1.1.1)
50
+ colorize (0.8.1)
51
+ concurrent-ruby (1.0.2)
52
+ diff-lcs (1.2.5)
53
+ erubis (2.7.0)
54
+ factory_girl (4.5.0)
55
+ activesupport (>= 3.0.0)
56
+ factory_girl_rails (4.6.0)
57
+ factory_girl (~> 4.5.0)
58
+ railties (>= 3.0.0)
59
+ ffi (1.9.14)
60
+ formatador (0.2.5)
61
+ globalid (0.3.7)
62
+ activesupport (>= 4.1.0)
63
+ guard (2.14.0)
64
+ formatador (>= 0.2.4)
65
+ listen (>= 2.7, < 4.0)
66
+ lumberjack (~> 1.0)
67
+ nenv (~> 0.1)
68
+ notiffany (~> 0.0)
69
+ pry (>= 0.9.12)
70
+ shellany (~> 0.0)
71
+ thor (>= 0.18.1)
72
+ guard-compat (1.2.1)
73
+ guard-rspec (4.7.3)
74
+ guard (~> 2.1)
75
+ guard-compat (~> 1.1)
76
+ rspec (>= 2.99.0, < 4.0)
77
+ i18n (0.7.0)
78
+ json (1.8.3)
79
+ listen (3.1.5)
80
+ rb-fsevent (~> 0.9, >= 0.9.4)
81
+ rb-inotify (~> 0.9, >= 0.9.7)
82
+ ruby_dep (~> 1.2)
83
+ loofah (2.0.3)
84
+ nokogiri (>= 1.5.9)
85
+ lumberjack (1.0.10)
86
+ mail (2.6.4)
87
+ mime-types (>= 1.16, < 4)
88
+ method_source (0.8.2)
89
+ mime-types (3.1)
90
+ mime-types-data (~> 3.2015)
91
+ mime-types-data (3.2016.0521)
92
+ mini_portile2 (2.1.0)
93
+ minitest (5.9.0)
94
+ nenv (0.3.0)
95
+ nokogiri (1.6.8)
96
+ mini_portile2 (~> 2.1.0)
97
+ pkg-config (~> 1.1.7)
98
+ notiffany (0.1.1)
99
+ nenv (~> 0.1)
100
+ shellany (~> 0.0)
101
+ pkg-config (1.1.7)
102
+ pry (0.10.4)
103
+ coderay (~> 1.1.0)
104
+ method_source (~> 0.8.1)
105
+ slop (~> 3.4)
106
+ pry-rails (0.3.4)
107
+ pry (>= 0.9.10)
108
+ rack (1.6.4)
109
+ rack-test (0.6.3)
110
+ rack (>= 1.0)
111
+ rails (4.2.7.1)
112
+ actionmailer (= 4.2.7.1)
113
+ actionpack (= 4.2.7.1)
114
+ actionview (= 4.2.7.1)
115
+ activejob (= 4.2.7.1)
116
+ activemodel (= 4.2.7.1)
117
+ activerecord (= 4.2.7.1)
118
+ activesupport (= 4.2.7.1)
119
+ bundler (>= 1.3.0, < 2.0)
120
+ railties (= 4.2.7.1)
121
+ sprockets-rails
122
+ rails-deprecated_sanitizer (1.0.3)
123
+ activesupport (>= 4.2.0.alpha)
124
+ rails-dom-testing (1.0.7)
125
+ activesupport (>= 4.2.0.beta, < 5.0)
126
+ nokogiri (~> 1.6.0)
127
+ rails-deprecated_sanitizer (>= 1.0.1)
128
+ rails-html-sanitizer (1.0.3)
129
+ loofah (~> 2.0)
130
+ railties (4.2.7.1)
131
+ actionpack (= 4.2.7.1)
132
+ activesupport (= 4.2.7.1)
133
+ rake (>= 0.8.7)
134
+ thor (>= 0.18.1, < 2.0)
135
+ rake (11.3.0)
136
+ rb-fsevent (0.9.7)
137
+ rb-inotify (0.9.7)
138
+ ffi (>= 0.5.0)
139
+ rspec (3.4.0)
140
+ rspec-core (~> 3.4.0)
141
+ rspec-expectations (~> 3.4.0)
142
+ rspec-mocks (~> 3.4.0)
143
+ rspec-core (3.4.4)
144
+ rspec-support (~> 3.4.0)
145
+ rspec-expectations (3.4.0)
146
+ diff-lcs (>= 1.2.0, < 2.0)
147
+ rspec-support (~> 3.4.0)
148
+ rspec-mocks (3.4.1)
149
+ diff-lcs (>= 1.2.0, < 2.0)
150
+ rspec-support (~> 3.4.0)
151
+ rspec-rails (3.4.2)
152
+ actionpack (>= 3.0, < 4.3)
153
+ activesupport (>= 3.0, < 4.3)
154
+ railties (>= 3.0, < 4.3)
155
+ rspec-core (~> 3.4.0)
156
+ rspec-expectations (~> 3.4.0)
157
+ rspec-mocks (~> 3.4.0)
158
+ rspec-support (~> 3.4.0)
159
+ rspec-support (3.4.1)
160
+ ruby_dep (1.4.0)
161
+ ruby_http_client (3.0.0)
162
+ sendgrid-ruby (4.0.4)
163
+ ruby_http_client (~> 3.0.0)
164
+ shellany (0.0.1)
165
+ slop (3.6.0)
166
+ sprockets (3.7.0)
167
+ concurrent-ruby (~> 1.0)
168
+ rack (> 1, < 3)
169
+ sprockets-rails (3.2.0)
170
+ actionpack (>= 4.0)
171
+ activesupport (>= 4.0)
172
+ sprockets (>= 3.0.0)
173
+ sqlite3 (1.3.11)
174
+ thor (0.19.1)
175
+ thread_safe (0.3.5)
176
+ tzinfo (1.2.2)
177
+ thread_safe (~> 0.1)
178
+
179
+ PLATFORMS
180
+ ruby
181
+
182
+ DEPENDENCIES
183
+ factory_girl_rails (~> 4.6.0)
184
+ guard-rspec (~> 4.7)
185
+ pry
186
+ pry-rails
187
+ rspec-rails (~> 3.4.0)
188
+ send_grid_mailer!
189
+ sqlite3
190
+
191
+ BUNDLED WITH
192
+ 1.12.5
data/Guardfile ADDED
@@ -0,0 +1,15 @@
1
+ guard :rspec, cmd: "bundle exec rspec" do
2
+ spec_dic = "spec/dummy/spec"
3
+ # RSpec files
4
+ watch("spec/spec_helper.rb") { spec_dic }
5
+ watch("spec/rails_helper.rb") { spec_dic }
6
+ watch(%r{^spec\/dummy\/spec\/support\/(.+)\.rb$}) { spec_dic }
7
+ watch(%r{^spec\/dummy\/spec\/.+_spec\.rb$})
8
+ # Engine files
9
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/dummy/spec/lib/#{m[1]}_spec.rb" }
10
+ watch(%r{^app/(.+)\.rb$}) { |m| "spec/dummy/spec/#{m[1]}_spec.rb" }
11
+ watch(%r{^app/(.*)(\.erb)$}) { |m| "spec/dummy/spec/#{m[1]}#{m[2]}_spec.rb" }
12
+ # Dummy app files
13
+ watch(%r{^spec\/dummy\/app/(.+)\.rb$}) { |m| "spec/dummy/spec/#{m[1]}_spec.rb" }
14
+ watch(%r{^spec\/dummy\/app/(.*)(\.erb)$}) { |m| "spec/dummy/spec/#{m[1]}#{m[2]}_spec.rb" }
15
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright 2016 Platanus
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all 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
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,209 @@
1
+ # SendGrid Mailer
2
+
3
+ Is an Action Mailer adapter for using SendGrid in a Rails application and
4
+ It's built on top of the [sengrid-ruby](https://github.com/sendgrid/sendgrid-ruby) gem.
5
+
6
+ ## Installation
7
+
8
+ Add to your Gemfile:
9
+
10
+ ```ruby
11
+ gem "send_grid_mailer"
12
+ ```
13
+
14
+ ```bash
15
+ bundle install
16
+ ```
17
+
18
+ In your environment file you need to add:
19
+
20
+ ```ruby
21
+ config.action_mailer.delivery_method = :sendgrid
22
+ config.action_mailer.sendgrid_settings = {
23
+ api_key: "YOUR-SENDGRID-API-KEY"
24
+ }
25
+ ```
26
+
27
+ ## Usage
28
+
29
+ With this adapter you will be able to:
30
+
31
+ #### Set E-mail's Subject
32
+
33
+ ```ruby
34
+ class TestMailer < ApplicationMailer
35
+ def my_email
36
+ set_subject("My Subject")
37
+ mail
38
+ end
39
+
40
+ def my_email # through mail method's params
41
+ mail(subject: "My Subject")
42
+ end
43
+ end
44
+ ```
45
+
46
+ #### Set E-mail's Body
47
+
48
+ ```ruby
49
+ class TestMailer < ApplicationMailer
50
+ def my_email
51
+ set_content("Body")
52
+ mail
53
+ end
54
+
55
+ def my_email # through mail method's params
56
+ mail(body: "<h1>Body</h1>", content_type: "text/html")
57
+ end
58
+ end
59
+ ```
60
+
61
+ #### Set E-mail's Sender
62
+
63
+ ```ruby
64
+ class TestMailer < ApplicationMailer
65
+ default from: "default-sender@platan.us"
66
+
67
+ def my_email
68
+ set_sender("override-default-sender@platan.us")
69
+ mail
70
+ end
71
+
72
+ def my_email # through mail method's params
73
+ mail(from: "override@platan.us", body: "Body")
74
+ end
75
+ end
76
+ ```
77
+
78
+ #### Set E-mail's Recipients
79
+
80
+ ```ruby
81
+ class TestMailer < ApplicationMailer
82
+ def my_email
83
+ set_recipients(:to, "r1@platan.us", "r2@platan.us")
84
+ set_recipients(:cc, ["r4@platan.us"])
85
+ set_recipients(:bcc, "r5@platan.us")
86
+ mail
87
+ end
88
+
89
+ def my_email # through mail method's params
90
+ mail(
91
+ to: ["r1@platan.us", "r2@platan.us"],
92
+ cc: ["r4@platan.us"],
93
+ bcc: "r5@platan.us"
94
+ )
95
+ end
96
+ end
97
+ ```
98
+
99
+ #### Set E-mail's Subject
100
+
101
+ ```ruby
102
+ class TestMailer < ApplicationMailer
103
+ def my_email
104
+ set_subject("My Subject")
105
+ mail
106
+ end
107
+
108
+ def my_email # through mail method's params
109
+ mail(subject: "My Subject")
110
+ end
111
+ end
112
+ ```
113
+
114
+ #### Set E-mail's Headers
115
+
116
+ ```ruby
117
+ class TestMailer < ApplicationMailer
118
+ def my_email
119
+ headers["HEADER-1"] = "VALUE-1"
120
+ headers["HEADER-2"] = "VALUE-2"
121
+ mail
122
+ end
123
+
124
+ def my_email # through mail method's params
125
+ mail(headers: { "HEADER-1" => "VALUE-1", "HEADER-2" => "VALUE-2" })
126
+ end
127
+ end
128
+ ```
129
+
130
+ #### Set E-mail's Attachments
131
+
132
+ ```ruby
133
+ class TestMailer < ApplicationMailer
134
+ def my_email # using Action Mailer method
135
+ attachments["platanus.png"] = File.read("file-path")
136
+ mail
137
+ end
138
+
139
+ def my_email # using this gem method
140
+ file = File.read("file-path")
141
+ add_attachment(file, "platanus.png", "image/png", "inline")
142
+ mail
143
+ end
144
+ end
145
+ ```
146
+
147
+ #### Set SendGrid's Template
148
+
149
+ ```ruby
150
+ class TestMailer < ApplicationMailer
151
+ def my_email
152
+ set_template_id("XXX")
153
+ mail
154
+ end
155
+
156
+ def my_email # through template's name
157
+ set_template_name("my template name")
158
+ mail
159
+ end
160
+
161
+ def my_email # through mail method's params
162
+ mail(template_id: "XXX")
163
+ end
164
+ end
165
+ ```
166
+
167
+ #### Add Substitutions in SendGrid's Template
168
+
169
+ ```ruby
170
+ class TestMailer < ApplicationMailer
171
+ def my_email
172
+ substitute "%key1%", "value1"
173
+ substitute "%key2%", "value2"
174
+ mail
175
+ end
176
+ end
177
+ ```
178
+
179
+ > Remember: you need to specify al least: `body`, `template`, `template name` or a Rails template.
180
+
181
+ ## Testing
182
+
183
+ To run the specs you need to execute, **in the root path of the gem**, the following command:
184
+
185
+ ```bash
186
+ bundle exec guard
187
+ ```
188
+
189
+ You need to put **all your tests** in the `/send_grid_mailer/spec/dummy/spec/` directory.
190
+
191
+ ## Contributing
192
+
193
+ 1. Fork it
194
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
195
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
196
+ 4. Push to the branch (`git push origin my-new-feature`)
197
+ 5. Create new Pull Request
198
+
199
+ ## Credits
200
+
201
+ Thank you [contributors](https://github.com/platanus/send_grid_mailer/graphs/contributors)!
202
+
203
+ <img src="http://platan.us/gravatar_with_text.png" alt="Platanus" width="250"/>
204
+
205
+ SendGrid Mailer is maintained by [platanus](http://platan.us).
206
+
207
+ ## License
208
+
209
+ SendGrid Mailer is © 2016 platanus, spa. It is free software and may be redistributed under the terms specified in the LICENSE file.