Class: ExceptionNotifier::HipchatNotifier

Inherits:
BaseNotifier show all
Defined in:
lib/exception_notifier/hipchat_notifier.rb

Instance Attribute Summary collapse

Attributes inherited from BaseNotifier

#base_options

Instance Method Summary collapse

Methods inherited from BaseNotifier

#_post_callback, #_pre_callback, #send_notice

Constructor Details

#initialize(options) ⇒ HipchatNotifier

Returns a new instance of HipchatNotifier.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# 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

Instance Attribute Details

#fromObject

Returns the value of attribute from.



4
5
6
# File 'lib/exception_notifier/hipchat_notifier.rb', line 4

def from
  @from
end

#message_optionsObject

Returns the value of attribute message_options.



6
7
8
# File 'lib/exception_notifier/hipchat_notifier.rb', line 6

def message_options
  @message_options
end

#roomObject

Returns the value of attribute room.



5
6
7
# File 'lib/exception_notifier/hipchat_notifier.rb', line 5

def room
  @room
end

Instance Method Details

#call(exception, options = {}) ⇒ Object



30
31
32
33
34
35
36
37
# 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