slack-notify 0.3.2 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/slack-notify/client.rb +15 -13
- data/lib/slack-notify/payload.rb +15 -13
- data/lib/slack-notify/version.rb +1 -1
- data/spec/slack-notify/client_spec.rb +7 -7
- data/spec/slack-notify/payload_spec.rb +1 -0
- 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: 20a2b6939a5568e6d47b85ce5324cd5625027a1c
|
4
|
+
data.tar.gz: 7215519c083be5901151756f7a099f12589dfd07
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4588aff57f04f9d036b5e200e195f59c75d1d2d4110dd1e2d37be95add91901cb8ba9c5d2abaed8fda10b04779e5ab0225030899f65f33d2031a3730d0033372
|
7
|
+
data.tar.gz: 1d0b1f9fac8129006e1e3c6b85e3548610ccb798c7a2f210a57536c8f23130761cc3fc55cc3b717edfa6f53f275820b5bc68a4d06ef096612cd88dbc3cd0cd17
|
data/lib/slack-notify/client.rb
CHANGED
@@ -6,13 +6,14 @@ module SlackNotify
|
|
6
6
|
include SlackNotify::Connection
|
7
7
|
|
8
8
|
def initialize(team, token, options = {})
|
9
|
-
@team
|
10
|
-
@token
|
11
|
-
@username
|
12
|
-
@channel
|
13
|
-
@icon_url
|
14
|
-
@icon_emoji
|
15
|
-
@link_names
|
9
|
+
@team = team
|
10
|
+
@token = token
|
11
|
+
@username = options[:username]
|
12
|
+
@channel = options[:channel]
|
13
|
+
@icon_url = options[:icon_url]
|
14
|
+
@icon_emoji = options[:icon_emoji]
|
15
|
+
@link_names = options[:link_names]
|
16
|
+
@unfurl_links = options[:unfurl_links] || "1"
|
16
17
|
|
17
18
|
validate_arguments
|
18
19
|
end
|
@@ -24,12 +25,13 @@ module SlackNotify
|
|
24
25
|
def notify(text, channel = nil)
|
25
26
|
delivery_channels(channel).each do |chan|
|
26
27
|
payload = SlackNotify::Payload.new(
|
27
|
-
text:
|
28
|
-
channel:
|
29
|
-
username:
|
30
|
-
icon_url:
|
31
|
-
icon_emoji:
|
32
|
-
link_names:
|
28
|
+
text: text,
|
29
|
+
channel: chan,
|
30
|
+
username: @username,
|
31
|
+
icon_url: @icon_url,
|
32
|
+
icon_emoji: @icon_emoji,
|
33
|
+
link_names: @link_names,
|
34
|
+
unfurl_links: @unfurl_links
|
33
35
|
)
|
34
36
|
|
35
37
|
send_payload(payload)
|
data/lib/slack-notify/payload.rb
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
module SlackNotify
|
2
2
|
class Payload
|
3
|
-
attr_accessor :username, :text, :channel, :icon_url, :icon_emoji, :link_names
|
3
|
+
attr_accessor :username, :text, :channel, :icon_url, :icon_emoji, :link_names, :unfurl_links
|
4
4
|
|
5
5
|
def initialize(options = {})
|
6
|
-
@username
|
7
|
-
@channel
|
8
|
-
@text
|
9
|
-
@icon_url
|
10
|
-
@icon_emoji
|
11
|
-
@link_names
|
6
|
+
@username = options[:username] || "webhookbot"
|
7
|
+
@channel = options[:channel] || "#general"
|
8
|
+
@text = options[:text]
|
9
|
+
@icon_url = options[:icon_url]
|
10
|
+
@icon_emoji = options[:icon_emoji]
|
11
|
+
@link_names = options[:link_names]
|
12
|
+
@unfurl_links = options[:unfurl_links] || "1"
|
12
13
|
|
13
14
|
unless channel[0] =~ /^(#|@)/
|
14
15
|
@channel = "##{@channel}"
|
@@ -17,12 +18,13 @@ module SlackNotify
|
|
17
18
|
|
18
19
|
def to_hash
|
19
20
|
hash = {
|
20
|
-
text:
|
21
|
-
username:
|
22
|
-
channel:
|
23
|
-
icon_url:
|
24
|
-
icon_emoji:
|
25
|
-
link_names:
|
21
|
+
text: text,
|
22
|
+
username: username,
|
23
|
+
channel: channel,
|
24
|
+
icon_url: icon_url,
|
25
|
+
icon_emoji: icon_emoji,
|
26
|
+
link_names: link_names,
|
27
|
+
unfurl_links: unfurl_links
|
26
28
|
}
|
27
29
|
|
28
30
|
hash.delete_if { |_,v| v.nil? }
|
data/lib/slack-notify/version.rb
CHANGED
@@ -48,7 +48,7 @@ describe SlackNotify::Client do
|
|
48
48
|
|
49
49
|
it "delivers payload" do
|
50
50
|
stub_request(:post, "https://foo.slack.com/services/hooks/incoming-webhook?token=token").
|
51
|
-
with(:body => {"{\"text\":\"Message\",\"username\":\"webhookbot\",\"channel\":\"#general\"}"=>true},
|
51
|
+
with(:body => {"{\"text\":\"Message\",\"username\":\"webhookbot\",\"channel\":\"#general\",\"unfurl_links\":\"1\"}"=>true},
|
52
52
|
:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Type'=>'application/x-www-form-urlencoded'}).
|
53
53
|
to_return(:status => 200, :body => "", :headers => {})
|
54
54
|
|
@@ -84,7 +84,7 @@ describe SlackNotify::Client do
|
|
84
84
|
|
85
85
|
before do
|
86
86
|
stub_request(:post, "https://foo.slack.com/services/hooks/incoming-webhook?token=bar").
|
87
|
-
with(:body => {"{\"text\":\"Message\",\"username\":\"webhookbot\",\"channel\":\"#general\",\"icon_url\":\"foobar\"}"=>true},
|
87
|
+
with(:body => {"{\"text\":\"Message\",\"username\":\"webhookbot\",\"channel\":\"#general\",\"icon_url\":\"foobar\",\"unfurl_links\":\"1\"}"=>true},
|
88
88
|
:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Type'=>'application/x-www-form-urlencoded', 'User-Agent'=>'Faraday v0.9.0'}).
|
89
89
|
to_return(:status => 200, :body => "", :headers => {})
|
90
90
|
end
|
@@ -99,7 +99,7 @@ describe SlackNotify::Client do
|
|
99
99
|
|
100
100
|
before do
|
101
101
|
stub_request(:post, "https://foo.slack.com/services/hooks/incoming-webhook?token=bar").
|
102
|
-
with(:body => {"{\"text\":\"Message\",\"username\":\"webhookbot\",\"channel\":\"#general\",\"icon_emoji\":\"foobar\"}"=>true},
|
102
|
+
with(:body => {"{\"text\":\"Message\",\"username\":\"webhookbot\",\"channel\":\"#general\",\"icon_emoji\":\"foobar\",\"unfurl_links\":\"1\"}"=>true},
|
103
103
|
:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Type'=>'application/x-www-form-urlencoded', 'User-Agent'=>'Faraday v0.9.0'}).
|
104
104
|
to_return(:status => 200, :body => "", :headers => {})
|
105
105
|
end
|
@@ -114,7 +114,7 @@ describe SlackNotify::Client do
|
|
114
114
|
|
115
115
|
before do
|
116
116
|
stub_request(:post, "https://foo.slack.com/services/hooks/incoming-webhook?token=bar").
|
117
|
-
with(:body => {"{\"text\":\"Message\",\"username\":\"webhookbot\",\"channel\":\"#general\",\"link_names\":1}"=>true},
|
117
|
+
with(:body => {"{\"text\":\"Message\",\"username\":\"webhookbot\",\"channel\":\"#general\",\"link_names\":1,\"unfurl_links\":\"1\"}"=>true},
|
118
118
|
:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Type'=>'application/x-www-form-urlencoded', 'User-Agent'=>'Faraday v0.9.0'}).
|
119
119
|
to_return(:status => 200, :body => "", :headers => {})
|
120
120
|
end
|
@@ -138,7 +138,7 @@ describe SlackNotify::Client do
|
|
138
138
|
context "when team name is invalid" do
|
139
139
|
before do
|
140
140
|
stub_request(:post, "https://foo.slack.com/services/hooks/incoming-webhook?token=token").
|
141
|
-
with(:body => {"{\"text\":\"Message\",\"username\":\"webhookbot\",\"channel\":\"#general\"}"=>true},
|
141
|
+
with(:body => {"{\"text\":\"Message\",\"username\":\"webhookbot\",\"channel\":\"#general\",\"unfurl_links\":\"1\"}"=>true},
|
142
142
|
:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Type'=>'application/x-www-form-urlencoded'}).
|
143
143
|
to_return(:status => 404, :body => "Line 1\nLine 2\nLine 3", :headers => {})
|
144
144
|
end
|
@@ -151,7 +151,7 @@ describe SlackNotify::Client do
|
|
151
151
|
context "when token is invalid" do
|
152
152
|
before do
|
153
153
|
stub_request(:post, "https://foo.slack.com/services/hooks/incoming-webhook?token=token").
|
154
|
-
with(:body => {"{\"text\":\"Message\",\"username\":\"webhookbot\",\"channel\":\"#general\"}"=>true},
|
154
|
+
with(:body => {"{\"text\":\"Message\",\"username\":\"webhookbot\",\"channel\":\"#general\",\"unfurl_links\":\"1\"}"=>true},
|
155
155
|
:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Type'=>'application/x-www-form-urlencoded'}).
|
156
156
|
to_return(:status => 500, :body => "No hooks", :headers => {})
|
157
157
|
end
|
@@ -165,7 +165,7 @@ describe SlackNotify::Client do
|
|
165
165
|
context "when channel is invalid" do
|
166
166
|
before do
|
167
167
|
stub_request(:post, "https://foo.slack.com/services/hooks/incoming-webhook?token=token").
|
168
|
-
with(:body => {"{\"text\":\"message\",\"username\":\"webhookbot\",\"channel\":\"#foobar\"}"=>true},
|
168
|
+
with(:body => {"{\"text\":\"message\",\"username\":\"webhookbot\",\"channel\":\"#foobar\",\"unfurl_links\":\"1\"}"=>true},
|
169
169
|
:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Type'=>'application/x-www-form-urlencoded'}).
|
170
170
|
to_return(:status => 500, :body => "Invalid channel specified", :headers => {})
|
171
171
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: slack-notify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dan Sosedoff
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-10-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|