slack-notifier 2.0.0 → 2.1.0

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: 47af99d5a1eeca46a62425be8842bc6ff89d9d51
4
- data.tar.gz: 3d0519d10cb7a251a49b32b0d27b2e0616f08c54
3
+ metadata.gz: 2de365236adc9d11e81ff2d438f8f8623de09e8a
4
+ data.tar.gz: cdf04ae41bb99465317aa0be35aecb9fa841d52b
5
5
  SHA512:
6
- metadata.gz: 0d9a915eb0ebc25b3d1d4042055419cf8628404cf9282fffa41a4f4dfada1eb8aac4c02c9b7415226895a160ee326f0c82d048fa84ede13f829dac19130b2cc8
7
- data.tar.gz: 314a2d7812c2d699f201753e15fbcd6c34c778f863123f2e70e7731d8753a338e984bbcb3dd4cd125f01509990b79fc84ac8a3b7daf5b2e70f5484c66cede356
6
+ metadata.gz: a83b5175eacbc6694b640ccdb42dbf11f7fcd46d35ee91c59da8d0cb48972f77fcaef35a2caa4175bf6e95b9480b51ed4a36a4bcff39e789f0b744ec5b56f06c
7
+ data.tar.gz: 1f0fa17db345193cf89a412934743bc2b972c434e19557a6f64cbebbda15149b6690507306767a3ec4906b4f7811b0b38ef4fd753f4f2c22861940001ddaf7e8
@@ -5,7 +5,7 @@ module Slack
5
5
  def initialize
6
6
  @http_client = Util::HTTPClient
7
7
  @defaults = {}
8
- @middleware = [:format_message, :format_attachments]
8
+ @middleware = [:format_message, :format_attachments, :at]
9
9
  end
10
10
 
11
11
  def http_client client=nil
@@ -19,3 +19,4 @@ require_relative "payload_middleware/stack"
19
19
  require_relative "payload_middleware/base"
20
20
  require_relative "payload_middleware/format_message"
21
21
  require_relative "payload_middleware/format_attachments"
22
+ require_relative "payload_middleware/at"
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Slack
4
+ class Notifier
5
+ class PayloadMiddleware
6
+ class At < Base
7
+ middleware_name :at
8
+
9
+ options at: []
10
+
11
+ def call payload={}
12
+ return payload unless payload[:at]
13
+
14
+ payload[:text] = "#{format_ats(payload.delete(:at))}#{payload[:text]}"
15
+ payload
16
+ end
17
+
18
+ private
19
+
20
+ def format_ats ats
21
+ Array(ats).map { |at| "<#{at_cmd_char(at)}#{at}> " }
22
+ .join("")
23
+ end
24
+
25
+ def at_cmd_char at
26
+ case at
27
+ when :here, :channel, :everyone, :group
28
+ "!"
29
+ else
30
+ "@"
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -24,11 +24,9 @@ module Slack
24
24
  @options = self.class.default_opts.merge opts
25
25
  end
26
26
 
27
- # rubocop:disable Lint/UnusedMethodArgument
28
- def call payload={}
27
+ def call _payload={}
29
28
  raise NoMethodError, "method `call` not defined for class #{self.class}"
30
29
  end
31
- # rubocop:enable Lint/UnusedMethodArgument
32
30
  end
33
31
  end
34
32
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  module Slack
3
3
  class Notifier
4
- VERSION = "2.0.0".freeze # rubocop:disable Style/RedundantFreeze
4
+ VERSION = "2.1.0".freeze # rubocop:disable Style/RedundantFreeze
5
5
  end
6
6
  end
@@ -43,10 +43,10 @@ RSpec.describe Slack::Notifier::Config do
43
43
  end
44
44
 
45
45
  describe "#middleware" do
46
- it "is [:format_message, :format_attachments] if not set" do
46
+ it "is [:format_message, :format_attachments, :at] if not set" do
47
47
  subject = described_class.new
48
48
 
49
- expect(subject.middleware).to eq [:format_message, :format_attachments]
49
+ expect(subject.middleware).to eq [:format_message, :format_attachments, :at]
50
50
  end
51
51
 
52
52
  it "takes an array or a splat of args" do
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe Slack::Notifier::PayloadMiddleware::At do
4
+ it "can handle array at" do
5
+ subject = described_class.new(:notifier)
6
+ payload = { text: "hello", at: [:john, :ken, :here] }
7
+
8
+ expect(subject.call(payload)).to eq text: "<@john> <@ken> <!here> hello"
9
+ end
10
+
11
+ it "can handle single at option" do
12
+ subject = described_class.new(:notifier)
13
+ payload = { text: "hello", at: :alice }
14
+
15
+ expect(subject.call(payload)).to eq text: "<@alice> hello"
16
+ end
17
+
18
+ it "generates :text in payload if given :at & no :text" do
19
+ subject = described_class.new(:notifier)
20
+ input_payload = { at: [:here], attachments: [{ text: "hello" }] }
21
+ output_payload = { text: "<!here> ", attachments: [{ text: "hello" }] }
22
+
23
+ expect(subject.call(input_payload)).to eq output_payload
24
+ end
25
+ 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: 2.0.0
4
+ version: 2.1.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: 2017-01-02 00:00:00.000000000 Z
11
+ date: 2017-03-03 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: " A slim ruby wrapper for posting to slack webhooks "
14
14
  email:
@@ -20,6 +20,7 @@ files:
20
20
  - lib/slack-notifier.rb
21
21
  - lib/slack-notifier/config.rb
22
22
  - lib/slack-notifier/payload_middleware.rb
23
+ - lib/slack-notifier/payload_middleware/at.rb
23
24
  - lib/slack-notifier/payload_middleware/base.rb
24
25
  - lib/slack-notifier/payload_middleware/format_attachments.rb
25
26
  - lib/slack-notifier/payload_middleware/format_message.rb
@@ -31,6 +32,7 @@ files:
31
32
  - spec/end_to_end_spec.rb
32
33
  - spec/integration/ping_integration_test.rb
33
34
  - spec/lib/slack-notifier/config_spec.rb
35
+ - spec/lib/slack-notifier/payload_middleware/at_spec.rb
34
36
  - spec/lib/slack-notifier/payload_middleware/base_spec.rb
35
37
  - spec/lib/slack-notifier/payload_middleware/format_attachments_spec.rb
36
38
  - spec/lib/slack-notifier/payload_middleware/format_message_spec.rb
@@ -68,6 +70,7 @@ test_files:
68
70
  - spec/end_to_end_spec.rb
69
71
  - spec/integration/ping_integration_test.rb
70
72
  - spec/lib/slack-notifier/config_spec.rb
73
+ - spec/lib/slack-notifier/payload_middleware/at_spec.rb
71
74
  - spec/lib/slack-notifier/payload_middleware/base_spec.rb
72
75
  - spec/lib/slack-notifier/payload_middleware/format_attachments_spec.rb
73
76
  - spec/lib/slack-notifier/payload_middleware/format_message_spec.rb