Class: Gwtf::Notifier::Pushover
- Defined in:
- lib/gwtf/notifier/pushover.rb
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
Methods inherited from Base
Constructor Details
This class inherits a constructor from Gwtf::Notifier::Base
Instance Method Details
#notify ⇒ Object
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 |
# File 'lib/gwtf/notifier/pushover.rb', line 4 def notify config_file = File.join(Etc.getpwuid.dir, ".pushover") raise "Please configure pushover in ~/.pushover" unless File.exist?(config_file) config = YAML.load_file(config_file) raise "Config needs to be a hash" unless config.is_a?(Hash) raise "Config must include :app_token" unless config[:app_token] uri = URI.parse(recipient) raise "Recipient must have a host portion" unless uri.host ::Pushover.token = config[:app_token] ::Pushover.user = uri.host if item.project == "default" msg = "%s: %s" % [ item.item_id, item.subject ] else msg = "%s:%s: %s" % [ item.project, item.item_id, item.subject ] end result = ::Pushover.notification( :title => config.fetch(:title, "gwtf"), :sound => config.fetch(:sound, "pushover"), :message => msg ) unless result.code == 200 raise("Failed to notify via pushover: %s" % responce.inspect) end end |