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.
- checksums.yaml +5 -5
- data/.travis.yml +1 -1
- data/CHANGELOG.md +18 -0
- data/Gemfile +3 -1
- data/README.md +95 -77
- data/Rakefile +13 -11
- data/lib/uniform_notifier.rb +38 -6
- data/lib/uniform_notifier/airbrake.rb +3 -3
- data/lib/uniform_notifier/base.rb +17 -14
- data/lib/uniform_notifier/bugsnag.rb +4 -7
- data/lib/uniform_notifier/customized_logger.rb +6 -4
- data/lib/uniform_notifier/errors.rb +3 -1
- data/lib/uniform_notifier/growl.rb +20 -21
- data/lib/uniform_notifier/honeybadger.rb +5 -4
- data/lib/uniform_notifier/javascript_alert.rb +7 -3
- data/lib/uniform_notifier/javascript_console.rb +18 -14
- data/lib/uniform_notifier/rails_logger.rb +3 -1
- data/lib/uniform_notifier/raise.rb +4 -2
- data/lib/uniform_notifier/rollbar.rb +8 -1
- data/lib/uniform_notifier/sentry.rb +21 -0
- data/lib/uniform_notifier/slack.rb +20 -22
- data/lib/uniform_notifier/terminal_notifier.rb +24 -0
- data/lib/uniform_notifier/version.rb +3 -1
- data/lib/uniform_notifier/xmpp.rb +25 -24
- data/spec/spec_helper.rb +8 -6
- data/spec/uniform_notifier/airbrake_spec.rb +12 -10
- data/spec/uniform_notifier/base_spec.rb +12 -14
- data/spec/uniform_notifier/bugsnag_spec.rb +33 -19
- data/spec/uniform_notifier/customized_logger_spec.rb +9 -7
- data/spec/uniform_notifier/growl_spec.rb +41 -23
- data/spec/uniform_notifier/honeybadger_spec.rb +12 -10
- data/spec/uniform_notifier/javascript_alert_spec.rb +29 -9
- data/spec/uniform_notifier/javascript_console_spec.rb +55 -17
- data/spec/uniform_notifier/rails_logger_spec.rb +9 -7
- data/spec/uniform_notifier/raise_spec.rb +15 -16
- data/spec/uniform_notifier/rollbar_spec.rb +15 -6
- data/spec/uniform_notifier/sentry_spec.rb +27 -0
- data/spec/uniform_notifier/slack_spec.rb +12 -8
- data/spec/uniform_notifier/terminal_notifier_spec.rb +27 -0
- data/spec/uniform_notifier/xmpp_spec.rb +21 -15
- data/uniform_notifier.gemspec +24 -17
- metadata +33 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: dacef5e1c0f74c728aa2a8e4b6fe6e31701b426657c3416a9180f768f61fad4c
|
4
|
+
data.tar.gz: 86c66452779fae50c955177392892a33aaa34624274b7c5c1faaec72f56d2917
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ea912a1f196dacde8e5146304f3b5fb0d76b9d46f35a12e76b0a50e1e4c52b5b27e2dd6742fb1f5276f1a73b53e15d667f9485ababca63c16e896302d762f203
|
7
|
+
data.tar.gz: f58c6974795db0b7e6e1e04bf33997bdcc280999f6b5bbf0ef6b0b20b323fed7d005b2bc24fce7b444f78ce9186d75bbe6c024a2e8d4fec42b9ce6998b3ce0a9
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -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
data/README.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
# UniformNotifier
|
2
2
|
|
3
|
+
[](http://travis-ci.org/flyerhzm/uniform_notifier)
|
5
|
+
[](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
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
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
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
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
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
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 =
|
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
|
15
|
-
spec.pattern =
|
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 =
|
21
|
+
rdoc.rdoc_dir = 'rdoc'
|
20
22
|
rdoc.title = "uniform_notifier #{UniformNotifier::VERSION}"
|
21
|
-
rdoc.rdoc_files.include(
|
22
|
-
rdoc.rdoc_files.include(
|
23
|
+
rdoc.rdoc_files.include('README*')
|
24
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
23
25
|
end
|
24
26
|
|
25
|
-
task :
|
27
|
+
task default: :spec
|
data/lib/uniform_notifier.rb
CHANGED
@@ -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 = [
|
18
|
-
|
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 = [
|
21
|
-
|
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
|
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(
|
9
|
+
def self.inline_notify(data)
|
8
10
|
return unless active?
|
9
11
|
|
10
12
|
# For compatibility to the old protocol
|
11
|
-
data = { :
|
13
|
+
data = { title: data } if data.is_a?(String)
|
12
14
|
|
13
|
-
_inline_notify(
|
15
|
+
_inline_notify(data)
|
14
16
|
end
|
15
17
|
|
16
|
-
def self.out_of_channel_notify(
|
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 = { :
|
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(
|
28
|
-
end
|
29
|
+
def self._inline_notify(data); end
|
29
30
|
|
30
|
-
def self._out_of_channel_notify(
|
31
|
-
|
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
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
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
|