slack-notifier 1.0.0 → 1.1.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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 31725a6d5391e72e7d0b4c40733209b2f07cca3a
|
4
|
+
data.tar.gz: 52ac6b2e70a4bc138a5957b0131136109bae87bd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 75075f1cb873ce237063f7f68425d9745a85b007744fa78741c0a04954de6d5b0d7647480bde366d739fedc48175aaa677841a001eea5fe2d83f501e8be91343
|
7
|
+
data.tar.gz: c0546c41a9eec3ccd44bf8537ca415ea2183a30f4859cde34d40b3d0e71baf6a9732cf68056a72cba06de4bd95dfd9d92ba7da3f8d42aa79c27553dc2f2bebd8
|
data/lib/slack-notifier.rb
CHANGED
@@ -7,20 +7,27 @@ require_relative 'slack-notifier/link_formatter'
|
|
7
7
|
|
8
8
|
module Slack
|
9
9
|
class Notifier
|
10
|
-
attr_reader :endpoint, :
|
10
|
+
attr_reader :endpoint, :default_payload
|
11
11
|
|
12
12
|
def initialize webhook_url, options={}
|
13
13
|
@endpoint = URI.parse webhook_url
|
14
|
-
@http_client = options.delete(:http_client) || DefaultHTTPClient
|
15
14
|
@default_payload = options
|
16
15
|
end
|
17
16
|
|
18
17
|
def ping message, options={}
|
19
|
-
message
|
20
|
-
payload
|
18
|
+
message = LinkFormatter.format(message)
|
19
|
+
payload = default_payload.merge(options).merge(text: message)
|
20
|
+
client = payload.delete(:http_client) || http_client
|
21
|
+
http_options = payload.delete(:http_options)
|
21
22
|
|
23
|
+
params = { payload: payload.to_json }
|
24
|
+
params[:http_options] = http_options if http_options
|
22
25
|
|
23
|
-
|
26
|
+
client.post endpoint, params
|
27
|
+
end
|
28
|
+
|
29
|
+
def http_client
|
30
|
+
default_payload.fetch :http_client, DefaultHTTPClient
|
24
31
|
end
|
25
32
|
|
26
33
|
def channel
|
@@ -9,11 +9,12 @@ module Slack
|
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
|
-
attr_reader :uri, :params
|
12
|
+
attr_reader :uri, :params, :http_options
|
13
13
|
|
14
14
|
def initialize uri, params
|
15
|
-
@uri
|
16
|
-
@
|
15
|
+
@uri = uri
|
16
|
+
@http_options = params.delete(:http_options) || {}
|
17
|
+
@params = params
|
17
18
|
end
|
18
19
|
|
19
20
|
def call
|
@@ -33,6 +34,14 @@ module Slack
|
|
33
34
|
http = Net::HTTP.new uri.host, uri.port
|
34
35
|
http.use_ssl = (uri.scheme == "https")
|
35
36
|
|
37
|
+
http_options.each do |opt, val|
|
38
|
+
if http.respond_to? "#{opt}="
|
39
|
+
http.send "#{opt}=", val
|
40
|
+
else
|
41
|
+
warn "Net::HTTP doesn't respond to `#{opt}=`, ignoring that option"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
36
45
|
return http
|
37
46
|
end
|
38
47
|
|
@@ -18,4 +18,20 @@ describe Slack::Notifier::DefaultHTTPClient do
|
|
18
18
|
# where the internals are run through
|
19
19
|
end
|
20
20
|
|
21
|
-
|
21
|
+
describe "#initialize" do
|
22
|
+
it "allows setting of options for Net::HTTP" do
|
23
|
+
net_http_double = instance_double("Net::HTTP")
|
24
|
+
http_client = described_class.new( URI.parse('http://example.com'), http_options: { open_timeout: 5 })
|
25
|
+
|
26
|
+
allow( Net::HTTP ).to receive(:new)
|
27
|
+
.and_return(net_http_double)
|
28
|
+
allow( net_http_double ).to receive(:use_ssl=)
|
29
|
+
allow( net_http_double ).to receive(:request)
|
30
|
+
|
31
|
+
expect( net_http_double ).to receive(:open_timeout=).with(5)
|
32
|
+
|
33
|
+
http_client.call
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
@@ -50,7 +50,7 @@ describe Slack::Notifier do
|
|
50
50
|
it "uses default channel" do
|
51
51
|
expect( Slack::Notifier::DefaultHTTPClient ).to receive(:post)
|
52
52
|
.with @endpoint_double,
|
53
|
-
payload: '{"
|
53
|
+
payload: '{"channel":"#default","text":"the message"}'
|
54
54
|
|
55
55
|
subject.ping "the message"
|
56
56
|
end
|
@@ -58,7 +58,7 @@ describe Slack::Notifier do
|
|
58
58
|
it "allows override channel to be set" do
|
59
59
|
expect( Slack::Notifier::DefaultHTTPClient ).to receive(:post)
|
60
60
|
.with @endpoint_double,
|
61
|
-
payload: '{"
|
61
|
+
payload: '{"channel":"new","text":"the message"}'
|
62
62
|
|
63
63
|
subject.ping "the message", channel: "new"
|
64
64
|
end
|
@@ -74,7 +74,7 @@ describe Slack::Notifier do
|
|
74
74
|
|
75
75
|
expect( Slack::Notifier::DefaultHTTPClient ).to receive(:post)
|
76
76
|
.with @endpoint_double,
|
77
|
-
payload: '{"
|
77
|
+
payload: '{"channel":"channel","text":"the message"}'
|
78
78
|
|
79
79
|
described_class.new("http://example.com").ping "the message", channel: "channel"
|
80
80
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: slack-notifier
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steven Sloan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-02-09 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: " A slim ruby wrapper for posting to slack webhooks "
|
14
14
|
email:
|