class ExceptionNotifier::HipchatNotifier

Attributes

from[RW]
message_options[RW]
room[RW]

Public Class Methods

new(options) click to toggle source
Calls superclass method ExceptionNotifier::BaseNotifier.new
# File lib/exception_notifier/hipchat_notifier.rb, line 8
def initialize(options)
  super
  begin
    api_token         = options.delete(:api_token)
    room_name         = options.delete(:room_name)
    opts              = {
                          :api_version => options.delete(:api_version) || 'v1'
                        }
    @from             = options.delete(:from) || 'Exception'
    @room             = HipChat::Client.new(api_token, opts)[room_name]
    @message_template = options.delete(:message_template) || ->(exception) {
      msg = "A new exception occurred: '#{Rack::Utils.escape_html(exception.message)}'"
      msg += " on '#{exception.backtrace.first}'" if exception.backtrace
      msg
    }
    @message_options  = options
    @message_options[:color] ||= 'red'
  rescue
    @room = nil
  end
end

Public Instance Methods

call(exception, options={}) click to toggle source
# File lib/exception_notifier/hipchat_notifier.rb, line 30
def call(exception, options={})
  return if !active?

  message = @message_template.call(exception)
  send_notice(exception, options, message, @message_options) do |msg, message_opts|
    @room.send(@from, msg, message_opts)
  end
end

Private Instance Methods

active?() click to toggle source
# File lib/exception_notifier/hipchat_notifier.rb, line 41
def active?
  !@room.nil?
end