Module: Pushover
- Defined in:
- lib/argosnap/notifications/pushover.rb
Overview
pushover.net module
Class Method Summary collapse
Class Method Details
.send(token, user, message, log, amount) ⇒ Object
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 |
# File 'lib/argosnap/notifications/pushover.rb', line 3 def self.send(token, user, , log, amount) begin # be nice to Pushover API sleep(5) url = URI.parse("https://api.pushover.net/1/messages.json") req = Net::HTTP::Post.new(url.path) req.set_form_data({ token: token, user: user, message: }) res = Net::HTTP.new(url.host, url.port) res.use_ssl = true res.verify_mode = OpenSSL::SSL::VERIFY_PEER res.start do |http| status = http.request(req).code if status == '200' log.info('Notification sent via Pushover!') log.info("Current amount of picoUSD: #{amount}") elsif (400...500).to_a.include?(status) log.error("Please revise your Pushover credentials. API request failed.") else log.error("Request returned status code: #{status}, Pushover notification probably failed.") end end end rescue SocketError log.error("No internet connection available, Pushover notification failed.") end |