slack-notify 0.1.2 → 0.1.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 43f177e7190a379067808a7a424ba8b6e11cbdc6
4
- data.tar.gz: 1e500c4795f082d1ea07327ecc1d8a6c49be9032
3
+ metadata.gz: 9e75c555cef9d6c7b413b5ab5ae37baa9f7c9a02
4
+ data.tar.gz: d2c6913f055d0786e00d1bfe0fb27316e4298d9a
5
5
  SHA512:
6
- metadata.gz: 251c13145bf1ee1abf9026dbfc2543716e5275e1a3df0f3cc42de365d72911e807b29291927c5e8796cb989cce259fcbce3ce6060de204174af73da5de17b2f6
7
- data.tar.gz: 3d5bce3eb6d4422ae811b62a2f93152556984abc01f9691cdd8805be7b28d7cf5b313d72bf7f8862c5c7994119ed11d8d4fdde7be888577fc787bc144d8c1dd8
6
+ metadata.gz: 35134ea19abf2ea554e5ac308f759e9093671633e8fd7f9e88bff2093c5dfe720e16c17f86565fa596d571acecb4c7a17e5da690332454883405a1c74d3f6f12
7
+ data.tar.gz: a5d8b639e4c2f0eebc812a6f6b558c4b5ebac6a7e7bfb02f7af78eeec1819e6f431c1b31d56e6fd0d78a0f1374270ee124ceec92b3188c10d39c98ba01d66f3c
@@ -1,3 +1,3 @@
1
1
  module SlackNotify
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
data/lib/slack-notify.rb CHANGED
@@ -22,10 +22,7 @@ module SlackNotify
22
22
  end
23
23
 
24
24
  def notify(text, channel = nil)
25
- channels = [channel || @channel].flatten.compact.uniq
26
-
27
- channels.each do |chan|
28
- chan.prepend("#") if chan[0] != "#"
25
+ format_channel(channel).each do |chan|
29
26
  send_payload(text: text, username: @username, channel: chan)
30
27
  end
31
28
 
@@ -34,6 +31,12 @@ module SlackNotify
34
31
 
35
32
  private
36
33
 
34
+ def format_channel(channel)
35
+ [channel || @channel].flatten.compact.uniq.map do |name|
36
+ name[0] != "#" ? "##{name}" : name
37
+ end
38
+ end
39
+
37
40
  def send_payload(payload)
38
41
  conn = Faraday.new(hook_url, { timeout: 5, open_timeout: 5 }) do |c|
39
42
  c.use(Faraday::Request::UrlEncoded)
@@ -95,6 +95,30 @@ describe SlackNotify::Client do
95
95
  expect(client.notify("Message")).to eq true
96
96
  end
97
97
 
98
+ context "with settings from environment variables" do
99
+ let(:vars) { ["SLACK_TEAM", "SLACK_TOKEN", "SLACK_CHANNEL", "SLACK_USER"] }
100
+
101
+ let(:client) do
102
+ described_class.new(ENV["SLACK_TEAM"], ENV["SLACK_TOKEN"], {
103
+ channel: ENV["SLACK_CHANNEL"],
104
+ username: ENV["SLACK_USER"]
105
+ })
106
+ end
107
+
108
+ before do
109
+ vars.each { |v| ENV[v] = "foobar" }
110
+ client.stub(:send_payload) { true }
111
+ end
112
+
113
+ after do
114
+ vars.each { |v| ENV.delete(v) }
115
+ end
116
+
117
+ it "sends data to channel specified by environment variables" do
118
+ client.notify("Message")
119
+ end
120
+ end
121
+
98
122
  context "with multiple channels" do
99
123
  before do
100
124
  client.stub(:send_payload) { true }
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.2
4
+ version: 0.1.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-02-10 00:00:00.000000000 Z
11
+ date: 2014-02-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler