Class: HipchatAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/bilgerat.rb

Overview

In theory in the future there might be different adapters that can plug in to the output formatter, but for now there is just this one.

Constant Summary collapse

DEFAULTS =
{
    :message_format => 'text',
    :notify => '1'
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.hip_post(message, options = {}) ⇒ Object

Send a message to a HipChat room TODO: fork a thread so we don’t block tests while we wait for the network. Also on the puts calls because on at least one occasion a call blocked and locked up cucumber.



177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
# File 'lib/bilgerat.rb', line 177

def hip_post(message, options = {})
  if ENV['DEBUG_BILGERAT']
    unless @debug_file
      @debug_file = File.open(ENV['DEBUG_BILGERAT'], 'w')
      @debug_file.puts "<debugfile>"
      at_exit { @debug_file.puts "</debugfile>" }
    end
    @debug_file.puts "<HIPPOST>#{ message }</HIPPOST>"
  end

  return unless configured?

  def option(sym)
    return options[sym] if options.keys.include?(sym)
    DEFAULTS[sym]
  end

  # Replace the 'error' color with a real color
  options[:color] = error_color if options[:color] == :error

  begin
    client[config['room']].send(username, message, DEFAULTS.merge(options))
    #puts "sent msg to hipchat"
  rescue  => ex
    STDERR.puts "Caught #{ex.class}; disabling hipchat notification"
    @configured = false
  end
end

Instance Method Details

#option(sym) ⇒ Object



189
190
191
192
# File 'lib/bilgerat.rb', line 189

def option(sym)
  return options[sym] if options.keys.include?(sym)
  DEFAULTS[sym]
end