uniform_notifier 1.10.0 → 1.13.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. checksums.yaml +5 -5
  2. data/.travis.yml +1 -1
  3. data/CHANGELOG.md +18 -0
  4. data/Gemfile +3 -1
  5. data/README.md +95 -77
  6. data/Rakefile +13 -11
  7. data/lib/uniform_notifier.rb +38 -6
  8. data/lib/uniform_notifier/airbrake.rb +3 -3
  9. data/lib/uniform_notifier/base.rb +17 -14
  10. data/lib/uniform_notifier/bugsnag.rb +4 -7
  11. data/lib/uniform_notifier/customized_logger.rb +6 -4
  12. data/lib/uniform_notifier/errors.rb +3 -1
  13. data/lib/uniform_notifier/growl.rb +20 -21
  14. data/lib/uniform_notifier/honeybadger.rb +5 -4
  15. data/lib/uniform_notifier/javascript_alert.rb +7 -3
  16. data/lib/uniform_notifier/javascript_console.rb +18 -14
  17. data/lib/uniform_notifier/rails_logger.rb +3 -1
  18. data/lib/uniform_notifier/raise.rb +4 -2
  19. data/lib/uniform_notifier/rollbar.rb +8 -1
  20. data/lib/uniform_notifier/sentry.rb +21 -0
  21. data/lib/uniform_notifier/slack.rb +20 -22
  22. data/lib/uniform_notifier/terminal_notifier.rb +24 -0
  23. data/lib/uniform_notifier/version.rb +3 -1
  24. data/lib/uniform_notifier/xmpp.rb +25 -24
  25. data/spec/spec_helper.rb +8 -6
  26. data/spec/uniform_notifier/airbrake_spec.rb +12 -10
  27. data/spec/uniform_notifier/base_spec.rb +12 -14
  28. data/spec/uniform_notifier/bugsnag_spec.rb +33 -19
  29. data/spec/uniform_notifier/customized_logger_spec.rb +9 -7
  30. data/spec/uniform_notifier/growl_spec.rb +41 -23
  31. data/spec/uniform_notifier/honeybadger_spec.rb +12 -10
  32. data/spec/uniform_notifier/javascript_alert_spec.rb +29 -9
  33. data/spec/uniform_notifier/javascript_console_spec.rb +55 -17
  34. data/spec/uniform_notifier/rails_logger_spec.rb +9 -7
  35. data/spec/uniform_notifier/raise_spec.rb +15 -16
  36. data/spec/uniform_notifier/rollbar_spec.rb +15 -6
  37. data/spec/uniform_notifier/sentry_spec.rb +27 -0
  38. data/spec/uniform_notifier/slack_spec.rb +12 -8
  39. data/spec/uniform_notifier/terminal_notifier_spec.rb +27 -0
  40. data/spec/uniform_notifier/xmpp_spec.rb +21 -15
  41. data/uniform_notifier.gemspec +24 -17
  42. metadata +33 -25
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: ce5c6778339ac98c3683322370c55b36e2e0f6d8
4
- data.tar.gz: 2c10528a49539b46b7cdfbde658d5032e04ccffb
2
+ SHA256:
3
+ metadata.gz: dacef5e1c0f74c728aa2a8e4b6fe6e31701b426657c3416a9180f768f61fad4c
4
+ data.tar.gz: 86c66452779fae50c955177392892a33aaa34624274b7c5c1faaec72f56d2917
5
5
  SHA512:
6
- metadata.gz: bdff272e464293c384f81eb736b0e1d639293ae84b97c3212cff43f8ea5e150f43095f5f4efd055c57c50eb9be4e9d664d75efcf4b3d07d16083b058cf65e335
7
- data.tar.gz: 0918ca02b1d871578e5cd5c45bb0037553ef7739adcbdd73d4655dad8d796290a0890e38de0fe1168c57af2dce392d458ab998507141a3ed46ed1c1cdea466a4
6
+ metadata.gz: ea912a1f196dacde8e5146304f3b5fb0d76b9d46f35a12e76b0a50e1e4c52b5b27e2dd6742fb1f5276f1a73b53e15d667f9485ababca63c16e896302d762f203
7
+ data.tar.gz: f58c6974795db0b7e6e1e04bf33997bdcc280999f6b5bbf0ef6b0b20b323fed7d005b2bc24fce7b444f78ce9186d75bbe6c024a2e8d4fec42b9ce6998b3ce0a9
@@ -1,3 +1,3 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.0.0
3
+ - 2.3.6
@@ -1,5 +1,23 @@
1
1
  # Next Release
2
2
 
3
+ ## 1.13.0 (10/05/2019)
4
+
5
+ * Add Honeybadger class dependecy injection.
6
+ * Allow configuration of Rollbar level.
7
+
8
+ ## 1.12.1 (10/30/2018)
9
+
10
+ * Require Ruby 2.3+
11
+
12
+ ## 1.12.0 (08/17/2018)
13
+
14
+ * Add [terminal-notifier](https://github.com/julienXX/terminal-notifier) support
15
+ * Lots of refactors from Awesome Code
16
+
17
+ ## 1.11.0 (11/13/2017)
18
+
19
+ * Add Sentry notifier
20
+
3
21
  ## 1.10.0 (01/06/2016)
4
22
 
5
23
  * Add honeybadger notifier
data/Gemfile CHANGED
@@ -1,4 +1,6 @@
1
- source "http://rubygems.org"
1
+ # frozen_string_literal: true
2
+
3
+ source 'http://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in uniform_notifier.gemspec
4
6
  gemspec
data/README.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # UniformNotifier
2
2
 
3
+ [![Build
4
+ Status](https://secure.travis-ci.org/flyerhzm/uniform_notifier.svg)](http://travis-ci.org/flyerhzm/uniform_notifier)
5
+ [![AwesomeCode Status for flyerhzm/uniform_notifier](https://awesomecode.io/projects/3e29a7de-0b37-4ecf-b06d-410ebf815174/status)](https://awesomecode.io/repos/flyerhzm/uniform_notifier)
6
+
3
7
  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.
4
8
 
5
9
  ## Install
@@ -40,11 +44,15 @@ if you want to notify by slack, you should install slack-notifier first
40
44
 
41
45
  gem install slack-notifier
42
46
 
47
+ if you want to notify by terminal-notifier, you must install it first
48
+
49
+ gem install terminal-notifier
50
+
43
51
  ### add it into Gemfile (Bundler)
44
52
 
45
53
  gem "uniform_notifier"
46
54
 
47
- you should add ruby-growl, ruby_gntp, xmpp4r, airbrake, bugsnag, honeybadger, slack-notifier gem if you want.
55
+ you should add ruby-growl, ruby_gntp, xmpp4r, airbrake, bugsnag, honeybadger, slack-notifier, terminal-notifier gem if you want.
48
56
 
49
57
  ## Usage
50
58
 
@@ -54,80 +62,95 @@ the other is <code>out_of_channel_notify</code>, for rails logger, customized lo
54
62
 
55
63
  By default, all notifiers are disabled, you should enable them first.
56
64
 
57
- # javascript alert
58
- UniformNotifier.alert = true
59
-
60
- # javascript console (Safari/Webkit browsers or Firefox w/Firebug installed)
61
- UniformNotifier.console = true
62
-
63
- # rails logger
64
- UniformNotifier.rails_logger = true
65
-
66
- # airbrake
67
- UniformNotifier.airbrake = true
68
- # airbrake with options
69
- UniformNotifier.airbrake = { :error_class => Exception }
70
-
71
- # Honeybadger
72
- #
73
- # Reporting live data from development is disabled by default. Ensure
74
- # that the `report_data` option is enabled via configuration.
75
- UniformNotifier.honeybadger = true
76
- # Honeybadger with options
77
- UniformNotifier.honeybadger = { :error_class => 'Exception' }
78
-
79
- # rollbar
80
- UniformNotifier.rollbar = true
81
-
82
- # bugsnag
83
- UniformNotifier.bugsnag = true
84
- # bugsnag with options
85
- UniformNotifier.bugsnag = { :api_key => 'something' }
86
-
87
- # slack
88
- UniformNotifier.slack = true
89
- # slack with options
90
- UniformNotifier.slack = { :webhook_url => 'http://some.slack.url', :foo => 'bar' }
91
-
92
- # customized logger
93
- logger = File.open('notify.log', 'a+')
94
- logger.sync = true
95
- UniformNotifier.customized_logger = logger
96
-
97
- # growl without password
98
- UniformNotifier.growl = true
99
- # growl with passowrd
100
- UniformNotifier.growl = { :password => 'growl password' }
101
-
102
- # xmpp
103
- UniformNotifier.xmpp = { :account => 'sender_account@jabber.org',
104
- :password => 'password_for_jabber',
105
- :receiver => 'recipient_account@jabber.org',
106
- :show_online_status => true }
107
-
108
- # raise an error
109
- UniformNotifier.raise = true # raise a generic exception
110
-
111
- class MyExceptionClass < Exception; end
112
- UniformNotifier.raise = MyExceptionClass # raise a custom exception type
113
-
114
- UniformNotifier.raise = false # don't raise errors
65
+ ```ruby
66
+ # javascript alert
67
+ UniformNotifier.alert = true
68
+ # javascript alert with options
69
+ # the attributes key adds custom attributes to the script tag appended to the body
70
+ UniformNotifier.alert = { :attributes => { :nonce => 'mySecret-nonce', 'data-key' => 'value' } }
71
+
72
+ # javascript console (Safari/Webkit browsers or Firefox w/Firebug installed)
73
+ UniformNotifier.console = true
74
+ # javascript console with options
75
+ # the attributes key adds custom attributes to the script tag appended to the body
76
+ UniformNotifier.console = { :attributes => { :nonce => 'mySecret-nonce', 'data-key' => 'value' } }
77
+
78
+ # rails logger
79
+ UniformNotifier.rails_logger = true
80
+
81
+ # airbrake
82
+ UniformNotifier.airbrake = true
83
+ # airbrake with options
84
+ UniformNotifier.airbrake = { :error_class => Exception }
85
+
86
+ # Honeybadger
87
+ #
88
+ # Reporting live data from development is disabled by default. Ensure
89
+ # that the `report_data` option is enabled via configuration.
90
+ UniformNotifier.honeybadger = true
91
+ # Honeybadger with options
92
+ UniformNotifier.honeybadger = { :error_class => 'Exception' }
93
+
94
+ # rollbar
95
+ UniformNotifier.rollbar = true
96
+ # rollbar with options (level can be 'debug', 'info', 'warning', 'error' or 'critical')
97
+ UniformNotifier.rollbar = { :level => 'warning' }
98
+
99
+ # bugsnag
100
+ UniformNotifier.bugsnag = true
101
+ # bugsnag with options
102
+ UniformNotifier.bugsnag = { :api_key => 'something' }
103
+
104
+ # slack
105
+ UniformNotifier.slack = true
106
+ # slack with options
107
+ UniformNotifier.slack = { :webhook_url => 'http://some.slack.url', :channel => '#default', :username => 'notifier' }
108
+
109
+ # customized logger
110
+ logger = File.open('notify.log', 'a+')
111
+ logger.sync = true
112
+ UniformNotifier.customized_logger = logger
113
+
114
+ # growl without password
115
+ UniformNotifier.growl = true
116
+ # growl with passowrd
117
+ UniformNotifier.growl = { :password => 'growl password' }
118
+
119
+ # xmpp
120
+ UniformNotifier.xmpp = { :account => 'sender_account@jabber.org',
121
+ :password => 'password_for_jabber',
122
+ :receiver => 'recipient_account@jabber.org',
123
+ :show_online_status => true }
124
+
125
+ # terminal-notifier
126
+ UniformNotifier.terminal_notifier = true
127
+
128
+ # raise an error
129
+ UniformNotifier.raise = true # raise a generic exception
130
+
131
+ class MyExceptionClass < Exception; end
132
+ UniformNotifier.raise = MyExceptionClass # raise a custom exception type
133
+
134
+ UniformNotifier.raise = false # don't raise errors
135
+ ```
115
136
 
116
137
  After that, you can enjoy the notifiers, that's cool!
117
138
 
118
- # the notify message will be notified to rails logger, customized logger, growl or xmpp.
119
- UniformNotifier.active_notifiers.each do |notifier|
120
- notifier.out_of_channel_notify("customize message")
121
- end
122
-
123
- # the notify message will be wrapped by <script type="text/javascript">...</script>,
124
- # you should append the javascript_str at the bottom of http response body.
125
- # for more information, please check https://github.com/flyerhzm/bullet/blob/master/lib/bullet/rack.rb
126
- responses = []
127
- UniformNotifier.active_notifiers.each do |notifier|
128
- responses << notifier.inline_notify("customize message")
129
- end
130
- javascript_str = responses.join("\n")
139
+ ```ruby
140
+ # the notify message will be notified to rails logger, customized logger, growl or xmpp.
141
+ UniformNotifier.active_notifiers.each do |notifier|
142
+ notifier.out_of_channel_notify("customize message")
143
+ end
144
+
145
+ # the notify message will be wrapped by <script type="text/javascript">...</script>,
146
+ # you should append the javascript_str at the bottom of http response body.
147
+ # for more information, please check https://github.com/flyerhzm/bullet/blob/master/lib/bullet/rack.rb
148
+ responses = []
149
+ UniformNotifier.active_notifiers.each do |notifier|
150
+ responses << notifier.inline_notify("customize message")
151
+ end
152
+ javascript_str = responses.join("\n")
153
+ ```
131
154
 
132
155
  ## Growl Support
133
156
 
@@ -141,10 +164,6 @@ To get Growl support up-and-running, follow the steps below:
141
164
  * Restart Growl ("General" tab -> Stop Growl -> Start Growl)
142
165
  * 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.
143
166
 
144
- ### Ruby 1.9 issue
145
-
146
- ruby-growl gem has an issue about md5 in ruby 1.9, if you use growl and ruby 1.9, check this [gist][1]
147
-
148
167
  ## XMPP/Jabber Support
149
168
 
150
169
  To get XMPP support up-and-running, follow the steps below:
@@ -157,4 +176,3 @@ To get XMPP support up-and-running, follow the steps below:
157
176
 
158
177
 
159
178
  [0]: https://github.com/flyerhzm/bullet
160
- [1]: https://gist.github.com/300184
data/Rakefile CHANGED
@@ -1,25 +1,27 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bundler'
2
4
  Bundler::GemHelper.install_tasks
3
5
 
4
- require "rake"
5
- require "rdoc/task"
6
- require "rspec"
7
- require "rspec/core/rake_task"
6
+ require 'rake'
7
+ require 'rdoc/task'
8
+ require 'rspec'
9
+ require 'rspec/core/rake_task'
8
10
 
9
11
  RSpec::Core::RakeTask.new(:spec) do |spec|
10
- spec.pattern = "spec/**/*_spec.rb"
12
+ spec.pattern = 'spec/**/*_spec.rb'
11
13
  end
12
14
 
13
15
  RSpec::Core::RakeTask.new('spec:progress') do |spec|
14
- spec.rspec_opts = %w(--format progress)
15
- spec.pattern = "spec/**/*_spec.rb"
16
+ spec.rspec_opts = %w[--format progress]
17
+ spec.pattern = 'spec/**/*_spec.rb'
16
18
  end
17
19
 
18
20
  Rake::RDocTask.new do |rdoc|
19
- rdoc.rdoc_dir = "rdoc"
21
+ rdoc.rdoc_dir = 'rdoc'
20
22
  rdoc.title = "uniform_notifier #{UniformNotifier::VERSION}"
21
- rdoc.rdoc_files.include("README*")
22
- rdoc.rdoc_files.include("lib/**/*.rb")
23
+ rdoc.rdoc_files.include('README*')
24
+ rdoc.rdoc_files.include('lib/**/*.rb')
23
25
  end
24
26
 
25
- task :default => :spec
27
+ task default: :spec
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'uniform_notifier/base'
2
4
  require 'uniform_notifier/errors'
3
5
  require 'uniform_notifier/javascript_alert'
@@ -8,25 +10,55 @@ require 'uniform_notifier/xmpp'
8
10
  require 'uniform_notifier/rails_logger'
9
11
  require 'uniform_notifier/customized_logger'
10
12
  require 'uniform_notifier/airbrake'
13
+ require 'uniform_notifier/sentry'
11
14
  require 'uniform_notifier/rollbar'
12
15
  require 'uniform_notifier/bugsnag'
13
16
  require 'uniform_notifier/slack'
14
17
  require 'uniform_notifier/raise'
18
+ require 'uniform_notifier/terminal_notifier'
15
19
 
16
20
  class UniformNotifier
17
- AVAILABLE_NOTIFIERS = [:alert, :console, :growl, :honeybadger, :xmpp, :rails_logger,
18
- :customized_logger, :airbrake, :rollbar, :bugsnag, :slack, :raise]
21
+ AVAILABLE_NOTIFIERS = %i[
22
+ alert
23
+ console
24
+ growl
25
+ honeybadger
26
+ xmpp
27
+ rails_logger
28
+ customized_logger
29
+ airbrake
30
+ rollbar
31
+ bugsnag
32
+ slack
33
+ raise
34
+ sentry
35
+ terminal_notifier
36
+ ].freeze
19
37
 
20
- NOTIFIERS = [JavascriptAlert, JavascriptConsole, Growl, HoneybadgerNotifier, Xmpp, RailsLogger,
21
- CustomizedLogger, AirbrakeNotifier, RollbarNotifier, BugsnagNotifier, Raise, Slack]
38
+ NOTIFIERS = [
39
+ JavascriptAlert,
40
+ JavascriptConsole,
41
+ Growl,
42
+ HoneybadgerNotifier,
43
+ Xmpp,
44
+ RailsLogger,
45
+ CustomizedLogger,
46
+ AirbrakeNotifier,
47
+ RollbarNotifier,
48
+ BugsnagNotifier,
49
+ Raise,
50
+ Slack,
51
+ SentryNotifier,
52
+ TerminalNotifier
53
+ ].freeze
22
54
 
23
55
  class NotificationError < StandardError; end
24
56
 
25
- class <<self
57
+ class << self
26
58
  attr_accessor(*AVAILABLE_NOTIFIERS)
27
59
 
28
60
  def active_notifiers
29
- NOTIFIERS.select { |notifier| notifier.active? }
61
+ NOTIFIERS.select(&:active?)
30
62
  end
31
63
 
32
64
  undef :growl=
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class UniformNotifier
2
4
  class AirbrakeNotifier < Base
3
5
  def self.active?
@@ -10,9 +12,7 @@ class UniformNotifier
10
12
  message = data.values.compact.join("\n")
11
13
 
12
14
  opt = {}
13
- if UniformNotifier.airbrake.is_a?(Hash)
14
- opt = UniformNotifier.airbrake
15
- end
15
+ opt = UniformNotifier.airbrake if UniformNotifier.airbrake.is_a?(Hash)
16
16
 
17
17
  exception = Exception.new(message)
18
18
  Airbrake.notify(exception, opt)
@@ -1,40 +1,43 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class UniformNotifier
2
4
  class Base
3
5
  def self.active?
4
6
  false
5
7
  end
6
8
 
7
- def self.inline_notify( data )
9
+ def self.inline_notify(data)
8
10
  return unless active?
9
11
 
10
12
  # For compatibility to the old protocol
11
- data = { :title => data } if data.is_a?(String)
13
+ data = { title: data } if data.is_a?(String)
12
14
 
13
- _inline_notify( data )
15
+ _inline_notify(data)
14
16
  end
15
17
 
16
- def self.out_of_channel_notify( data )
18
+ def self.out_of_channel_notify(data)
17
19
  return unless active?
18
20
 
19
21
  # For compatibility to the old protocol
20
- data = { :title => data } if data.is_a?(String)
22
+ data = { title: data } if data.is_a?(String)
21
23
 
22
24
  _out_of_channel_notify(data)
23
25
  end
24
26
 
25
27
  protected
26
28
 
27
- def self._inline_notify( data )
28
- end
29
+ def self._inline_notify(data); end
29
30
 
30
- def self._out_of_channel_notify( data )
31
- end
31
+ def self._out_of_channel_notify(data); end
32
+
33
+ def self.wrap_js_association(code, attributes = {})
34
+ attributes = { type: 'text/javascript' }.merge(attributes || {})
35
+ attributes_string = attributes.map { |k, v| "#{k}=#{v.to_s.inspect}" }.join(' ')
32
36
 
33
- def self.wrap_js_association( code )
34
- <<-CODE
35
- <script type="text/javascript">/*<![CDATA[*/
36
- #{code}
37
- /*]]>*/</script>
37
+ <<~CODE
38
+ <script #{attributes_string}>/*<![CDATA[*/
39
+ #{code}
40
+ /*]]>*/</script>
38
41
  CODE
39
42
  end
40
43
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class UniformNotifier
2
4
  class BugsnagNotifier < Base
3
5
  def self.active?
@@ -8,16 +10,11 @@ class UniformNotifier
8
10
 
9
11
  def self._out_of_channel_notify(data)
10
12
  opt = {}
11
- if UniformNotifier.bugsnag.is_a?(Hash)
12
- opt = UniformNotifier.bugsnag
13
- end
13
+ opt = UniformNotifier.bugsnag if UniformNotifier.bugsnag.is_a?(Hash)
14
14
 
15
15
  exception = Exception.new(data[:title])
16
16
  exception.set_backtrace(data[:backtrace]) if data[:backtrace]
17
- Bugsnag.notify(exception, opt.merge(
18
- :grouping_hash => data[:body] || data[:title],
19
- :notification => data
20
- ))
17
+ Bugsnag.notify(exception, opt.merge(grouping_hash: data[:body] || data[:title], notification: data))
21
18
  end
22
19
  end
23
20
  end