uniform-notifier-1.13.0/0000755000175000017500000000000013703133607016313 5ustar debbiecocoadebbiecocoauniform-notifier-1.13.0/README.md0000644000175000017500000001465013703133607017600 0ustar debbiecocoadebbiecocoa# UniformNotifier [![Build Status](https://secure.travis-ci.org/flyerhzm/uniform_notifier.png)](http://travis-ci.org/flyerhzm/uniform_notifier) [![AwesomeCode Status for flyerhzm/uniform_notifier](https://awesomecode.io/projects/3e29a7de-0b37-4ecf-b06d-410ebf815174/status)](https://awesomecode.io/repos/flyerhzm/uniform_notifier) uniform_notifier is extracted from [bullet][0], it gives you the ability to send notification through rails logger, customized logger, javascript alert, javascript console, growl, xmpp, airbrake and honeybadger. ## Install ### install directly gem install uniform_notifier if you want to notify by growl < v1.3, you should install ruby-growl first gem install ruby-growl if you want to notify by growl v1.3+, you should install ruby_gntp first gem install ruby_gntp if you want to notify by xmpp, you should install xmpp4r first gem install xmpp4r if you want to notify by airbrake, you should install airbrake first gem install airbrake if you want to notify by Honeybadger, you should install honeybadger first gem install honeybadger if you want to notify by rollbar, you should install rollbar first gem install rollbar if you want to notify by bugsnag, you should install bugsnag first gem install bugsnag if you want to notify by slack, you should install slack-notifier first gem install slack-notifier if you want to notify by terminal-notifier, you must install it first gem install terminal-notifier ### add it into Gemfile (Bundler) gem "uniform_notifier" you should add ruby-growl, ruby_gntp, xmpp4r, airbrake, bugsnag, honeybadger, slack-notifier, terminal-notifier gem if you want. ## Usage There are two types of notifications, one is inline_notify, for javascript alert and javascript console notifiers, which returns a string and will be combined, the other is out_of_channel_notify, for rails logger, customized logger, growl and xmpp, which doesn't return anything, just send the message to the notifiers. By default, all notifiers are disabled, you should enable them first. ```ruby # javascript alert UniformNotifier.alert = true # javascript alert with options # the attributes key adds custom attributes to the script tag appended to the body UniformNotifier.alert = { :attributes => { :nonce => 'mySecret-nonce', 'data-key' => 'value' } } # javascript console (Safari/Webkit browsers or Firefox w/Firebug installed) UniformNotifier.console = true # javascript console with options # the attributes key adds custom attributes to the script tag appended to the body UniformNotifier.console = { :attributes => { :nonce => 'mySecret-nonce', 'data-key' => 'value' } } # rails logger UniformNotifier.rails_logger = true # airbrake UniformNotifier.airbrake = true # airbrake with options UniformNotifier.airbrake = { :error_class => Exception } # Honeybadger # # Reporting live data from development is disabled by default. Ensure # that the `report_data` option is enabled via configuration. UniformNotifier.honeybadger = true # Honeybadger with options UniformNotifier.honeybadger = { :error_class => 'Exception' } # rollbar UniformNotifier.rollbar = true # rollbar with options (level can be 'debug', 'info', 'warning', 'error' or 'critical') UniformNotifier.rollbar = { :level => 'warning' } # bugsnag UniformNotifier.bugsnag = true # bugsnag with options UniformNotifier.bugsnag = { :api_key => 'something' } # slack UniformNotifier.slack = true # slack with options UniformNotifier.slack = { :webhook_url => 'http://some.slack.url', :channel => '#default', :username => 'notifier' } # customized logger logger = File.open('notify.log', 'a+') logger.sync = true UniformNotifier.customized_logger = logger # growl without password UniformNotifier.growl = true # growl with passowrd UniformNotifier.growl = { :password => 'growl password' } # xmpp UniformNotifier.xmpp = { :account => 'sender_account@jabber.org', :password => 'password_for_jabber', :receiver => 'recipient_account@jabber.org', :show_online_status => true } # terminal-notifier UniformNotifier.terminal_notifier = true # raise an error UniformNotifier.raise = true # raise a generic exception class MyExceptionClass < Exception; end UniformNotifier.raise = MyExceptionClass # raise a custom exception type UniformNotifier.raise = false # don't raise errors ``` After that, you can enjoy the notifiers, that's cool! ```ruby # the notify message will be notified to rails logger, customized logger, growl or xmpp. UniformNotifier.active_notifiers.each do |notifier| notifier.out_of_channel_notify("customize message") end # the notify message will be wrapped by , # you should append the javascript_str at the bottom of http response body. # for more information, please check https://github.com/flyerhzm/bullet/blob/master/lib/bullet/rack.rb responses = [] UniformNotifier.active_notifiers.each do |notifier| responses << notifier.inline_notify("customize message") end javascript_str = responses.join("\n") ``` ## Growl Support To get Growl support up-and-running, follow the steps below: * For Growl < v1.3, install the ruby-growl gem: gem install ruby-growl * For Growl v1.3+, install the ruby_gntp gem: gem install ruby_gntp * Open the Growl preference pane in Systems Preferences * Click the "Network" tab * Make sure both "Listen for incoming notifications" and "Allow remote application registration" are checked. *Note*: If you set a password, you will need to set UniformNotifier.growl_password = { :password => 'growl password' } in the config file. * Restart Growl ("General" tab -> Stop Growl -> Start Growl) * Boot up your application. UniformNotifier will automatically send a Growl notification when Growl is turned on. If you do not see it when your application loads, make sure it is enabled in your initializer and double-check the steps above. ## XMPP/Jabber Support To get XMPP support up-and-running, follow the steps below: * Install the xmpp4r gem: gem install xmpp4r * Make both the sender and the recipient account add each other as contacts. This will require you to manually log into both accounts, add each other as contact and confirm each others contact request. * Boot up your application. UniformNotifier will automatically send an XMPP notification when XMPP is turned on. [0]: https://github.com/flyerhzm/bullet uniform-notifier-1.13.0/.gitignore0000644000175000017500000000005513703133607020303 0ustar debbiecocoadebbiecocoapkg/* *.gem .bundle .rvmrc bin/ Gemfile.lock uniform-notifier-1.13.0/LICENSE0000644000175000017500000000206613703133607017324 0ustar debbiecocoadebbiecocoaCopyright (c) 2010 Richard Huang (flyerhzm@gmail.com) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. uniform-notifier-1.13.0/.travis.yml0000644000175000017500000000003613703133607020423 0ustar debbiecocoadebbiecocoalanguage: ruby rvm: - 2.3.6 uniform-notifier-1.13.0/lib/0000755000175000017500000000000013703133607017061 5ustar debbiecocoadebbiecocoauniform-notifier-1.13.0/lib/uniform_notifier.rb0000644000175000017500000000350013703133607022762 0ustar debbiecocoadebbiecocoa# frozen_string_literal: true require 'uniform_notifier/base' require 'uniform_notifier/errors' 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' require 'uniform_notifier/airbrake' require 'uniform_notifier/sentry' require 'uniform_notifier/rollbar' require 'uniform_notifier/bugsnag' require 'uniform_notifier/slack' require 'uniform_notifier/raise' require 'uniform_notifier/terminal_notifier' class UniformNotifier AVAILABLE_NOTIFIERS = %i[alert console growl honeybadger xmpp rails_logger customized_logger airbrake rollbar bugsnag slack raise sentry terminal_notifier].freeze NOTIFIERS = [JavascriptAlert, JavascriptConsole, Growl, HoneybadgerNotifier, Xmpp, RailsLogger, CustomizedLogger, AirbrakeNotifier, RollbarNotifier, BugsnagNotifier, Raise, Slack, SentryNotifier, TerminalNotifier].freeze class NotificationError < StandardError; end class </**/ CODE end end end uniform-notifier-1.13.0/lib/uniform_notifier/airbrake.rb0000644000175000017500000000067313703133607024552 0ustar debbiecocoadebbiecocoa# frozen_string_literal: true class UniformNotifier class AirbrakeNotifier < Base def self.active? !!UniformNotifier.airbrake end protected def self._out_of_channel_notify(data) message = data.values.compact.join("\n") opt = {} opt = UniformNotifier.airbrake if UniformNotifier.airbrake.is_a?(Hash) exception = Exception.new(message) Airbrake.notify(exception, opt) end end end uniform-notifier-1.13.0/lib/uniform_notifier/javascript_console.rb0000644000175000017500000000150213703133607026652 0ustar debbiecocoadebbiecocoa# frozen_string_literal: true class UniformNotifier class JavascriptConsole < Base def self.active? !!UniformNotifier.console end protected def self._inline_notify(data) message = data.values.compact.join("\n") options = UniformNotifier.console.is_a?(Hash) ? UniformNotifier.console : {} script_attributes = options[:attributes] || {} code = <<~CODE if (typeof(console) !== 'undefined' && console.log) { if (console.groupCollapsed && console.groupEnd) { console.groupCollapsed(#{'Uniform Notifier'.inspect}); console.log(#{message.inspect}); console.groupEnd(); } else { console.log(#{message.inspect}); } } CODE wrap_js_association code, script_attributes end end end uniform-notifier-1.13.0/lib/uniform_notifier/honeybadger.rb0000644000175000017500000000102113703133607025245 0ustar debbiecocoadebbiecocoa# frozen_string_literal: true 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 = {} opt = UniformNotifier.honeybadger if UniformNotifier.honeybadger.is_a?(Hash) exception = Exception.new(message) honeybadger_class = opt[:honeybadger_class] || Honeybadger honeybadger_class.notify(exception, opt) end end end uniform-notifier-1.13.0/lib/uniform_notifier/slack.rb0000644000175000017500000000227413703133607024066 0ustar debbiecocoadebbiecocoa# frozen_string_literal: true class UniformNotifier class Slack < Base POSSIBLE_OPTIONS = %i[username channel].freeze @slack = nil class << self def active? @slack end def setup_connection(config = {}) webhook_url, options = parse_config(config) fail_connection('webhook_url required for Slack notification') unless webhook_url require 'slack-notifier' @slack = ::Slack::Notifier.new webhook_url, options rescue LoadError fail_connection 'You must install the slack-notifier gem to use Slack notification: '\ '`gem install slack-notifier`' end protected def _out_of_channel_notify(data) message = data.values.compact.join("\n") notify(message) end private def fail_connection(message) @slack = nil raise NotificationError, message end def notify(message) @slack.ping message end def parse_config(config) options = config.select do |name, value| POSSIBLE_OPTIONS.include?(name) && !value.nil? end [config[:webhook_url], options] end end end end uniform-notifier-1.13.0/lib/uniform_notifier/sentry.rb0000644000175000017500000000067313703133607024316 0ustar debbiecocoadebbiecocoa# frozen_string_literal: true class UniformNotifier class SentryNotifier < Base def self.active? !!UniformNotifier.sentry end protected def self._out_of_channel_notify(data) message = data.values.compact.join("\n") opt = {} opt = UniformNotifier.sentry if UniformNotifier.sentry.is_a?(Hash) exception = Exception.new(message) Raven.capture_exception(exception, opt) end end end uniform-notifier-1.13.0/lib/uniform_notifier/version.rb0000644000175000017500000000011613703133607024447 0ustar debbiecocoadebbiecocoa# frozen_string_literal: true class UniformNotifier VERSION = '1.13.0' end uniform-notifier-1.13.0/lib/uniform_notifier/raise.rb0000644000175000017500000000064713703133607024076 0ustar debbiecocoadebbiecocoa# frozen_string_literal: true class UniformNotifier class Raise < Base def self.active? @exception_class end def self.setup_connection(exception_class) @exception_class = exception_class == true ? Exception : exception_class end protected def self._out_of_channel_notify(data) message = data.values.compact.join("\n") raise @exception_class, message end end end uniform-notifier-1.13.0/lib/uniform_notifier/bugsnag.rb0000644000175000017500000000117313703133607024414 0ustar debbiecocoadebbiecocoa# frozen_string_literal: true class UniformNotifier class BugsnagNotifier < Base def self.active? !!UniformNotifier.bugsnag end protected def self._out_of_channel_notify(data) opt = {} opt = UniformNotifier.bugsnag if UniformNotifier.bugsnag.is_a?(Hash) exception = Exception.new(data[:title]) exception.set_backtrace(data[:backtrace]) if data[:backtrace] Bugsnag.notify(exception, opt.merge( grouping_hash: data[:body] || data[:title], notification: data )) end end end uniform-notifier-1.13.0/lib/uniform_notifier/growl.rb0000644000175000017500000000434713703133607024126 0ustar debbiecocoadebbiecocoa# frozen_string_literal: true class UniformNotifier class Growl < Base @growl = nil def self.active? @growl end def self.setup_connection(growl) setup_connection_growl(growl) rescue LoadError begin setup_connection_gntp(growl) rescue LoadError @growl = nil raise NotificationError, 'You must install the ruby-growl or the ruby_gntp gem to use Growl notification: `gem install ruby-growl` or `gem install ruby_gntp`' end end def self.setup_connection_growl(growl) return unless growl require 'ruby-growl' if growl.instance_of?(Hash) @password = growl.include?(:password) ? growl[:password] : nil @host = growl.include?(:host) ? growl[:host] : 'localhost' end @password ||= nil @host ||= 'localhost' @growl = ::Growl.new @host, 'uniform_notifier' @growl.add_notification 'uniform_notifier' @growl.password = @password notify 'Uniform Notifier Growl has been turned on' if !growl.instance_of?(Hash) || !growl[:quiet] end def self.setup_connection_gntp(growl) return unless growl require 'ruby_gntp' if growl.instance_of?(Hash) @password = growl.include?(:password) ? growl[:password] : nil @host = growl.include?(:host) ? growl[:host] : 'localhost' end @password ||= nil @host ||= 'localhost' @growl = GNTP.new('uniform_notifier', @host, @password, 23053) @growl.register(notifications: [{ name: 'uniform_notifier', enabled: true, }]) notify 'Uniform Notifier Growl has been turned on (using GNTP)' if !growl.instance_of?(Hash) || !growl[:quiet] end protected def self._out_of_channel_notify(data) message = data.values.compact.join("\n") notify(message) end private def self.notify(message) if defined?(::Growl) && @growl.is_a?(::Growl) @growl.notify('uniform_notifier', 'Uniform Notifier', message) elsif defined?(::GNTP) && @growl.is_a?(::GNTP) @growl.notify( name: 'uniform_notifier', title: 'Uniform Notifier', text: message ) end end end end uniform-notifier-1.13.0/lib/uniform_notifier/javascript_alert.rb0000644000175000017500000000072313703133607026323 0ustar debbiecocoadebbiecocoa# frozen_string_literal: true class UniformNotifier class JavascriptAlert < Base def self.active? !!UniformNotifier.alert end protected def self._inline_notify(data) message = data.values.compact.join("\n") options = UniformNotifier.alert.is_a?(Hash) ? UniformNotifier.alert : {} script_attributes = options[:attributes] || {} wrap_js_association "alert( #{message.inspect} );", script_attributes end end end uniform-notifier-1.13.0/lib/uniform_notifier/rails_logger.rb0000644000175000017500000000045413703133607025440 0ustar debbiecocoadebbiecocoa# frozen_string_literal: true class UniformNotifier class RailsLogger < Base def self.active? UniformNotifier.rails_logger end protected def self._out_of_channel_notify(data) message = data.values.compact.join("\n") Rails.logger.warn message end end end uniform-notifier-1.13.0/Gemfile0000644000175000017500000000021713703133607017606 0ustar debbiecocoadebbiecocoa# frozen_string_literal: true source 'http://rubygems.org' # Specify your gem's dependencies in uniform_notifier.gemspec gemspec gem 'rake' uniform-notifier-1.13.0/Rakefile0000644000175000017500000000113713703133607017762 0ustar debbiecocoadebbiecocoa# frozen_string_literal: true require 'bundler' Bundler::GemHelper.install_tasks require 'rake' require 'rdoc/task' require 'rspec' require 'rspec/core/rake_task' RSpec::Core::RakeTask.new(:spec) do |spec| spec.pattern = 'spec/**/*_spec.rb' end RSpec::Core::RakeTask.new('spec:progress') do |spec| spec.rspec_opts = %w[--format progress] spec.pattern = 'spec/**/*_spec.rb' end Rake::RDocTask.new do |rdoc| rdoc.rdoc_dir = 'rdoc' rdoc.title = "uniform_notifier #{UniformNotifier::VERSION}" rdoc.rdoc_files.include('README*') rdoc.rdoc_files.include('lib/**/*.rb') end task default: :spec uniform-notifier-1.13.0/uniform_notifier.gemspec0000644000175000017500000000301413703133607023234 0ustar debbiecocoadebbiecocoa# frozen_string_literal: true $LOAD_PATH.push File.expand_path('../lib', __FILE__) require 'uniform_notifier/version' Gem::Specification.new do |s| s.name = 'uniform_notifier' s.version = UniformNotifier::VERSION s.platform = Gem::Platform::RUBY s.authors = ['Richard Huang'] s.email = ['flyerhzm@gmail.com'] s.homepage = 'http://rubygems.org/gems/uniform_notifier' s.summary = 'uniform notifier for rails logger, customized logger, javascript alert, javascript console, growl and xmpp' s.description = 'uniform notifier for rails logger, customized logger, javascript alert, javascript console, growl and xmpp' s.license = 'MIT' s.required_ruby_version = '>= 2.3' s.add_development_dependency 'ruby-growl', ['= 4.0'] s.add_development_dependency 'ruby_gntp', ['= 0.3.4'] s.add_development_dependency 'xmpp4r', ['= 0.5'] s.add_development_dependency 'slack-notifier', ['>= 1.0'] s.add_development_dependency 'rspec', ['> 0'] s.files = `git ls-files`.split("\n") s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) } s.require_paths = ['lib'] if s.respond_to?(:metadata) s.metadata['changelog_uri'] = 'https://github.com/flyerhzm/uniform_notifier/blob/master/CHANGELOG.md' s.metadata['source_code_uri'] = 'https://github.com/flyerhzm/uniform_notifier' s.metadata['bug_tracker_uri'] = 'https://github.com/flyerhzm/uniform_notifier/issues' end end uniform-notifier-1.13.0/spec/0000755000175000017500000000000013703133607017245 5ustar debbiecocoadebbiecocoauniform-notifier-1.13.0/spec/spec_helper.rb0000644000175000017500000000031513703133607022062 0ustar debbiecocoadebbiecocoa# frozen_string_literal: true $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) require 'uniform_notifier' require 'ruby-growl' require 'xmpp4r' require 'slack-notifier' require 'rspec' uniform-notifier-1.13.0/spec/uniform_notifier/0000755000175000017500000000000013703133607022623 5ustar debbiecocoadebbiecocoauniform-notifier-1.13.0/spec/uniform_notifier/growl_spec.rb0000644000175000017500000000576613703133607025332 0ustar debbiecocoadebbiecocoa# frozen_string_literal: true require 'spec_helper' RSpec.describe UniformNotifier::Growl do it 'should not notify growl' do expect(UniformNotifier::Growl.out_of_channel_notify(title: 'notify growl')).to be_nil end it 'should notify growl without password' do growl = double('growl', is_a?: true) expect(Growl).to receive(:new).with('localhost', 'uniform_notifier').and_return(growl) expect(growl).to receive(:add_notification).with('uniform_notifier') expect(growl).to receive(:password=).with(nil) expect(growl).to receive(:notify).with('uniform_notifier', 'Uniform Notifier', 'Uniform Notifier Growl has been turned on').ordered expect(growl).to receive(:notify).with('uniform_notifier', 'Uniform Notifier', 'notify growl without password').ordered UniformNotifier.growl = true UniformNotifier::Growl.out_of_channel_notify(title: 'notify growl without password') end it 'should notify growl with password' do growl = double('growl', is_a?: true) expect(Growl).to receive(:new).with('localhost', 'uniform_notifier').and_return(growl) expect(growl).to receive(:add_notification).with('uniform_notifier') expect(growl).to receive(:password=).with('123456') expect(growl).to receive(:notify).with('uniform_notifier', 'Uniform Notifier', 'Uniform Notifier Growl has been turned on').ordered expect(growl).to receive(:notify).with('uniform_notifier', 'Uniform Notifier', 'notify growl with password').ordered UniformNotifier.growl = { password: '123456' } UniformNotifier::Growl.out_of_channel_notify(title: 'notify growl with password') end it 'should notify growl with host' do growl = double('growl', is_a?: true) expect(Growl).to receive(:new).with('10.10.156.17', 'uniform_notifier').and_return(growl) expect(growl).to receive(:add_notification).with('uniform_notifier') expect(growl).to receive(:password=).with('123456') expect(growl).to receive(:notify).with('uniform_notifier', 'Uniform Notifier', 'Uniform Notifier Growl has been turned on').ordered expect(growl).to receive(:notify).with('uniform_notifier', 'Uniform Notifier', 'notify growl with password').ordered UniformNotifier.growl = { password: '123456', host: '10.10.156.17' } UniformNotifier::Growl.out_of_channel_notify(title: 'notify growl with password') end it 'should notify growl with quiet' do growl = double('growl', is_a?: true) expect(Growl).to receive(:new).with('localhost', 'uniform_notifier').and_return(growl) expect(growl).to receive(:add_notification).with('uniform_notifier') expect(growl).to receive(:password=).with('123456') expect(growl).not_to receive(:notify).with('uniform_notifier', 'Uniform Notifier', 'Uniform Notifier Growl has been turned on') expect(growl).to receive(:notify).with('uniform_notifier', 'Uniform Notifier', 'notify growl with password') UniformNotifier.growl = { password: '123456', quiet: true } UniformNotifier::Growl.out_of_channel_notify(title: 'notify growl with password') end end uniform-notifier-1.13.0/spec/uniform_notifier/customized_logger_spec.rb0000644000175000017500000000134313703133607027710 0ustar debbiecocoadebbiecocoa# frozen_string_literal: true require 'spec_helper' RSpec.describe UniformNotifier::CustomizedLogger do it 'should not notify to customized logger' do expect(UniformNotifier::CustomizedLogger.out_of_channel_notify(title: 'notify rails logger')).to be_nil end it 'should notify to customized logger' do logger = File.open('test.log', 'a+') logger.sync = true now = Time.now allow(Time).to receive(:now).and_return(now) UniformNotifier.customized_logger = logger UniformNotifier::CustomizedLogger.out_of_channel_notify(title: 'notify rails logger') logger.seek(0) expect(logger.read).to eq "#{now.strftime('%Y-%m-%d %H:%M:%S')}[WARN] notify rails logger" File.delete('test.log') end end uniform-notifier-1.13.0/spec/uniform_notifier/airbrake_spec.rb0000644000175000017500000000150013703133607025736 0ustar debbiecocoadebbiecocoa# frozen_string_literal: true require 'spec_helper' class Airbrake # mock Airbrake end RSpec.describe UniformNotifier::AirbrakeNotifier do it 'should not notify airbrake' do expect(UniformNotifier::AirbrakeNotifier.out_of_channel_notify(title: 'notify airbrake')).to be_nil end it 'should notify airbrake' do expect(Airbrake).to receive(:notify).with(UniformNotifier::Exception.new('notify airbrake'), {}) UniformNotifier.airbrake = true UniformNotifier::AirbrakeNotifier.out_of_channel_notify(title: 'notify airbrake') end it 'should notify airbrake' do expect(Airbrake).to receive(:notify).with(UniformNotifier::Exception.new('notify airbrake'), foo: :bar) UniformNotifier.airbrake = { foo: :bar } UniformNotifier::AirbrakeNotifier.out_of_channel_notify('notify airbrake') end end uniform-notifier-1.13.0/spec/uniform_notifier/rails_logger_spec.rb0000644000175000017500000000114113703133607026630 0ustar debbiecocoadebbiecocoa# frozen_string_literal: true require 'spec_helper' class Rails # mock Rails end RSpec.describe UniformNotifier::RailsLogger do it 'should not notify rails logger' do expect(UniformNotifier::RailsLogger.out_of_channel_notify(title: 'notify rails logger')).to be_nil end it 'should notify rails logger' do logger = double('logger') expect(Rails).to receive(:logger).and_return(logger) expect(logger).to receive(:warn).with('notify rails logger') UniformNotifier.rails_logger = true UniformNotifier::RailsLogger.out_of_channel_notify(title: 'notify rails logger') end end uniform-notifier-1.13.0/spec/uniform_notifier/honeybadger_spec.rb0000644000175000017500000000156613703133607026461 0ustar debbiecocoadebbiecocoa# frozen_string_literal: true require 'spec_helper' class Honeybadger # mock Honeybadger end RSpec.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 uniform-notifier-1.13.0/spec/uniform_notifier/base_spec.rb0000644000175000017500000000142613703133607025077 0ustar debbiecocoadebbiecocoa# frozen_string_literal: true require 'spec_helper' RSpec.describe UniformNotifier::Base do context '#inline_channel_notify' do before do allow(UniformNotifier::Base).to receive(:active?).and_return(true) end it 'should keep the compatibility' do expect(UniformNotifier::Base).to receive(:_inline_notify).once.with(title: 'something') UniformNotifier::Base.inline_notify('something') end end context '#out_of_channel_notify' do before do allow(UniformNotifier::Base).to receive(:active?).and_return(true) end it 'should keep the compatibility' do expect(UniformNotifier::Base).to receive(:_out_of_channel_notify).once.with(title: 'something') UniformNotifier::Base.out_of_channel_notify('something') end end end uniform-notifier-1.13.0/spec/uniform_notifier/slack_spec.rb0000644000175000017500000000376713703133607025274 0ustar debbiecocoadebbiecocoa# frozen_string_literal: true require 'spec_helper' RSpec.describe UniformNotifier::Slack do context 'not enabled' do it 'should not notify slack' do expect_any_instance_of(Slack::Notifier).to_not receive(:ping) expect(UniformNotifier::Slack.out_of_channel_notify(title: 'notify slack')).to be_nil end end context 'configuration' do context 'no webhook_url is given' do it 'should raise an error' do expect { UniformNotifier.slack = {} }.to raise_error(UniformNotifier::NotificationError) end it 'should not notify slack' do begin UniformNotifier.slack = {} rescue UniformNotifier::NotificationError ensure expect_any_instance_of(Slack::Notifier).to_not receive(:ping) expect(UniformNotifier::Slack.out_of_channel_notify(title: 'notify slack')).to be_nil end end end it 'should remove invalid options' do expect(Slack::Notifier).to receive(:new).with('http://some.slack.url', {}).and_return(true) UniformNotifier.slack = { webhook_url: 'http://some.slack.url', pizza: 'pepperoni' } expect(UniformNotifier::Slack.active?).to eq true end it 'should allow username and channel config options' do expect(Slack::Notifier).to receive(:new).with('http://some.slack.url', username: 'The Dude', channel: '#carpets').and_return(true) UniformNotifier.slack = { webhook_url: 'http://some.slack.url', username: 'The Dude', channel: '#carpets' } expect(UniformNotifier::Slack.active?).to eq true end end context 'properly configured' do before(:example) do @message = 'notify slack' allow_any_instance_of(Slack::Notifier).to receive(:ping).and_return(@message) end it 'should notify slack' do UniformNotifier.slack = { webhook_url: 'http://some.slack.url' } expect_any_instance_of(Slack::Notifier).to receive(:ping) expect(UniformNotifier::Slack.out_of_channel_notify(title: @message)).to eq @message end end end uniform-notifier-1.13.0/spec/uniform_notifier/sentry_spec.rb0000644000175000017500000000145713703133607025515 0ustar debbiecocoadebbiecocoa# frozen_string_literal: true require 'spec_helper' class Raven # mock Sentry end RSpec.describe UniformNotifier::SentryNotifier do it 'should not notify sentry' do expect(UniformNotifier::SentryNotifier.out_of_channel_notify(title: 'notify sentry')).to be_nil end it 'should notify sentry' do expect(Raven).to receive(:capture_exception).with(UniformNotifier::Exception.new('notify sentry'), {}) UniformNotifier.sentry = true UniformNotifier::SentryNotifier.out_of_channel_notify(title: 'notify sentry') end it 'should notify sentry' do expect(Raven).to receive(:capture_exception).with(UniformNotifier::Exception.new('notify sentry'), foo: :bar) UniformNotifier.sentry = { foo: :bar } UniformNotifier::SentryNotifier.out_of_channel_notify('notify sentry') end end uniform-notifier-1.13.0/spec/uniform_notifier/xmpp_spec.rb0000644000175000017500000000445013703133607025151 0ustar debbiecocoadebbiecocoa# frozen_string_literal: true require 'spec_helper' RSpec.describe UniformNotifier::Xmpp do it 'should not notify xmpp' do expect(UniformNotifier::Xmpp.out_of_channel_notify(title: 'notify xmpp')).to be_nil end it 'should notify xmpp without online status' do jid = double('jid') xmpp = double('xmpp') expect(Jabber::JID).to receive(:new).with('from@gmail.com').and_return(jid) expect(Jabber::Client).to receive(:new).with(jid).and_return(xmpp) expect(xmpp).to receive(:connect) expect(xmpp).to receive(:auth).with('123456') message = double('message') expect(Jabber::Message).to receive(:new).with('to@gmail.com', 'notify xmpp').and_return(message) expect(message).to receive(:set_type).with(:normal).and_return(message) expect(message).to receive(:set_subject).with('Uniform Notifier').and_return(message) expect(xmpp).to receive(:send).with(message) UniformNotifier.xmpp = { account: 'from@gmail.com', password: '123456', receiver: 'to@gmail.com', show_online_status: false } UniformNotifier::Xmpp.out_of_channel_notify(title: 'notify xmpp') end it 'should notify xmpp with online status' do jid = double('jid') xmpp = double('xmpp') expect(Jabber::JID).to receive(:new).with('from@gmail.com').and_return(jid) expect(Jabber::Client).to receive(:new).with(jid).and_return(xmpp) expect(xmpp).to receive(:connect) expect(xmpp).to receive(:auth).with('123456') presence = double('presence') now = Time.now allow(Time).to receive(:now).and_return(now) expect(Jabber::Presence).to receive(:new).and_return(presence) expect(presence).to receive(:set_status).with("Uniform Notifier started on #{now}").and_return(presence) expect(xmpp).to receive(:send).with(presence) message = double('message') expect(Jabber::Message).to receive(:new).with('to@gmail.com', 'notify xmpp').and_return(message) expect(message).to receive(:set_type).with(:normal).and_return(message) expect(message).to receive(:set_subject).with('Uniform Notifier').and_return(message) expect(xmpp).to receive(:send).with(message) UniformNotifier.xmpp = { account: 'from@gmail.com', password: '123456', receiver: 'to@gmail.com', show_online_status: true } UniformNotifier::Xmpp.out_of_channel_notify(title: 'notify xmpp') end end uniform-notifier-1.13.0/spec/uniform_notifier/terminal_notifier_spec.rb0000644000175000017500000000170113703133607027673 0ustar debbiecocoadebbiecocoa# frozen_string_literal: true require 'spec_helper' RSpec.describe UniformNotifier::TerminalNotifier do it 'should not notify terminal-notifier when disabled' do expect(UniformNotifier::TerminalNotifier.out_of_channel_notify(title: 'notify terminal')).to be_nil end it "should raise an exception when terminal-notifier gem isn't available" do UniformNotifier.terminal_notifier = true expect { UniformNotifier::TerminalNotifier.out_of_channel_notify(body: 'body', title: 'notify terminal') }.to raise_error(UniformNotifier::NotificationError, /terminal-notifier gem/) end it 'should notify terminal-notifier when enabled' do module TerminalNotifier # mock TerminalNotifier end expect(TerminalNotifier).to receive(:notify).with('body', title: 'notify terminal') UniformNotifier.terminal_notifier = true UniformNotifier::TerminalNotifier.out_of_channel_notify(body: 'body', title: 'notify terminal') end end uniform-notifier-1.13.0/spec/uniform_notifier/rollbar_spec.rb0000644000175000017500000000147213703133607025623 0ustar debbiecocoadebbiecocoa# frozen_string_literal: true require 'spec_helper' class Rollbar # mock Rollbar end RSpec.describe UniformNotifier::RollbarNotifier do it 'should not notify rollbar' do expect(UniformNotifier::RollbarNotifier.out_of_channel_notify(title: 'notify rollbar')).to be_nil end it 'should notify rollbar' do expect(Rollbar).to receive(:log).with('info', UniformNotifier::Exception.new('notify rollbar')) UniformNotifier.rollbar = true UniformNotifier::RollbarNotifier.out_of_channel_notify(title: 'notify rollbar') end it 'should notify rollbar' do expect(Rollbar).to receive(:log).with('warning', UniformNotifier::Exception.new('notify rollbar')) UniformNotifier.rollbar = { level: 'warning' } UniformNotifier::RollbarNotifier.out_of_channel_notify(title: 'notify rollbar') end end uniform-notifier-1.13.0/spec/uniform_notifier/javascript_console_spec.rb0000644000175000017500000000433313703133607030055 0ustar debbiecocoadebbiecocoa# frozen_string_literal: true require 'spec_helper' RSpec.describe UniformNotifier::JavascriptConsole do it 'should not notify message' do expect(UniformNotifier::JavascriptConsole.inline_notify(title: 'javascript console!')).to be_nil end it 'should notify message' do UniformNotifier.console = true expect(UniformNotifier::JavascriptConsole.inline_notify(title: 'javascript console!')).to eq <<~CODE CODE end it 'should accept custom attributes' do UniformNotifier.console = { attributes: { nonce: 'my-nonce', 'data-key' => :value } } expect(UniformNotifier::JavascriptConsole.inline_notify(title: 'javascript console!')).to eq <<~CODE CODE end it 'should have default attributes if no attributes settings exist' do UniformNotifier.console = {} expect(UniformNotifier::JavascriptConsole.inline_notify(title: 'javascript console!')).to eq <<~CODE CODE end end uniform-notifier-1.13.0/spec/uniform_notifier/raise_spec.rb0000644000175000017500000000172013703133607025265 0ustar debbiecocoadebbiecocoa# frozen_string_literal: true require 'spec_helper' RSpec.describe UniformNotifier::Raise do it 'should not notify message' do expect(UniformNotifier::Raise.out_of_channel_notify(title: 'notification')).to be_nil end it 'should raise error of the default class' do UniformNotifier.raise = true expect { UniformNotifier::Raise.out_of_channel_notify(title: 'notification') }.to raise_error(UniformNotifier::Exception, 'notification') end it 'allows the user to override the default exception class' do klass = Class.new(Exception) UniformNotifier.raise = klass expect { UniformNotifier::Raise.out_of_channel_notify(title: 'notification') }.to raise_error(klass, 'notification') end it 'can be turned from on to off again' do UniformNotifier.raise = true UniformNotifier.raise = false expect { UniformNotifier::Raise.out_of_channel_notify(title: 'notification') }.not_to raise_error end end uniform-notifier-1.13.0/spec/uniform_notifier/bugsnag_spec.rb0000644000175000017500000000447213703133607025617 0ustar debbiecocoadebbiecocoa# frozen_string_literal: true require 'spec_helper' class Bugsnag # mock Bugsnag end RSpec.describe UniformNotifier::BugsnagNotifier do let(:notification_data) { {} } it 'should not notify bugsnag' do expect(Bugsnag).not_to receive(:notify) UniformNotifier::BugsnagNotifier.out_of_channel_notify(notification_data) end context 'with string notification' do let(:notification_data) { { user: 'user', title: 'notify bugsnag', url: 'URL', body: 'something' } } it 'should notify bugsnag' do expect(Bugsnag).to receive(:notify).with(UniformNotifier::Exception.new(notification_data[:title]), grouping_hash: notification_data[:body], notification: notification_data) UniformNotifier.bugsnag = true UniformNotifier::BugsnagNotifier.out_of_channel_notify(notification_data) end it 'should notify bugsnag with option' do expect(Bugsnag).to receive(:notify).with(UniformNotifier::Exception.new(notification_data[:title]), foo: :bar, grouping_hash: notification_data[:body], notification: notification_data) UniformNotifier.bugsnag = { foo: :bar } UniformNotifier::BugsnagNotifier.out_of_channel_notify(notification_data) end end context 'with hash notification' do let(:notification_data) { 'notify bugsnag' } it 'should notify bugsnag' do expect(Bugsnag).to receive(:notify).with(UniformNotifier::Exception.new('notify bugsnag'), grouping_hash: 'notify bugsnag', notification: { title: 'notify bugsnag' }) UniformNotifier.bugsnag = true UniformNotifier::BugsnagNotifier.out_of_channel_notify(notification_data) end it 'should notify bugsnag with option' do expect(Bugsnag).to receive(:notify).with(UniformNotifier::Exception.new('notify bugsnag'), foo: :bar, grouping_hash: 'notify bugsnag', notification: { title: 'notify bugsnag' }) UniformNotifier.bugsnag = { foo: :bar } UniformNotifier::BugsnagNotifier.out_of_channel_notify(notification_data) end end it 'should notify bugsnag with correct backtrace' do expect(Bugsnag).to receive(:notify) do |error| expect(error).to be_a UniformNotifier::Exception expect(error.backtrace).to eq ['bugsnag spec test'] end UniformNotifier.bugsnag = true UniformNotifier::BugsnagNotifier.out_of_channel_notify(backtrace: ['bugsnag spec test']) end end uniform-notifier-1.13.0/spec/uniform_notifier/javascript_alert_spec.rb0000644000175000017500000000235613703133607027525 0ustar debbiecocoadebbiecocoa# frozen_string_literal: true require 'spec_helper' RSpec.describe UniformNotifier::JavascriptAlert do it 'should not notify message' do expect(UniformNotifier::JavascriptAlert.inline_notify(title: 'javascript alert!')).to be_nil end it 'should notify message' do UniformNotifier.alert = true expect(UniformNotifier::JavascriptAlert.inline_notify(title: 'javascript alert!')).to eq <<~CODE CODE end it 'should accept custom attributes' do UniformNotifier.alert = { attributes: { nonce: 'my-nonce', 'data-key' => :value } } expect(UniformNotifier::JavascriptAlert.inline_notify(title: 'javascript alert!')).to eq <<~CODE CODE end it 'should have default attributes if no attributes settings exist' do UniformNotifier.alert = {} expect(UniformNotifier::JavascriptAlert.inline_notify(title: 'javascript alert!')).to eq <<~CODE CODE end end uniform-notifier-1.13.0/CHANGELOG.md0000644000175000017500000000211413703133607020122 0ustar debbiecocoadebbiecocoa# Next Release ## 1.13.0 (10/05/2019) * Add Honeybadger class dependecy injection. * Allow configuration of Rollbar level. ## 1.12.1 (10/30/2018) * Require Ruby 2.3+ ## 1.12.0 (08/17/2018) * Add [terminal-notifier](https://github.com/julienXX/terminal-notifier) support * Lots of refactors from Awesome Code ## 1.11.0 (11/13/2017) * Add Sentry notifier ## 1.10.0 (01/06/2016) * Add honeybadger notifier * Eliminate ruby warnings ## 1.9.0 (04/19/2015) * Add `UniformNotifier::AVAILABLE_NOTIFIERS` constant ## 1.8.0 (03/17/2015) * Add rollbar notifier ## 1.7.0 (02/08/2015) * Add slack notifier ## 1.6.0 (04/30/2014) * Support detail notify data * Add options for airbrake and bugsnag notifiers ## 1.5.0 (04/26/2014) * Add bugsnag notifier * Use custom excaption ## 1.4.0 (11/03/2013) * Raise should implement `out_of_channel_notify` instead of `inline_notify` ## 1.3.0 (08/28/2012) * Add raise notifier ## 1.2.0 (03/03/2013) * Compatible with ruby-growl 4.0 gem ## 1.1.0 (09/28/2012) * Add growl gntp support * Add airbrake notifier ## 1.0.0 (11/19/2010) * First release