slack-ruby-client 0.13.1 → 0.14.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -0
- data/.rubocop_todo.yml +9 -32
- data/.travis.yml +4 -4
- data/CHANGELOG.md +10 -0
- data/Dangerfile +1 -0
- data/Gemfile +1 -3
- data/LICENSE.md +1 -1
- data/README.md +100 -13
- data/bin/commands.rb +1 -0
- data/bin/commands/apps.rb +14 -0
- data/bin/commands/chat.rb +5 -1
- data/bin/commands/conversations.rb +1 -0
- data/bin/commands/files.rb +8 -9
- data/bin/commands/reactions.rb +2 -2
- data/bin/slack +1 -1
- data/lib/slack-ruby-client.rb +4 -0
- data/lib/slack/events/config.rb +31 -0
- data/lib/slack/events/request.rb +60 -0
- data/lib/slack/real_time/client.rb +35 -7
- data/lib/slack/real_time/concurrency/async.rb +34 -2
- data/lib/slack/real_time/concurrency/celluloid.rb +28 -9
- data/lib/slack/real_time/concurrency/eventmachine.rb +25 -4
- data/lib/slack/real_time/socket.rb +19 -0
- data/lib/slack/real_time/stores/store.rb +2 -0
- data/lib/slack/version.rb +1 -1
- data/lib/slack/web/api/endpoints.rb +2 -0
- data/lib/slack/web/api/endpoints/apps.rb +26 -0
- data/lib/slack/web/api/endpoints/chat.rb +30 -4
- data/lib/slack/web/api/endpoints/conversations.rb +2 -0
- data/lib/slack/web/api/endpoints/files.rb +8 -9
- data/lib/slack/web/api/endpoints/reactions.rb +2 -2
- data/lib/slack/web/api/patches/chat.6.block-kit-support.patch +69 -0
- data/lib/slack/web/pagination/cursor.rb +3 -0
- data/lib/tasks/real_time.rake +2 -0
- data/lib/tasks/web.rake +1 -0
- data/slack-ruby-client.gemspec +3 -2
- data/spec/integration/integration_spec.rb +64 -6
- data/spec/slack/events/config_spec.rb +29 -0
- data/spec/slack/events/request_spec.rb +121 -0
- data/spec/slack/real_time/client_spec.rb +36 -1
- data/spec/slack/real_time/concurrency/eventmachine_spec.rb +1 -0
- data/spec/slack/web/api/endpoints/apps_spec.rb +15 -0
- data/spec/slack/web/api/endpoints/custom_specs/chat_spec.rb +45 -24
- data/spec/spec_helper.rb +1 -0
- data/spec/support/queue_with_timeout.rb +4 -4
- metadata +29 -4
@@ -42,7 +42,7 @@ RSpec.describe Slack::RealTime::Client do
|
|
42
42
|
end
|
43
43
|
end
|
44
44
|
end
|
45
|
-
context 'client with a full store', vcr: { cassette_name: 'web/rtm_start' } do
|
45
|
+
context 'client with a full store', vcr: { cassette_name: 'web/rtm_start', allow_playback_repeats: true } do
|
46
46
|
let(:client) { Slack::RealTime::Client.new(store_class: Slack::RealTime::Stores::Store) }
|
47
47
|
let(:url) { 'wss://ms173.slack-msgs.com/websocket/lqcUiAvrKTP-uuid=' }
|
48
48
|
describe '#start!' do
|
@@ -127,6 +127,29 @@ RSpec.describe Slack::RealTime::Client do
|
|
127
127
|
end
|
128
128
|
end
|
129
129
|
end
|
130
|
+
describe '#start_async' do
|
131
|
+
let(:socket) { double(Slack::RealTime::Socket, connected?: true) }
|
132
|
+
before do
|
133
|
+
allow(Slack::RealTime::Socket).to receive(:new).with(url, ping: 30, logger: Slack::Logger.default).and_return(socket)
|
134
|
+
allow(socket).to receive(:connect!)
|
135
|
+
allow(socket).to receive(:start_async)
|
136
|
+
client.start_async
|
137
|
+
end
|
138
|
+
describe '#run_ping!' do
|
139
|
+
it 'sends ping messages when the websocket connection is idle' do
|
140
|
+
allow(socket).to receive(:time_since_last_message).and_return(30)
|
141
|
+
expect(socket).to receive(:send_data).with('{"type":"ping","id":1}')
|
142
|
+
client.run_ping!
|
143
|
+
end
|
144
|
+
it 'reconnects the websocket if it has been idle for too long' do
|
145
|
+
allow(socket).to receive(:time_since_last_message).and_return(75)
|
146
|
+
allow(socket).to receive(:connected?).and_return(true)
|
147
|
+
expect(socket).to receive(:close)
|
148
|
+
expect(socket).to receive(:restart_async)
|
149
|
+
client.run_ping!
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
130
153
|
end
|
131
154
|
context 'client with starter store', vcr: { cassette_name: 'web/rtm_connect' } do
|
132
155
|
let(:client) { Slack::RealTime::Client.new(store_class: Slack::RealTime::Stores::Starter) }
|
@@ -241,6 +264,18 @@ RSpec.describe Slack::RealTime::Client do
|
|
241
264
|
end
|
242
265
|
end
|
243
266
|
end
|
267
|
+
describe '#run_ping?' do
|
268
|
+
it 'returns true when websocket_ping is greater than 0' do
|
269
|
+
client.websocket_ping = 30
|
270
|
+
expect(client.run_ping?).to be true
|
271
|
+
end
|
272
|
+
it 'returns false when websocket_ping is less than 1' do
|
273
|
+
client.websocket_ping = 0
|
274
|
+
expect(client.run_ping?).to be false
|
275
|
+
client.websocket_ping = nil
|
276
|
+
expect(client.run_ping?).to be false
|
277
|
+
end
|
278
|
+
end
|
244
279
|
end
|
245
280
|
context 'with custom settings' do
|
246
281
|
describe '#initialize' do
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# This file was auto-generated by lib/tasks/web.rake
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe Slack::Web::Api::Endpoints::Apps do
|
6
|
+
let(:client) { Slack::Web::Client.new }
|
7
|
+
context 'apps_uninstall' do
|
8
|
+
it 'requires client_id' do
|
9
|
+
expect { client.apps_uninstall(client_secret: 'f25b5ceaf8a3c2a2c4f52bb4f0b0499e') }.to raise_error ArgumentError, /Required arguments :client_id missing/
|
10
|
+
end
|
11
|
+
it 'requires client_secret' do
|
12
|
+
expect { client.apps_uninstall(client_id: '56579136444.26251006572') }.to raise_error ArgumentError, /Required arguments :client_secret missing/
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -8,19 +8,20 @@ RSpec.describe Slack::Web::Api::Endpoints::Chat do
|
|
8
8
|
allow(described_class).to receive(:users_id).and_return(user)
|
9
9
|
end
|
10
10
|
|
11
|
-
it 'automatically converts attachments into JSON' do
|
11
|
+
it 'automatically converts attachments and blocks into JSON' do
|
12
12
|
expect(client).to receive(:post).with(
|
13
13
|
'chat.postEphemeral',
|
14
14
|
channel: 'channel',
|
15
15
|
text: 'text',
|
16
16
|
user: '123',
|
17
|
-
attachments: '[]'
|
17
|
+
attachments: '[]',
|
18
|
+
blocks: '[]'
|
18
19
|
)
|
19
|
-
client.chat_postEphemeral(channel: 'channel', text: 'text', user: '123', attachments: [])
|
20
|
+
client.chat_postEphemeral(channel: 'channel', text: 'text', user: '123', attachments: [], blocks: [])
|
20
21
|
end
|
21
22
|
context 'text and user arguments' do
|
22
23
|
it 'requires text or attachments' do
|
23
|
-
expect { client.chat_postEphemeral(channel: 'channel') }.to raise_error ArgumentError, /Required arguments :text or :
|
24
|
+
expect { client.chat_postEphemeral(channel: 'channel') }.to raise_error ArgumentError, /Required arguments :text, :attachments or :blocks missing/
|
24
25
|
end
|
25
26
|
it 'requires user' do
|
26
27
|
expect { client.chat_postEphemeral(channel: 'channel', text: 'text') }.to raise_error ArgumentError, /Required arguments :user missing/
|
@@ -40,21 +41,32 @@ RSpec.describe Slack::Web::Api::Endpoints::Chat do
|
|
40
41
|
expect { client.chat_postEphemeral(channel: 'channel', attachments: [], user: '123') }.to_not raise_error
|
41
42
|
end
|
42
43
|
end
|
44
|
+
context 'blocks argument' do
|
45
|
+
it 'optional blocks' do
|
46
|
+
expect(client).to receive(:post).with('chat.postEphemeral', hash_including(blocks: '[]'))
|
47
|
+
expect { client.chat_postEphemeral(channel: 'channel', text: 'text', user: '123', blocks: []) }.to_not raise_error
|
48
|
+
end
|
49
|
+
it 'blocks without text' do
|
50
|
+
expect(client).to receive(:post).with('chat.postEphemeral', hash_including(blocks: '[]'))
|
51
|
+
expect { client.chat_postEphemeral(channel: 'channel', blocks: [], user: '123') }.to_not raise_error
|
52
|
+
end
|
53
|
+
end
|
43
54
|
end
|
44
55
|
|
45
56
|
context 'chat_postMessage' do
|
46
|
-
it 'automatically converts attachments into JSON' do
|
57
|
+
it 'automatically converts attachments and blocks into JSON' do
|
47
58
|
expect(client).to receive(:post).with(
|
48
59
|
'chat.postMessage',
|
49
60
|
channel: 'channel',
|
50
61
|
text: 'text',
|
51
|
-
attachments: '[]'
|
62
|
+
attachments: '[]',
|
63
|
+
blocks: '[]'
|
52
64
|
)
|
53
|
-
client.chat_postMessage(channel: 'channel', text: 'text', attachments: [])
|
65
|
+
client.chat_postMessage(channel: 'channel', text: 'text', attachments: [], blocks: [])
|
54
66
|
end
|
55
|
-
context 'text and
|
56
|
-
it 'requires text or
|
57
|
-
expect { client.chat_postMessage(channel: 'channel') }.to raise_error ArgumentError, /Required arguments :text or :
|
67
|
+
context 'text, attachment and blocks arguments' do
|
68
|
+
it 'requires text, attachments or blocks' do
|
69
|
+
expect { client.chat_postMessage(channel: 'channel') }.to raise_error ArgumentError, /Required arguments :text, :attachments or :blocks missing/
|
58
70
|
end
|
59
71
|
it 'only text' do
|
60
72
|
expect(client).to receive(:post).with('chat.postMessage', hash_including(text: 'text'))
|
@@ -64,33 +76,38 @@ RSpec.describe Slack::Web::Api::Endpoints::Chat do
|
|
64
76
|
expect(client).to receive(:post).with('chat.postMessage', hash_including(attachments: '[]'))
|
65
77
|
expect { client.chat_postMessage(channel: 'channel', attachments: []) }.to_not raise_error
|
66
78
|
end
|
67
|
-
it '
|
68
|
-
expect(client).to receive(:post).with('chat.postMessage', hash_including(
|
69
|
-
expect { client.chat_postMessage(channel: 'channel',
|
79
|
+
it 'only blocks' do
|
80
|
+
expect(client).to receive(:post).with('chat.postMessage', hash_including(blocks: '[]'))
|
81
|
+
expect { client.chat_postMessage(channel: 'channel', blocks: []) }.to_not raise_error
|
82
|
+
end
|
83
|
+
it 'all text, attachments and blocks' do
|
84
|
+
expect(client).to receive(:post).with('chat.postMessage', hash_including(text: 'text', attachments: '[]', blocks: '[]'))
|
85
|
+
expect { client.chat_postMessage(channel: 'channel', text: 'text', attachments: [], blocks: []) }.to_not raise_error
|
70
86
|
end
|
71
87
|
end
|
72
88
|
end
|
73
89
|
|
74
90
|
context 'chat_update' do
|
75
91
|
let(:ts) { '1405894322.002768' }
|
76
|
-
it 'automatically converts attachments into JSON' do
|
92
|
+
it 'automatically converts attachments and blocks into JSON' do
|
77
93
|
expect(client).to receive(:post).with(
|
78
94
|
'chat.update',
|
79
|
-
attachments: '[]',
|
80
95
|
channel: 'channel',
|
81
96
|
text: 'text',
|
82
|
-
ts: ts
|
97
|
+
ts: ts,
|
98
|
+
attachments: '[]',
|
99
|
+
blocks: '[]'
|
83
100
|
)
|
84
|
-
client.chat_update(
|
101
|
+
client.chat_update(channel: 'channel', text: 'text', ts: ts, attachments: [], blocks: [])
|
85
102
|
end
|
86
103
|
context 'ts arguments' do
|
87
104
|
it 'requires ts' do
|
88
105
|
expect { client.chat_update(channel: 'channel', text: 'text') }.to raise_error ArgumentError, /Required arguments :ts missing>/
|
89
106
|
end
|
90
107
|
end
|
91
|
-
context 'text and
|
92
|
-
it 'requires text or
|
93
|
-
expect { client.chat_update(channel: 'channel', ts: ts) }.to raise_error ArgumentError, /Required arguments :text or :
|
108
|
+
context 'text, attachment and blocks arguments' do
|
109
|
+
it 'requires text, attachments or blocks' do
|
110
|
+
expect { client.chat_update(channel: 'channel', ts: ts) }.to raise_error ArgumentError, /Required arguments :text, :attachments or :blocks missing/
|
94
111
|
end
|
95
112
|
it 'only text' do
|
96
113
|
expect(client).to receive(:post).with('chat.update', hash_including(text: 'text'))
|
@@ -98,11 +115,15 @@ RSpec.describe Slack::Web::Api::Endpoints::Chat do
|
|
98
115
|
end
|
99
116
|
it 'only attachments' do
|
100
117
|
expect(client).to receive(:post).with('chat.update', hash_including(attachments: '[]'))
|
101
|
-
expect { client.chat_update(
|
118
|
+
expect { client.chat_update(channel: 'channel', ts: ts, attachments: []) }.to_not raise_error
|
119
|
+
end
|
120
|
+
it 'only blocks' do
|
121
|
+
expect(client).to receive(:post).with('chat.update', hash_including(blocks: '[]'))
|
122
|
+
expect { client.chat_update(channel: 'channel', ts: ts, blocks: []) }.to_not raise_error
|
102
123
|
end
|
103
|
-
it '
|
104
|
-
expect(client).to receive(:post).with('chat.update', hash_including(text: 'text', attachments: '[]'))
|
105
|
-
expect { client.chat_update(
|
124
|
+
it 'all text, attachments and blocks' do
|
125
|
+
expect(client).to receive(:post).with('chat.update', hash_including(text: 'text', attachments: '[]', blocks: '[]'))
|
126
|
+
expect { client.chat_update(channel: 'channel', text: 'text', ts: ts, attachments: [], blocks: []) }.to_not raise_error
|
106
127
|
end
|
107
128
|
end
|
108
129
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -6,15 +6,15 @@ class QueueWithTimeout
|
|
6
6
|
@recieved = ConditionVariable.new
|
7
7
|
end
|
8
8
|
|
9
|
-
def push(
|
9
|
+
def push(item)
|
10
10
|
@mutex.synchronize do
|
11
|
-
@queue <<
|
11
|
+
@queue << item
|
12
12
|
@recieved.signal
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
-
def <<(
|
17
|
-
push(
|
16
|
+
def <<(item)
|
17
|
+
push(item)
|
18
18
|
end
|
19
19
|
|
20
20
|
def pop(non_block = false)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: slack-ruby-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.14.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Doubrovkine
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-02-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -156,14 +156,28 @@ dependencies:
|
|
156
156
|
requirements:
|
157
157
|
- - '='
|
158
158
|
- !ruby/object:Gem::Version
|
159
|
-
version: 0.
|
159
|
+
version: 0.61.1
|
160
160
|
type: :development
|
161
161
|
prerelease: false
|
162
162
|
version_requirements: !ruby/object:Gem::Requirement
|
163
163
|
requirements:
|
164
164
|
- - '='
|
165
165
|
- !ruby/object:Gem::Version
|
166
|
-
version: 0.
|
166
|
+
version: 0.61.1
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: timecop
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - ">="
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
type: :development
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - ">="
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0'
|
167
181
|
- !ruby/object:Gem::Dependency
|
168
182
|
name: vcr
|
169
183
|
requirement: !ruby/object:Gem::Requirement
|
@@ -216,6 +230,7 @@ files:
|
|
216
230
|
- UPGRADING.md
|
217
231
|
- bin/commands.rb
|
218
232
|
- bin/commands/api.rb
|
233
|
+
- bin/commands/apps.rb
|
219
234
|
- bin/commands/apps_permissions.rb
|
220
235
|
- bin/commands/apps_permissions_resources.rb
|
221
236
|
- bin/commands/apps_permissions_scopes.rb
|
@@ -273,6 +288,8 @@ files:
|
|
273
288
|
- lib/slack-ruby-client.rb
|
274
289
|
- lib/slack.rb
|
275
290
|
- lib/slack/config.rb
|
291
|
+
- lib/slack/events/config.rb
|
292
|
+
- lib/slack/events/request.rb
|
276
293
|
- lib/slack/logger.rb
|
277
294
|
- lib/slack/messages/formatting.rb
|
278
295
|
- lib/slack/messages/message.rb
|
@@ -304,6 +321,7 @@ files:
|
|
304
321
|
- lib/slack/version.rb
|
305
322
|
- lib/slack/web/api/endpoints.rb
|
306
323
|
- lib/slack/web/api/endpoints/api.rb
|
324
|
+
- lib/slack/web/api/endpoints/apps.rb
|
307
325
|
- lib/slack/web/api/endpoints/apps_permissions.rb
|
308
326
|
- lib/slack/web/api/endpoints/apps_permissions_resources.rb
|
309
327
|
- lib/slack/web/api/endpoints/apps_permissions_scopes.rb
|
@@ -356,6 +374,7 @@ files:
|
|
356
374
|
- lib/slack/web/api/patches/chat.3.update-attachments-support.patch
|
357
375
|
- lib/slack/web/api/patches/chat.4.postEphemeral-attachments-support.patch
|
358
376
|
- lib/slack/web/api/patches/chat.5.postEphemeral-text-or-attachments.patch
|
377
|
+
- lib/slack/web/api/patches/chat.6.block-kit-support.patch
|
359
378
|
- lib/slack/web/api/patches/dialog.1.open-json-support.patch
|
360
379
|
- lib/slack/web/api/schema/group.json
|
361
380
|
- lib/slack/web/api/schema/method.json
|
@@ -391,6 +410,8 @@ files:
|
|
391
410
|
- spec/fixtures/slack/web/users_list.yml
|
392
411
|
- spec/integration/integration_spec.rb
|
393
412
|
- spec/slack/config_spec.rb
|
413
|
+
- spec/slack/events/config_spec.rb
|
414
|
+
- spec/slack/events/request_spec.rb
|
394
415
|
- spec/slack/messages/formatting_spec.rb
|
395
416
|
- spec/slack/real_time/api/message_spec.rb
|
396
417
|
- spec/slack/real_time/api/ping_spec.rb
|
@@ -416,6 +437,7 @@ files:
|
|
416
437
|
- spec/slack/web/api/endpoints/apps_permissions_scopes_spec.rb
|
417
438
|
- spec/slack/web/api/endpoints/apps_permissions_spec.rb
|
418
439
|
- spec/slack/web/api/endpoints/apps_permissions_users_spec.rb
|
440
|
+
- spec/slack/web/api/endpoints/apps_spec.rb
|
419
441
|
- spec/slack/web/api/endpoints/bots_spec.rb
|
420
442
|
- spec/slack/web/api/endpoints/conversations_spec.rb
|
421
443
|
- spec/slack/web/api/endpoints/custom_specs/auth_spec.rb
|
@@ -499,6 +521,8 @@ test_files:
|
|
499
521
|
- spec/fixtures/slack/web/users_list.yml
|
500
522
|
- spec/integration/integration_spec.rb
|
501
523
|
- spec/slack/config_spec.rb
|
524
|
+
- spec/slack/events/config_spec.rb
|
525
|
+
- spec/slack/events/request_spec.rb
|
502
526
|
- spec/slack/messages/formatting_spec.rb
|
503
527
|
- spec/slack/real_time/api/message_spec.rb
|
504
528
|
- spec/slack/real_time/api/ping_spec.rb
|
@@ -524,6 +548,7 @@ test_files:
|
|
524
548
|
- spec/slack/web/api/endpoints/apps_permissions_scopes_spec.rb
|
525
549
|
- spec/slack/web/api/endpoints/apps_permissions_spec.rb
|
526
550
|
- spec/slack/web/api/endpoints/apps_permissions_users_spec.rb
|
551
|
+
- spec/slack/web/api/endpoints/apps_spec.rb
|
527
552
|
- spec/slack/web/api/endpoints/bots_spec.rb
|
528
553
|
- spec/slack/web/api/endpoints/conversations_spec.rb
|
529
554
|
- spec/slack/web/api/endpoints/custom_specs/auth_spec.rb
|