slack-notifier 0.4.1 → 0.5.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 +23 -20
- data/lib/slack-notifier/version.rb +1 -1
- data/spec/integration/ping_integration_test.rb +1 -1
- data/spec/lib/slack-notifier_spec.rb +17 -12
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3ed944b7001667e3e533abc25325fec4d7bfa99b
|
4
|
+
data.tar.gz: 4d0ae7eb667f225b42b5621afdc2ffbac463f471
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 53703f1a9413e12505c0d2338776738eb25c5383c1448fd4e2efeb65f71eaccd4b6bf101263639e25bc957c588af4d4b094c77ae45f61ffb3adf0e8707db20d0
|
7
|
+
data.tar.gz: f35eb71b3e57950f2e648e241682a054fbe98d6a7c96719f766d478c704d8afdefd96b853d8237f9dcbef2ebbf3a69195196b717a4242128f58db5ef2e84436a
|
data/lib/slack-notifier.rb
CHANGED
@@ -7,17 +7,19 @@ require_relative 'slack-notifier/link_formatter'
|
|
7
7
|
|
8
8
|
module Slack
|
9
9
|
class Notifier
|
10
|
+
attr_reader :team, :token, :hook_name, :default_payload
|
10
11
|
|
11
|
-
|
12
|
-
# if they are set
|
13
|
-
attr_accessor :channel, :username
|
14
|
-
|
15
|
-
attr_reader :team, :token, :hook_name
|
16
|
-
|
17
|
-
def initialize team, token, hook_name = default_hook_name
|
12
|
+
def initialize team, token, hook_name=default_hook_name, default_payload={}
|
18
13
|
@team = team
|
19
14
|
@token = token
|
20
|
-
|
15
|
+
|
16
|
+
if hook_name.is_a? Hash
|
17
|
+
@hook_name = default_hook_name
|
18
|
+
@default_payload = hook_name
|
19
|
+
else
|
20
|
+
@hook_name = hook_name
|
21
|
+
@default_payload = default_payload
|
22
|
+
end
|
21
23
|
end
|
22
24
|
|
23
25
|
def ping message, options={}
|
@@ -27,12 +29,20 @@ module Slack
|
|
27
29
|
HTTPPost.to endpoint, payload: payload.to_json
|
28
30
|
end
|
29
31
|
|
32
|
+
def channel
|
33
|
+
default_payload[:channel]
|
34
|
+
end
|
35
|
+
|
30
36
|
def channel= channel
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
37
|
+
default_payload[:channel] = channel
|
38
|
+
end
|
39
|
+
|
40
|
+
def username
|
41
|
+
default_payload[:username]
|
42
|
+
end
|
43
|
+
|
44
|
+
def username= username
|
45
|
+
default_payload[:username] = username
|
36
46
|
end
|
37
47
|
|
38
48
|
private
|
@@ -41,13 +51,6 @@ module Slack
|
|
41
51
|
'incoming-webhook'
|
42
52
|
end
|
43
53
|
|
44
|
-
def default_payload
|
45
|
-
payload = {}
|
46
|
-
payload[:channel] = channel if channel
|
47
|
-
payload[:username] = username if username
|
48
|
-
payload
|
49
|
-
end
|
50
|
-
|
51
54
|
def endpoint
|
52
55
|
URI.parse "https://#{team}.slack.com/services/hooks/#{hook_name}?token=#{token}"
|
53
56
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
require_relative '../../lib/slack-notifier'
|
2
2
|
|
3
|
-
notifier = Slack::Notifier.new ENV['SLACK_TEAM'], ENV['SLACK_TOKEN']
|
3
|
+
notifier = Slack::Notifier.new ENV['SLACK_TEAM'], ENV['SLACK_TOKEN'], username: 'notifier'
|
4
4
|
puts "testing with ruby #{RUBY_VERSION}"
|
5
5
|
notifier.ping "hello from notifier test script on ruby: #{RUBY_VERSION}"
|
@@ -12,10 +12,21 @@ describe Slack::Notifier do
|
|
12
12
|
expect( subject.token ).to eq 'token'
|
13
13
|
end
|
14
14
|
|
15
|
-
it
|
15
|
+
it "sets the optional service hook name" do
|
16
16
|
subject = described_class.new 'team', 'token', 'custom_hook_name'
|
17
17
|
expect( subject.hook_name ).to eq 'custom_hook_name'
|
18
18
|
end
|
19
|
+
|
20
|
+
it "sets the default_payload options" do
|
21
|
+
subject = described_class.new 'team', 'token', channel: 'foo'
|
22
|
+
expect( subject.channel ).to eq 'foo'
|
23
|
+
end
|
24
|
+
|
25
|
+
it "can set service hook & default_payload options" do
|
26
|
+
subject = described_class.new 'team', 'token', 'hook_name', channel: 'foo'
|
27
|
+
expect( subject.channel ).to eq 'foo'
|
28
|
+
expect( subject.hook_name ).to eq 'hook_name'
|
29
|
+
end
|
19
30
|
end
|
20
31
|
|
21
32
|
describe "#ping" do
|
@@ -99,18 +110,12 @@ describe Slack::Notifier do
|
|
99
110
|
subject.channel = "#foo"
|
100
111
|
expect( subject.channel ).to eq "#foo"
|
101
112
|
end
|
113
|
+
end
|
102
114
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
subject.channel = "@foo"
|
108
|
-
expect( subject.channel ).to eq "@foo"
|
109
|
-
end
|
110
|
-
|
111
|
-
it "adds a '#' prefix to channel if it has no prefix" do
|
112
|
-
subject.channel = "foo"
|
113
|
-
expect( subject.channel ).to eq "#foo"
|
115
|
+
describe "#username=" do
|
116
|
+
it "sets the given username" do
|
117
|
+
subject.username = "foo"
|
118
|
+
expect( subject.username ).to eq "foo"
|
114
119
|
end
|
115
120
|
end
|
116
121
|
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: 0.
|
4
|
+
version: 0.5.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-
|
11
|
+
date: 2014-05-14 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: " A slim ruby wrapper for posting to slack webhooks "
|
14
14
|
email:
|