lita-slack 1.3.0 → 1.4.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/lita/adapters/slack/api.rb +4 -0
- data/lib/lita/adapters/slack.rb +6 -0
- data/lita-slack.gemspec +1 -1
- data/spec/lita/adapters/slack/api_spec.rb +58 -0
- data/spec/lita/adapters/slack_spec.rb +15 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ed147f3d6aec0c4afbcde9e0f587a8a83b8e5780
|
4
|
+
data.tar.gz: a757cb838975b7a45287a6a2aaf9539b94e0a3f7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e07d8afcff6063c866a80eb1ddeb5c5eca7bb3b6c764d9aa3db5fa9871cde8157c529793061f546bb2ea10b01bcee1a4492fa0275e52dabc30a754b28302f2b6
|
7
|
+
data.tar.gz: 547446df11c1e54eaef121ec0b5c0150d31d1ccb6c8fc16aa1fa29775d66488637cf956975b59d947347f7d014c653b250fa82719918e8ee3146ae47a6b19856
|
data/lib/lita/adapters/slack.rb
CHANGED
@@ -21,6 +21,12 @@ module Lita
|
|
21
21
|
rtm_connection.send_messages(channel_for(target), strings)
|
22
22
|
end
|
23
23
|
|
24
|
+
def set_topic(target, topic)
|
25
|
+
channel = target.room
|
26
|
+
Lita.logger.debug("Setting topic for channel #{channel}: #{topic}")
|
27
|
+
API.new(config).set_topic(channel, topic)
|
28
|
+
end
|
29
|
+
|
24
30
|
def shut_down
|
25
31
|
return unless rtm_connection
|
26
32
|
|
data/lita-slack.gemspec
CHANGED
@@ -66,6 +66,64 @@ describe Lita::Adapters::Slack::API do
|
|
66
66
|
end
|
67
67
|
end
|
68
68
|
|
69
|
+
describe "#set_topic" do
|
70
|
+
let(:channel) { 'C1234567890' }
|
71
|
+
let(:topic) { 'Topic' }
|
72
|
+
let(:stubs) do
|
73
|
+
Faraday::Adapter::Test::Stubs.new do |stub|
|
74
|
+
stub.post(
|
75
|
+
'https://slack.com/api/channels.setTopic',
|
76
|
+
token: token,
|
77
|
+
channel: channel,
|
78
|
+
topic: topic
|
79
|
+
) do
|
80
|
+
[http_status, {}, http_response]
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
context "with a successful response" do
|
86
|
+
let(:http_response) do
|
87
|
+
MultiJson.dump({
|
88
|
+
ok: true,
|
89
|
+
topic: 'Topic'
|
90
|
+
})
|
91
|
+
end
|
92
|
+
|
93
|
+
it "returns a response with the channel's topic" do
|
94
|
+
response = subject.set_topic(channel, topic)
|
95
|
+
|
96
|
+
expect(response['topic']).to eq(topic)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
context "with a Slack error" do
|
101
|
+
let(:http_response) do
|
102
|
+
MultiJson.dump({
|
103
|
+
ok: false,
|
104
|
+
error: 'invalid_auth'
|
105
|
+
})
|
106
|
+
end
|
107
|
+
|
108
|
+
it "raises a RuntimeError" do
|
109
|
+
expect { subject.set_topic(channel, topic) }.to raise_error(
|
110
|
+
"Slack API call to channels.setTopic returned an error: invalid_auth."
|
111
|
+
)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
context "with an HTTP error" do
|
116
|
+
let(:http_status) { 422 }
|
117
|
+
let(:http_response) { '' }
|
118
|
+
|
119
|
+
it "raises a RuntimeError" do
|
120
|
+
expect { subject.set_topic(channel, topic) }.to raise_error(
|
121
|
+
"Slack API call to channels.setTopic failed with status code 422."
|
122
|
+
)
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
69
127
|
describe "#rtm_start" do
|
70
128
|
let(:http_status) { 200 }
|
71
129
|
let(:stubs) do
|
@@ -73,6 +73,21 @@ describe Lita::Adapters::Slack, lita: true do
|
|
73
73
|
end
|
74
74
|
end
|
75
75
|
|
76
|
+
describe "#set_topic" do
|
77
|
+
let(:api) { instance_double('Lita::Adapters::Slack::API') }
|
78
|
+
|
79
|
+
before do
|
80
|
+
allow(Lita::Adapters::Slack::API).to receive(:new).with(subject.config).and_return(api)
|
81
|
+
allow(api).to receive(:set_topic).and_return(Hash.new)
|
82
|
+
end
|
83
|
+
|
84
|
+
it "sets a new topic for the room" do
|
85
|
+
source = instance_double("Lita::Source", room: 'C1234567890')
|
86
|
+
expect(api).to receive(:set_topic).with('C1234567890', 'Topic')
|
87
|
+
subject.set_topic(source, 'Topic')
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
76
91
|
describe "#shut_down" do
|
77
92
|
before { allow(rtm_connection).to receive(:shut_down) }
|
78
93
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lita-slack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ken J.
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-05-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: eventmachine
|