activity_notification 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/.rubocop.yml +1 -1
- data/CHANGELOG.md +23 -11
- data/Gemfile.lock +52 -40
- data/README.md +177 -14
- data/activity_notification.gemspec +3 -1
- data/app/controllers/activity_notification/subscriptions_controller.rb +48 -2
- data/app/views/activity_notification/optional_targets/default/base/_default.text.erb +10 -0
- data/app/views/activity_notification/optional_targets/default/slack/_default.text.erb +6 -0
- data/app/views/activity_notification/subscriptions/default/_notification_keys.html.erb +19 -0
- data/app/views/activity_notification/subscriptions/default/_subscription.html.erb +32 -3
- data/app/views/activity_notification/subscriptions/default/index.html.erb +4 -0
- data/app/views/activity_notification/subscriptions/default/show.html.erb +5 -0
- data/app/views/activity_notification/subscriptions/default/subscribe_to_optional_target.js.erb +6 -0
- data/app/views/activity_notification/subscriptions/default/unsubscribe_to_optional_target.js.erb +6 -0
- data/gemfiles/Gemfile.rails-4.2.lock +15 -3
- data/gemfiles/Gemfile.rails-5.0.lock +47 -35
- data/lib/activity_notification.rb +1 -0
- data/lib/activity_notification/apis/notification_api.rb +83 -26
- data/lib/activity_notification/apis/subscription_api.rb +93 -8
- data/lib/activity_notification/common.rb +6 -2
- data/lib/activity_notification/helpers/view_helpers.rb +43 -0
- data/lib/activity_notification/models/concerns/notifiable.rb +73 -28
- data/lib/activity_notification/models/concerns/subscriber.rb +34 -7
- data/lib/activity_notification/models/concerns/target.rb +25 -13
- data/lib/activity_notification/models/subscription.rb +13 -2
- data/lib/activity_notification/optional_targets/amazon_sns.rb +42 -0
- data/lib/activity_notification/optional_targets/base.rb +79 -0
- data/lib/activity_notification/optional_targets/slack.rb +33 -0
- data/lib/activity_notification/rails/routes.rb +30 -20
- data/lib/activity_notification/roles/acts_as_notifiable.rb +70 -11
- data/lib/activity_notification/version.rb +1 -1
- data/lib/generators/activity_notification/views_generator.rb +2 -2
- data/lib/generators/templates/migrations/migration.rb +2 -2
- data/spec/concerns/apis/notification_api_spec.rb +97 -0
- data/spec/concerns/apis/subscription_api_spec.rb +206 -41
- data/spec/concerns/common_spec.rb +7 -2
- data/spec/concerns/models/notifiable_spec.rb +88 -2
- data/spec/concerns/models/subscriber_spec.rb +114 -13
- data/spec/concerns/models/target_spec.rb +17 -0
- data/spec/controllers/subscriptions_controller_shared_examples.rb +251 -28
- data/spec/helpers/view_helpers_spec.rb +56 -0
- data/spec/optional_targets/amazon_sns_spec.rb +46 -0
- data/spec/optional_targets/base_spec.rb +43 -0
- data/spec/optional_targets/slack_spec.rb +46 -0
- data/spec/rails_app/app/controllers/comments_controller.rb +1 -0
- data/spec/rails_app/app/models/admin.rb +1 -2
- data/spec/rails_app/app/models/article.rb +2 -3
- data/spec/rails_app/app/models/comment.rb +19 -7
- data/spec/rails_app/app/views/activity_notification/optional_targets/admins/amazon_sns/comment/_default.text.erb +8 -0
- data/spec/rails_app/db/migrate/20160715050420_create_activity_notification_tables.rb +1 -1
- data/spec/rails_app/db/migrate/20160715050433_create_test_tables.rb +2 -0
- data/spec/rails_app/db/schema.rb +3 -1
- data/spec/rails_app/db/seeds.rb +1 -1
- data/spec/rails_app/lib/custom_optional_targets/console_output.rb +13 -0
- data/spec/rails_app/lib/custom_optional_targets/wrong_target.rb +10 -0
- data/spec/roles/acts_as_notifiable_spec.rb +124 -2
- metadata +49 -4
- data/spec/rails_app/app/models/notification.rb +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6a65b89d38b765fb3308dddba4204f205bfb67c2
|
4
|
+
data.tar.gz: b44aeebf83a7718a987e97b3bb62bf3011cd7b39
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: af081cfffaf148d44c78e0fb3fddebfe213cebb970f585ac207c59fa62c96a2b5bd80b1dd720c7da148aa9e75a36556d6bb97ff4291a83bff4fd6905b96648ce
|
7
|
+
data.tar.gz: 815e00820bdf7d1f5f0486c00ee0e2d7eacd73b51d90b1f3ee1d6809cf875c1af3b24e9a44191c4e64f20cab04d1c179ff3814717a54b338e84c5af5dca0b27f
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
@@ -229,7 +229,7 @@ Metrics/CyclomaticComplexity:
|
|
229
229
|
A complexity metric that is strongly correlated to the number
|
230
230
|
of test cases needed to validate a method.
|
231
231
|
Enabled: true
|
232
|
-
Max:
|
232
|
+
Max: 9
|
233
233
|
|
234
234
|
Metrics/LineLength:
|
235
235
|
Description: 'Limit lines to 80 characters.'
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,15 @@
|
|
1
|
+
## 1.2.0 / 2017-01-06
|
2
|
+
[Full Changelog](http://github.com/simukappu/activity_notification/compare/v1.1.0...v1.2.0)
|
3
|
+
|
4
|
+
Enhancements:
|
5
|
+
|
6
|
+
* Add optional target function
|
7
|
+
* Optional target development framework
|
8
|
+
* Subscription management for optional targets
|
9
|
+
* Amazon SNS client as default optional target implementation
|
10
|
+
* Slack client as default optional target implementation
|
11
|
+
* Add `:restrict_with_*` and `:update_group_and_*` options to `:dependent_notifications` of `acts_as_notifiable`
|
12
|
+
|
1
13
|
## 1.1.0 / 2016-12-18
|
2
14
|
[Full Changelog](http://github.com/simukappu/activity_notification/compare/v1.0.2...v1.1.0)
|
3
15
|
|
@@ -5,18 +17,18 @@ Enhancements:
|
|
5
17
|
|
6
18
|
* Add subscription management framework
|
7
19
|
* Subscription management model and API
|
8
|
-
* Default subscription
|
9
|
-
* Add Subscriber role configuration to Target role
|
10
|
-
* Add as_latest_group_member option to batch mailer API
|
11
|
-
* Add group_expiry_delay option to notification API
|
20
|
+
* Default subscription controllers, routing and views
|
21
|
+
* Add `Subscriber` role configuration to `Target` role
|
22
|
+
* Add `:as_latest_group_member` option to batch mailer API
|
23
|
+
* Add `:group_expiry_delay` option to notification API
|
12
24
|
|
13
25
|
Bug Fixes:
|
14
26
|
|
15
|
-
* Fix unserializable error in Target#send_batch_unopened_notification_email since unnecessary options are passed to mailer
|
27
|
+
* Fix unserializable error in `Target#send_batch_unopened_notification_email` since unnecessary options are passed to mailer
|
16
28
|
|
17
29
|
Breaking Changes:
|
18
30
|
|
19
|
-
* Remove notifiable_type from the argument of overriden method or configured lambda function
|
31
|
+
* Remove `notifiable_type` from the argument of overriden method or configured lambda function with `:batch_email_allowed` option in `acts_as_target` role
|
20
32
|
|
21
33
|
## 1.0.2 / 2016-11-14
|
22
34
|
[Full Changelog](http://github.com/simukappu/activity_notification/compare/v1.0.1...v1.0.2)
|
@@ -33,15 +45,15 @@ Enhancements:
|
|
33
45
|
* Add function to send batch email notification
|
34
46
|
* Batch mailer API
|
35
47
|
* Default batch notification email templates
|
36
|
-
* Target role configuration for batch email notification
|
48
|
+
* `Target` role configuration for batch email notification
|
37
49
|
* Improve target API
|
38
50
|
* Add `:reverse`, `:with_group_members`, `:as_latest_group_member` and `:custom_filter` options to API loading notification index
|
39
|
-
* Add methods to get notifications for specified target type grouped by targets like `notification_index_map`
|
51
|
+
* Add methods to get notifications for specified target type grouped by targets like `Target#notification_index_map`
|
40
52
|
* Arrange default notification email view templates
|
41
53
|
|
42
54
|
Breaking Changes:
|
43
55
|
|
44
|
-
* Use instance
|
56
|
+
* Use instance variable `@notification.notifiable` instead of `@notifiable` in notification email templates
|
45
57
|
|
46
58
|
## 1.0.0 / 2016-10-06
|
47
59
|
[Full Changelog](http://github.com/simukappu/activity_notification/compare/v0.0.10...v1.0.0)
|
@@ -63,7 +75,7 @@ Enhancements:
|
|
63
75
|
|
64
76
|
Breaking Changes:
|
65
77
|
|
66
|
-
* Rename `opened_limit` configuration parameter to `opened_index_limit`
|
78
|
+
* Rename `config.opened_limit` configuration parameter to `config.opened_index_limit`
|
67
79
|
* http://github.com/simukappu/activity_notification/commit/591e53cd8977220f819c11cd702503fc72dd1fd1
|
68
80
|
|
69
81
|
## 0.0.10 / 2016-09-11
|
@@ -72,7 +84,7 @@ Breaking Changes:
|
|
72
84
|
Enhancements:
|
73
85
|
|
74
86
|
* Improve controller action and notification API
|
75
|
-
* Add filter options to `open_all` action and `open_all_of` method
|
87
|
+
* Add filter options to `NotificationsController#open_all` action and `Target#open_all_of` method
|
76
88
|
* Add source documentation with YARD
|
77
89
|
* Support rails 5.0 and update gem dependency
|
78
90
|
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
activity_notification (1.
|
4
|
+
activity_notification (1.2.0)
|
5
5
|
activerecord (>= 4.2.0)
|
6
6
|
i18n (>= 0.5.0)
|
7
7
|
jquery-rails (>= 3.1.1)
|
@@ -10,39 +10,39 @@ PATH
|
|
10
10
|
GEM
|
11
11
|
remote: https://rubygems.org/
|
12
12
|
specs:
|
13
|
-
actioncable (5.0.
|
14
|
-
actionpack (= 5.0.
|
13
|
+
actioncable (5.0.1)
|
14
|
+
actionpack (= 5.0.1)
|
15
15
|
nio4r (~> 1.2)
|
16
16
|
websocket-driver (~> 0.6.1)
|
17
|
-
actionmailer (5.0.
|
18
|
-
actionpack (= 5.0.
|
19
|
-
actionview (= 5.0.
|
20
|
-
activejob (= 5.0.
|
17
|
+
actionmailer (5.0.1)
|
18
|
+
actionpack (= 5.0.1)
|
19
|
+
actionview (= 5.0.1)
|
20
|
+
activejob (= 5.0.1)
|
21
21
|
mail (~> 2.5, >= 2.5.4)
|
22
22
|
rails-dom-testing (~> 2.0)
|
23
|
-
actionpack (5.0.
|
24
|
-
actionview (= 5.0.
|
25
|
-
activesupport (= 5.0.
|
23
|
+
actionpack (5.0.1)
|
24
|
+
actionview (= 5.0.1)
|
25
|
+
activesupport (= 5.0.1)
|
26
26
|
rack (~> 2.0)
|
27
27
|
rack-test (~> 0.6.3)
|
28
28
|
rails-dom-testing (~> 2.0)
|
29
29
|
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
30
|
-
actionview (5.0.
|
31
|
-
activesupport (= 5.0.
|
30
|
+
actionview (5.0.1)
|
31
|
+
activesupport (= 5.0.1)
|
32
32
|
builder (~> 3.1)
|
33
33
|
erubis (~> 2.7.0)
|
34
34
|
rails-dom-testing (~> 2.0)
|
35
35
|
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
36
|
-
activejob (5.0.
|
37
|
-
activesupport (= 5.0.
|
36
|
+
activejob (5.0.1)
|
37
|
+
activesupport (= 5.0.1)
|
38
38
|
globalid (>= 0.3.6)
|
39
|
-
activemodel (5.0.
|
40
|
-
activesupport (= 5.0.
|
41
|
-
activerecord (5.0.
|
42
|
-
activemodel (= 5.0.
|
43
|
-
activesupport (= 5.0.
|
39
|
+
activemodel (5.0.1)
|
40
|
+
activesupport (= 5.0.1)
|
41
|
+
activerecord (5.0.1)
|
42
|
+
activemodel (= 5.0.1)
|
43
|
+
activesupport (= 5.0.1)
|
44
44
|
arel (~> 7.0)
|
45
|
-
activesupport (5.0.
|
45
|
+
activesupport (5.0.1)
|
46
46
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
47
47
|
i18n (~> 0.7)
|
48
48
|
minitest (~> 5.1)
|
@@ -52,12 +52,20 @@ GEM
|
|
52
52
|
railties (>= 3.0)
|
53
53
|
rspec-rails (>= 2.2)
|
54
54
|
arel (7.1.4)
|
55
|
+
aws-sdk (2.6.43)
|
56
|
+
aws-sdk-resources (= 2.6.43)
|
57
|
+
aws-sdk-core (2.6.43)
|
58
|
+
aws-sigv4 (~> 1.0)
|
59
|
+
jmespath (~> 1.0)
|
60
|
+
aws-sdk-resources (2.6.43)
|
61
|
+
aws-sdk-core (= 2.6.43)
|
62
|
+
aws-sigv4 (1.0.0)
|
55
63
|
bcrypt (3.1.11)
|
56
64
|
builder (3.2.2)
|
57
|
-
bullet (5.
|
65
|
+
bullet (5.5.0)
|
58
66
|
activesupport (>= 3.0.0)
|
59
67
|
uniform_notifier (~> 1.10.0)
|
60
|
-
concurrent-ruby (1.0.
|
68
|
+
concurrent-ruby (1.0.4)
|
61
69
|
coveralls (0.8.17)
|
62
70
|
json (>= 1.8, < 3)
|
63
71
|
simplecov (~> 0.12.0)
|
@@ -81,7 +89,8 @@ GEM
|
|
81
89
|
globalid (0.3.7)
|
82
90
|
activesupport (>= 4.1.0)
|
83
91
|
i18n (0.7.0)
|
84
|
-
|
92
|
+
jmespath (1.3.1)
|
93
|
+
jquery-rails (4.2.2)
|
85
94
|
rails-dom-testing (>= 1, < 3)
|
86
95
|
railties (>= 4.2.0)
|
87
96
|
thor (>= 0.14, < 2.0)
|
@@ -97,36 +106,36 @@ GEM
|
|
97
106
|
mini_portile2 (2.1.0)
|
98
107
|
minitest (5.10.1)
|
99
108
|
nio4r (1.2.1)
|
100
|
-
nokogiri (1.
|
109
|
+
nokogiri (1.7.0)
|
101
110
|
mini_portile2 (~> 2.1.0)
|
102
111
|
orm_adapter (0.5.0)
|
103
112
|
rack (2.0.1)
|
104
113
|
rack-test (0.6.3)
|
105
114
|
rack (>= 1.0)
|
106
|
-
rails (5.0.
|
107
|
-
actioncable (= 5.0.
|
108
|
-
actionmailer (= 5.0.
|
109
|
-
actionpack (= 5.0.
|
110
|
-
actionview (= 5.0.
|
111
|
-
activejob (= 5.0.
|
112
|
-
activemodel (= 5.0.
|
113
|
-
activerecord (= 5.0.
|
114
|
-
activesupport (= 5.0.
|
115
|
+
rails (5.0.1)
|
116
|
+
actioncable (= 5.0.1)
|
117
|
+
actionmailer (= 5.0.1)
|
118
|
+
actionpack (= 5.0.1)
|
119
|
+
actionview (= 5.0.1)
|
120
|
+
activejob (= 5.0.1)
|
121
|
+
activemodel (= 5.0.1)
|
122
|
+
activerecord (= 5.0.1)
|
123
|
+
activesupport (= 5.0.1)
|
115
124
|
bundler (>= 1.3.0, < 2.0)
|
116
|
-
railties (= 5.0.
|
125
|
+
railties (= 5.0.1)
|
117
126
|
sprockets-rails (>= 2.0.0)
|
118
127
|
rails-controller-testing (1.0.1)
|
119
128
|
actionpack (~> 5.x)
|
120
129
|
actionview (~> 5.x)
|
121
130
|
activesupport (~> 5.x)
|
122
|
-
rails-dom-testing (2.0.
|
131
|
+
rails-dom-testing (2.0.2)
|
123
132
|
activesupport (>= 4.2.0, < 6.0)
|
124
|
-
nokogiri (~> 1.6
|
133
|
+
nokogiri (~> 1.6)
|
125
134
|
rails-html-sanitizer (1.0.3)
|
126
135
|
loofah (~> 2.0)
|
127
|
-
railties (5.0.
|
128
|
-
actionpack (= 5.0.
|
129
|
-
activesupport (= 5.0.
|
136
|
+
railties (5.0.1)
|
137
|
+
actionpack (= 5.0.1)
|
138
|
+
activesupport (= 5.0.1)
|
130
139
|
method_source
|
131
140
|
rake (>= 0.8.7)
|
132
141
|
thor (>= 0.18.1, < 2.0)
|
@@ -155,7 +164,8 @@ GEM
|
|
155
164
|
json (>= 1.8, < 3)
|
156
165
|
simplecov-html (~> 0.10.0)
|
157
166
|
simplecov-html (0.10.0)
|
158
|
-
|
167
|
+
slack-notifier (1.5.1)
|
168
|
+
sprockets (3.7.1)
|
159
169
|
concurrent-ruby (~> 1.0)
|
160
170
|
rack (> 1, < 3)
|
161
171
|
sprockets-rails (3.2.0)
|
@@ -187,6 +197,7 @@ PLATFORMS
|
|
187
197
|
DEPENDENCIES
|
188
198
|
activity_notification!
|
189
199
|
ammeter
|
200
|
+
aws-sdk (~> 2)
|
190
201
|
bullet
|
191
202
|
coveralls
|
192
203
|
devise (~> 4.2.0)
|
@@ -195,6 +206,7 @@ DEPENDENCIES
|
|
195
206
|
rails-controller-testing
|
196
207
|
rspec-rails (~> 3.5.1)
|
197
208
|
simplecov (~> 0.12.0)
|
209
|
+
slack-notifier (~> 1.5.1)
|
198
210
|
sqlite3 (~> 1.3.12)
|
199
211
|
timecop
|
200
212
|
yard (~> 0.9.5)
|
data/README.md
CHANGED
@@ -21,20 +21,24 @@
|
|
21
21
|
* Notification views (presentation of notifications)
|
22
22
|
* Grouping notifications (grouping like `"Kevin and 7 other users posted comments to this article"`)
|
23
23
|
* Email notification
|
24
|
-
* Batch email notification
|
25
|
-
* Subscription management
|
24
|
+
* Batch email notification (event driven or periodical email notification, daily or weekly etc)
|
25
|
+
* Subscription management (opt-in or opt-out by each target and notification type)
|
26
26
|
* Integration with [Devise](https://github.com/plataformatec/devise) authentication
|
27
|
+
* Optional notification targets (Configurable optional notification targets like Amazon SNS, Slack, SMS and so on)
|
27
28
|
|
28
|
-
### Notification index
|
29
|
-
<kbd>![
|
29
|
+
### Notification index and plugin notifications
|
30
|
+
<kbd>![plugin-notifications-image](https://raw.githubusercontent.com/simukappu/activity_notification/images/activity_notification_plugin_focus_with_subscription.png)</kbd>
|
30
31
|
|
31
|
-
|
32
|
-
<kbd>![plugin-notifications](https://raw.githubusercontent.com/simukappu/activity_notification/images/activity_notification_plugin_focus_with_subscription.png)</kbd>
|
32
|
+
`activity_notification` deeply uses [PublicActivity](https://github.com/pokonski/public_activity) as reference in presentation layer.
|
33
33
|
|
34
|
-
### Subscription management
|
35
|
-
<kbd>![subscription-management](https://raw.githubusercontent.com/simukappu/activity_notification/images/
|
34
|
+
### Subscription management of notifications
|
35
|
+
<kbd>![subscription-management-image](https://raw.githubusercontent.com/simukappu/activity_notification/images/activity_notification_subscription_management_with_optional_targets.png)</kbd>
|
36
36
|
|
37
|
-
|
37
|
+
### Amazon SNS as optional notification target
|
38
|
+
<kbd>![optional-target-amazon-sns-email-image](https://raw.githubusercontent.com/simukappu/activity_notification/images/activity_notification_optional_target_amazon_sns_email.png)</kbd>
|
39
|
+
|
40
|
+
### Slack as optional notification target
|
41
|
+
<kbd>![optional-target-slack-image](https://raw.githubusercontent.com/simukappu/activity_notification/images/activity_notification_optional_target_slack.png)</kbd>
|
38
42
|
|
39
43
|
|
40
44
|
## Table of contents
|
@@ -70,6 +74,12 @@
|
|
70
74
|
2. [Manage subscriptions](#manage-subscriptions)
|
71
75
|
3. [Customize Subscriptions](#customize-subscriptions)
|
72
76
|
5. [Integration with Devise](#integration-with-devise)
|
77
|
+
6. [Optional notification targets](#optional-notification-targets)
|
78
|
+
1. [Setup optional targets](#setup-optional-targets)
|
79
|
+
2. [Customizing message format](#Customizing-message-format)
|
80
|
+
3. [Amazon SNS as optional target](#amazon-sns-as-optional-target)
|
81
|
+
4. [Slack as optional target](#slack-as-optional-target)
|
82
|
+
5. [Developing custom optional targets](#developing-custom-optional-targets)
|
73
83
|
4. [Testing](#testing)
|
74
84
|
5. [Documentation](#documentation)
|
75
85
|
6. **[Common examples](#common-examples)**
|
@@ -337,7 +347,7 @@ Sometimes, it's desirable to pass additional local variables to partials. It can
|
|
337
347
|
|
338
348
|
`activity_notification` looks for views in `app/views/activity_notification/notifications/:target`.
|
339
349
|
|
340
|
-
For example, if you have
|
350
|
+
For example, if you have a notification with `:key` set to `"notification.comment.reply"` and rendered it with `:target` set to `:users`, the gem will look for a partial in `app/views/activity_notification/notifications/users/comment/_reply.html.(|erb|haml|slim|something_else)`.
|
341
351
|
|
342
352
|
*Hint*: the `"notification."` prefix in `:key` is completely optional, you can skip it in your projects or use this prefix only to make namespace.
|
343
353
|
|
@@ -406,7 +416,7 @@ This structure is valid for notifications with keys `"notification.comment.reply
|
|
406
416
|
|
407
417
|
#### Setup mailer
|
408
418
|
|
409
|
-
|
419
|
+
Set up SMTP server configuration for `ActionMailer`. Then, you need to set up the default URL options for the `activity_notification` mailer in each environment. Here is a possible configuration for `config/environments/development.rb`:
|
410
420
|
|
411
421
|
```ruby
|
412
422
|
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
|
@@ -450,7 +460,7 @@ end
|
|
450
460
|
|
451
461
|
#### Email templates
|
452
462
|
|
453
|
-
`activity_notification` will look for email template in the same way as notification views. For example, if you have
|
463
|
+
`activity_notification` will look for email template in the same way as notification views. For example, if you have a notification with `:key` set to `"notification.comment.reply"` and target_type `users`, the gem will look for a partial in `app/views/activity_notification/mailer/users/comment/_reply.html.(|erb|haml|slim|something_else)`.
|
454
464
|
|
455
465
|
If this template is missing, the gem will look for a partial in `default` as the target type which means `activity_notification/mailer/default/_default.html.(|erb|haml|slim|something_else)`.
|
456
466
|
|
@@ -473,7 +483,7 @@ notification:
|
|
473
483
|
|
474
484
|
#### Setup batch mailer
|
475
485
|
|
476
|
-
|
486
|
+
Set up SMTP server configuration for `ActionMailer` and the default URL options for the `activity_notification` mailer in each environment.
|
477
487
|
|
478
488
|
Batch email notification is disabled as default. You can configure to enable email notification in initializer `activity_notification.rb` like single email notification.
|
479
489
|
|
@@ -574,7 +584,7 @@ notification:
|
|
574
584
|
mail_subject: 'New comment to your article'
|
575
585
|
```
|
576
586
|
|
577
|
-
Then, you will see `Kevin and 7 other users
|
587
|
+
Then, you will see `Kevin and 7 other users posted 10 comments to your article"`.
|
578
588
|
|
579
589
|
|
580
590
|
### Subscription management
|
@@ -738,6 +748,159 @@ end
|
|
738
748
|
In this example `activity_notification` will confirm the `user` who `admin` belongs to with authenticated user by devise.
|
739
749
|
|
740
750
|
|
751
|
+
### Optional notification targets
|
752
|
+
|
753
|
+
`activity_notification` supports configurable optional notification targets like Amazon SNS, Slack, SMS and so on.
|
754
|
+
|
755
|
+
#### Setup optional targets
|
756
|
+
|
757
|
+
`activity_notification` provides default optional target implementation for Amazon SNS and Slack.
|
758
|
+
You can develop any optional target classes which extends `ActivityNotification::OptionalTarget::Base`, and configure them to notifiable model by `acts_as_notifiable` like this.
|
759
|
+
|
760
|
+
```ruby
|
761
|
+
class Comment < ActiveRecord::Base
|
762
|
+
belongs_to :article
|
763
|
+
belongs_to :user
|
764
|
+
|
765
|
+
require 'activity_notification/optional_targets/amazon_sns'
|
766
|
+
require 'activity_notification/optional_targets/slack'
|
767
|
+
require 'custom_optional_targets/console_output'
|
768
|
+
acts_as_notifiable :admins, targets: Admin.all,
|
769
|
+
notifiable_path: :article_notifiable_path,
|
770
|
+
# Set optional target implementation class and initializing parameters
|
771
|
+
optional_targets: {
|
772
|
+
ActivityNotification::OptionalTarget::AmazonSNS => { topic_arn: 'arn:aws:sns:XXXXX:XXXXXXXXXXXX:XXXXX' },
|
773
|
+
ActivityNotification::OptionalTarget::Slack => {
|
774
|
+
webhook_url: 'https://hooks.slack.com/services/XXXXXXXXX/XXXXXXXXX/XXXXXXXXXXXXXXXXXXXXXXXX',
|
775
|
+
slack_name: :slack_name, channel: 'activity_notification', username: 'ActivityNotification', icon_emoji: ":ghost:"
|
776
|
+
},
|
777
|
+
CustomOptionalTarget::ConsoleOutput => {}
|
778
|
+
}
|
779
|
+
|
780
|
+
def article_notifiable_path
|
781
|
+
article_path(article)
|
782
|
+
end
|
783
|
+
end
|
784
|
+
```
|
785
|
+
|
786
|
+
Write `require` statement for optional target implementation classes and set them with initializing parameters to `acts_as_notifiable`.
|
787
|
+
`activity_notification` will publish all notifications of those targets and notifiables to optional targets.
|
788
|
+
|
789
|
+
#### Customizing message format
|
790
|
+
|
791
|
+
Optional targets prepare publishing messages from notification instance using view template like rendering notifications.
|
792
|
+
As default, all optional targets use `app/views/activity_notification/optional_targets/default/base/_default.text.erb`.
|
793
|
+
You can customize this template by creating `app/views/activity_notification/optional_targets/<target_class_name>/<optional_target_class_name>/<notification_key>.text.(|erb|haml|slim|something_else)`.
|
794
|
+
For example, if you have a notification for `:users` target with `:key` set to `"notification.comment.reply"` and `ActivityNotification::OptionalTarget::AmazonSNS` optional target is configured, the gem will look for a partial in `app/views/activity_notification/optional_targets/users/amazon_sns/comment/_reply.text.erb`.
|
795
|
+
The gem will also look for templates whose `<target_class_name>` is `default`, `<optional_target_class_name>` is `base` or `<notification_key>` is `default`, which means `app/views/activity_notification/optional_targets/users/amazon_sns/_default.text.erb`, `app/views/activity_notification/optional_targets/users/base/_default.text.erb`, `app/views/activity_notification/optional_targets/default/amazon_sns/_default.text.erb` and `app/views/activity_notification/optional_targets/default/base/_default.text.erb`.
|
796
|
+
|
797
|
+
#### Amazon SNS as optional target
|
798
|
+
|
799
|
+
`activity_notification` provides `ActivityNotification::OptionalTarget::AmazonSNS` as default optional target implementation for Amazon SNS.
|
800
|
+
|
801
|
+
First, add `aws-sdk` gem to your Gemfile and set AWS Credentials for SDK (See [Configuring the AWS SDK for Ruby](https://docs.aws.amazon.com/sdk-for-ruby/v2/developer-guide/setup-config.html)).
|
802
|
+
|
803
|
+
```ruby
|
804
|
+
gem 'aws-sdk', '~> 2'
|
805
|
+
```
|
806
|
+
|
807
|
+
```ruby
|
808
|
+
require 'aws-sdk'
|
809
|
+
Aws.config.update(
|
810
|
+
region: 'your_region',
|
811
|
+
credentials: Aws::Credentials.new('your_access_key_id', 'your_secret_access_key')
|
812
|
+
)
|
813
|
+
```
|
814
|
+
|
815
|
+
Then, write `require 'activity_notification/optional_targets/amazon_sns'` statement in your notifiable model and set `ActivityNotification::OptionalTarget::AmazonSNS` to `acts_as_notifiable` with `:topic_arn`, `:target_arn` or `:phone_number` initializing parameters.
|
816
|
+
Any other options for `Aws::SNS::Client.new` are available as initializing parameters. See [API Reference of Class: Aws::SNS::Client](http://docs.aws.amazon.com/sdkforruby/api/Aws/SNS/Client.html) for more details.
|
817
|
+
|
818
|
+
```ruby
|
819
|
+
class Comment < ActiveRecord::Base
|
820
|
+
require 'activity_notification/optional_targets/amazon_sns'
|
821
|
+
acts_as_notifiable :admins, targets: Admin.all,
|
822
|
+
optional_targets: {
|
823
|
+
ActivityNotification::OptionalTarget::AmazonSNS => { topic_arn: 'arn:aws:sns:XXXXX:XXXXXXXXXXXX:XXXXX' }
|
824
|
+
}
|
825
|
+
end
|
826
|
+
```
|
827
|
+
|
828
|
+
#### Slack as optional target
|
829
|
+
|
830
|
+
`activity_notification` provides `ActivityNotification::OptionalTarget::Slack` as default optional target implementation for Slack.
|
831
|
+
|
832
|
+
First, add `slack-notifier` gem to your Gemfile and create Incoming WebHooks in Slack (See [Incoming WebHooks](https://wemakejp.slack.com/apps/A0F7XDUAZ-incoming-webhooks)).
|
833
|
+
|
834
|
+
```ruby
|
835
|
+
gem 'slack-notifier'
|
836
|
+
```
|
837
|
+
|
838
|
+
Then, write `require 'activity_notification/optional_targets/slack'` statement in your notifiable model and set `ActivityNotification::OptionalTarget::Slack` to `acts_as_notifiable` with `:webhook_url` and `:slack_name` initializing parameters. `:webhook_url` is created WebHook URL and required, `:slack_name` is target's slack user name as String value, symbol method name or lambda function and is optional.
|
839
|
+
Any other options for `Slack::Notifier.new` are available as initializing parameters. See [Github slack-notifier](https://github.com/stevenosloan/slack-notifier) and [API Reference of Class: Slack::Notifier](http://www.rubydoc.info/gems/slack-notifier/1.5.1/Slack/Notifier) for more details.
|
840
|
+
|
841
|
+
```ruby
|
842
|
+
class Comment < ActiveRecord::Base
|
843
|
+
require 'activity_notification/optional_targets/slack'
|
844
|
+
acts_as_notifiable :admins, targets: Admin.all,
|
845
|
+
optional_targets: {
|
846
|
+
ActivityNotification::OptionalTarget::Slack => {
|
847
|
+
webhook_url: 'https://hooks.slack.com/services/XXXXXXXXX/XXXXXXXXX/XXXXXXXXXXXXXXXXXXXXXXXX',
|
848
|
+
slack_name: :slack_name, channel: 'activity_notification', username: 'ActivityNotification', icon_emoji: ":ghost:"
|
849
|
+
}
|
850
|
+
}
|
851
|
+
end
|
852
|
+
```
|
853
|
+
|
854
|
+
#### Developing custom optional targets
|
855
|
+
|
856
|
+
You can develop any custom optional targets.
|
857
|
+
Custom optional target class must extend `ActivityNotification::OptionalTarget::Base` and override `initialize_target` and `notify` method.
|
858
|
+
You can use `render_notification_message` method to prepare message from notification instance using view template.
|
859
|
+
|
860
|
+
For example, create `lib/custom_optional_targets/amazon_sns.rb` as follows:
|
861
|
+
|
862
|
+
```ruby
|
863
|
+
module CustomOptionalTarget
|
864
|
+
# Custom optional target implementation for mobile push notification or SMS using Amazon SNS.
|
865
|
+
class AmazonSNS < ActivityNotification::OptionalTarget::Base
|
866
|
+
require 'aws-sdk'
|
867
|
+
|
868
|
+
# Initialize method to prepare Aws::SNS::Client
|
869
|
+
def initialize_target(options = {})
|
870
|
+
@topic_arn = options.delete(:topic_arn)
|
871
|
+
@target_arn = options.delete(:target_arn)
|
872
|
+
@phone_number = options.delete(:phone_number)
|
873
|
+
@sns_client = Aws::SNS::Client.new(options)
|
874
|
+
end
|
875
|
+
|
876
|
+
# Publishes notification message to Amazon SNS
|
877
|
+
def notify(notification, options = {})
|
878
|
+
@sns_client.publish(
|
879
|
+
topic_arn: notification.target.resolve_value(options.delete(:topic_arn) || @topic_arn),
|
880
|
+
target_arn: notification.target.resolve_value(options.delete(:target_arn) || @target_arn),
|
881
|
+
phone_number: notification.target.resolve_value(options.delete(:phone_number) || @phone_number),
|
882
|
+
message: render_notification_message(notification, options)
|
883
|
+
)
|
884
|
+
end
|
885
|
+
end
|
886
|
+
end
|
887
|
+
```
|
888
|
+
|
889
|
+
Then, you can configure them to notifiable model by `acts_as_notifiable` like this.
|
890
|
+
|
891
|
+
```ruby
|
892
|
+
class Comment < ActiveRecord::Base
|
893
|
+
require 'custom_optional_targets/amazon_sns'
|
894
|
+
acts_as_notifiable :admins, targets: Admin.all,
|
895
|
+
optional_targets: {
|
896
|
+
CustomOptionalTarget::AmazonSNS => { topic_arn: 'arn:aws:sns:XXXXX:XXXXXXXXXXXX:XXXXX' }
|
897
|
+
}
|
898
|
+
end
|
899
|
+
```
|
900
|
+
|
901
|
+
`acts_as_notifiable` creates optional target instances and calls `initialize_target` method with initializing parameters.
|
902
|
+
|
903
|
+
|
741
904
|
## Testing
|
742
905
|
|
743
906
|
### Testing your application
|