Skip to content

Commit

Permalink
Add support for honeybadger.
Browse files Browse the repository at this point in the history
  • Loading branch information
Joshua Wood committed Apr 24, 2015
1 parent e59037e commit c47af25
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lib/uniform_notifier.rb
Expand Up @@ -3,6 +3,7 @@
require 'uniform_notifier/javascript_alert'
require 'uniform_notifier/javascript_console'
require 'uniform_notifier/growl'
require 'uniform_notifier/honeybadger'
require 'uniform_notifier/xmpp'
require 'uniform_notifier/rails_logger'
require 'uniform_notifier/customized_logger'
Expand All @@ -13,11 +14,11 @@
require 'uniform_notifier/raise'

class UniformNotifier
AVAILABLE_NOTIFIERS = [:alert, :console, :growl, :xmpp, :rails_logger, :customized_logger,
:airbrake, :rollbar, :bugsnag, :slack, :raise]
AVAILABLE_NOTIFIERS = [:alert, :console, :growl, :honeybadger, :xmpp, :rails_logger,
:customized_logger, :airbrake, :rollbar, :bugsnag, :slack, :raise]

NOTIFIERS = [JavascriptAlert, JavascriptConsole, Growl, Xmpp, RailsLogger, CustomizedLogger,
AirbrakeNotifier, RollbarNotifier, BugsnagNotifier, Raise, Slack]
NOTIFIERS = [JavascriptAlert, JavascriptConsole, Growl, HoneybadgerNotifier, Xmpp, RailsLogger,
CustomizedLogger, AirbrakeNotifier, RollbarNotifier, BugsnagNotifier, Raise, Slack]

class NotificationError < StandardError; end

Expand Down
21 changes: 21 additions & 0 deletions lib/uniform_notifier/honeybadger.rb
@@ -0,0 +1,21 @@
class UniformNotifier
class HoneybadgerNotifier < Base
def self.active?
!!UniformNotifier.honeybadger
end

protected

def self._out_of_channel_notify(data)
message = data.values.compact.join("\n")

opt = {}
if UniformNotifier.honeybadger.is_a?(Hash)
opt = UniformNotifier.honeybadger
end

exception = Exception.new(message)
Honeybadger.notify(exception, opt)
end
end
end
25 changes: 25 additions & 0 deletions spec/uniform_notifier/honeybadger_spec.rb
@@ -0,0 +1,25 @@
require "spec_helper"

class Honeybadger
# mock Honeybadger
end

describe UniformNotifier::HoneybadgerNotifier do
it "should not notify honeybadger" do
expect(UniformNotifier::HoneybadgerNotifier.out_of_channel_notify(:title => "notify honeybadger")).to be_nil
end

it "should notify honeybadger" do
expect(Honeybadger).to receive(:notify).with(UniformNotifier::Exception.new("notify honeybadger"), {})

UniformNotifier.honeybadger = true
UniformNotifier::HoneybadgerNotifier.out_of_channel_notify(:title => "notify honeybadger")
end

it "should notify honeybadger" do
expect(Honeybadger).to receive(:notify).with(UniformNotifier::Exception.new("notify honeybadger"), :foo => :bar)

UniformNotifier.honeybadger = { :foo => :bar }
UniformNotifier::HoneybadgerNotifier.out_of_channel_notify("notify honeybadger")
end
end

0 comments on commit c47af25

Please sign in to comment.