Class: Gwtf::Notifier::Boxcar

Inherits:
Base
  • Object
show all
Defined in:
lib/gwtf/notifier/boxcar.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
33
34
35
# File 'lib/gwtf/notifier/boxcar.rb', line 4

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

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

  email_address = "%s@%s" % [uri.user, uri.host]

  bp = BoxcarAPI::Provider.new(config[:apikey], config[:apisecret], config[:sender])

  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

  res = bp.notify(email_address, msg, {:from_screen_name => config[:sender], :icon_url => "http://www.devco.net/images/gwtf.jpg"})

  raise "Failed to send message to Boxcar, got code #{res.code}" unless res.code == 200
end