slack-notify 0.1.0 → 0.1.1

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: 9bb78e8f557ad72bf40e7dada483c74f363eb9b5
4
- data.tar.gz: a53d66d0b94c5bbb8b88ddeacfb3bf9abb4cf711
3
+ metadata.gz: 57d6d5e9bc2495e9e867ebb9c15123cbff6432a0
4
+ data.tar.gz: ece231fb7b78c6b715dacdfadf4b622d9697dca8
5
5
  SHA512:
6
- metadata.gz: 3c1ffa1661501b852ac68c44dfe1b1a88fb0fbfa240c3e09e024a597bff004e6d1c6a9e4f4244f3e2e3b957e50e8d9bfb2cd9d103ac62a2a160448f327b9b6a8
7
- data.tar.gz: ca8cac631640524704dbbe5ef810f3ab8d04ef41f87b263229e8ed148030696dfbe9b0eeab1c127dd354ece20388b01811858438ab67dcfdbbeda9d1cb7cde51
6
+ metadata.gz: d5ae0948e81205f17980748fed744f81e218db8105675696a7c421205980f592cb57f3f3a59310330397ed30b70021f17a9753bfa2bde4967c467bb76819414a
7
+ data.tar.gz: 0c688b5b481e6c43a7bf6589085aef0ac4284e73709348f34c0b6dfa659f8652c16133aefd9319b85cb730b1625d2c5201f19e7d861805738a465a4b838e0511
data/README.md CHANGED
@@ -33,13 +33,13 @@ require "slack-notify"
33
33
  Initialize client:
34
34
 
35
35
  ```ruby
36
- client = SlackNotify::Client.new("subdomain", "token")
36
+ client = SlackNotify::Client.new("team", "token")
37
37
  ```
38
38
 
39
39
  Initialize with options:
40
40
 
41
41
  ```ruby
42
- client = SlackNotify::Client.new("subdomain", "token", {
42
+ client = SlackNotify::Client.new("team", "token", {
43
43
  channel: "#development",
44
44
  username: "mybot"
45
45
  })
@@ -56,6 +56,7 @@ Send message:
56
56
  ```ruby
57
57
  client.notify("Hello There!")
58
58
  client.notify("Another message", "#channel2")
59
+ client.notify("Message", ["#channel1", "#channel2"])
59
60
  ```
60
61
 
61
62
  ## Gotchas
@@ -1,3 +1,3 @@
1
1
  module SlackNotify
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/lib/slack-notify.rb CHANGED
@@ -6,13 +6,13 @@ require "faraday"
6
6
 
7
7
  module SlackNotify
8
8
  class Client
9
- def initialize(subdomain, token, options={})
10
- @subdomain = subdomain
11
- @token = token
12
- @username = options[:username] || "webhookbot"
13
- @channel = options[:channel] || "#general"
9
+ def initialize(team, token, options={})
10
+ @team = team
11
+ @token = token
12
+ @username = options[:username] || "webhookbot"
13
+ @channel = options[:channel] || "#general"
14
14
 
15
- raise ArgumentError, "Subdomain required" if @subdomain.nil?
15
+ raise ArgumentError, "Team name required" if @team.nil?
16
16
  raise ArgumentError, "Token required" if @token.nil?
17
17
  end
18
18
 
@@ -21,20 +21,20 @@ module SlackNotify
21
21
  end
22
22
 
23
23
  def notify(text, channel=nil)
24
- send_payload(
25
- text: text,
26
- channel: channel || @channel,
27
- username: @username
28
- )
24
+ channels = [channel || @channel].flatten.compact.uniq
25
+
26
+ channels.each do |chan|
27
+ chan.prepend("#") if chan[0] != "#"
28
+ send_payload(text: text, username: @username, channel: chan)
29
+ end
30
+
31
+ true
29
32
  end
30
33
 
31
34
  private
32
35
 
33
36
  def send_payload(payload)
34
- url = "https://#{@subdomain}.slack.com/services/hooks/incoming-webhook"
35
- url << "?token=#{@token}"
36
-
37
- response = Faraday.post(url) do |req|
37
+ response = Faraday.post(hook_url) do |req|
38
38
  req.body = JSON.dump(payload)
39
39
  end
40
40
 
@@ -48,5 +48,9 @@ module SlackNotify
48
48
  end
49
49
  end
50
50
  end
51
+
52
+ def hook_url
53
+ "https://#{@team}.slack.com/services/hooks/incoming-webhook?token=#{@token}"
54
+ end
51
55
  end
52
56
  end
data/slack-notify.gemspec CHANGED
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_development_dependency "bundler", "~> 1.3"
22
22
  spec.add_development_dependency "rake", "~> 10"
23
- spec.add_development_dependency "simplecov", "~> 0.8"
23
+ spec.add_development_dependency "simplecov", "~> 0.7"
24
24
  spec.add_development_dependency "rspec", "~> 2.13"
25
25
  spec.add_development_dependency "webmock", "~> 1.0"
26
26
 
@@ -2,9 +2,9 @@ require "spec_helper"
2
2
 
3
3
  describe SlackNotify::Client do
4
4
  describe "#initialize" do
5
- it "requires subdomain" do
5
+ it "requires team name" do
6
6
  expect { described_class.new(nil, nil) }.
7
- to raise_error ArgumentError, "Subdomain required"
7
+ to raise_error ArgumentError, "Team name required"
8
8
  end
9
9
 
10
10
  it "requires token" do
@@ -79,19 +79,39 @@ describe SlackNotify::Client do
79
79
 
80
80
  it "delivers payload" do
81
81
  stub_request(:post, "https://foo.slack.com/services/hooks/incoming-webhook?token=token").
82
- with(:body => {"{\"text\":\"Message\",\"channel\":\"#general\",\"username\":\"webhookbot\"}"=>true},
82
+ with(:body => {"{\"text\":\"Message\",\"username\":\"webhookbot\",\"channel\":\"#general\"}"=>true},
83
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'}).
84
84
  to_return(:status => 200, :body => "", :headers => {})
85
85
 
86
86
  expect(client.notify("Message")).to eq true
87
87
  end
88
88
 
89
- context "invalid subdomain" do
89
+ context "with multiple channels" do
90
+ before do
91
+ client.stub(:send_payload) { true }
92
+ end
93
+
94
+ it "delivers payload to multiple channels" do
95
+ expect(client).to receive(:send_payload).exactly(2).times
96
+ client.notify("Message", ["#channel1", "#channel2"])
97
+ end
98
+ end
99
+
100
+ context "when pound symbol is missing" do
101
+ before { client.stub(:send_payload).and_return(true) }
102
+
103
+ it "adds pound symbol to channel name" do
104
+ expect(client).to receive(:send_payload).with(text: "Message", username: "webhookbot", channel: "#foobar")
105
+ client.notify("Message", "foobar")
106
+ end
107
+ end
108
+
109
+ context "when team name is invalid" do
90
110
  before do
91
111
  stub_request(:post, "https://foo.slack.com/services/hooks/incoming-webhook?token=token").
92
- with(:body => {"{\"text\":\"Message\",\"channel\":\"#general\",\"username\":\"webhookbot\"}"=>true},
112
+ with(:body => {"{\"text\":\"Message\",\"username\":\"webhookbot\",\"channel\":\"#general\"}"=>true},
93
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'}).
94
- to_return(:status => 404, :body => "Multi line\ncontent\nhtml stuff", :headers => {})
114
+ to_return(:status => 404, :body => "Line 1\nLine 2\nLine 3", :headers => {})
95
115
  end
96
116
 
97
117
  it "raises error" do
@@ -99,12 +119,12 @@ describe SlackNotify::Client do
99
119
  end
100
120
  end
101
121
 
102
- context "invalid token" do
122
+ context "when token is invalid" do
103
123
  before do
104
124
  stub_request(:post, "https://foo.slack.com/services/hooks/incoming-webhook?token=token").
105
- with(:body => {"{\"text\":\"Message\",\"channel\":\"#general\",\"username\":\"webhookbot\"}"=>true},
125
+ with(:body => {"{\"text\":\"Message\",\"username\":\"webhookbot\",\"channel\":\"#general\"}"=>true},
106
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'}).
107
- to_return(:status => 404, :body => "No hooks", :headers => {})
127
+ to_return(:status => 400, :body => "No hooks", :headers => {})
108
128
  end
109
129
 
110
130
  it "raises error" do
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.0
4
+ version: 0.1.1
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-10-31 00:00:00.000000000 Z
11
+ date: 2013-11-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - ~>
46
46
  - !ruby/object:Gem::Version
47
- version: '0.8'
47
+ version: '0.7'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ~>
53
53
  - !ruby/object:Gem::Version
54
- version: '0.8'
54
+ version: '0.7'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -154,4 +154,3 @@ summary: Send notifications to Slack channel
154
154
  test_files:
155
155
  - spec/slack-notify/client_spec.rb
156
156
  - spec/spec_helper.rb
157
- has_rdoc: