Class: ExceptionsToHipchat::Notifier
- Inherits:
-
Object
- Object
- ExceptionsToHipchat::Notifier
- Defined in:
- lib/exceptions_to_hipchat/notifier.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, options = {}, client = nil) ⇒ Notifier
constructor
A new instance of Notifier.
- #message_for(exception) ⇒ Object
- #send_to_hipchat(exception) ⇒ Object
Constructor Details
#initialize(app, options = {}, client = nil) ⇒ Notifier
Returns a new instance of Notifier.
5 6 7 8 9 10 11 12 13 |
# File 'lib/exceptions_to_hipchat/notifier.rb', line 5 def initialize(app, = {}, client = nil) @app = app @client = client || HipChat::Client.new([:api_token] || raise("HipChat API token is required")) @room = [:room] || raise("HipChat room is required") @color = [:color] || :red @notify = [:notify] @user = ([:user] || "Notifier")[0...14] @ignore = [:ignore] end |
Instance Method Details
#call(env) ⇒ Object
15 16 17 18 19 20 |
# File 'lib/exceptions_to_hipchat/notifier.rb', line 15 def call(env) @app.call(env) rescue Exception => exception send_to_hipchat(exception) unless @ignore && @ignore.match(exception.to_s) raise exception end |
#message_for(exception) ⇒ Object
30 31 32 |
# File 'lib/exceptions_to_hipchat/notifier.rb', line 30 def (exception) "[#{exception.class}] #{exception}" end |
#send_to_hipchat(exception) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/exceptions_to_hipchat/notifier.rb', line 22 def send_to_hipchat(exception) begin @client[@room].send(@user, (exception), :color => @color, :notify => @notify) rescue => hipchat_exception $stderr.puts "\nWARN: Unable to send message to HipChat: #{hipchat_exception}\n" end end |