Sha256: fe2c4d9a350919e8785223e20af4040d819dc0978fe43188c8284803d7194ae5

Contents?: true

Size: 1.1 KB

Versions: 3

Compression:

Stored size: 1.1 KB

Contents

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)
        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

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

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

    private

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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
exception_notification-4.1.1 lib/exception_notifier/hipchat_notifier.rb
exception_notification-4.1.0 lib/exception_notifier/hipchat_notifier.rb
exception_notification-4.1.0.rc2 lib/exception_notifier/hipchat_notifier.rb