uniform_notifier 1.11.0 → 1.13.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +5 -5
  2. data/.travis.yml +1 -1
  3. data/CHANGELOG.md +17 -1
  4. data/Gemfile +3 -1
  5. data/README.md +95 -77
  6. data/Rakefile +13 -11
  7. data/lib/uniform_notifier.rb +37 -10
  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 +3 -3
  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 +12 -10
  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 +30 -25
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: daf1fcd71af2c468e1ba0fe5173fac2205bae8dd
4
- data.tar.gz: c97aeac72e004d585fba564dc09fbc408d5af426
2
+ SHA256:
3
+ metadata.gz: caeab8d8f879b1215cb8f9e7523400cc2965820eecfc78d2cb0ba25186b47973
4
+ data.tar.gz: 3a7dc976b54fcb942ebe201634b59147b8b92488b9971a25d4ce89615a3c6dbf
5
5
  SHA512:
6
- metadata.gz: 23fe312e299e387bba4da21216ad2e0c5dd87e92c032fed14fb5fedd210c21c7a925be46cdfb7a1056609b4493fc17de29fa1c00c9581b970510f9780d8ffd30
7
- data.tar.gz: 00446377e262d875c05f5fb78ec8086c9502559e908909243c965687f17abe7bd27f7b586b5a5ab6b17f6ba8038ceb42a1300b98c01d394941f87e2e634f1c65
6
+ metadata.gz: b036883f44cc5504b74695abe5a967fa8c673eb006b3704402bf2802c97baeaa1fcb27f54bd62f8fd6a2b1fa6eac7cd466f8e55621e533749548ae37b41a0f0e
7
+ data.tar.gz: 38c16a936df8d779f778a23dfa740d507548e26c9b4d28b42bcebab2ebc59872ffb56cc23dbb8fff0275d036d925a99e2cef1983eae8c9add4d81dfc0a84deb3
@@ -1,3 +1,3 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.0.0
3
+ - 2.3.6
@@ -1,6 +1,22 @@
1
1
  # Next Release
2
2
 
3
- ## 1.11.0 (13/11/2017)
3
+ * Fix UniformNotifier::Raise.active? when .rails= receives a false value
4
+
5
+ ## 1.13.0 (10/05/2019)
6
+
7
+ * Add Honeybadger class dependecy injection.
8
+ * Allow configuration of Rollbar level.
9
+
10
+ ## 1.12.1 (10/30/2018)
11
+
12
+ * Require Ruby 2.3+
13
+
14
+ ## 1.12.0 (08/17/2018)
15
+
16
+ * Add [terminal-notifier](https://github.com/julienXX/terminal-notifier) support
17
+ * Lots of refactors from Awesome Code
18
+
19
+ ## 1.11.0 (11/13/2017)
4
20
 
5
21
  * Add Sentry notifier
6
22
 
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', :channel => '#default', :username => 'notifier' }
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'
@@ -13,25 +15,50 @@ require 'uniform_notifier/rollbar'
13
15
  require 'uniform_notifier/bugsnag'
14
16
  require 'uniform_notifier/slack'
15
17
  require 'uniform_notifier/raise'
18
+ require 'uniform_notifier/terminal_notifier'
16
19
 
17
20
  class UniformNotifier
18
- AVAILABLE_NOTIFIERS = [:alert, :console, :growl, :honeybadger, :xmpp, :rails_logger,
19
- :customized_logger, :airbrake, :rollbar, :bugsnag, :slack, :raise,
20
- :sentry
21
- ]
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
22
37
 
23
- NOTIFIERS = [JavascriptAlert, JavascriptConsole, Growl, HoneybadgerNotifier, Xmpp, RailsLogger,
24
- CustomizedLogger, AirbrakeNotifier, RollbarNotifier, BugsnagNotifier, Raise, Slack,
25
- SentryNotifier
26
- ]
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
27
54
 
28
55
  class NotificationError < StandardError; end
29
56
 
30
- class <<self
57
+ class << self
31
58
  attr_accessor(*AVAILABLE_NOTIFIERS)
32
59
 
33
60
  def active_notifiers
34
- NOTIFIERS.select { |notifier| notifier.active? }
61
+ NOTIFIERS.select(&:active?)
35
62
  end
36
63
 
37
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