Class: ExceptionNotifier::HipchatNotifier

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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
# File 'lib/exception_notifier/hipchat_notifier.rb', line 8

def initialize(options)
  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) {
      "A new exception occurred: '#{exception.message}' on '#{exception.backtrace.first}'"
    }
    @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



27
28
29
30
31
32
# File 'lib/exception_notifier/hipchat_notifier.rb', line 27

def call(exception, options={})
  return if !active?

  message = @message_template.call(exception)
  @room.send(@from, message, @message_options)
end