forked from lobsters/lobsters
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpushover.rb
36 lines (31 loc) · 867 Bytes
/
pushover.rb
1
2
3
4
5
6
7
8
9
10
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
class Pushover
# these need to be overridden in config/initializers/production.rb
cattr_accessor :API_TOKEN
cattr_accessor :SUBSCRIPTION_CODE
def self.enabled?
self.API_TOKEN.present?
end
def self.push(user, params)
if !self.enabled?
return
end
begin
if params[:message].to_s == ""
params[:message] = "(No message)"
end
s = Sponge.new
s.fetch("https://api.pushover.net/1/messages.json", :post, {
:token => self.API_TOKEN,
:user => user,
}.merge(params))
rescue => e
Rails.logger.error "error sending to pushover: #{e.inspect}"
end
end
def self.subscription_url(params)
u = "https://pushover.net/subscribe/#{self.SUBSCRIPTION_CODE}"
u << "?success=#{CGI.escape(params[:success])}"
u << "&failure=#{CGI.escape(params[:failure])}"
u
end
end