slack-notify 0.1.1 → 0.1.2

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: 57d6d5e9bc2495e9e867ebb9c15123cbff6432a0
4
- data.tar.gz: ece231fb7b78c6b715dacdfadf4b622d9697dca8
3
+ metadata.gz: 43f177e7190a379067808a7a424ba8b6e11cbdc6
4
+ data.tar.gz: 1e500c4795f082d1ea07327ecc1d8a6c49be9032
5
5
  SHA512:
6
- metadata.gz: d5ae0948e81205f17980748fed744f81e218db8105675696a7c421205980f592cb57f3f3a59310330397ed30b70021f17a9753bfa2bde4967c467bb76819414a
7
- data.tar.gz: 0c688b5b481e6c43a7bf6589085aef0ac4284e73709348f34c0b6dfa659f8652c16133aefd9319b85cb730b1625d2c5201f19e7d861805738a465a4b838e0511
6
+ metadata.gz: 251c13145bf1ee1abf9026dbfc2543716e5275e1a3df0f3cc42de365d72911e807b29291927c5e8796cb989cce259fcbce3ce6060de204174af73da5de17b2f6
7
+ data.tar.gz: 3d5bce3eb6d4422ae811b62a2f93152556984abc01f9691cdd8805be7b28d7cf5b313d72bf7f8862c5c7994119ed11d8d4fdde7be888577fc787bc144d8c1dd8
@@ -1,4 +1,4 @@
1
- Copyright (c) 2013 Dan Sosedoff
1
+ Copyright (c) 2013-2014 Dan Sosedoff, dan.sosedoff@gmail.com
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -68,6 +68,6 @@ Some of the issues while Slack is in beta:
68
68
 
69
69
  ## License
70
70
 
71
- Copyright (c) 2013 Dan Sosedoff
71
+ Copyright (c) 2013-2014 Dan Sosedoff, <dan.sosedoff@gmail.com>
72
72
 
73
73
  MIT License
@@ -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] || "#general"
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
- response = Faraday.post(hook_url) do |req|
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
- if response.success?
42
- true
43
- else
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
- "https://#{@team}.slack.com/services/hooks/incoming-webhook?token=#{@token}"
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
@@ -1,3 +1,3 @@
1
1
  module SlackNotify
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -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", "~> 0.8"
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', 'User-Agent'=>'Faraday v0.8.8'}).
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', 'User-Agent'=>'Faraday v0.8.8'}).
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', 'User-Agent'=>'Faraday v0.8.8'}).
127
- to_return(:status => 400, :body => "No hooks", :headers => {})
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.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: 2013-11-02 00:00:00.000000000 Z
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: '0.8'
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: '0.8'
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.0.5
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