hertz-courier-email 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8f33e033f5036a05468307ad5fbc8597579f525d
4
+ data.tar.gz: 15785f77be756740e6b284eb4dda3d7d523ba3a3
5
+ SHA512:
6
+ metadata.gz: ddfc76602a4dc09f9795a79b7ef430abdba9c2431ffaadf7f545524981613605c52aee644bc5bcd48e134b9688620595863bff497689225bd611782be1fed3ae
7
+ data.tar.gz: e54753df1ab1327f229c09923b123eae57c98680450cabc63a71ffd7d94b1336e9c2d53e5121cc4d39689854e538622e54a4f94cd335563387f367dfb348c629
@@ -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.
@@ -0,0 +1,106 @@
1
+ # Hertz::Courier::Email
2
+
3
+ [![Dependency Status](https://gemnasium.com/badges/github.com/alessandro1997/hertz-courier-email.svg)](https://gemnasium.com/github.com/alessandro1997/hertz-courier-email)
4
+ [![Code Climate](https://codeclimate.com/github/alessandro1997/hertz-courier-email/badges/gpa.svg)](https://codeclimate.com/github/alessandro1997/hertz-courier-email)
5
+
6
+ This is a [Hertz](https://github.com/alessandro1997/hertz) courier for sending
7
+ notifications to your users via email throuh ActionMailer.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'hertz-courier-email'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ ```console
20
+ $ bundle
21
+ ```
22
+
23
+ Or install it yourself as:
24
+
25
+ ```console
26
+ $ gem install hertz-courier-email
27
+ ```
28
+
29
+ Then, run the installer generator:
30
+
31
+ ```console
32
+ $ rails g hertz:courier:email:install
33
+ ```
34
+
35
+ You will also need to expose the `hertz_email` method in your receiver class:
36
+
37
+ ```ruby
38
+ class User < ActiveRecord::Base
39
+ include Hertz::Notifiable
40
+
41
+ def hertz_email
42
+ email
43
+ end
44
+ end
45
+ ```
46
+
47
+ If `#hertz_email` returns an empty value (i.e. `false`, `nil` or an empty
48
+ string) at the time the job is executed, the notification will not be delivered.
49
+ This allows you to programmatically enable/disable email notifications for a
50
+ user:
51
+
52
+ ```ruby
53
+ class User
54
+ include Hertz::Notifiable
55
+
56
+ def hertz_email
57
+ email if email_verified?
58
+ end
59
+ end
60
+ ```
61
+
62
+ ## Usage
63
+
64
+ In order to use this courier, add `:email` to `deliver_by` in the notification
65
+ model(s):
66
+
67
+ ```ruby
68
+ class CommentNotification < Hertz::Notification
69
+ deliver_by :email
70
+ end
71
+ ```
72
+
73
+ Now, add the `email_subject` method in your notification class:
74
+
75
+ ```ruby
76
+ class CommentNotification < Hertz::Notification
77
+ def email_subject
78
+ 'You have a new comment!'
79
+ end
80
+ end
81
+ ```
82
+
83
+ Finally, you should create a template for every notification you send by email.
84
+ For `CommentNotification` you'd create a template at
85
+ `app/views/hertz/courier/email/notification_mailer/comment_notification.html.erb`:
86
+
87
+ ```erb
88
+ <p>Hey <%= @notification.receiver.hertz_email %>,</p>
89
+ <p>you've got a new comment!</p>
90
+ ```
91
+
92
+ As you can see, templates have access to the `@notification` instance variable.
93
+
94
+ ## Contributing
95
+
96
+ Bug reports and pull requests are welcome on GitHub at
97
+ https://github.com/alessandro1997/hertz-courier-email.
98
+
99
+ ## License
100
+
101
+ The gem is available as open source under the terms of the
102
+ [MIT License](http://opensource.org/licenses/MIT).
103
+
104
+ # To do
105
+
106
+ - [ ] Store notification delivery in the DB to avoid resending
@@ -0,0 +1,30 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'Hertz'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+ load 'rails/tasks/statistics.rake'
20
+
21
+ Bundler::GemHelper.install_tasks
22
+
23
+ Rake::TestTask.new(:spec) do |t|
24
+ t.libs << 'lib'
25
+ t.libs << 'spec'
26
+ t.pattern = 'spec/**/*_spec.rb'
27
+ t.verbose = false
28
+ end
29
+
30
+ task default: :spec
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+ module Hertz
3
+ module Courier
4
+ module Email
5
+ class NotificationDeliveryJob < ActiveJob::Base
6
+ queue_as :default
7
+
8
+ def perform(notification)
9
+ return unless notification.receiver.hertz_email.present?
10
+
11
+ Hertz::Courier::Email::NotificationMailer
12
+ .notification_email(notification)
13
+ .deliver_now
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+ module Hertz
3
+ module Courier
4
+ module Email
5
+ class NotificationMailer < Hertz::Courier::Email.base_mailer
6
+ def notification_email(notification)
7
+ @notification = notification
8
+
9
+ mail(
10
+ to: notification.receiver.hertz_email,
11
+ subject: notification.email_subject,
12
+ template_name: view_for(notification)
13
+ )
14
+ end
15
+
16
+ private
17
+
18
+ def view_for(notification)
19
+ if notification.respond_to?(:email_template)
20
+ notification.email_template
21
+ else
22
+ notification.class.to_s.underscore
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+ module Hertz
3
+ module Courier
4
+ module Email
5
+ class InstallGenerator < Rails::Generators::Base
6
+ source_root File.expand_path('../templates', __FILE__)
7
+
8
+ def copy_initializer_file
9
+ copy_file 'initializer.rb', 'config/initializers/hertz_email.rb'
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+ Hertz::Courier::Email.configure do |config|
3
+ # Your base mailer class, for delivering notifications by email.
4
+ config.base_mailer = '::ApplicationMailer'
5
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+ require 'hertz'
3
+
4
+ require 'hertz/courier/email/engine'
5
+ require 'hertz/courier/email/version'
6
+
7
+ module Hertz
8
+ module Courier
9
+ module Email
10
+ class << self
11
+ mattr_writer :base_mailer
12
+
13
+ def base_mailer
14
+ (@base_mailer || '::ApplicationMailer').constantize
15
+ end
16
+
17
+ def configure
18
+ yield(self)
19
+ end
20
+
21
+ def deliver_notification(notification)
22
+ Hertz::Courier::Email::NotificationDeliveryJob
23
+ .perform_later(notification)
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+ module Hertz
3
+ module Courier
4
+ module Email
5
+ class Engine < ::Rails::Engine
6
+ isolate_namespace Hertz::Courier::Email
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+ module Hertz
3
+ module Courier
4
+ module Email
5
+ VERSION = '1.0.0'
6
+ end
7
+ end
8
+ end
metadata ADDED
@@ -0,0 +1,208 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hertz-courier-email
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Alessandro Desantis
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-05-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 4.2.6
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 4.2.6
27
+ - !ruby/object:Gem::Dependency
28
+ name: hertz
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 1.0.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 1.0.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: rubocop
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop-rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec-rails
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec-activejob
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: fuubar
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: faker
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: database_cleaner
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: factory_girl_rails
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: pg
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ description:
168
+ email:
169
+ - desa.alessandro@gmail.com
170
+ executables: []
171
+ extensions: []
172
+ extra_rdoc_files: []
173
+ files:
174
+ - MIT-LICENSE
175
+ - README.md
176
+ - Rakefile
177
+ - app/jobs/hertz/courier/email/notification_delivery_job.rb
178
+ - app/mailers/hertz/courier/email/notification_mailer.rb
179
+ - lib/generators/hertz/courier/email/install_generator.rb
180
+ - lib/generators/hertz/courier/email/templates/initializer.rb
181
+ - lib/hertz/courier/email.rb
182
+ - lib/hertz/courier/email/engine.rb
183
+ - lib/hertz/courier/email/version.rb
184
+ homepage: https://github.com/alessandro1997/hertz-courier-email
185
+ licenses:
186
+ - MIT
187
+ metadata: {}
188
+ post_install_message:
189
+ rdoc_options: []
190
+ require_paths:
191
+ - lib
192
+ required_ruby_version: !ruby/object:Gem::Requirement
193
+ requirements:
194
+ - - ">="
195
+ - !ruby/object:Gem::Version
196
+ version: '0'
197
+ required_rubygems_version: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - ">="
200
+ - !ruby/object:Gem::Version
201
+ version: '0'
202
+ requirements: []
203
+ rubyforge_project:
204
+ rubygems_version: 2.5.1
205
+ signing_key:
206
+ specification_version: 4
207
+ summary: An ActionMailer courier for Hertz.
208
+ test_files: []