slack-notifier 0.6.1 → 1.0.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: 64899197a10189dcf547d2145599c9cd2f58dc58
4
- data.tar.gz: 760a4379a03ce8171fa78c41f903bd718ee6469e
3
+ metadata.gz: a423a9d3657e72895726732371162ca6999c1cb6
4
+ data.tar.gz: d929fe769de577f03331eebac18796eb2ab06b28
5
5
  SHA512:
6
- metadata.gz: 43b0dba726b3e0d06b8616bbcfe8f3dc4f742f480794c59a4bd6f2c1a4a1fa2e1628bf28258315be502c3ca3248d661e56f34fadc39258b0ccd911ffa4a94a60
7
- data.tar.gz: 24a89065f0d7f010c09bd8f71f89989a1b824c6ab483cfeeeed1e6507a362c9acabfd011471ed66cbba7fef584a57fa55cf4ca8b95a6ef33af07dd9adfa3753b
6
+ metadata.gz: 74aa5dfc1e49ab07922382bc69e8357ac5a7f5cca7ca9df110bee939da04a77eccb719db27c49864d65a317a4f3d224876b210bb5cebf2a5b14018064d950139
7
+ data.tar.gz: a4716f34f9e618a016d691830a82ee6b589e51af8b53a3d44625585b042b0c47b17f57db8426bcabaed5a798839a4d984a31dc213bc530e8a4da2a10a970f606
@@ -7,14 +7,11 @@ require_relative 'slack-notifier/link_formatter'
7
7
 
8
8
  module Slack
9
9
  class Notifier
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
10
+ attr_reader :endpoint, :http_client, :default_payload
11
+
12
+ def initialize webhook_url, options={}
13
+ @endpoint = URI.parse webhook_url
14
+ @http_client = options.delete(:http_client) || DefaultHTTPClient
18
15
  @default_payload = options
19
16
  end
20
17
 
@@ -42,15 +39,5 @@ module Slack
42
39
  default_payload[:username] = username
43
40
  end
44
41
 
45
- private
46
-
47
- def default_hook_name
48
- 'incoming-webhook'
49
- end
50
-
51
- def endpoint
52
- URI.parse "https://#{team}.slack.com/services/hooks/#{hook_name}?token=#{token}"
53
- end
54
-
55
42
  end
56
43
  end
@@ -1,5 +1,5 @@
1
1
  module Slack
2
2
  class Notifier
3
- VERSION = "0.6.1"
3
+ VERSION = "1.0.0"
4
4
  end
5
- end
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'], username: 'notifier'
3
+ notifier = Slack::Notifier.new ENV['SLACK_WEBHOOK_URL'], username: 'notifier'
4
4
  puts "testing with ruby #{RUBY_VERSION}"
5
5
  notifier.ping "hello from notifier test script on ruby: #{RUBY_VERSION}"
@@ -1,38 +1,23 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Slack::Notifier do
4
- subject { described_class.new 'team', 'token' }
4
+ subject { described_class.new 'http://example.com' }
5
5
 
6
6
  describe "#initialize" do
7
- it "sets the given team" do
8
- expect( subject.team ).to eq 'team'
9
- end
10
-
11
- it "sets the given token" do
12
- expect( subject.token ).to eq 'token'
13
- end
14
-
15
- it "sets the optional service hook name" do
16
- subject = described_class.new 'team', 'token', hook_name: 'custom_hook_name'
17
- expect( subject.hook_name ).to eq 'custom_hook_name'
7
+ it "sets the given hook_url to the endpoint URI" do
8
+ expect( subject.endpoint ).to eq URI.parse 'http://example.com'
18
9
  end
19
10
 
20
11
  it "sets the default_payload options" do
21
- subject = described_class.new 'team', 'token', channel: 'foo'
12
+ subject = described_class.new 'http://example.com', channel: 'foo'
22
13
  expect( subject.channel ).to eq 'foo'
23
14
  end
24
15
 
25
16
  it "sets a custom http client" do
26
17
  client = double("CustomClient")
27
- subject = described_class.new 'team', 'token', http_client: client
18
+ subject = described_class.new 'http://example.com', http_client: client
28
19
  expect( subject.http_client ).to eq client
29
20
  end
30
-
31
- it "can set service hook & default_payload options" do
32
- subject = described_class.new 'team', 'token', hook_name: 'hook_name', channel: 'foo'
33
- expect( subject.channel ).to eq 'foo'
34
- expect( subject.hook_name ).to eq 'hook_name'
35
- end
36
21
  end
37
22
 
38
23
  describe "#ping" do
@@ -44,7 +29,7 @@ describe Slack::Notifier do
44
29
  expect( Slack::Notifier::LinkFormatter ).to receive(:format)
45
30
  .with("the message")
46
31
 
47
- described_class.new('team','token').ping "the message", channel: 'foo'
32
+ described_class.new('http://example.com').ping "the message", channel: 'foo'
48
33
  end
49
34
 
50
35
  context "with a default channel set" do
@@ -84,29 +69,14 @@ describe Slack::Notifier do
84
69
  it "posts with the correct endpoint & data" do
85
70
  @endpoint_double = instance_double "URI::HTTP"
86
71
  allow( URI ).to receive(:parse)
87
- .with("https://team.slack.com/services/hooks/incoming-webhook?token=token")
72
+ .with("http://example.com")
88
73
  .and_return(@endpoint_double)
89
74
 
90
75
  expect( Slack::Notifier::DefaultHTTPClient ).to receive(:post)
91
76
  .with @endpoint_double,
92
77
  payload: '{"text":"the message","channel":"channel"}'
93
78
 
94
- described_class.new("team","token").ping "the message", channel: "channel"
95
- end
96
- end
97
-
98
- context "with custom webhook name" do
99
- it "posts with the correct endpoint & data" do
100
- @endpoint_double = instance_double "URI::HTTP"
101
- allow( URI ).to receive(:parse)
102
- .with("https://team.slack.com/services/hooks/custom_hook_name?token=token")
103
- .and_return(@endpoint_double)
104
-
105
- expect( Slack::Notifier::DefaultHTTPClient ).to receive(:post)
106
- .with @endpoint_double,
107
- payload: '{"text":"the message","channel":"channel"}'
108
-
109
- described_class.new("team","token", hook_name: "custom_hook_name").ping "the message", channel: "channel"
79
+ described_class.new("http://example.com").ping "the message", channel: "channel"
110
80
  end
111
81
  end
112
82
 
@@ -114,14 +84,14 @@ describe Slack::Notifier do
114
84
  it "uses it" do
115
85
  endpoint_double = instance_double "URI::HTTP"
116
86
  allow( URI ).to receive(:parse)
117
- .with("https://team.slack.com/services/hooks/incoming-webhook?token=token")
87
+ .with("http://example.com")
118
88
  .and_return(endpoint_double)
119
89
  client = double("CustomClient")
120
90
  expect( client ).to receive(:post)
121
91
  .with endpoint_double,
122
92
  payload: '{"text":"the message"}'
123
93
 
124
- described_class.new('team','token',http_client: client).ping "the message"
94
+ described_class.new('http://example.com',http_client: client).ping "the message"
125
95
  end
126
96
  end
127
97
  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.6.1
4
+ version: 1.0.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-21 00:00:00.000000000 Z
11
+ date: 2014-10-23 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: " A slim ruby wrapper for posting to slack webhooks "
14
14
  email: