Class: Gwtf::Notifier::Notifo

Inherits:
Base
  • Object
show all
Defined in:
lib/gwtf/notifier/notifo.rb

Instance Attribute Summary

Attributes inherited from Base

#item, #recipient

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Gwtf::Notifier::Base

Instance Method Details

#notifyObject



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
# File 'lib/gwtf/notifier/notifo.rb', line 4

def notify
  config_file = File.join(Etc.getpwuid.dir, ".notifo")

  raise "Please configure notifo in ~/.notifo" 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 :apiuser" unless config[:apiuser]
  raise "Config must include :apisecret" unless config[:apisecret]
  raise "Config must include :sender" unless config[:sender]

  uri = URI.parse(recipient)

  raise "Recipient must have a user portion" unless uri.user
  raise "Recipient must have a host portion" unless uri.host

  notifo = ::Notifo.new(config[:apiuser], config[:apisecret])

  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

  # notifo gem doesn't return anything on failure
  notifo.post(uri.user, msg, config[:sender])

end