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
# 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)
    @from             = options.delete(:from) || 'Exception'
    @room     			  = HipChat::Client.new(api_token)[room_name]
    @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



21
22
23
24
25
26
# File 'lib/exception_notifier/hipchat_notifier.rb', line 21

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

  message = "A new exception occurred: '#{exception.message}' on '#{exception.backtrace.first}'"
  @room.send(@from, message, @message_options)
end