slack-notify 0.1.1 → 0.1.2
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/LICENSE.txt +1 -1
- data/README.md +1 -1
- data/lib/slack-notify.rb +24 -8
- data/lib/slack-notify/version.rb +1 -1
- data/slack-notify.gemspec +4 -4
- data/spec/slack-notify/client_spec.rb +27 -4
- metadata +10 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 43f177e7190a379067808a7a424ba8b6e11cbdc6
|
4
|
+
data.tar.gz: 1e500c4795f082d1ea07327ecc1d8a6c49be9032
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 251c13145bf1ee1abf9026dbfc2543716e5275e1a3df0f3cc42de365d72911e807b29291927c5e8796cb989cce259fcbce3ce6060de204174af73da5de17b2f6
|
7
|
+
data.tar.gz: 3d5bce3eb6d4422ae811b62a2f93152556984abc01f9691cdd8805be7b28d7cf5b313d72bf7f8862c5c7994119ed11d8d4fdde7be888577fc787bc144d8c1dd8
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
data/lib/slack-notify.rb
CHANGED
@@ -6,21 +6,22 @@ require "faraday"
|
|
6
6
|
|
7
7
|
module SlackNotify
|
8
8
|
class Client
|
9
|
-
def initialize(team, token, options={})
|
9
|
+
def initialize(team, token, options = {})
|
10
10
|
@team = team
|
11
11
|
@token = token
|
12
12
|
@username = options[:username] || "webhookbot"
|
13
|
-
@channel = options[:channel]
|
13
|
+
@channel = options[:channel] || "#general"
|
14
14
|
|
15
15
|
raise ArgumentError, "Team name required" if @team.nil?
|
16
16
|
raise ArgumentError, "Token required" if @token.nil?
|
17
|
+
raise ArgumentError, "Invalid team name" unless valid_team_name?
|
17
18
|
end
|
18
19
|
|
19
20
|
def test
|
20
21
|
notify("This is a test message!")
|
21
22
|
end
|
22
23
|
|
23
|
-
def notify(text, channel=nil)
|
24
|
+
def notify(text, channel = nil)
|
24
25
|
channels = [channel || @channel].flatten.compact.uniq
|
25
26
|
|
26
27
|
channels.each do |chan|
|
@@ -34,13 +35,20 @@ module SlackNotify
|
|
34
35
|
private
|
35
36
|
|
36
37
|
def send_payload(payload)
|
37
|
-
|
38
|
+
conn = Faraday.new(hook_url, { timeout: 5, open_timeout: 5 }) do |c|
|
39
|
+
c.use(Faraday::Request::UrlEncoded)
|
40
|
+
c.adapter(Faraday.default_adapter)
|
41
|
+
end
|
42
|
+
|
43
|
+
response = conn.post do |req|
|
38
44
|
req.body = JSON.dump(payload)
|
39
45
|
end
|
40
46
|
|
41
|
-
|
42
|
-
|
43
|
-
|
47
|
+
handle_response(response)
|
48
|
+
end
|
49
|
+
|
50
|
+
def handle_response(response)
|
51
|
+
unless response.success?
|
44
52
|
if response.body.include?("\n")
|
45
53
|
raise SlackNotify::Error
|
46
54
|
else
|
@@ -49,8 +57,16 @@ module SlackNotify
|
|
49
57
|
end
|
50
58
|
end
|
51
59
|
|
60
|
+
def valid_team_name?
|
61
|
+
@team =~ /^[a-z\d\-]+$/ ? true : false
|
62
|
+
end
|
63
|
+
|
52
64
|
def hook_url
|
53
|
-
"
|
65
|
+
"#{base_url}/services/hooks/incoming-webhook?token=#{@token}"
|
66
|
+
end
|
67
|
+
|
68
|
+
def base_url
|
69
|
+
"https://#{@team}.slack.com"
|
54
70
|
end
|
55
71
|
end
|
56
72
|
end
|
data/lib/slack-notify/version.rb
CHANGED
data/slack-notify.gemspec
CHANGED
@@ -8,9 +8,9 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = SlackNotify::VERSION
|
9
9
|
spec.authors = ["Dan Sosedoff"]
|
10
10
|
spec.email = ["dan.sosedoff@gmail.com"]
|
11
|
-
spec.description = %q{Send notifications to Slack channel}
|
12
|
-
spec.summary = %q{Send notifications to Slack channel}
|
13
|
-
spec.homepage = ""
|
11
|
+
spec.description = %q{Send notifications to a Slack channel}
|
12
|
+
spec.summary = %q{Send notifications to a Slack channel}
|
13
|
+
spec.homepage = "https://github.com/sosedoff/slack-notify"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
16
|
spec.files = `git ls-files`.split($/)
|
@@ -24,6 +24,6 @@ Gem::Specification.new do |spec|
|
|
24
24
|
spec.add_development_dependency "rspec", "~> 2.13"
|
25
25
|
spec.add_development_dependency "webmock", "~> 1.0"
|
26
26
|
|
27
|
-
spec.add_dependency "faraday", "
|
27
|
+
spec.add_dependency "faraday", "< 0.9.0"
|
28
28
|
spec.add_dependency "json", "~> 1.8"
|
29
29
|
end
|
@@ -11,6 +11,15 @@ describe SlackNotify::Client do
|
|
11
11
|
expect { described_class.new("foobar", nil) }.
|
12
12
|
to raise_error ArgumentError, "Token required"
|
13
13
|
end
|
14
|
+
|
15
|
+
it "raises error on invalid team name" do
|
16
|
+
names = ["foo bar", "foo $bar", "foo.bar"]
|
17
|
+
|
18
|
+
names.each do |name|
|
19
|
+
expect { described_class.new(name, "token") }.
|
20
|
+
to raise_error "Invalid team name"
|
21
|
+
end
|
22
|
+
end
|
14
23
|
end
|
15
24
|
|
16
25
|
describe "#test" do
|
@@ -80,7 +89,7 @@ describe SlackNotify::Client do
|
|
80
89
|
it "delivers payload" do
|
81
90
|
stub_request(:post, "https://foo.slack.com/services/hooks/incoming-webhook?token=token").
|
82
91
|
with(:body => {"{\"text\":\"Message\",\"username\":\"webhookbot\",\"channel\":\"#general\"}"=>true},
|
83
|
-
:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Type'=>'application/x-www-form-urlencoded'
|
92
|
+
:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Type'=>'application/x-www-form-urlencoded'}).
|
84
93
|
to_return(:status => 200, :body => "", :headers => {})
|
85
94
|
|
86
95
|
expect(client.notify("Message")).to eq true
|
@@ -110,7 +119,7 @@ describe SlackNotify::Client do
|
|
110
119
|
before do
|
111
120
|
stub_request(:post, "https://foo.slack.com/services/hooks/incoming-webhook?token=token").
|
112
121
|
with(:body => {"{\"text\":\"Message\",\"username\":\"webhookbot\",\"channel\":\"#general\"}"=>true},
|
113
|
-
:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Type'=>'application/x-www-form-urlencoded'
|
122
|
+
:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Type'=>'application/x-www-form-urlencoded'}).
|
114
123
|
to_return(:status => 404, :body => "Line 1\nLine 2\nLine 3", :headers => {})
|
115
124
|
end
|
116
125
|
|
@@ -123,8 +132,8 @@ describe SlackNotify::Client do
|
|
123
132
|
before do
|
124
133
|
stub_request(:post, "https://foo.slack.com/services/hooks/incoming-webhook?token=token").
|
125
134
|
with(:body => {"{\"text\":\"Message\",\"username\":\"webhookbot\",\"channel\":\"#general\"}"=>true},
|
126
|
-
:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Type'=>'application/x-www-form-urlencoded'
|
127
|
-
to_return(:status =>
|
135
|
+
:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Type'=>'application/x-www-form-urlencoded'}).
|
136
|
+
to_return(:status => 500, :body => "No hooks", :headers => {})
|
128
137
|
end
|
129
138
|
|
130
139
|
it "raises error" do
|
@@ -132,5 +141,19 @@ describe SlackNotify::Client do
|
|
132
141
|
.to raise_error SlackNotify::Error, "No hooks"
|
133
142
|
end
|
134
143
|
end
|
144
|
+
|
145
|
+
context "when channel is invalid" do
|
146
|
+
before do
|
147
|
+
stub_request(:post, "https://foo.slack.com/services/hooks/incoming-webhook?token=token").
|
148
|
+
with(:body => {"{\"text\":\"message\",\"username\":\"webhookbot\",\"channel\":\"#foobar\"}"=>true},
|
149
|
+
:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Type'=>'application/x-www-form-urlencoded'}).
|
150
|
+
to_return(:status => 500, :body => "Invalid channel specified", :headers => {})
|
151
|
+
end
|
152
|
+
|
153
|
+
it "raises error" do
|
154
|
+
expect { client.notify("message", "foobar") }.
|
155
|
+
to raise_error SlackNotify::Error, "Invalid channel specified"
|
156
|
+
end
|
157
|
+
end
|
135
158
|
end
|
136
159
|
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.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dan Sosedoff
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-02-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -84,16 +84,16 @@ dependencies:
|
|
84
84
|
name: faraday
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- -
|
87
|
+
- - <
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
89
|
+
version: 0.9.0
|
90
90
|
type: :runtime
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- -
|
94
|
+
- - <
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
96
|
+
version: 0.9.0
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: json
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -108,7 +108,7 @@ dependencies:
|
|
108
108
|
- - ~>
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '1.8'
|
111
|
-
description: Send notifications to Slack channel
|
111
|
+
description: Send notifications to a Slack channel
|
112
112
|
email:
|
113
113
|
- dan.sosedoff@gmail.com
|
114
114
|
executables: []
|
@@ -127,7 +127,7 @@ files:
|
|
127
127
|
- slack-notify.gemspec
|
128
128
|
- spec/slack-notify/client_spec.rb
|
129
129
|
- spec/spec_helper.rb
|
130
|
-
homepage:
|
130
|
+
homepage: https://github.com/sosedoff/slack-notify
|
131
131
|
licenses:
|
132
132
|
- MIT
|
133
133
|
metadata: {}
|
@@ -147,10 +147,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
147
147
|
version: '0'
|
148
148
|
requirements: []
|
149
149
|
rubyforge_project:
|
150
|
-
rubygems_version: 2.
|
150
|
+
rubygems_version: 2.1.11
|
151
151
|
signing_key:
|
152
152
|
specification_version: 4
|
153
|
-
summary: Send notifications to Slack channel
|
153
|
+
summary: Send notifications to a Slack channel
|
154
154
|
test_files:
|
155
155
|
- spec/slack-notify/client_spec.rb
|
156
156
|
- spec/spec_helper.rb
|