File: hipchat_notifier.rb

package info (click to toggle)
ruby-exception-notification 4.0.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 808 kB
  • sloc: javascript: 7,680; ruby: 1,130; makefile: 2
file content (34 lines) | stat: -rw-r--r-- 829 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
module ExceptionNotifier
  class HipchatNotifier

    attr_accessor :from
    attr_accessor :room
    attr_accessor :message_options

    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

    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

    private

    def active?
      !@room.nil?
    end
  end
end