hertz-email 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +128 -0
- data/Rakefile +6 -0
- data/app/jobs/hertz/courier/email/notification_delivery_job.rb +20 -0
- data/app/mailers/hertz/courier/email/notification_mailer.rb +38 -0
- data/lib/generators/hertz/courier/email/install_generator.rb +15 -0
- data/lib/generators/hertz/courier/email/templates/initializer.rb +6 -0
- data/lib/hertz/courier/email.rb +28 -0
- data/lib/hertz/courier/email/engine.rb +11 -0
- data/lib/hertz/courier/email/version.rb +9 -0
- metadata +228 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 43158448cc5f38f5297de7897bbca720660ed53a3b9b54e48a9575d8972f967c
|
4
|
+
data.tar.gz: c41d7b93ecb80fee73ca72dec24066b86f5c598df851cc367118f18d84d9e42a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 938b7a352b89458aa5ac3345dae591aa7cbfc3aa3751f250d6a8e23f1ce0f505bdebd79da1f03e1a900434ad3b8db82799b535d943eb349c80047265c55874aa
|
7
|
+
data.tar.gz: cd13ccb6e7f76369bc5908f0609878fe0a2ef4d50203397690582210ce898a4f55f467969b9abeac6280ae21c73970f706f7fa96ed4c0a3cd0ee59a66f018de2
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2016 Alessandro Desantis
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
# Hertz::Courier::Email
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/aldesantis/hertz-email.svg?branch=master)](https://travis-ci.org/aldesantis/hertz-email)
|
4
|
+
[![Dependency Status](https://gemnasium.com/badges/github.com/aldesantis/hertz-email.svg)](https://gemnasium.com/github.com/aldesantis/hertz-email)
|
5
|
+
[![Coverage Status](https://coveralls.io/repos/github/aldesantis/hertz-email/badge.svg?branch=master)](https://coveralls.io/github/aldesantis/hertz-email?branch=master)
|
6
|
+
[![Maintainability](https://api.codeclimate.com/v1/badges/c71c1821b56b288ea71a/maintainability)](https://codeclimate.com/github/aldesantis/hertz-email/maintainability)
|
7
|
+
|
8
|
+
This is a [Hertz](https://github.com/alessandro1997/hertz) courier for sending email notifications to your users through
|
9
|
+
ActionMailer.
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Add this line to your application's Gemfile:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
gem 'hertz-email'
|
17
|
+
```
|
18
|
+
|
19
|
+
And then execute:
|
20
|
+
|
21
|
+
```console
|
22
|
+
$ bundle
|
23
|
+
```
|
24
|
+
|
25
|
+
Or install it yourself as:
|
26
|
+
|
27
|
+
```console
|
28
|
+
$ gem install hertz-email
|
29
|
+
```
|
30
|
+
|
31
|
+
Then, run the installer generator:
|
32
|
+
|
33
|
+
```console
|
34
|
+
$ rails g hertz:courier:email:install
|
35
|
+
```
|
36
|
+
|
37
|
+
You will also need to expose the `hertz_email` method in your receiver class. This can be either a single email or an
|
38
|
+
array of emails:
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
class User < ActiveRecord::Base
|
42
|
+
include Hertz::Notifiable
|
43
|
+
|
44
|
+
def hertz_email
|
45
|
+
email
|
46
|
+
end
|
47
|
+
end
|
48
|
+
```
|
49
|
+
|
50
|
+
If `#hertz_email` returns an empty value (i.e. `false`, `nil`, an empty string or an empty array) at the time the job is
|
51
|
+
executed, the notification will not be delivered. This allows you to programmatically enable/disable email notifications
|
52
|
+
for a user:
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
class User
|
56
|
+
include Hertz::Notifiable
|
57
|
+
|
58
|
+
def hertz_email
|
59
|
+
email if email_verified?
|
60
|
+
end
|
61
|
+
end
|
62
|
+
```
|
63
|
+
|
64
|
+
Or even to choose what addresses they can receive emails to:
|
65
|
+
|
66
|
+
```ruby
|
67
|
+
class User
|
68
|
+
include Hertz::Notifiable
|
69
|
+
|
70
|
+
def hertz_email
|
71
|
+
emails.select(&:verified?)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
```
|
75
|
+
|
76
|
+
## Usage
|
77
|
+
|
78
|
+
In order to use this courier, add `:email` to `#deliver_by` in the notification model(s):
|
79
|
+
|
80
|
+
```ruby
|
81
|
+
class CommentNotification < Hertz::Notification
|
82
|
+
deliver_by :email
|
83
|
+
end
|
84
|
+
```
|
85
|
+
|
86
|
+
Now, add the `#email_subject` method in your notification class:
|
87
|
+
|
88
|
+
```ruby
|
89
|
+
class CommentNotification < Hertz::Notification
|
90
|
+
def email_subject
|
91
|
+
'You have a new comment!'
|
92
|
+
end
|
93
|
+
end
|
94
|
+
```
|
95
|
+
|
96
|
+
You may also pass more options to the `#mail` method of the mailer by defining a `#email_options` method:
|
97
|
+
|
98
|
+
```ruby
|
99
|
+
class CommentNotification < Hertz::Notification
|
100
|
+
def email_options
|
101
|
+
{
|
102
|
+
# generate a custom Reply-To address for the receiver
|
103
|
+
reply_to: "replies+#{receiver.id}@example.com"
|
104
|
+
}
|
105
|
+
end
|
106
|
+
end
|
107
|
+
```
|
108
|
+
|
109
|
+
Finally, you should create a template for every notification you send by email. For `CommentNotification` you'd create a
|
110
|
+
template at `app/views/hertz/courier/email/notification_mailer/comment_notification.html.erb`:
|
111
|
+
|
112
|
+
```erb
|
113
|
+
<p>Hey <%= @notification.receiver.hertz_email %>,</p>
|
114
|
+
<p>you've got a new comment!</p>
|
115
|
+
```
|
116
|
+
|
117
|
+
As you can see, templates have access to the `@notification` instance variable.
|
118
|
+
|
119
|
+
**NOTE:** This courier uses the [deliveries API](https://github.com/alessandro1997/hertz#tracking-delivery-status)
|
120
|
+
to prevent double deliveries.
|
121
|
+
|
122
|
+
## Contributing
|
123
|
+
|
124
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/alessandro1997/hertz-email.
|
125
|
+
|
126
|
+
## License
|
127
|
+
|
128
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Hertz
|
4
|
+
module Courier
|
5
|
+
module Email
|
6
|
+
class NotificationDeliveryJob < ActiveJob::Base
|
7
|
+
queue_as :default
|
8
|
+
|
9
|
+
def perform(notification)
|
10
|
+
return unless notification.receiver.hertz_email.present?
|
11
|
+
return if notification.delivered_with?(:email)
|
12
|
+
|
13
|
+
Hertz::Courier::Email::NotificationMailer.notification_email(notification).deliver_now
|
14
|
+
|
15
|
+
notification.mark_delivered_with(:email)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Hertz
|
4
|
+
module Courier
|
5
|
+
module Email
|
6
|
+
class NotificationMailer < Hertz::Courier::Email.base_mailer
|
7
|
+
def notification_email(notification)
|
8
|
+
@notification = notification
|
9
|
+
mail email_options_for(notification)
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def email_options_for(notification)
|
15
|
+
options = {
|
16
|
+
to: notification.receiver.hertz_email,
|
17
|
+
subject: notification.email_subject,
|
18
|
+
template_name: view_for(notification)
|
19
|
+
}
|
20
|
+
|
21
|
+
if notification.respond_to?(:email_options)
|
22
|
+
options = options.merge(notification.email_options)
|
23
|
+
end
|
24
|
+
|
25
|
+
options
|
26
|
+
end
|
27
|
+
|
28
|
+
def view_for(notification)
|
29
|
+
if notification.respond_to?(:email_template)
|
30
|
+
notification.email_template
|
31
|
+
else
|
32
|
+
notification.class.to_s.underscore
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Hertz
|
4
|
+
module Courier
|
5
|
+
module Email
|
6
|
+
class InstallGenerator < Rails::Generators::Base
|
7
|
+
source_root File.expand_path('../templates', __FILE__)
|
8
|
+
|
9
|
+
def copy_initializer_file
|
10
|
+
copy_file 'initializer.rb', 'config/initializers/hertz_email.rb'
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'hertz'
|
4
|
+
|
5
|
+
require 'hertz/courier/email/engine'
|
6
|
+
require 'hertz/courier/email/version'
|
7
|
+
|
8
|
+
module Hertz
|
9
|
+
module Courier
|
10
|
+
module Email
|
11
|
+
class << self
|
12
|
+
mattr_writer :base_mailer
|
13
|
+
|
14
|
+
def base_mailer
|
15
|
+
(@base_mailer || '::ApplicationMailer').constantize
|
16
|
+
end
|
17
|
+
|
18
|
+
def configure
|
19
|
+
yield(self)
|
20
|
+
end
|
21
|
+
|
22
|
+
def deliver_notification(notification)
|
23
|
+
Hertz::Courier::Email::NotificationDeliveryJob.perform_later(notification)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,228 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hertz-email
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alessandro Desantis
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-02-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: hertz
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rails
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 4.2.0
|
34
|
+
- - "<"
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '6'
|
37
|
+
type: :runtime
|
38
|
+
prerelease: false
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 4.2.0
|
44
|
+
- - "<"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '6'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: coveralls
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: database_cleaner
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: factory_bot_rails
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: faker
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
type: :development
|
97
|
+
prerelease: false
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
- !ruby/object:Gem::Dependency
|
104
|
+
name: fuubar
|
105
|
+
requirement: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
type: :development
|
111
|
+
prerelease: false
|
112
|
+
version_requirements: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
- !ruby/object:Gem::Dependency
|
118
|
+
name: pg
|
119
|
+
requirement: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - "~>"
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0.21'
|
124
|
+
type: :development
|
125
|
+
prerelease: false
|
126
|
+
version_requirements: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - "~>"
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '0.21'
|
131
|
+
- !ruby/object:Gem::Dependency
|
132
|
+
name: rspec-activejob
|
133
|
+
requirement: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - ">="
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '0'
|
138
|
+
type: :development
|
139
|
+
prerelease: false
|
140
|
+
version_requirements: !ruby/object:Gem::Requirement
|
141
|
+
requirements:
|
142
|
+
- - ">="
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: '0'
|
145
|
+
- !ruby/object:Gem::Dependency
|
146
|
+
name: rspec-rails
|
147
|
+
requirement: !ruby/object:Gem::Requirement
|
148
|
+
requirements:
|
149
|
+
- - ">="
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: '0'
|
152
|
+
type: :development
|
153
|
+
prerelease: false
|
154
|
+
version_requirements: !ruby/object:Gem::Requirement
|
155
|
+
requirements:
|
156
|
+
- - ">="
|
157
|
+
- !ruby/object:Gem::Version
|
158
|
+
version: '0'
|
159
|
+
- !ruby/object:Gem::Dependency
|
160
|
+
name: rubocop
|
161
|
+
requirement: !ruby/object:Gem::Requirement
|
162
|
+
requirements:
|
163
|
+
- - ">="
|
164
|
+
- !ruby/object:Gem::Version
|
165
|
+
version: '0'
|
166
|
+
type: :development
|
167
|
+
prerelease: false
|
168
|
+
version_requirements: !ruby/object:Gem::Requirement
|
169
|
+
requirements:
|
170
|
+
- - ">="
|
171
|
+
- !ruby/object:Gem::Version
|
172
|
+
version: '0'
|
173
|
+
- !ruby/object:Gem::Dependency
|
174
|
+
name: rubocop-rspec
|
175
|
+
requirement: !ruby/object:Gem::Requirement
|
176
|
+
requirements:
|
177
|
+
- - ">="
|
178
|
+
- !ruby/object:Gem::Version
|
179
|
+
version: '0'
|
180
|
+
type: :development
|
181
|
+
prerelease: false
|
182
|
+
version_requirements: !ruby/object:Gem::Requirement
|
183
|
+
requirements:
|
184
|
+
- - ">="
|
185
|
+
- !ruby/object:Gem::Version
|
186
|
+
version: '0'
|
187
|
+
description:
|
188
|
+
email:
|
189
|
+
- desa.alessandro@gmail.com
|
190
|
+
executables: []
|
191
|
+
extensions: []
|
192
|
+
extra_rdoc_files: []
|
193
|
+
files:
|
194
|
+
- MIT-LICENSE
|
195
|
+
- README.md
|
196
|
+
- Rakefile
|
197
|
+
- app/jobs/hertz/courier/email/notification_delivery_job.rb
|
198
|
+
- app/mailers/hertz/courier/email/notification_mailer.rb
|
199
|
+
- lib/generators/hertz/courier/email/install_generator.rb
|
200
|
+
- lib/generators/hertz/courier/email/templates/initializer.rb
|
201
|
+
- lib/hertz/courier/email.rb
|
202
|
+
- lib/hertz/courier/email/engine.rb
|
203
|
+
- lib/hertz/courier/email/version.rb
|
204
|
+
homepage: https://github.com/alessandro1997/hertz-email
|
205
|
+
licenses:
|
206
|
+
- MIT
|
207
|
+
metadata: {}
|
208
|
+
post_install_message:
|
209
|
+
rdoc_options: []
|
210
|
+
require_paths:
|
211
|
+
- lib
|
212
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
213
|
+
requirements:
|
214
|
+
- - ">="
|
215
|
+
- !ruby/object:Gem::Version
|
216
|
+
version: '0'
|
217
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
218
|
+
requirements:
|
219
|
+
- - ">="
|
220
|
+
- !ruby/object:Gem::Version
|
221
|
+
version: '0'
|
222
|
+
requirements: []
|
223
|
+
rubyforge_project:
|
224
|
+
rubygems_version: 2.7.5
|
225
|
+
signing_key:
|
226
|
+
specification_version: 4
|
227
|
+
summary: An ActionMailer courier for Hertz.
|
228
|
+
test_files: []
|