slack-notifier 0.2.0 → 0.3.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/lib/slack-notifier.rb +9 -4
- data/lib/slack-notifier/version.rb +1 -1
- data/spec/lib/slack-notifier_spec.rb +33 -7
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8e49764cf6dc75809e6155065bd277f9451d64ff
|
4
|
+
data.tar.gz: 9ad72756470888e48c487042f17f668440dd7e41
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 305a9e8e70b81cdca0cdc9d76262245e0852d845093f6a321a64ce9c1abc702e2a97d706dca7cbd270ee6fe4a1cd73b3f64ae72081fe9340a324979004345dff
|
7
|
+
data.tar.gz: 88097ecf33b8c3c62f301ca6a81feb7fd17555aca735ea1ac14bd5a92ce94c522983e68f1b5730da7ce2a0222c167febfea486da11de72cf0331d16cdc14d036
|
data/lib/slack-notifier.rb
CHANGED
@@ -11,11 +11,12 @@ module Slack
|
|
11
11
|
# if they are set
|
12
12
|
attr_accessor :channel, :username
|
13
13
|
|
14
|
-
attr_reader :team, :token
|
14
|
+
attr_reader :team, :token, :hook_name
|
15
15
|
|
16
|
-
def initialize team, token
|
16
|
+
def initialize team, token, hook_name = default_hook_name
|
17
17
|
@team = team
|
18
18
|
@token = token
|
19
|
+
@hook_name = hook_name
|
19
20
|
end
|
20
21
|
|
21
22
|
def ping message, options={}
|
@@ -31,6 +32,10 @@ module Slack
|
|
31
32
|
|
32
33
|
private
|
33
34
|
|
35
|
+
def default_hook_name
|
36
|
+
'incoming-webhook'
|
37
|
+
end
|
38
|
+
|
34
39
|
def default_payload
|
35
40
|
payload = {}
|
36
41
|
payload[:channel] = channel if channel
|
@@ -39,8 +44,8 @@ module Slack
|
|
39
44
|
end
|
40
45
|
|
41
46
|
def endpoint
|
42
|
-
URI.parse "https://#{team}.slack.com/services/hooks
|
47
|
+
URI.parse "https://#{team}.slack.com/services/hooks/#{hook_name}?token=#{token}"
|
43
48
|
end
|
44
49
|
|
45
50
|
end
|
46
|
-
end
|
51
|
+
end
|
@@ -12,15 +12,16 @@ describe Slack::Notifier do
|
|
12
12
|
subject = described_class.new 'team', 'token'
|
13
13
|
expect( subject.token ).to eq 'token'
|
14
14
|
end
|
15
|
+
|
16
|
+
it 'sets the optional service hook name' do
|
17
|
+
subject = described_class.new 'team', 'token', 'custom_hook_name'
|
18
|
+
expect( subject.hook_name ).to eq 'custom_hook_name'
|
19
|
+
end
|
15
20
|
end
|
16
21
|
|
17
22
|
describe "#ping" do
|
18
23
|
before :each do
|
19
24
|
allow( Net::HTTP ).to receive(:post_form)
|
20
|
-
@endpoint_double = instance_double "URI::HTTP"
|
21
|
-
allow( URI ).to receive(:parse)
|
22
|
-
.with("https://team.slack.com/services/hooks/incoming-webhook?token=token")
|
23
|
-
.and_return(@endpoint_double)
|
24
25
|
end
|
25
26
|
|
26
27
|
it "passes the message through LinkFormatter" do
|
@@ -39,6 +40,9 @@ describe Slack::Notifier do
|
|
39
40
|
context "with a default channel set" do
|
40
41
|
|
41
42
|
before :each do
|
43
|
+
@endpoint_double = instance_double "URI::HTTP"
|
44
|
+
allow( URI ).to receive(:parse)
|
45
|
+
.and_return(@endpoint_double)
|
42
46
|
@subject = described_class.new('team','token')
|
43
47
|
@subject.channel = 'default'
|
44
48
|
end
|
@@ -67,13 +71,35 @@ describe Slack::Notifier do
|
|
67
71
|
|
68
72
|
end
|
69
73
|
|
70
|
-
|
74
|
+
context "with default webhook" do
|
75
|
+
it "posts with the correct endpoint & data" do
|
76
|
+
@endpoint_double = instance_double "URI::HTTP"
|
77
|
+
allow( URI ).to receive(:parse)
|
78
|
+
.with("https://team.slack.com/services/hooks/incoming-webhook?token=token")
|
79
|
+
.and_return(@endpoint_double)
|
80
|
+
|
81
|
+
expect( Net::HTTP ).to receive(:post_form)
|
82
|
+
.with @endpoint_double,
|
83
|
+
payload: '{"text":"the message","channel":"channel"}'
|
84
|
+
|
85
|
+
described_class.new("team","token").ping "the message", channel: "channel"
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
context "with custom webhook name" do
|
90
|
+
it "posts with the correct endpoint & data" do
|
91
|
+
@endpoint_double = instance_double "URI::HTTP"
|
92
|
+
allow( URI ).to receive(:parse)
|
93
|
+
.with("https://team.slack.com/services/hooks/custom_hook_name?token=token")
|
94
|
+
.and_return(@endpoint_double)
|
95
|
+
|
71
96
|
expect( Net::HTTP ).to receive(:post_form)
|
72
97
|
.with @endpoint_double,
|
73
98
|
payload: '{"text":"the message","channel":"channel"}'
|
74
99
|
|
75
|
-
described_class.new("team","token").ping "the message", channel: "channel"
|
100
|
+
described_class.new("team","token","custom_hook_name").ping "the message", channel: "channel"
|
101
|
+
end
|
76
102
|
end
|
77
103
|
end
|
78
104
|
|
79
|
-
end
|
105
|
+
end
|
metadata
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: slack-notifier
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.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: 2014-03-
|
11
|
+
date: 2014-03-20 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description:
|
13
|
+
description: " A slim ruby wrapper for posting to slack webhooks "
|
14
14
|
email:
|
15
15
|
- stevenosloan@gmail.com
|
16
16
|
executables: []
|
@@ -33,12 +33,12 @@ require_paths:
|
|
33
33
|
- lib
|
34
34
|
required_ruby_version: !ruby/object:Gem::Requirement
|
35
35
|
requirements:
|
36
|
-
- -
|
36
|
+
- - ">="
|
37
37
|
- !ruby/object:Gem::Version
|
38
38
|
version: '0'
|
39
39
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
40
40
|
requirements:
|
41
|
-
- -
|
41
|
+
- - ">="
|
42
42
|
- !ruby/object:Gem::Version
|
43
43
|
version: '0'
|
44
44
|
requirements: []
|
@@ -51,3 +51,4 @@ test_files:
|
|
51
51
|
- spec/lib/slack-notifier/link_formatter_spec.rb
|
52
52
|
- spec/lib/slack-notifier_spec.rb
|
53
53
|
- spec/spec_helper.rb
|
54
|
+
has_rdoc:
|