uniform_notifier 1.5.0 → 1.6.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 26d6f86098312bf5878fca405b3bf651089d4c5b
4
- data.tar.gz: e71a2a6610ac742438c4d113af2be3622e736ae1
3
+ metadata.gz: 169bfc94c2eacda49ee03c204a9d6533ac8d24e5
4
+ data.tar.gz: eda7a77778c26b9875d48807b712eb112a7fdfda
5
5
  SHA512:
6
- metadata.gz: 31e976a8477db1b6e0828f68f96f649817f1fd83442f26cc2432035a8bed44fb13181b116f39d10c4423703b27e1ff8881a1ecb2c523197eecfd3fa60a539931
7
- data.tar.gz: e0f3976a882378ad18457852c595eddf2c7c83461e476683a179d477354c3d31adb24350bca4a44702a0886b27d825d56b175e744c110b06361c047a777f03a6
6
+ metadata.gz: 9c13344e390f5bc8df51048af5baf7618279e8dfc4210a6ce922c950ccdab8cd983769cfb055a8b7c1a32991936ddbebe013c04d69a16887b171794d479d96bc
7
+ data.tar.gz: 78e83f46ab990bf1933a00dac4a97c8cfaae2ca45c2f8ac619dead742951e4c29df2f05adbb272c9e68397ddc334a570a8173ba0f9ddb3f5ac0251d710744e85
data/README.md CHANGED
@@ -53,9 +53,13 @@ By default, all notifiers are disabled, you should enable them first.
53
53
 
54
54
  # airbrake
55
55
  UniformNotifier.airbrake = true
56
+ # airbrake with options
57
+ UniformNotifier.airbrake = { :error_class => Exception }
56
58
 
57
59
  # bugsnag
58
60
  UniformNotifier.bugsnag = true
61
+ # bugsnag with options
62
+ UniformNotifier.bugsnag = { :api_key => 'something' }
59
63
 
60
64
  # customized logger
61
65
  logger = File.open('notify.log', 'a+')
@@ -1,13 +1,21 @@
1
1
  module UniformNotifier
2
2
  class AirbrakeNotifier < Base
3
3
  def self.active?
4
- UniformNotifier.airbrake
4
+ !!UniformNotifier.airbrake
5
5
  end
6
6
 
7
- def self.out_of_channel_notify(message)
8
- return unless active?
7
+ protected
8
+
9
+ def self._out_of_channel_notify(data)
10
+ message = data.values.compact.join("\n")
11
+
12
+ opt = {}
13
+ if UniformNotifier.airbrake.is_a?(Hash)
14
+ opt = UniformNotifier.airbrake
15
+ end
16
+
9
17
  exception = Exception.new(message)
10
- Airbrake.notify(exception)
18
+ Airbrake.notify(exception, opt)
11
19
  end
12
20
  end
13
21
  end
@@ -4,18 +4,38 @@ module UniformNotifier
4
4
  false
5
5
  end
6
6
 
7
- def self.inline_notify( message )
7
+ def self.inline_notify( data )
8
+ return unless active?
9
+
10
+ # For compatibility to the old protocol
11
+ data = { :title => data } if data.is_a?(String)
12
+
13
+ _inline_notify( data )
14
+ end
15
+
16
+ def self.out_of_channel_notify( data )
17
+ return unless active?
18
+
19
+ # For compatibility to the old protocol
20
+ data = { :title => data } if data.is_a?(String)
21
+
22
+ _out_of_channel_notify(data)
23
+ end
24
+
25
+ protected
26
+
27
+ def self._inline_notify( data )
8
28
  end
9
29
 
10
- def self.out_of_channel_notify( message )
30
+ def self._out_of_channel_notify( data )
11
31
  end
12
32
 
13
- def self.wrap_js_association( message )
33
+ def self.wrap_js_association( code )
14
34
  <<-CODE
15
35
  <script type="text/javascript">/*<![CDATA[*/
16
- #{message}
36
+ #{code}
17
37
  /*]]>*/</script>
18
38
  CODE
19
39
  end
20
40
  end
21
- end
41
+ end
@@ -1,13 +1,21 @@
1
1
  module UniformNotifier
2
2
  class BugsnagNotifier < Base
3
3
  def self.active?
4
- UniformNotifier.bugsnag
4
+ !!UniformNotifier.bugsnag
5
5
  end
6
6
 
7
- def self.out_of_channel_notify(message)
8
- return unless active?
7
+ protected
8
+
9
+ def self._out_of_channel_notify(data)
10
+ message = data.values.compact.join("\n")
11
+
12
+ opt = {}
13
+ if UniformNotifier.bugsnag.is_a?(Hash)
14
+ opt = UniformNotifier.bugsnag
15
+ end
16
+
9
17
  exception = Exception.new(message)
10
- Bugsnag.notify(exception)
18
+ Bugsnag.notify(exception, opt)
11
19
  end
12
20
  end
13
21
  end
@@ -6,8 +6,8 @@ module UniformNotifier
6
6
  @logger
7
7
  end
8
8
 
9
- def self.out_of_channel_notify( message )
10
- return unless active?
9
+ def self._out_of_channel_notify( data )
10
+ message = data.values.compact.join("\n")
11
11
  @logger.warn message
12
12
  end
13
13
 
@@ -6,11 +6,6 @@ module UniformNotifier
6
6
  @growl
7
7
  end
8
8
 
9
- def self.out_of_channel_notify( message )
10
- return unless active?
11
- notify( message )
12
- end
13
-
14
9
  def self.setup_connection( growl )
15
10
  setup_connection_growl(growl)
16
11
  rescue LoadError
@@ -45,6 +40,14 @@ module UniformNotifier
45
40
 
46
41
  notify 'Uniform Notifier Growl has been turned on (using GNTP)' if !growl.instance_of?(Hash) || !growl[:quiet]
47
42
  end
43
+
44
+ protected
45
+
46
+ def self._out_of_channel_notify( data )
47
+ message = data.values.compact.join("\n")
48
+
49
+ notify( message )
50
+ end
48
51
 
49
52
  private
50
53
  def self.notify( message )
@@ -3,11 +3,13 @@ module UniformNotifier
3
3
  def self.active?
4
4
  UniformNotifier.alert
5
5
  end
6
+
7
+ protected
6
8
 
7
- def self.inline_notify( message )
8
- return unless self.active?
9
+ def self._inline_notify( data )
10
+ message = data.values.compact.join("\n")
9
11
 
10
12
  wrap_js_association "alert( #{message.inspect} );"
11
13
  end
12
14
  end
13
- end
15
+ end
@@ -4,8 +4,10 @@ module UniformNotifier
4
4
  UniformNotifier.console
5
5
  end
6
6
 
7
- def self.inline_notify( message )
8
- return unless active?
7
+ protected
8
+
9
+ def self._inline_notify( data )
10
+ message = data.values.compact.join("\n")
9
11
 
10
12
  code = <<-CODE
11
13
  if (typeof(console) !== 'undefined' && console.log) {
@@ -22,4 +24,4 @@ CODE
22
24
  wrap_js_association code
23
25
  end
24
26
  end
25
- end
27
+ end
@@ -4,9 +4,12 @@ module UniformNotifier
4
4
  UniformNotifier.rails_logger
5
5
  end
6
6
 
7
- def self.out_of_channel_notify( message )
8
- return unless active?
7
+ protected
8
+
9
+ def self._out_of_channel_notify( data )
10
+ message = data.values.compact.join("\n")
11
+
9
12
  Rails.logger.warn message
10
13
  end
11
14
  end
12
- end
15
+ end
@@ -4,14 +4,16 @@ module UniformNotifier
4
4
  @exception_class
5
5
  end
6
6
 
7
- def self.out_of_channel_notify( message )
8
- return unless self.active?
9
-
10
- raise @exception_class, message
11
- end
12
-
13
7
  def self.setup_connection(exception_class)
14
8
  @exception_class = exception_class == true ? Exception : exception_class
15
9
  end
10
+
11
+ protected
12
+
13
+ def self._out_of_channel_notify( data )
14
+ message = data.values.compact.join("\n")
15
+
16
+ raise @exception_class, message
17
+ end
16
18
  end
17
19
  end
@@ -1,3 +1,3 @@
1
1
  module UniformNotifier
2
- VERSION = "1.5.0"
2
+ VERSION = "1.6.0"
3
3
  end
@@ -8,11 +8,6 @@ module UniformNotifier
8
8
  @xmpp
9
9
  end
10
10
 
11
- def self.out_of_channel_notify( message )
12
- return unless active?
13
- notify( message )
14
- end
15
-
16
11
  def self.setup_connection( xmpp_information )
17
12
  return unless xmpp_information
18
13
 
@@ -31,6 +26,14 @@ module UniformNotifier
31
26
  raise NotificationError.new( 'You must install the xmpp4r gem to use XMPP notification: `gem install xmpp4r`' )
32
27
  end
33
28
 
29
+ protected
30
+
31
+ def self._out_of_channel_notify( data )
32
+ message = data.values.compact.join("\n")
33
+
34
+ notify( message )
35
+ end
36
+
34
37
  private
35
38
  def self.connect
36
39
  jid = Jabber::JID.new( @account )
@@ -6,13 +6,20 @@ end
6
6
 
7
7
  describe UniformNotifier::AirbrakeNotifier do
8
8
  it "should not notify airbrake" do
9
- UniformNotifier::AirbrakeNotifier.out_of_channel_notify("notify airbrake").should be_nil
9
+ UniformNotifier::AirbrakeNotifier.out_of_channel_notify(:title => "notify airbrake").should be_nil
10
10
  end
11
11
 
12
12
  it "should notify airbrake" do
13
- Airbrake.should_receive(:notify).with(UniformNotifier::Exception.new("notify airbrake"))
13
+ Airbrake.should_receive(:notify).with(UniformNotifier::Exception.new("notify airbrake"), {})
14
14
 
15
15
  UniformNotifier.airbrake = true
16
+ UniformNotifier::AirbrakeNotifier.out_of_channel_notify(:title => "notify airbrake")
17
+ end
18
+
19
+ it "should notify airbrake" do
20
+ Airbrake.should_receive(:notify).with(UniformNotifier::Exception.new("notify airbrake"), :foo => :bar)
21
+
22
+ UniformNotifier.airbrake = { :foo => :bar }
16
23
  UniformNotifier::AirbrakeNotifier.out_of_channel_notify("notify airbrake")
17
24
  end
18
25
  end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ describe UniformNotifier::Base do
4
+ context "#inline_channel_notify" do
5
+ before do
6
+ UniformNotifier::Base.stub(:active?).and_return(true)
7
+ end
8
+ it "should keep the compatibility" do
9
+ UniformNotifier::Base.should_receive(:_inline_notify).once.with(:title => "something")
10
+ UniformNotifier::Base.inline_notify("something")
11
+ end
12
+ end
13
+ context "#out_of_channel_notify" do
14
+ before do
15
+ UniformNotifier::Base.stub(:active?).and_return(true)
16
+ end
17
+ it "should keep the compatibility" do
18
+ UniformNotifier::Base.should_receive(:_out_of_channel_notify).once.with(:title => "something")
19
+ UniformNotifier::Base.out_of_channel_notify("something")
20
+ end
21
+ end
22
+ end
@@ -6,13 +6,20 @@ end
6
6
 
7
7
  describe UniformNotifier::BugsnagNotifier do
8
8
  it "should not notify bugsnag" do
9
- UniformNotifier::BugsnagNotifier.out_of_channel_notify("notify bugsnag").should be_nil
9
+ UniformNotifier::BugsnagNotifier.out_of_channel_notify(:title => "notify bugsnag").should be_nil
10
10
  end
11
11
 
12
12
  it "should notify bugsnag" do
13
- Bugsnag.should_receive(:notify).with(UniformNotifier::Exception.new("notify bugsnag"))
13
+ Bugsnag.should_receive(:notify).with(UniformNotifier::Exception.new("notify bugsnag"), {})
14
14
 
15
15
  UniformNotifier.bugsnag = true
16
+ UniformNotifier::BugsnagNotifier.out_of_channel_notify(:title => "notify bugsnag")
17
+ end
18
+
19
+ it "should notify bugsnag with option" do
20
+ Bugsnag.should_receive(:notify).with(UniformNotifier::Exception.new("notify bugsnag"), :foo => :bar)
21
+
22
+ UniformNotifier.bugsnag = { :foo => :bar }
16
23
  UniformNotifier::BugsnagNotifier.out_of_channel_notify("notify bugsnag")
17
24
  end
18
25
  end
@@ -2,7 +2,7 @@ require "spec_helper"
2
2
 
3
3
  describe UniformNotifier::CustomizedLogger do
4
4
  it "should not notify to customized logger" do
5
- UniformNotifier::CustomizedLogger.out_of_channel_notify("notify rails logger").should be_nil
5
+ UniformNotifier::CustomizedLogger.out_of_channel_notify(:title => "notify rails logger").should be_nil
6
6
  end
7
7
 
8
8
  it "should notify to customized logger" do
@@ -12,7 +12,7 @@ describe UniformNotifier::CustomizedLogger do
12
12
  now = Time.now
13
13
  Time.stub(:now).and_return(now)
14
14
  UniformNotifier.customized_logger = logger
15
- UniformNotifier::CustomizedLogger.out_of_channel_notify("notify rails logger")
15
+ UniformNotifier::CustomizedLogger.out_of_channel_notify(:title => "notify rails logger")
16
16
 
17
17
  logger.seek(0)
18
18
  logger.read.should == "#{now.strftime("%Y-%m-%d %H:%M:%S")}[WARN] notify rails logger"
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  describe UniformNotifier::Growl do
4
4
 
5
5
  it "should not notify growl" do
6
- UniformNotifier::Growl.out_of_channel_notify('notify growl').should be_nil
6
+ UniformNotifier::Growl.out_of_channel_notify(:title => 'notify growl').should be_nil
7
7
  end
8
8
 
9
9
  it "should notify growl without password" do
@@ -15,7 +15,7 @@ describe UniformNotifier::Growl do
15
15
  growl.should_receive(:notify).with('uniform_notifier', 'Uniform Notifier', 'notify growl without password').ordered
16
16
 
17
17
  UniformNotifier.growl = true
18
- UniformNotifier::Growl.out_of_channel_notify('notify growl without password')
18
+ UniformNotifier::Growl.out_of_channel_notify(:title => 'notify growl without password')
19
19
  end
20
20
 
21
21
  it "should notify growl with password" do
@@ -27,7 +27,7 @@ describe UniformNotifier::Growl do
27
27
  growl.should_receive(:notify).with('uniform_notifier', 'Uniform Notifier', 'notify growl with password').ordered
28
28
 
29
29
  UniformNotifier.growl = { :password => '123456' }
30
- UniformNotifier::Growl.out_of_channel_notify('notify growl with password')
30
+ UniformNotifier::Growl.out_of_channel_notify(:title => 'notify growl with password')
31
31
  end
32
32
 
33
33
  it "should notify growl with quiet" do
@@ -39,6 +39,6 @@ describe UniformNotifier::Growl do
39
39
  growl.should_receive(:notify).with('uniform_notifier', 'Uniform Notifier', 'notify growl with password')
40
40
 
41
41
  UniformNotifier.growl = { :password => '123456', :quiet => true }
42
- UniformNotifier::Growl.out_of_channel_notify('notify growl with password')
42
+ UniformNotifier::Growl.out_of_channel_notify(:title => 'notify growl with password')
43
43
  end
44
44
  end
@@ -2,15 +2,15 @@ require "spec_helper"
2
2
 
3
3
  describe UniformNotifier::JavascriptAlert do
4
4
  it "should not notify message" do
5
- UniformNotifier::JavascriptAlert.inline_notify("javascript alert!").should be_nil
5
+ UniformNotifier::JavascriptAlert.inline_notify(:title => "javascript alert!").should be_nil
6
6
  end
7
7
 
8
8
  it "should notify message" do
9
9
  UniformNotifier.alert = true
10
- UniformNotifier::JavascriptAlert.inline_notify("javascript alert!").should == <<-CODE
10
+ UniformNotifier::JavascriptAlert.inline_notify(:title => "javascript alert!").should == <<-CODE
11
11
  <script type="text/javascript">/*<![CDATA[*/
12
12
  alert( "javascript alert!" );
13
13
  /*]]>*/</script>
14
14
  CODE
15
15
  end
16
- end
16
+ end
@@ -2,12 +2,12 @@ require "spec_helper"
2
2
 
3
3
  describe UniformNotifier::JavascriptConsole do
4
4
  it "should not notify message" do
5
- UniformNotifier::JavascriptConsole.inline_notify("javascript console!").should be_nil
5
+ UniformNotifier::JavascriptConsole.inline_notify(:title => "javascript console!").should be_nil
6
6
  end
7
7
 
8
8
  it "should notify message" do
9
9
  UniformNotifier.console = true
10
- UniformNotifier::JavascriptConsole.inline_notify("javascript console!").should == <<-CODE
10
+ UniformNotifier::JavascriptConsole.inline_notify(:title => "javascript console!").should == <<-CODE
11
11
  <script type="text/javascript">/*<![CDATA[*/
12
12
  if (typeof(console) !== 'undefined' && console.log) {
13
13
  if (console.groupCollapsed && console.groupEnd) {
@@ -22,4 +22,4 @@ if (typeof(console) !== 'undefined' && console.log) {
22
22
  /*]]>*/</script>
23
23
  CODE
24
24
  end
25
- end
25
+ end
@@ -6,7 +6,7 @@ end
6
6
 
7
7
  describe UniformNotifier::RailsLogger do
8
8
  it "should not notify rails logger" do
9
- UniformNotifier::RailsLogger.out_of_channel_notify("notify rails logger").should be_nil
9
+ UniformNotifier::RailsLogger.out_of_channel_notify(:title => "notify rails logger").should be_nil
10
10
  end
11
11
 
12
12
  it "should notify rails logger" do
@@ -15,6 +15,6 @@ describe UniformNotifier::RailsLogger do
15
15
  logger.should_receive(:warn).with("notify rails logger")
16
16
 
17
17
  UniformNotifier.rails_logger = true
18
- UniformNotifier::RailsLogger.out_of_channel_notify("notify rails logger")
18
+ UniformNotifier::RailsLogger.out_of_channel_notify(:title => "notify rails logger")
19
19
  end
20
- end
20
+ end
@@ -2,13 +2,13 @@ require "spec_helper"
2
2
 
3
3
  describe UniformNotifier::Raise do
4
4
  it "should not notify message" do
5
- UniformNotifier::Raise.out_of_channel_notify("notification").should be_nil
5
+ UniformNotifier::Raise.out_of_channel_notify(:title => "notification").should be_nil
6
6
  end
7
7
 
8
8
  it "should raise error of the default class" do
9
9
  UniformNotifier.raise = true
10
10
  expect {
11
- UniformNotifier::Raise.out_of_channel_notify("notification")
11
+ UniformNotifier::Raise.out_of_channel_notify(:title => "notification")
12
12
  }.to raise_error(UniformNotifier::Exception, "notification")
13
13
  end
14
14
 
@@ -16,7 +16,7 @@ describe UniformNotifier::Raise do
16
16
  klass = Class.new(Exception)
17
17
  UniformNotifier.raise = klass
18
18
  expect {
19
- UniformNotifier::Raise.out_of_channel_notify("notification")
19
+ UniformNotifier::Raise.out_of_channel_notify(:title => "notification")
20
20
  }.to raise_error(klass, "notification")
21
21
  end
22
22
 
@@ -25,7 +25,7 @@ describe UniformNotifier::Raise do
25
25
  UniformNotifier.raise = false
26
26
 
27
27
  expect {
28
- UniformNotifier::Raise.out_of_channel_notify("notification")
28
+ UniformNotifier::Raise.out_of_channel_notify(:title => "notification")
29
29
  }.not_to raise_error
30
30
  end
31
31
  end
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  describe UniformNotifier::Xmpp do
4
4
  it "should not notify xmpp" do
5
- UniformNotifier::Xmpp.out_of_channel_notify("notify xmpp").should be_nil
5
+ UniformNotifier::Xmpp.out_of_channel_notify(:title => "notify xmpp").should be_nil
6
6
  end
7
7
 
8
8
  it "should notify xmpp without online status" do
@@ -20,7 +20,7 @@ describe UniformNotifier::Xmpp do
20
20
  xmpp.should_receive(:send).with(message)
21
21
 
22
22
  UniformNotifier.xmpp = {:account => 'from@gmail.com', :password => '123456', :receiver => 'to@gmail.com', :show_online_status => false}
23
- UniformNotifier::Xmpp.out_of_channel_notify('notify xmpp')
23
+ UniformNotifier::Xmpp.out_of_channel_notify(:title => 'notify xmpp')
24
24
  end
25
25
 
26
26
  it "should notify xmpp with online status" do
@@ -45,6 +45,6 @@ describe UniformNotifier::Xmpp do
45
45
  xmpp.should_receive(:send).with(message)
46
46
 
47
47
  UniformNotifier.xmpp = {:account => 'from@gmail.com', :password => '123456', :receiver => 'to@gmail.com', :show_online_status => true}
48
- UniformNotifier::Xmpp.out_of_channel_notify('notify xmpp')
48
+ UniformNotifier::Xmpp.out_of_channel_notify(:title => 'notify xmpp')
49
49
  end
50
50
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uniform_notifier
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Huang
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-26 00:00:00.000000000 Z
11
+ date: 2014-04-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby-growl
@@ -95,6 +95,7 @@ files:
95
95
  - lib/uniform_notifier/xmpp.rb
96
96
  - spec/spec_helper.rb
97
97
  - spec/uniform_notifier/airbrake_spec.rb
98
+ - spec/uniform_notifier/base_spec.rb
98
99
  - spec/uniform_notifier/bugsnag_spec.rb
99
100
  - spec/uniform_notifier/customized_logger_spec.rb
100
101
  - spec/uniform_notifier/growl_spec.rb
@@ -131,6 +132,7 @@ summary: uniform notifier for rails logger, customized logger, javascript alert,
131
132
  test_files:
132
133
  - spec/spec_helper.rb
133
134
  - spec/uniform_notifier/airbrake_spec.rb
135
+ - spec/uniform_notifier/base_spec.rb
134
136
  - spec/uniform_notifier/bugsnag_spec.rb
135
137
  - spec/uniform_notifier/customized_logger_spec.rb
136
138
  - spec/uniform_notifier/growl_spec.rb
@@ -139,4 +141,3 @@ test_files:
139
141
  - spec/uniform_notifier/rails_logger_spec.rb
140
142
  - spec/uniform_notifier/raise_spec.rb
141
143
  - spec/uniform_notifier/xmpp_spec.rb
142
- has_rdoc: