simply_notify 0.3.2 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +153 -42
- data/lib/generators/notifier_generator.rb +86 -12
- data/lib/simply_notify/version.rb +1 -1
- data/lib/simply_notify.rb +5 -1
- data/simply_notify.gemspec +4 -2
- metadata +32 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 46c6e557ede2e4b6a9815f391f708f0a146f54c5
|
4
|
+
data.tar.gz: 97c24083c8b87635431a44415cbc4e27ce3f0faf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2b180c9479e94d35d5e83bb9dbbbb01aa83c48cc02b0b68afaf0d553c81e3dbb9ebd5e0f29bf7c85d82e61f61b2d5cbac93073c690d19ecee219dcd6b81fe9b2
|
7
|
+
data.tar.gz: 6395e4da8ab81d55b563eb9be04d2473b64738803eb423051d3bd4e8cedffc72ce600d0586a707e88a29eb9be15c8f3636e2d602dcb1f52069e1ef3cc2ac3cfd
|
data/README.md
CHANGED
@@ -1,9 +1,6 @@
|
|
1
1
|
# SimplyNotify
|
2
2
|
|
3
|
-
simply_notify
|
4
|
-
|
5
|
-
Check out ahoy_email for more information on email analytics --> https://github.com/ankane/ahoy_email
|
6
|
-
|
3
|
+
simply_notify allows users to set preferences on how they want to receive notifications. Notifications are sent to users via email using actionmailer. Users can set their account preferences to receive notifications either in real time or a list of notifications every 24 hours. Ahoy_email is used for email tracking. For more information on gem dependncies of simply_notify, check out the additional information section.
|
7
4
|
|
8
5
|
# Installation
|
9
6
|
|
@@ -21,86 +18,200 @@ Or install it yourself as:
|
|
21
18
|
|
22
19
|
$ gem install simply_notify
|
23
20
|
|
24
|
-
|
25
21
|
# Usage
|
26
22
|
|
27
23
|
###Step 1
|
28
24
|
|
29
|
-
Generate
|
30
|
-
|
31
|
-
rails generate notifier
|
25
|
+
Generate mailer, views, and ahoy_email initializer.
|
32
26
|
|
27
|
+
$ rails generate notifier
|
33
28
|
|
34
29
|
###Step 2
|
35
30
|
|
36
31
|
Generate ahoy_messages table.
|
37
32
|
|
38
|
-
rails generate ahoy_email:install
|
39
|
-
rake db:migrate
|
40
|
-
|
33
|
+
$ rails generate ahoy_email:install
|
34
|
+
$ rake db:migrate
|
41
35
|
|
42
36
|
###Step 3
|
43
37
|
|
44
|
-
|
38
|
+
Generate notifications table.
|
39
|
+
|
40
|
+
$ rails g migration add_notificationFrequency_to_users notifificationFrequency:integer
|
41
|
+
$ rake db:migrate
|
42
|
+
|
43
|
+
notificationFrequency values:
|
44
|
+
nil or 0 = user does not receive notifications via email
|
45
|
+
1 = user receives notifications in real time via email
|
46
|
+
2 = user receives a list of notifications every 24 hours via email
|
47
|
+
|
48
|
+
###Step 4
|
49
|
+
|
50
|
+
Generate notifications model.
|
51
|
+
|
52
|
+
$ rails g model Notification recipient_id:integer creator_id:integer action:string url:string
|
53
|
+
$ rake db:migrate
|
54
|
+
|
55
|
+
###Step 5
|
56
|
+
|
57
|
+
Generate notifications controller.
|
45
58
|
|
46
|
-
|
59
|
+
$ rake g controller notifications
|
47
60
|
|
48
|
-
|
49
|
-
most_recent_id = Assignment.maximum('id')
|
61
|
+
###Step 6
|
50
62
|
|
51
|
-
|
52
|
-
|
63
|
+
Generate config/schedule.rb for cron jobs.
|
64
|
+
|
65
|
+
$ cd /apps/my-great-project
|
66
|
+
$ wheneverize .
|
67
|
+
|
68
|
+
###Step 7
|
53
69
|
|
54
|
-
|
55
|
-
|
56
|
-
|
70
|
+
Add create/mailer to create method in appropriate controllers, such as this example in controllers/assignments_controller.rb.
|
71
|
+
|
72
|
+
if Assignment.where(:id) != nil
|
73
|
+
most_recent_id = Assignment.maximum(:id).next
|
74
|
+
else
|
75
|
+
most_recent_id = 1
|
76
|
+
end
|
77
|
+
url = "http://localhost:3000/posts?assignment_id=#{most_recent_id}"
|
57
78
|
@users = User.all
|
58
79
|
@users.each do |u|
|
59
|
-
|
80
|
+
Notification.create(recipient: u, action: "New Assignment", url: url)
|
81
|
+
if (u.notificationFrequency == 1 || u.admin == true)
|
82
|
+
# use nil as parameter if you want link to be homepage, can also use url
|
83
|
+
# change title of email by changing 'Notifications'
|
84
|
+
Notifier.new_notification(u, nil, 'Notifications').deliver_now
|
85
|
+
end
|
60
86
|
end
|
61
87
|
|
88
|
+
###Step 8
|
62
89
|
|
63
|
-
|
64
|
-
|
65
|
-
Configure SMTP settings and set homepage as absolute url.
|
66
|
-
|
67
|
-
For example, sending emails from a gmail account (added to appropriate environments, such as config/environments/development.rb):
|
90
|
+
Configure SMTP settings for sending from gmail account and set homepage as absolute url (add to appropriate environments, such as config/environments/development.rb).
|
68
91
|
|
69
92
|
# SMTP Config
|
70
|
-
#
|
71
|
-
config.
|
72
|
-
#
|
73
|
-
|
74
|
-
|
75
|
-
}
|
76
|
-
# Set as the host
|
77
|
-
config.action_mailer.default_url_options = {:host => "localhost:3000"}
|
93
|
+
config.absolute_site_url = 'http://localhost:3000/' #Set as your homepage
|
94
|
+
config.action_mailer.default_options = {
|
95
|
+
from: "YOUR_FROM_EMAIL@gmail.com" #Set as your from email
|
96
|
+
}
|
97
|
+
config.action_mailer.default_url_options = {:host => "localhost:3000"} #Set as the host
|
78
98
|
config.action_mailer.delivery_method = :smtp
|
79
99
|
config.action_mailer.perform_deliveries = true
|
80
100
|
config.action_mailer.smtp_settings = {
|
81
101
|
address: 'smtp.gmail.com',
|
82
102
|
port: 587,
|
83
103
|
domain: 'gmail.com',
|
84
|
-
#
|
85
|
-
|
86
|
-
# Set as your password
|
87
|
-
password: 'YOUR_PASSWORD',
|
104
|
+
user_name: 'YOUR_USERNAME@gmail.com', #Set as your email
|
105
|
+
password: 'YOUR_PASSWORD', #Set as your password
|
88
106
|
authentication: 'plain',
|
89
107
|
enable_starttls_auto: true }
|
90
108
|
|
109
|
+
###Step 9
|
110
|
+
|
111
|
+
Edit configure_permitted_parameters method in controllers/application_controller.rb
|
112
|
+
|
113
|
+
def configure_permitted_parameters
|
114
|
+
devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(:name, :email, :password, :password_confirmation, :optout, :nickname, :notificationFrequency) }
|
115
|
+
devise_parameter_sanitizer.for(:account_update) { |u| u.permit(:name, :email, :password, :password_confirmation, :optout, :nickname, :notificationFrequency, :current_password) }
|
116
|
+
end
|
117
|
+
|
118
|
+
###Step 10
|
119
|
+
|
120
|
+
Add radio buttons to view/devise/registrations/edit.html.erb form.
|
121
|
+
|
122
|
+
<div class="field">
|
123
|
+
<h2>Notification Frequency</h2>
|
124
|
+
<p>Select from one of the options below:</p>
|
125
|
+
<%= f.radio_button :notificationFrequency, nil %>
|
126
|
+
<%= f.label("I do not want to receive notifications by email") %></br>
|
127
|
+
<%= f.radio_button :notificationFrequency, 1 %>
|
128
|
+
<%= f.label("I want to receive a single notification by email every time a new notifcation appears on my account") %></br>
|
129
|
+
<%= f.radio_button :notificationFrequency, 2 %>
|
130
|
+
<%= f.label("I want to receive a list of notifications for my account by email every 24 hours") %></br>
|
131
|
+
</div>
|
132
|
+
|
133
|
+
Add radio buttons to view/devise/registrations/new.html.erb form.
|
91
134
|
|
92
|
-
|
135
|
+
<div class="field">
|
136
|
+
<h2>Notification Frequency</h2>
|
137
|
+
<p>Select from one of the options below (this can be changed in your profile preferences at any time):</p>
|
138
|
+
<%= f.radio_button :notificationFrequency, nil %>
|
139
|
+
<%= f.label("I do not want to receive notifications by email") %></br>
|
140
|
+
<%= f.radio_button :notificationFrequency, 1 %>
|
141
|
+
<%= f.label("I want to receive a single notification by email every time a new notifcation appears on my account") %></br>
|
142
|
+
<%= f.radio_button :notificationFrequency, 2 %>
|
143
|
+
<%= f.label("I want to receive a list of notifications for my account by email every 24 hours") %></br>
|
144
|
+
</div>
|
93
145
|
|
94
|
-
|
146
|
+
###Step 11
|
95
147
|
|
96
|
-
|
148
|
+
Setup cron job frequency in config/schedule.rb.
|
97
149
|
|
150
|
+
every 1.day, :at => '8:00 pm' do
|
151
|
+
rake "cron:deliver_emails"
|
152
|
+
end
|
153
|
+
|
154
|
+
Create file as lib/tasks/cron.rake and set rake schedule.
|
155
|
+
|
156
|
+
namespace :cron do
|
157
|
+
desc "Send notification emails every 24 hours"
|
158
|
+
task deliver_emails: :environment do
|
159
|
+
users = User.where(notificationFrequency: 2)
|
160
|
+
users.each do |u|
|
161
|
+
Notifier.new_notification(u, nil, 'Daily Notifications').deliver_now
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
###Step 12
|
167
|
+
|
168
|
+
Add associations to Notification model in model/notification.rb.
|
169
|
+
|
170
|
+
belongs_to :recipient, class_name: "User"
|
171
|
+
belongs_to :creator, class_name: "User"
|
172
|
+
|
173
|
+
Add associations to User model in model/user.rb.
|
174
|
+
|
175
|
+
has_many :notifications
|
176
|
+
|
177
|
+
Add associations to any other models in which notifications are generated in their respective controllers.
|
178
|
+
|
179
|
+
has_many :notifications
|
180
|
+
|
181
|
+
###Step 13
|
182
|
+
|
183
|
+
Add route to config/routes.rb.
|
184
|
+
|
185
|
+
resources :notifications
|
186
|
+
|
187
|
+
###Step 14
|
188
|
+
|
189
|
+
Add to notifications controller.
|
190
|
+
|
191
|
+
cclass NotificationsController < ApplicationController
|
192
|
+
before_action :authenticate_user!
|
193
|
+
|
194
|
+
def index
|
195
|
+
@notifications = Notification.where(recipient: current_user)
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
# Additional Information
|
200
|
+
|
201
|
+
Check out the ahoy_email gem for more information on email analytics --> https://github.com/ankane/ahoy_email
|
202
|
+
|
203
|
+
Check out the whenever gem for more information on cron jobs --> https://github.com/javan/whenever
|
204
|
+
|
205
|
+
Check out the devise gem for more information on user authentication --> https://github.com/plataformatec/devise
|
206
|
+
|
207
|
+
###Important Note for Email Tracking
|
208
|
+
|
209
|
+
If you are using a localhost for development, such as localhost:3000, you will need to allow your system to be reachable from the outside in order to populate data into the ahoy_messages table for opened_at tracking. When the user opens their email, the image tag is fetched from your application server. The system must be reachable or it won't updated ahoy. Values will appear as 'nil' in the table. A service such as pagekite will do the trick!
|
98
210
|
|
99
211
|
# Contributing
|
100
212
|
|
101
213
|
Bug reports and pull requests are welcome on GitHub at https://github.com/tylerlichten/simply_notify.
|
102
214
|
|
103
|
-
|
104
215
|
# License
|
105
216
|
|
106
217
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
@@ -11,28 +11,102 @@ class NotifierGenerator < Rails::Generators::Base
|
|
11
11
|
def create_html_view_file
|
12
12
|
create_file "app/views/notifier/new_notification.html.erb",
|
13
13
|
"<!DOCTYPE html>
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
<html>
|
15
|
+
<head>
|
16
|
+
<meta content='text/html; charset=UTF-8' http-equiv='Content-Type' />
|
17
17
|
</head>
|
18
18
|
<body>
|
19
|
-
<h1>Hello
|
19
|
+
<h1>Hello!</h1>
|
20
20
|
<p>
|
21
|
-
|
22
|
-
Please visit the course website: <%= @url %><br
|
21
|
+
If your account has new notifications, they will be lised below.<br><br>
|
22
|
+
Please visit the course website at: <%= @url %><br>
|
23
|
+
Or you can follow the links provided by the notifications.<br><br>
|
23
24
|
Thanks!<br>
|
24
|
-
|
25
|
-
|
26
|
-
|
25
|
+
|
26
|
+
<% if @recipient.notificationFrequency == 2 && @recipient.admin == false %>
|
27
|
+
<h1>List of Notifications (past 24 hours):</h1>
|
28
|
+
<% i = 0 %>
|
29
|
+
<% @notifications.each do |x| %>
|
30
|
+
<% if x.recipient_id == @recipient.id && x.created_at >= 1.day.ago %>
|
31
|
+
<% i += 1 %>
|
32
|
+
<%= i %>.
|
33
|
+
<%= x.action %> --
|
34
|
+
<%= x.url %>
|
35
|
+
<br>
|
36
|
+
<% end %>
|
37
|
+
<% end %>
|
38
|
+
<% elsif @recipient.notificationFrequency == 1 && @recipient.admin == false %>
|
39
|
+
<h1>New Notification:</h1>
|
40
|
+
<% @notifications.reverse.each do |x| %>
|
41
|
+
<% if x.recipient_id == @recipient.id %>
|
42
|
+
<%= x.action %> --
|
43
|
+
<%= x.url %>
|
44
|
+
<% break %>
|
45
|
+
<% end %>
|
46
|
+
<% end %>
|
47
|
+
<% elsif @recipient.admin == true %>
|
48
|
+
<h1>List of all Notifications (past 24 hours):</h1>
|
49
|
+
<% i = 0 %>
|
50
|
+
<% @notifications.each do |x| %>
|
51
|
+
<% if x.created_at >= 1.day.ago %>
|
52
|
+
<% i += 1 %>
|
53
|
+
<%= i %>. User ID
|
54
|
+
<%= x.recipient_id %> --
|
55
|
+
<%= x.action %> --
|
56
|
+
<%= x.url %>
|
57
|
+
<br>
|
58
|
+
<% end %>
|
59
|
+
<% end %>
|
60
|
+
<% end %>
|
61
|
+
</p>
|
62
|
+
</body>
|
63
|
+
</html>"
|
27
64
|
end
|
28
65
|
|
29
66
|
def create_text_view_file
|
30
67
|
create_file "app/views/notifier/new_notification.text.erb",
|
31
68
|
"Hello,
|
32
|
-
|
33
|
-
Please visit the course website: <%= @url
|
69
|
+
If your account has new notifications, they will be lised below.
|
70
|
+
Please visit the course website at: <%= @url %>
|
71
|
+
Or you can follow the links provided by the notifications.
|
34
72
|
|
35
|
-
Thanks!
|
73
|
+
Thanks!
|
74
|
+
|
75
|
+
<% if @recipient.notificationFrequency == 2 && @recipient.admin == false %>
|
76
|
+
List of Notifications (past 24 hours):
|
77
|
+
<% i = 0 %>
|
78
|
+
<% @notifications.each do |x| %>
|
79
|
+
<% if x.recipient_id == @recipient.id && x.created_at >= 1.day.ago %>
|
80
|
+
<% i += 1 %>
|
81
|
+
<%= i %>.
|
82
|
+
<%= x.action %> --
|
83
|
+
<%= x.url %>
|
84
|
+
\r\n
|
85
|
+
<% end %>
|
86
|
+
<% end %>
|
87
|
+
<% elsif @recipient.notificationFrequency == 1 && @recipient.admin == false %>
|
88
|
+
New Notification:
|
89
|
+
<% @notifications.reverse.each do |x| %>
|
90
|
+
<% if x.recipient_id == @recipient.id %>
|
91
|
+
<%= x.action %> --
|
92
|
+
<%= x.url %>
|
93
|
+
<% break %>
|
94
|
+
<% end %>
|
95
|
+
<% end %>
|
96
|
+
<% elsif @recipient.admin == true %>
|
97
|
+
List of all Notifications (past 24 hours):
|
98
|
+
<% i = 0 %>
|
99
|
+
<% @notifications.each do |x| %>
|
100
|
+
<% if x.created_at >= 1.day.ago %>
|
101
|
+
<% i += 1 %>
|
102
|
+
<%= i %>. User ID
|
103
|
+
<%= x.recipient_id %> --
|
104
|
+
<%= x.action %> --
|
105
|
+
<%= x.url %>
|
106
|
+
\r\n
|
107
|
+
<% end %>
|
108
|
+
<% end %>
|
109
|
+
<% end %>"
|
36
110
|
end
|
37
111
|
|
38
112
|
def create_ahoy_email_initializer
|
data/lib/simply_notify.rb
CHANGED
@@ -10,12 +10,16 @@ class Notifier < ActionMailer::Base
|
|
10
10
|
|
11
11
|
if url.nil?
|
12
12
|
@url = Rails.application.config.absolute_site_url
|
13
|
+
@notifications = Notification.all
|
14
|
+
@recipient = recipient
|
13
15
|
mail(to: recipient.email,
|
14
16
|
subject: subject)
|
15
17
|
else
|
16
18
|
@url = url
|
19
|
+
@notifications = Notification.all
|
20
|
+
@recipient = recipient
|
17
21
|
mail(to: recipient.email,
|
18
22
|
subject: subject)
|
19
|
-
end
|
23
|
+
end
|
20
24
|
end
|
21
25
|
end
|
data/simply_notify.gemspec
CHANGED
@@ -9,8 +9,8 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.authors = ["Tyler Lichten"]
|
10
10
|
spec.email = ["tlich10@gmail.com"]
|
11
11
|
|
12
|
-
spec.summary = %q{Delivers
|
13
|
-
spec.description = %q{Delivers
|
12
|
+
spec.summary = %q{Delivers notifications by email to website users}
|
13
|
+
spec.description = %q{Delivers notifications by email to website users}
|
14
14
|
spec.homepage = ""
|
15
15
|
spec.license = "MIT"
|
16
16
|
|
@@ -23,6 +23,8 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.add_runtime_dependency "thor"
|
24
24
|
spec.add_runtime_dependency "ahoy_email"
|
25
25
|
spec.add_runtime_dependency "ahoy_matey"
|
26
|
+
spec.add_runtime_dependency "whenever"
|
27
|
+
spec.add_runtime_dependency "devise"
|
26
28
|
|
27
29
|
spec.add_development_dependency "bundler", "~> 1.11"
|
28
30
|
spec.add_development_dependency "rake", "~> 10.0"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simply_notify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tyler Lichten
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-04-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionmailer
|
@@ -66,6 +66,34 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: whenever
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
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: devise
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
69
97
|
- !ruby/object:Gem::Dependency
|
70
98
|
name: bundler
|
71
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -122,7 +150,7 @@ dependencies:
|
|
122
150
|
- - ">="
|
123
151
|
- !ruby/object:Gem::Version
|
124
152
|
version: '0'
|
125
|
-
description: Delivers
|
153
|
+
description: Delivers notifications by email to website users
|
126
154
|
email:
|
127
155
|
- tlich10@gmail.com
|
128
156
|
executables: []
|
@@ -165,5 +193,5 @@ rubyforge_project:
|
|
165
193
|
rubygems_version: 2.5.1
|
166
194
|
signing_key:
|
167
195
|
specification_version: 4
|
168
|
-
summary: Delivers
|
196
|
+
summary: Delivers notifications by email to website users
|
169
197
|
test_files: []
|