acts_as_notifiable_redmine 0.1 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6fb1c74cb7172a58728585e51cf267caf71195cc
4
- data.tar.gz: 11352631b7152326cd2fddd6b87e919f80416cf0
3
+ metadata.gz: e5726f65e38236c68fc89eaee4993903cd29fa9c
4
+ data.tar.gz: 276818b7c41e1e55160b417b15a5745ef4b33b8f
5
5
  SHA512:
6
- metadata.gz: 64a1b2ec08bc40ab7ac141ac4ab8053827549dbb69d6cb8f4080d74ce22162e6c87197ec1968ea9215f34c1925c74cc7d6b70fa7e9f888a90936fa77c2ad7ef8
7
- data.tar.gz: 8abaed0ab9aef03e7e626e0327e57be5c425697032c3293b247185fb233aafcca43650f88df3c1bfd4689ef3a683ae0c0c634f0c19c53939db28445ff2c9e8e9
6
+ metadata.gz: a962403064e8c8c7e2923587fdd66fe953eaf25940a50259d9f921dea8c6328cd14826356bcb41d5146af04399afefef4ad6607dbe9df4a61e5006bb0af0a1bb
7
+ data.tar.gz: 9fd8bc029266aad45630b02964efad6faf57e361b121593d660457720c11e3357edff6ea1bf15f59220974eea21110a4ac5093164bed42fcf06bece691a8c1e2
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ *.gem
data/README.md CHANGED
@@ -1,11 +1,10 @@
1
1
  ### A gem which makes notifying your Redmine instance easy ;)
2
2
 
3
- This gem is designed to integrate the [Pusher Notification System](http://pusher.com) in Redmine.
4
-
5
- It must be used with [Redmine Pusher Notifications](https://github.com/jbox-web/redmine_pusher_notifications).
3
+ This gem is designed to integrate the [Pusher Notification System](http://pusher.com) in Redmine but you may use it for other Rails apps ;)
6
4
 
7
5
  ## Code status
8
6
 
7
+ * [![Gem Version](https://badge.fury.io/rb/acts_as_notifiable_redmine.svg)](http://badge.fury.io/rb/acts_as_notifiable_redmine)
9
8
  * [![Code Climate](https://codeclimate.com/github/jbox-web/acts_as_notifiable_redmine.png)](https://codeclimate.com/github/jbox-web/acts_as_notifiable_redmine)
10
9
 
11
10
  ## Requirements
@@ -17,6 +16,129 @@ It must be used with [Redmine Pusher Notifications](https://github.com/jbox-web/
17
16
 
18
17
  gem install acts_as_notifiable_redmine
19
18
 
19
+ ## Example usage
20
+ First you need to configure you Pusher account :
21
+
22
+ ActsAsNotifiableRedmine::Notifications.register_courier :pusher do
23
+ app_id 'xxxxx'
24
+ key 'xxxxxxxxxxxxxxxxxxxx'
25
+ secret 'xxxxxxxxxxxxxxxxxxxx'
26
+ encrypted true
27
+ end
28
+
29
+ Then you need to register your channels and events : each channel can have many events.
30
+ It may also have an optional ```target``` parameter which can be a string or a Proc.
31
+
32
+ ActsAsNotifiableRedmine::Notifications.register_channel :channel_test do
33
+ target Proc.new { User.current.login }
34
+ event :event1, :sticky => true
35
+ event :event2, :sticky => false
36
+ event :event3
37
+ end
38
+
39
+ ActsAsNotifiableRedmine::Notifications.register_channel :broadcast do
40
+ target 'broadcast'
41
+ event :event1, :sticky => true
42
+ event :event2, :sticky => false
43
+ event :event3
44
+ end
45
+
46
+ Once done, you can get the registered channels and events with :
47
+
48
+ ActsAsNotifiableRedmine::Notifications.channels.each do |name, channel|
49
+ puts "#############"
50
+ puts "Channel :"
51
+ puts "name : #{channel.name}"
52
+ puts "identifier : #{channel.identifier}"
53
+ puts "token : #{channel.token}"
54
+ puts "events :"
55
+ channel.events.each do |event|
56
+ puts " * #{event.name} (sticky : #{event.sticky?})"
57
+ end
58
+ puts ""
59
+ end
60
+
61
+ To get the Pusher parameters :
62
+
63
+ courier = ActsAsNotifiableRedmine::Notifications.courier
64
+
65
+ puts "#############"
66
+ puts "Courier :"
67
+ puts "name : #{courier.name}"
68
+ puts "app_id : #{courier.app_id}"
69
+ puts "key : #{courier.key}"
70
+ puts "secret : #{courier.secret}"
71
+ puts "encrypted : #{courier.encrypted}"
72
+
73
+ Finally to send notifications :
74
+
75
+ ActsAsNotifiableRedmine::Notifications.send_notification([channel.token], event.name, {:title => 'Hello!', :message => 'This is a test message !'})
76
+
77
+ **Note** : The logic to determine wether or not to send a notification is let to the developer. You can easily do this with callbacks :
78
+
79
+ class Comment < ActiveRecord::Base
80
+ has_many :watchers
81
+ after_create :send_notification
82
+
83
+ private
84
+
85
+ def send_notification
86
+ channels = []
87
+ watchers.each do |watcher|
88
+ token = '<channel_name>-' + watcher.login
89
+ channels.push(token)
90
+ end
91
+ ActsAsNotifiableRedmine::Notifications.send_notification(channels, <event_name>, {:title => 'Hello!', :message => 'This is a test message !'})
92
+ end
93
+ end
94
+
95
+ And to display them (put this in the layout) :
96
+
97
+ <% if User.current.logged? %>
98
+
99
+ <%= javascript_tag do %>
100
+
101
+ $(document).ready(function() {
102
+ $.extend($.gritter.options, {
103
+ fade_in_speed: 'fast',
104
+ fade_out_speed: 'fast',
105
+ time: 6000,
106
+ });
107
+
108
+ $(function() {
109
+ var pusher = new Pusher('<%= ActsAsNotifiableRedmine::Notifications.courier.key %>');
110
+
111
+ <% ActsAsNotifiableRedmine::Notifications.channels.each do |name, channel| %>
112
+ var <%= j channel.identifier %> = pusher.subscribe('<%= channel.token %>');
113
+
114
+ <%= channel.identifier %>.bind('subscription_error', function(status) {
115
+ $.gritter.add({
116
+ title: 'Pusher : <%= channel.identifier %>',
117
+ text: 'Subscription error'
118
+ });
119
+ });
120
+
121
+ <% channel.events.each do |event| %>
122
+ <%= channel.identifier %>.bind('<%= event.name %>', function(data) {
123
+ $.gritter.add({
124
+ title: data.title,
125
+ text: data.message,
126
+ image: data.image,
127
+ sticky: <%= event.sticky? %>,
128
+ });
129
+ });
130
+
131
+ <% end %>
132
+
133
+ <% end %>
134
+
135
+ });
136
+ });
137
+ <% end %>
138
+ <% end %>
139
+
140
+ **Note** : [gritter](http://boedesign.com/blog/2009/07/11/growl-for-jquery-gritter/) is not bundled with the gem.
141
+
20
142
  ## Copyrights & License
21
143
  acts_as_notifiable_redmine is completely free and open source and released under the [MIT License](https://github.com/jbox-web/acts_as_notifiable_redmine/blob/devel/LICENSE.txt).
22
144
 
@@ -14,6 +14,8 @@ Gem::Specification.new do |s|
14
14
 
15
15
  s.rubyforge_project = "acts_as_notifiable_redmine"
16
16
 
17
+ s.add_dependency "pusher"
18
+
17
19
  s.files = `git ls-files`.split("\n")
18
20
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
21
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
@@ -1,3 +1,5 @@
1
+ require 'pusher'
2
+
1
3
  module ActsAsNotifiableRedmine
2
4
  module Couriers
3
5
 
@@ -1,3 +1,3 @@
1
1
  module ActsAsNotifiableRedmine
2
- VERSION = "0.1"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_as_notifiable_redmine
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.1'
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nicolas Rodriguez
@@ -9,7 +9,21 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
  date: 2014-05-31 00:00:00.000000000 Z
12
- dependencies: []
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: pusher
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  description:
14
28
  email:
15
29
  - nrodriguez@jbox-web.com
@@ -17,6 +31,7 @@ executables: []
17
31
  extensions: []
18
32
  extra_rdoc_files: []
19
33
  files:
34
+ - .gitignore
20
35
  - Gemfile
21
36
  - LICENSE.txt
22
37
  - README.md