slack-notifier 0.4.1 → 0.5.0

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: 9efa003e30e2530dfdb328138ac6b10e9c1ee92b
4
- data.tar.gz: 388a86cc5af5c0ce1547a2f4b351b81420ec0c40
3
+ metadata.gz: 3ed944b7001667e3e533abc25325fec4d7bfa99b
4
+ data.tar.gz: 4d0ae7eb667f225b42b5621afdc2ffbac463f471
5
5
  SHA512:
6
- metadata.gz: f5d939b3ec86e70ee8d13bf9438ebf9cbb1957a374c3622d8e5510df0d5c504f83067ec729cdfd38450f292f52c09eb2acb72aef4d2765a7352241cd4d41efc6
7
- data.tar.gz: ea3ff1b881b8dcc442bc2fd6939b24a56208e38592e961fad1c1dbdf56713f0221d929787bca67b526f98ef55bd652e04772f2d42b705fded3d37639d08ba657
6
+ metadata.gz: 53703f1a9413e12505c0d2338776738eb25c5383c1448fd4e2efeb65f71eaccd4b6bf101263639e25bc957c588af4d4b094c77ae45f61ffb3adf0e8707db20d0
7
+ data.tar.gz: f35eb71b3e57950f2e648e241682a054fbe98d6a7c96719f766d478c704d8afdefd96b853d8237f9dcbef2ebbf3a69195196b717a4242128f58db5ef2e84436a
@@ -7,17 +7,19 @@ require_relative 'slack-notifier/link_formatter'
7
7
 
8
8
  module Slack
9
9
  class Notifier
10
+ attr_reader :team, :token, :hook_name, :default_payload
10
11
 
11
- # these act as defaults
12
- # if they are set
13
- attr_accessor :channel, :username
14
-
15
- attr_reader :team, :token, :hook_name
16
-
17
- def initialize team, token, hook_name = default_hook_name
12
+ def initialize team, token, hook_name=default_hook_name, default_payload={}
18
13
  @team = team
19
14
  @token = token
20
- @hook_name = hook_name
15
+
16
+ if hook_name.is_a? Hash
17
+ @hook_name = default_hook_name
18
+ @default_payload = hook_name
19
+ else
20
+ @hook_name = hook_name
21
+ @default_payload = default_payload
22
+ end
21
23
  end
22
24
 
23
25
  def ping message, options={}
@@ -27,12 +29,20 @@ module Slack
27
29
  HTTPPost.to endpoint, payload: payload.to_json
28
30
  end
29
31
 
32
+ def channel
33
+ default_payload[:channel]
34
+ end
35
+
30
36
  def channel= channel
31
- @channel = if channel.start_with? '#', "@"
32
- channel
33
- else
34
- "##{channel}"
35
- end
37
+ default_payload[:channel] = channel
38
+ end
39
+
40
+ def username
41
+ default_payload[:username]
42
+ end
43
+
44
+ def username= username
45
+ default_payload[:username] = username
36
46
  end
37
47
 
38
48
  private
@@ -41,13 +51,6 @@ module Slack
41
51
  'incoming-webhook'
42
52
  end
43
53
 
44
- def default_payload
45
- payload = {}
46
- payload[:channel] = channel if channel
47
- payload[:username] = username if username
48
- payload
49
- end
50
-
51
54
  def endpoint
52
55
  URI.parse "https://#{team}.slack.com/services/hooks/#{hook_name}?token=#{token}"
53
56
  end
@@ -1,5 +1,5 @@
1
1
  module Slack
2
2
  class Notifier
3
- VERSION = "0.4.1"
3
+ VERSION = "0.5.0"
4
4
  end
5
5
  end
@@ -1,5 +1,5 @@
1
1
  require_relative '../../lib/slack-notifier'
2
2
 
3
- notifier = Slack::Notifier.new ENV['SLACK_TEAM'], ENV['SLACK_TOKEN']
3
+ notifier = Slack::Notifier.new ENV['SLACK_TEAM'], ENV['SLACK_TOKEN'], username: 'notifier'
4
4
  puts "testing with ruby #{RUBY_VERSION}"
5
5
  notifier.ping "hello from notifier test script on ruby: #{RUBY_VERSION}"
@@ -12,10 +12,21 @@ describe Slack::Notifier do
12
12
  expect( subject.token ).to eq 'token'
13
13
  end
14
14
 
15
- it 'sets the optional service hook name' do
15
+ it "sets the optional service hook name" do
16
16
  subject = described_class.new 'team', 'token', 'custom_hook_name'
17
17
  expect( subject.hook_name ).to eq 'custom_hook_name'
18
18
  end
19
+
20
+ it "sets the default_payload options" do
21
+ subject = described_class.new 'team', 'token', channel: 'foo'
22
+ expect( subject.channel ).to eq 'foo'
23
+ end
24
+
25
+ it "can set service hook & default_payload options" do
26
+ subject = described_class.new 'team', 'token', 'hook_name', channel: 'foo'
27
+ expect( subject.channel ).to eq 'foo'
28
+ expect( subject.hook_name ).to eq 'hook_name'
29
+ end
19
30
  end
20
31
 
21
32
  describe "#ping" do
@@ -99,18 +110,12 @@ describe Slack::Notifier do
99
110
  subject.channel = "#foo"
100
111
  expect( subject.channel ).to eq "#foo"
101
112
  end
113
+ end
102
114
 
103
- it "maintains channel prefix if it is '#' or '@'" do
104
- subject.channel = "#foo"
105
- expect( subject.channel ).to eq "#foo"
106
-
107
- subject.channel = "@foo"
108
- expect( subject.channel ).to eq "@foo"
109
- end
110
-
111
- it "adds a '#' prefix to channel if it has no prefix" do
112
- subject.channel = "foo"
113
- expect( subject.channel ).to eq "#foo"
115
+ describe "#username=" do
116
+ it "sets the given username" do
117
+ subject.username = "foo"
118
+ expect( subject.username ).to eq "foo"
114
119
  end
115
120
  end
116
121
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slack-notifier
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steven Sloan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-14 00:00:00.000000000 Z
11
+ date: 2014-05-14 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: " A slim ruby wrapper for posting to slack webhooks "
14
14
  email: