11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/resque/plugins/noti_failure/server.rb', line 11
def self.registered(app)
app.get '/noti/subscribe' do
token = ::Noti::Token.create_request_token(to('/noti/confirm'))
response.set_cookie('noti-request', token.request_token)
redirect token.redirect_url
end
app.get '/noti/confirm' do
cookie = request.cookies['noti-request']
unless cookie.nil?
access_token = ::Noti::Token.get_access_token(cookie)
Resque.redis.sadd('noti-users', access_token)
response.delete_cookie('noti-request')
end
redirect url_path('noti')
end
app.get '/noti' do
erb File.read(Resque::Plugins::NotiFailure::Server.erb_path('noti.erb'))
end
app.get '/noti/test' do
puts "Failure url : #{Resque::Failure.url}"
notification = Noti::Notification.new
notification.title = 'Test from resque'
notification.text = 'Some further information about this notification'
notification.url = to('/failed')
notification.sound = 'alert1'
notification.image = 'example'
Resque.redis.smembers('noti-users').each do |token|
begin
notification.deliver_to token
rescue Noti::Errors::AccessDenied
Resque.redis.srem('noti-users', token)
end
end
redirect url_path('noti')
end
end
|