uniform_notifier 1.11.0 → 1.12.0
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 +4 -4
- data/CHANGELOG.md +6 -1
- data/Gemfile +3 -1
- data/README.md +18 -1
- data/Rakefile +13 -11
- data/lib/uniform_notifier.rb +8 -7
- data/lib/uniform_notifier/airbrake.rb +2 -0
- data/lib/uniform_notifier/base.rb +17 -14
- data/lib/uniform_notifier/bugsnag.rb +5 -3
- data/lib/uniform_notifier/customized_logger.rb +6 -4
- data/lib/uniform_notifier/errors.rb +3 -1
- data/lib/uniform_notifier/growl.rb +23 -20
- data/lib/uniform_notifier/honeybadger.rb +2 -0
- 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 +3 -1
- data/lib/uniform_notifier/rollbar.rb +2 -0
- data/lib/uniform_notifier/sentry.rb +2 -0
- data/lib/uniform_notifier/slack.rb +20 -19
- data/lib/uniform_notifier/terminal_notifier.rb +23 -0
- data/lib/uniform_notifier/version.rb +3 -1
- data/lib/uniform_notifier/xmpp.rb +26 -23
- data/spec/spec_helper.rb +8 -6
- data/spec/uniform_notifier/airbrake_spec.rb +12 -10
- data/spec/uniform_notifier/base_spec.rb +10 -8
- data/spec/uniform_notifier/bugsnag_spec.rb +21 -19
- data/spec/uniform_notifier/customized_logger_spec.rb +9 -7
- data/spec/uniform_notifier/growl_spec.rb +19 -18
- 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 +13 -11
- data/spec/uniform_notifier/rollbar_spec.rb +8 -6
- data/spec/uniform_notifier/sentry_spec.rb +12 -10
- data/spec/uniform_notifier/slack_spec.rb +10 -8
- data/spec/uniform_notifier/terminal_notifier_spec.rb +25 -0
- data/spec/uniform_notifier/xmpp_spec.rb +17 -15
- data/uniform_notifier.gemspec +18 -17
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f27b211c1e550787b74d7a57a1f534fda78a5271
|
4
|
+
data.tar.gz: 052c8e0d80a431a89c71d5578c0603fd5609686f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 925e6cf2f2dfc20a84fef57e1bee9872d5ddb18396142b63e335f9db5fe275650a3def097a6a2688e7411ffe2dd980be1313b5271e577514193f9faf0f2f071b
|
7
|
+
data.tar.gz: 2056c09e18698a84e87f4c8029fea3c73643c7ded92af0f30a40c79edb58b02721a88517012183ebf76f1f6f829150307e3e594151c234fb9e2a438b1feb9eab
|
data/CHANGELOG.md
CHANGED
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/projects/32)
|
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
|
|
@@ -56,9 +64,15 @@ By default, all notifiers are disabled, you should enable them first.
|
|
56
64
|
|
57
65
|
# javascript alert
|
58
66
|
UniformNotifier.alert = true
|
67
|
+
# javascript alert with options
|
68
|
+
# the attributes key adds custom attributes to the script tag appended to the body
|
69
|
+
UniformNotifier.alert = { :attributes => { :nonce => 'mySecret-nonce', 'data-key' => 'value' } }
|
59
70
|
|
60
71
|
# javascript console (Safari/Webkit browsers or Firefox w/Firebug installed)
|
61
72
|
UniformNotifier.console = true
|
73
|
+
# javascript console with options
|
74
|
+
# the attributes key adds custom attributes to the script tag appended to the body
|
75
|
+
UniformNotifier.console = { :attributes => { :nonce => 'mySecret-nonce', 'data-key' => 'value' } }
|
62
76
|
|
63
77
|
# rails logger
|
64
78
|
UniformNotifier.rails_logger = true
|
@@ -105,6 +119,9 @@ By default, all notifiers are disabled, you should enable them first.
|
|
105
119
|
:receiver => 'recipient_account@jabber.org',
|
106
120
|
:show_online_status => true }
|
107
121
|
|
122
|
+
# terminal-notifier
|
123
|
+
UniformNotifier.terminal_notifier = true
|
124
|
+
|
108
125
|
# raise an error
|
109
126
|
UniformNotifier.raise = true # raise a generic exception
|
110
127
|
|
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'
|
@@ -13,17 +15,16 @@ 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 = [
|
19
|
-
|
20
|
-
|
21
|
-
]
|
21
|
+
AVAILABLE_NOTIFIERS = %i[alert console growl honeybadger xmpp rails_logger
|
22
|
+
customized_logger airbrake rollbar bugsnag slack raise
|
23
|
+
sentry terminal_notifier].freeze
|
22
24
|
|
23
25
|
NOTIFIERS = [JavascriptAlert, JavascriptConsole, Growl, HoneybadgerNotifier, Xmpp, RailsLogger,
|
24
26
|
CustomizedLogger, AirbrakeNotifier, RollbarNotifier, BugsnagNotifier, Raise, Slack,
|
25
|
-
SentryNotifier
|
26
|
-
]
|
27
|
+
SentryNotifier, TerminalNotifier].freeze
|
27
28
|
|
28
29
|
class NotificationError < StandardError; end
|
29
30
|
|
@@ -31,7 +32,7 @@ class UniformNotifier
|
|
31
32
|
attr_accessor(*AVAILABLE_NOTIFIERS)
|
32
33
|
|
33
34
|
def active_notifiers
|
34
|
-
NOTIFIERS.select
|
35
|
+
NOTIFIERS.select(&:active?)
|
35
36
|
end
|
36
37
|
|
37
38
|
undef :growl=
|
@@ -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?
|
@@ -15,9 +17,9 @@ class UniformNotifier
|
|
15
17
|
exception = Exception.new(data[:title])
|
16
18
|
exception.set_backtrace(data[:backtrace]) if data[:backtrace]
|
17
19
|
Bugsnag.notify(exception, opt.merge(
|
18
|
-
|
19
|
-
|
20
|
-
|
20
|
+
grouping_hash: data[:body] || data[:title],
|
21
|
+
notification: data
|
22
|
+
))
|
21
23
|
end
|
22
24
|
end
|
23
25
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class UniformNotifier
|
2
4
|
class CustomizedLogger < Base
|
3
5
|
@logger = nil
|
@@ -6,7 +8,7 @@ class UniformNotifier
|
|
6
8
|
@logger
|
7
9
|
end
|
8
10
|
|
9
|
-
def self._out_of_channel_notify(
|
11
|
+
def self._out_of_channel_notify(data)
|
10
12
|
message = data.values.compact.join("\n")
|
11
13
|
@logger.warn message
|
12
14
|
end
|
@@ -14,10 +16,10 @@ class UniformNotifier
|
|
14
16
|
def self.setup(logdev)
|
15
17
|
require 'logger'
|
16
18
|
|
17
|
-
@logger = Logger.new(
|
19
|
+
@logger = Logger.new(logdev)
|
18
20
|
|
19
|
-
def @logger.format_message(
|
20
|
-
"#{timestamp.strftime(
|
21
|
+
def @logger.format_message(severity, timestamp, _progname, msg)
|
22
|
+
"#{timestamp.strftime('%Y-%m-%d %H:%M:%S')}[#{severity}] #{msg}"
|
21
23
|
end
|
22
24
|
end
|
23
25
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class UniformNotifier
|
2
4
|
class Growl < Base
|
3
5
|
@growl = nil
|
@@ -6,18 +8,18 @@ class UniformNotifier
|
|
6
8
|
@growl
|
7
9
|
end
|
8
10
|
|
9
|
-
def self.setup_connection(
|
11
|
+
def self.setup_connection(growl)
|
10
12
|
setup_connection_growl(growl)
|
11
13
|
rescue LoadError
|
12
14
|
begin
|
13
15
|
setup_connection_gntp(growl)
|
14
16
|
rescue LoadError
|
15
17
|
@growl = nil
|
16
|
-
raise NotificationError
|
18
|
+
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`'
|
17
19
|
end
|
18
20
|
end
|
19
21
|
|
20
|
-
def self.setup_connection_growl(
|
22
|
+
def self.setup_connection_growl(growl)
|
21
23
|
return unless growl
|
22
24
|
require 'ruby-growl'
|
23
25
|
if growl.instance_of?(Hash)
|
@@ -33,7 +35,7 @@ class UniformNotifier
|
|
33
35
|
notify 'Uniform Notifier Growl has been turned on' if !growl.instance_of?(Hash) || !growl[:quiet]
|
34
36
|
end
|
35
37
|
|
36
|
-
def self.setup_connection_gntp(
|
38
|
+
def self.setup_connection_gntp(growl)
|
37
39
|
return unless growl
|
38
40
|
require 'ruby_gntp'
|
39
41
|
if growl.instance_of?(Hash)
|
@@ -43,33 +45,34 @@ class UniformNotifier
|
|
43
45
|
@password ||= nil
|
44
46
|
@host ||= 'localhost'
|
45
47
|
@growl = GNTP.new('uniform_notifier', @host, @password, 23053)
|
46
|
-
@growl.register(
|
47
|
-
|
48
|
-
|
49
|
-
|
48
|
+
@growl.register(notifications: [{
|
49
|
+
name: 'uniform_notifier',
|
50
|
+
enabled: true,
|
51
|
+
}])
|
50
52
|
|
51
53
|
notify 'Uniform Notifier Growl has been turned on (using GNTP)' if !growl.instance_of?(Hash) || !growl[:quiet]
|
52
54
|
end
|
53
55
|
|
54
56
|
protected
|
55
57
|
|
56
|
-
def self._out_of_channel_notify(
|
58
|
+
def self._out_of_channel_notify(data)
|
57
59
|
message = data.values.compact.join("\n")
|
58
60
|
|
59
|
-
notify(
|
61
|
+
notify(message)
|
60
62
|
end
|
61
63
|
|
62
64
|
private
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
65
|
+
|
66
|
+
def self.notify(message)
|
67
|
+
if defined?(::Growl) && @growl.is_a?(::Growl)
|
68
|
+
@growl.notify('uniform_notifier', 'Uniform Notifier', message)
|
69
|
+
elsif defined?(::GNTP) && @growl.is_a?(::GNTP)
|
70
|
+
@growl.notify(
|
71
|
+
name: 'uniform_notifier',
|
72
|
+
title: 'Uniform Notifier',
|
73
|
+
text: message
|
74
|
+
)
|
73
75
|
end
|
76
|
+
end
|
74
77
|
end
|
75
78
|
end
|
@@ -1,15 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class UniformNotifier
|
2
4
|
class JavascriptAlert < Base
|
3
5
|
def self.active?
|
4
|
-
UniformNotifier.alert
|
6
|
+
!!UniformNotifier.alert
|
5
7
|
end
|
6
8
|
|
7
9
|
protected
|
8
10
|
|
9
|
-
def self._inline_notify(
|
11
|
+
def self._inline_notify(data)
|
10
12
|
message = data.values.compact.join("\n")
|
13
|
+
options = UniformNotifier.alert.is_a?(Hash) ? UniformNotifier.alert : {}
|
14
|
+
script_attributes = options[:attributes] || {}
|
11
15
|
|
12
|
-
wrap_js_association "alert( #{message.inspect} );"
|
16
|
+
wrap_js_association "alert( #{message.inspect} );", script_attributes
|
13
17
|
end
|
14
18
|
end
|
15
19
|
end
|
@@ -1,27 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class UniformNotifier
|
2
4
|
class JavascriptConsole < Base
|
3
5
|
def self.active?
|
4
|
-
UniformNotifier.console
|
6
|
+
!!UniformNotifier.console
|
5
7
|
end
|
6
8
|
|
7
9
|
protected
|
8
10
|
|
9
|
-
def self._inline_notify(
|
11
|
+
def self._inline_notify(data)
|
10
12
|
message = data.values.compact.join("\n")
|
13
|
+
options = UniformNotifier.console.is_a?(Hash) ? UniformNotifier.console : {}
|
14
|
+
script_attributes = options[:attributes] || {}
|
11
15
|
|
12
|
-
code =
|
13
|
-
if (typeof(console) !== 'undefined' && console.log) {
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
}
|
22
|
-
CODE
|
16
|
+
code = <<~CODE
|
17
|
+
if (typeof(console) !== 'undefined' && console.log) {
|
18
|
+
if (console.groupCollapsed && console.groupEnd) {
|
19
|
+
console.groupCollapsed(#{'Uniform Notifier'.inspect});
|
20
|
+
console.log(#{message.inspect});
|
21
|
+
console.groupEnd();
|
22
|
+
} else {
|
23
|
+
console.log(#{message.inspect});
|
24
|
+
}
|
25
|
+
}
|
26
|
+
CODE
|
23
27
|
|
24
|
-
wrap_js_association code
|
28
|
+
wrap_js_association code, script_attributes
|
25
29
|
end
|
26
30
|
end
|
27
31
|
end
|