lita-slack 1.3.0 → 1.4.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: f3790328b5fe62b842097b9142959a8433dd59db
4
- data.tar.gz: 49f7ab55e0f429f40019b164ffbd1e391a7d5008
3
+ metadata.gz: ed147f3d6aec0c4afbcde9e0f587a8a83b8e5780
4
+ data.tar.gz: a757cb838975b7a45287a6a2aaf9539b94e0a3f7
5
5
  SHA512:
6
- metadata.gz: 61b7e539abbae3e559ab35bbac74bd1141db7485221141029ba30f9bf4e04abf91cccb1a7f0a3d867925ceb368f912ea6e981e5099a9f7d486fb81a97b09c9dc
7
- data.tar.gz: 34b03cc4dedac3ab9e0a468f2b888d4fd88b76c9f309f0774c2b39499b172f5686c0b208a95d462f922f656ce70dcb6cec1b11757edd7ce6d3db5fd12779f73d
6
+ metadata.gz: e07d8afcff6063c866a80eb1ddeb5c5eca7bb3b6c764d9aa3db5fa9871cde8157c529793061f546bb2ea10b01bcee1a4492fa0275e52dabc30a754b28302f2b6
7
+ data.tar.gz: 547446df11c1e54eaef121ec0b5c0150d31d1ccb6c8fc16aa1fa29775d66488637cf956975b59d947347f7d014c653b250fa82719918e8ee3146ae47a6b19856
@@ -19,6 +19,10 @@ module Lita
19
19
  SlackIM.new(response_data["channel"]["id"], user_id)
20
20
  end
21
21
 
22
+ def set_topic(channel, topic)
23
+ call_api("channels.setTopic", channel: channel, topic: topic)
24
+ end
25
+
22
26
  def rtm_start
23
27
  response_data = call_api("rtm.start")
24
28
 
@@ -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
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "lita-slack"
3
- spec.version = "1.3.0"
3
+ spec.version = "1.4.0"
4
4
  spec.authors = ["Ken J.", "Jimmy Cuadra"]
5
5
  spec.email = ["kenjij@gmail.com", "jimmy@jimmycuadra.com"]
6
6
  spec.description = %q{Lita adapter for Slack.}
@@ -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.3.0
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-04-10 00:00:00.000000000 Z
12
+ date: 2015-05-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: eventmachine