slack-notifier 1.0.0 → 1.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: a423a9d3657e72895726732371162ca6999c1cb6
4
- data.tar.gz: d929fe769de577f03331eebac18796eb2ab06b28
3
+ metadata.gz: 31725a6d5391e72e7d0b4c40733209b2f07cca3a
4
+ data.tar.gz: 52ac6b2e70a4bc138a5957b0131136109bae87bd
5
5
  SHA512:
6
- metadata.gz: 74aa5dfc1e49ab07922382bc69e8357ac5a7f5cca7ca9df110bee939da04a77eccb719db27c49864d65a317a4f3d224876b210bb5cebf2a5b14018064d950139
7
- data.tar.gz: a4716f34f9e618a016d691830a82ee6b589e51af8b53a3d44625585b042b0c47b17f57db8426bcabaed5a798839a4d984a31dc213bc530e8a4da2a10a970f606
6
+ metadata.gz: 75075f1cb873ce237063f7f68425d9745a85b007744fa78741c0a04954de6d5b0d7647480bde366d739fedc48175aaa677841a001eea5fe2d83f501e8be91343
7
+ data.tar.gz: c0546c41a9eec3ccd44bf8537ca415ea2183a30f4859cde34d40b3d0e71baf6a9732cf68056a72cba06de4bd95dfd9d92ba7da3f8d42aa79c27553dc2f2bebd8
@@ -7,20 +7,27 @@ require_relative 'slack-notifier/link_formatter'
7
7
 
8
8
  module Slack
9
9
  class Notifier
10
- attr_reader :endpoint, :http_client, :default_payload
10
+ attr_reader :endpoint, :default_payload
11
11
 
12
12
  def initialize webhook_url, options={}
13
13
  @endpoint = URI.parse webhook_url
14
- @http_client = options.delete(:http_client) || DefaultHTTPClient
15
14
  @default_payload = options
16
15
  end
17
16
 
18
17
  def ping message, options={}
19
- message = LinkFormatter.format(message)
20
- payload = { text: message }.merge(default_payload).merge(options)
18
+ message = LinkFormatter.format(message)
19
+ payload = default_payload.merge(options).merge(text: message)
20
+ client = payload.delete(:http_client) || http_client
21
+ http_options = payload.delete(:http_options)
21
22
 
23
+ params = { payload: payload.to_json }
24
+ params[:http_options] = http_options if http_options
22
25
 
23
- http_client.post endpoint, payload: payload.to_json
26
+ client.post endpoint, params
27
+ end
28
+
29
+ def http_client
30
+ default_payload.fetch :http_client, DefaultHTTPClient
24
31
  end
25
32
 
26
33
  def channel
@@ -9,11 +9,12 @@ module Slack
9
9
  end
10
10
  end
11
11
 
12
- attr_reader :uri, :params
12
+ attr_reader :uri, :params, :http_options
13
13
 
14
14
  def initialize uri, params
15
- @uri = uri
16
- @params = params
15
+ @uri = uri
16
+ @http_options = params.delete(:http_options) || {}
17
+ @params = params
17
18
  end
18
19
 
19
20
  def call
@@ -33,6 +34,14 @@ module Slack
33
34
  http = Net::HTTP.new uri.host, uri.port
34
35
  http.use_ssl = (uri.scheme == "https")
35
36
 
37
+ http_options.each do |opt, val|
38
+ if http.respond_to? "#{opt}="
39
+ http.send "#{opt}=", val
40
+ else
41
+ warn "Net::HTTP doesn't respond to `#{opt}=`, ignoring that option"
42
+ end
43
+ end
44
+
36
45
  return http
37
46
  end
38
47
 
@@ -1,5 +1,5 @@
1
1
  module Slack
2
2
  class Notifier
3
- VERSION = "1.0.0"
3
+ VERSION = "1.1.0"
4
4
  end
5
5
  end
@@ -18,4 +18,20 @@ describe Slack::Notifier::DefaultHTTPClient do
18
18
  # where the internals are run through
19
19
  end
20
20
 
21
- end
21
+ describe "#initialize" do
22
+ it "allows setting of options for Net::HTTP" do
23
+ net_http_double = instance_double("Net::HTTP")
24
+ http_client = described_class.new( URI.parse('http://example.com'), http_options: { open_timeout: 5 })
25
+
26
+ allow( Net::HTTP ).to receive(:new)
27
+ .and_return(net_http_double)
28
+ allow( net_http_double ).to receive(:use_ssl=)
29
+ allow( net_http_double ).to receive(:request)
30
+
31
+ expect( net_http_double ).to receive(:open_timeout=).with(5)
32
+
33
+ http_client.call
34
+ end
35
+ end
36
+
37
+ end
@@ -50,7 +50,7 @@ describe Slack::Notifier do
50
50
  it "uses default channel" do
51
51
  expect( Slack::Notifier::DefaultHTTPClient ).to receive(:post)
52
52
  .with @endpoint_double,
53
- payload: '{"text":"the message","channel":"#default"}'
53
+ payload: '{"channel":"#default","text":"the message"}'
54
54
 
55
55
  subject.ping "the message"
56
56
  end
@@ -58,7 +58,7 @@ describe Slack::Notifier do
58
58
  it "allows override channel to be set" do
59
59
  expect( Slack::Notifier::DefaultHTTPClient ).to receive(:post)
60
60
  .with @endpoint_double,
61
- payload: '{"text":"the message","channel":"new"}'
61
+ payload: '{"channel":"new","text":"the message"}'
62
62
 
63
63
  subject.ping "the message", channel: "new"
64
64
  end
@@ -74,7 +74,7 @@ describe Slack::Notifier do
74
74
 
75
75
  expect( Slack::Notifier::DefaultHTTPClient ).to receive(:post)
76
76
  .with @endpoint_double,
77
- payload: '{"text":"the message","channel":"channel"}'
77
+ payload: '{"channel":"channel","text":"the message"}'
78
78
 
79
79
  described_class.new("http://example.com").ping "the message", channel: "channel"
80
80
  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: 1.0.0
4
+ version: 1.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: 2014-10-23 00:00:00.000000000 Z
11
+ date: 2015-02-09 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: " A slim ruby wrapper for posting to slack webhooks "
14
14
  email: