slack-notifier 0.5.0 → 0.6.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 +4 -4
- data/lib/slack-notifier.rb +12 -15
- data/lib/slack-notifier/{http_post.rb → default_http_client.rb} +3 -3
- data/lib/slack-notifier/version.rb +1 -1
- data/spec/lib/slack-notifier/{http_post_spec.rb → default_http_client_spec.rb} +5 -5
- data/spec/lib/slack-notifier_spec.rb +29 -8
- metadata +5 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f3a07aa79b784ac446857af4e6256d467d0d09ab
|
4
|
+
data.tar.gz: 9d41a7a8c98ac9b9a780c1398c07b7a1988db111
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9ce9ea031ea4f5e996a784ebd43b22896ddc49b7d258ef353cfb59b7d30e6250178255390933322c146cebf46686f4cd333548df0a4cd3ebfd339c3180f9148e
|
7
|
+
data.tar.gz: d03f6d11af25cc31083478893f95be4c6172aa8533b2acf9b18cfa4e11c33dd096b6489dabeacf6a131b3553b1ff95c4683653af27b93133687be4abdd32dc40
|
data/lib/slack-notifier.rb
CHANGED
@@ -2,31 +2,28 @@ require 'net/http'
|
|
2
2
|
require 'uri'
|
3
3
|
require 'json'
|
4
4
|
|
5
|
-
require_relative 'slack-notifier/
|
5
|
+
require_relative 'slack-notifier/default_http_client'
|
6
6
|
require_relative 'slack-notifier/link_formatter'
|
7
7
|
|
8
8
|
module Slack
|
9
9
|
class Notifier
|
10
|
-
attr_reader :team, :token, :
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
@
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
else
|
20
|
-
@hook_name = hook_name
|
21
|
-
@default_payload = default_payload
|
22
|
-
end
|
10
|
+
attr_reader :team, :token, :http_client,
|
11
|
+
:hook_name, :default_payload
|
12
|
+
|
13
|
+
def initialize team, token, options={} # hook_name=default_hook_name, default_payload={}
|
14
|
+
@team = team
|
15
|
+
@token = token
|
16
|
+
@http_client = options.delete(:http_client) || DefaultHTTPClient
|
17
|
+
@hook_name = options.delete(:hook_name) || default_hook_name
|
18
|
+
@default_payload = options
|
23
19
|
end
|
24
20
|
|
25
21
|
def ping message, options={}
|
26
22
|
message = LinkFormatter.format(message)
|
27
23
|
payload = { text: message }.merge(default_payload).merge(options)
|
28
24
|
|
29
|
-
|
25
|
+
|
26
|
+
http_client.post endpoint, payload: payload.to_json
|
30
27
|
end
|
31
28
|
|
32
29
|
def channel
|
@@ -1,17 +1,17 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Slack::Notifier::
|
3
|
+
describe Slack::Notifier::DefaultHTTPClient do
|
4
4
|
|
5
|
-
describe "::
|
6
|
-
it "initializes
|
7
|
-
http_post_double = instance_double("Slack::Notifier::
|
5
|
+
describe "::post" do
|
6
|
+
it "initializes DefaultHTTPClient with the given uri and params then calls" do
|
7
|
+
http_post_double = instance_double("Slack::Notifier::DefaultHTTPClient")
|
8
8
|
|
9
9
|
expect( described_class ).to receive(:new)
|
10
10
|
.with( 'uri', 'params' )
|
11
11
|
.and_return( http_post_double )
|
12
12
|
expect( http_post_double ).to receive(:call)
|
13
13
|
|
14
|
-
described_class.
|
14
|
+
described_class.post 'uri', 'params'
|
15
15
|
end
|
16
16
|
|
17
17
|
# http_post is really tested in the integration spec,
|
@@ -13,7 +13,7 @@ describe Slack::Notifier do
|
|
13
13
|
end
|
14
14
|
|
15
15
|
it "sets the optional service hook name" do
|
16
|
-
subject = described_class.new 'team', 'token', 'custom_hook_name'
|
16
|
+
subject = described_class.new 'team', 'token', hook_name: 'custom_hook_name'
|
17
17
|
expect( subject.hook_name ).to eq 'custom_hook_name'
|
18
18
|
end
|
19
19
|
|
@@ -22,8 +22,14 @@ describe Slack::Notifier do
|
|
22
22
|
expect( subject.channel ).to eq 'foo'
|
23
23
|
end
|
24
24
|
|
25
|
+
it "sets a custom http client" do
|
26
|
+
client = double("CustomClient")
|
27
|
+
subject = described_class.new 'team', 'token', http_client: client
|
28
|
+
expect( subject.http_client ).to eq client
|
29
|
+
end
|
30
|
+
|
25
31
|
it "can set service hook & default_payload options" do
|
26
|
-
subject = described_class.new 'team', 'token', 'hook_name', channel: 'foo'
|
32
|
+
subject = described_class.new 'team', 'token', hook_name: 'hook_name', channel: 'foo'
|
27
33
|
expect( subject.channel ).to eq 'foo'
|
28
34
|
expect( subject.hook_name ).to eq 'hook_name'
|
29
35
|
end
|
@@ -31,7 +37,7 @@ describe Slack::Notifier do
|
|
31
37
|
|
32
38
|
describe "#ping" do
|
33
39
|
before :each do
|
34
|
-
allow( Slack::Notifier::
|
40
|
+
allow( Slack::Notifier::DefaultHTTPClient ).to receive(:post)
|
35
41
|
end
|
36
42
|
|
37
43
|
it "passes the message through LinkFormatter" do
|
@@ -57,7 +63,7 @@ describe Slack::Notifier do
|
|
57
63
|
end
|
58
64
|
|
59
65
|
it "uses default channel" do
|
60
|
-
expect( Slack::Notifier::
|
66
|
+
expect( Slack::Notifier::DefaultHTTPClient ).to receive(:post)
|
61
67
|
.with @endpoint_double,
|
62
68
|
payload: '{"text":"the message","channel":"#default"}'
|
63
69
|
|
@@ -65,7 +71,7 @@ describe Slack::Notifier do
|
|
65
71
|
end
|
66
72
|
|
67
73
|
it "allows override channel to be set" do
|
68
|
-
expect( Slack::Notifier::
|
74
|
+
expect( Slack::Notifier::DefaultHTTPClient ).to receive(:post)
|
69
75
|
.with @endpoint_double,
|
70
76
|
payload: '{"text":"the message","channel":"new"}'
|
71
77
|
|
@@ -81,7 +87,7 @@ describe Slack::Notifier do
|
|
81
87
|
.with("https://team.slack.com/services/hooks/incoming-webhook?token=token")
|
82
88
|
.and_return(@endpoint_double)
|
83
89
|
|
84
|
-
expect( Slack::Notifier::
|
90
|
+
expect( Slack::Notifier::DefaultHTTPClient ).to receive(:post)
|
85
91
|
.with @endpoint_double,
|
86
92
|
payload: '{"text":"the message","channel":"channel"}'
|
87
93
|
|
@@ -96,11 +102,26 @@ describe Slack::Notifier do
|
|
96
102
|
.with("https://team.slack.com/services/hooks/custom_hook_name?token=token")
|
97
103
|
.and_return(@endpoint_double)
|
98
104
|
|
99
|
-
expect( Slack::Notifier::
|
105
|
+
expect( Slack::Notifier::DefaultHTTPClient ).to receive(:post)
|
100
106
|
.with @endpoint_double,
|
101
107
|
payload: '{"text":"the message","channel":"channel"}'
|
102
108
|
|
103
|
-
described_class.new("team","token","custom_hook_name").ping "the message", channel: "channel"
|
109
|
+
described_class.new("team","token", hook_name: "custom_hook_name").ping "the message", channel: "channel"
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
context "with a custom http_client set" do
|
114
|
+
it "uses it" do
|
115
|
+
endpoint_double = instance_double "URI::HTTP"
|
116
|
+
allow( URI ).to receive(:parse)
|
117
|
+
.with("https://team.slack.com/services/hooks/incoming-webhook?token=token")
|
118
|
+
.and_return(endpoint_double)
|
119
|
+
client = double("CustomClient")
|
120
|
+
expect( client ).to receive(:post)
|
121
|
+
.with endpoint_double,
|
122
|
+
payload: '{"text":"the message"}'
|
123
|
+
|
124
|
+
described_class.new('team','token',http_client: client).ping "the message"
|
104
125
|
end
|
105
126
|
end
|
106
127
|
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
|
+
version: 0.6.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-
|
11
|
+
date: 2014-08-24 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: " A slim ruby wrapper for posting to slack webhooks "
|
14
14
|
email:
|
@@ -18,11 +18,11 @@ extensions: []
|
|
18
18
|
extra_rdoc_files: []
|
19
19
|
files:
|
20
20
|
- lib/slack-notifier.rb
|
21
|
-
- lib/slack-notifier/
|
21
|
+
- lib/slack-notifier/default_http_client.rb
|
22
22
|
- lib/slack-notifier/link_formatter.rb
|
23
23
|
- lib/slack-notifier/version.rb
|
24
24
|
- spec/integration/ping_integration_test.rb
|
25
|
-
- spec/lib/slack-notifier/
|
25
|
+
- spec/lib/slack-notifier/default_http_client_spec.rb
|
26
26
|
- spec/lib/slack-notifier/link_formatter_spec.rb
|
27
27
|
- spec/lib/slack-notifier_spec.rb
|
28
28
|
- spec/spec_helper.rb
|
@@ -52,8 +52,7 @@ specification_version: 4
|
|
52
52
|
summary: A slim ruby wrapper for posting to slack webhooks
|
53
53
|
test_files:
|
54
54
|
- spec/integration/ping_integration_test.rb
|
55
|
-
- spec/lib/slack-notifier/
|
55
|
+
- spec/lib/slack-notifier/default_http_client_spec.rb
|
56
56
|
- spec/lib/slack-notifier/link_formatter_spec.rb
|
57
57
|
- spec/lib/slack-notifier_spec.rb
|
58
58
|
- spec/spec_helper.rb
|
59
|
-
has_rdoc:
|