uniform_notifier 1.6.2 → 1.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: af156f048a5a329b12177c3f216ea1c37725913d
4
- data.tar.gz: 93332d5a47dd8fe72b9bb96f32af84a00311d90c
3
+ metadata.gz: ef9b9fde70b51c9e9f5ddb5478cdbcd425d0329c
4
+ data.tar.gz: 3ea627b20c17915ae9c14553c5d01514ea0399e4
5
5
  SHA512:
6
- metadata.gz: 0645408ab0c74162980903651b904181b815f3f9e0bcbcb3c2906c14e6c81765d989fcfa12893ee63692bb357abede0342df55db34c616eb1c3dadf43bb70f7a
7
- data.tar.gz: b160237f909b1063cd442df10d434edccb9a1c4d41b978255b011e31d68cfc7b4e2c2f0d72e781494f1f6fddf7898b5f8741da7b004744fadf6e841245844e08
6
+ metadata.gz: c7dd7f936ecda2ef1c3cf4f4b52eda389256b55bb296d5d201050ba0f43743371d4defc17029a7ddfdf620a292209a99e555018004c8eabee3ed4fa4fea4c01a
7
+ data.tar.gz: d9516d3ed87ac936ffec1cfbadb669071ab2c7f9f8bc23883f82632d9bb6820bb04d96336081363eeb403d364886ebae942354666749e7e8d5d0f2a21fa6bb7b
@@ -8,13 +8,14 @@ require 'uniform_notifier/rails_logger'
8
8
  require 'uniform_notifier/customized_logger'
9
9
  require 'uniform_notifier/airbrake'
10
10
  require 'uniform_notifier/bugsnag'
11
+ require 'uniform_notifier/slack'
11
12
  require 'uniform_notifier/raise'
12
13
 
13
14
  module UniformNotifier
14
15
  class NotificationError < StandardError; end
15
16
 
16
17
  class <<self
17
- attr_accessor :alert, :console, :growl, :rails_logger, :xmpp, :airbrake, :bugsnag, :raise
18
+ attr_accessor :alert, :console, :growl, :rails_logger, :xmpp, :airbrake, :bugsnag, :slack, :raise
18
19
 
19
20
  NOTIFIERS = [JavascriptAlert, JavascriptConsole, Growl, Xmpp, RailsLogger, CustomizedLogger, AirbrakeNotifier, BugsnagNotifier, Raise]
20
21
 
@@ -34,6 +35,10 @@ module UniformNotifier
34
35
  UniformNotifier::CustomizedLogger.setup(logdev)
35
36
  end
36
37
 
38
+ def slack=(slack)
39
+ UniformNotifier::Slack.setup_connection(slack)
40
+ end
41
+
37
42
  def raise=(exception_class)
38
43
  UniformNotifier::Raise.setup_connection(exception_class)
39
44
  end
@@ -0,0 +1,51 @@
1
+ module UniformNotifier
2
+ class Slack < Base
3
+ POSSIBLE_OPTIONS = [:username, :channel]
4
+
5
+ @slack = nil
6
+
7
+ class << self
8
+ def active?
9
+ @slack
10
+ end
11
+
12
+ def setup_connection(config={})
13
+ webhook_url, options = parse_config(config)
14
+ fail_connection('webhook_url required for Slack notification') unless webhook_url
15
+
16
+ require 'slack-notifier'
17
+ @slack = ::Slack::Notifier.new webhook_url, options
18
+ rescue LoadError
19
+ fail_connection 'You must install the slack-notifier gem to use Slack notification: '\
20
+ '`gem install slack-notifier`'
21
+ end
22
+
23
+ protected
24
+
25
+ def _out_of_channel_notify(data)
26
+ message = data.values.compact.join("\n")
27
+ notify(message)
28
+ end
29
+
30
+ private
31
+
32
+ def fail_connection(message)
33
+ @slack = nil
34
+ raise NotificationError.new(message)
35
+ end
36
+
37
+ def notify(message)
38
+ @slack.ping message
39
+ end
40
+
41
+ def parse_config(config)
42
+ options = config.select do |name, value|
43
+ POSSIBLE_OPTIONS.include?(name) && !value.nil?
44
+ end
45
+
46
+ return config[:webhook_url], options
47
+ end
48
+
49
+ end
50
+ end
51
+ end
@@ -1,3 +1,3 @@
1
1
  module UniformNotifier
2
- VERSION = "1.6.2"
2
+ VERSION = "1.7.0"
3
3
  end
data/spec/spec_helper.rb CHANGED
@@ -3,4 +3,5 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
3
3
  require "uniform_notifier"
4
4
  require "ruby-growl"
5
5
  require "xmpp4r"
6
+ require "slack-notifier"
6
7
  require "rspec"
@@ -0,0 +1,53 @@
1
+ require 'spec_helper'
2
+
3
+ describe UniformNotifier::Slack do
4
+ context 'not enabled' do
5
+ it 'should not notify slack' do
6
+ expect_any_instance_of(Slack::Notifier).to_not receive(:ping)
7
+ expect(UniformNotifier::Slack.out_of_channel_notify(:title => 'notify slack')).to be_nil
8
+ end
9
+ end
10
+
11
+ context 'configuration' do
12
+ context 'no webhook_url is given' do
13
+ it 'should raise an error' do
14
+ expect{ UniformNotifier.slack = {} }.to raise_error(UniformNotifier::NotificationError)
15
+ end
16
+
17
+ it 'should not notify slack' do
18
+ begin
19
+ UniformNotifier.slack = {}
20
+ rescue UniformNotifier::NotificationError
21
+ ensure
22
+ expect_any_instance_of(Slack::Notifier).to_not receive(:ping)
23
+ expect(UniformNotifier::Slack.out_of_channel_notify(:title => 'notify slack')).to be_nil
24
+ end
25
+ end
26
+ end
27
+
28
+ it 'should remove invalid options' do
29
+ expect(Slack::Notifier).to receive(:new).with('http://some.slack.url', {}).and_return(true)
30
+ UniformNotifier.slack = { :webhook_url => 'http://some.slack.url', :pizza => 'pepperoni' }
31
+ expect(UniformNotifier::Slack.active?).to eq true
32
+ end
33
+
34
+ it 'should allow username and channel config options' do
35
+ expect(Slack::Notifier).to receive(:new).with('http://some.slack.url', { :username => 'The Dude', :channel => '#carpets' }).and_return(true)
36
+ UniformNotifier.slack = { :webhook_url => 'http://some.slack.url', :username => 'The Dude', :channel => '#carpets' }
37
+ expect(UniformNotifier::Slack.active?).to eq true
38
+ end
39
+ end
40
+
41
+ context 'properly configured' do
42
+ before(:each) do
43
+ @message = 'notify slack'
44
+ allow_any_instance_of(Slack::Notifier).to receive(:ping).and_return(@message)
45
+ end
46
+
47
+ it 'should notify slack' do
48
+ UniformNotifier.slack = { :webhook_url => 'http://some.slack.url' }
49
+ expect_any_instance_of(Slack::Notifier).to receive(:ping)
50
+ expect(UniformNotifier::Slack.out_of_channel_notify(:title => @message)).to eq @message
51
+ end
52
+ end
53
+ end
@@ -17,6 +17,7 @@ Gem::Specification.new do |s|
17
17
  s.add_development_dependency %q<ruby-growl>, ["= 4.0"]
18
18
  s.add_development_dependency %q<ruby_gntp>, ["= 0.3.4"]
19
19
  s.add_development_dependency %q<xmpp4r>, ["= 0.5"]
20
+ s.add_development_dependency %q<slack-notifier>, [">= 1.0"]
20
21
  s.add_development_dependency %q<rspec>, ["> 0"]
21
22
 
22
23
  s.files = `git ls-files`.split("\n")
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.6.2
4
+ version: 1.7.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-06-10 00:00:00.000000000 Z
11
+ date: 2015-02-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby-growl
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - '='
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0.5'
55
+ - !ruby/object:Gem::Dependency
56
+ name: slack-notifier
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '1.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '1.0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: rspec
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -91,6 +105,7 @@ files:
91
105
  - lib/uniform_notifier/javascript_console.rb
92
106
  - lib/uniform_notifier/rails_logger.rb
93
107
  - lib/uniform_notifier/raise.rb
108
+ - lib/uniform_notifier/slack.rb
94
109
  - lib/uniform_notifier/version.rb
95
110
  - lib/uniform_notifier/xmpp.rb
96
111
  - spec/spec_helper.rb
@@ -103,6 +118,7 @@ files:
103
118
  - spec/uniform_notifier/javascript_console_spec.rb
104
119
  - spec/uniform_notifier/rails_logger_spec.rb
105
120
  - spec/uniform_notifier/raise_spec.rb
121
+ - spec/uniform_notifier/slack_spec.rb
106
122
  - spec/uniform_notifier/xmpp_spec.rb
107
123
  - uniform_notifier.gemspec
108
124
  homepage: http://rubygems.org/gems/uniform_notifier
@@ -124,7 +140,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
124
140
  version: '0'
125
141
  requirements: []
126
142
  rubyforge_project: uniform_notifier
127
- rubygems_version: 2.2.2
143
+ rubygems_version: 2.4.5
128
144
  signing_key:
129
145
  specification_version: 4
130
146
  summary: uniform notifier for rails logger, customized logger, javascript alert, javascript
@@ -140,4 +156,5 @@ test_files:
140
156
  - spec/uniform_notifier/javascript_console_spec.rb
141
157
  - spec/uniform_notifier/rails_logger_spec.rb
142
158
  - spec/uniform_notifier/raise_spec.rb
159
+ - spec/uniform_notifier/slack_spec.rb
143
160
  - spec/uniform_notifier/xmpp_spec.rb