slack-ruby-client 0.9.1 → 0.10.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.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop_todo.yml +16 -11
  3. data/CHANGELOG.md +11 -0
  4. data/README.md +40 -12
  5. data/UPGRADING.md +1 -1
  6. data/bin/commands.rb +1 -0
  7. data/bin/commands/channels.rb +3 -0
  8. data/bin/commands/conversations.rb +178 -0
  9. data/bin/commands/groups.rb +1 -9
  10. data/bin/commands/im.rb +3 -0
  11. data/bin/commands/rtm.rb +1 -0
  12. data/bin/commands/users.rb +3 -1
  13. data/lib/slack-ruby-client.rb +6 -0
  14. data/lib/slack/real_time/client.rb +1 -1
  15. data/lib/slack/real_time/concurrency/celluloid.rb +1 -1
  16. data/lib/slack/version.rb +1 -1
  17. data/lib/slack/web/api/endpoints.rb +2 -0
  18. data/lib/slack/web/api/endpoints/channels.rb +13 -1
  19. data/lib/slack/web/api/endpoints/conversations.rb +301 -0
  20. data/lib/slack/web/api/endpoints/groups.rb +2 -13
  21. data/lib/slack/web/api/endpoints/im.rb +13 -1
  22. data/lib/slack/web/api/endpoints/rtm.rb +2 -0
  23. data/lib/slack/web/api/endpoints/users.rb +11 -1
  24. data/lib/slack/web/api/templates/command.erb +2 -2
  25. data/lib/slack/web/api/templates/method.erb +10 -0
  26. data/lib/slack/web/config.rb +7 -3
  27. data/lib/slack/web/faraday/connection.rb +1 -1
  28. data/lib/slack/web/pagination/cursor.rb +48 -0
  29. data/spec/fixtures/slack/web/paginated_users_list.yml +181 -0
  30. data/spec/slack/real_time/client_spec.rb +60 -62
  31. data/spec/slack/real_time/concurrency/celluloid_spec.rb +41 -31
  32. data/spec/slack/web/api/endpoints/conversations_spec.rb +100 -0
  33. data/spec/slack/web/api/endpoints/custom_specs/users_spec.rb +8 -0
  34. data/spec/slack/web/api/pagination/cursor_spec.rb +70 -0
  35. metadata +12 -3
@@ -7,45 +7,55 @@ begin
7
7
  context 'with url' do
8
8
  let(:url) { 'wss://echo.websocket.org/websocket/xyz' }
9
9
  let(:logger) { ::Logger.new(STDOUT) }
10
- let(:test_socket) do
11
- Class.new(described_class) do
12
- def read
13
- fail EOFError
10
+
11
+ [EOFError, Errno::EPIPE].each do |err|
12
+ context "finishing run_loop with #{err}" do
13
+ let(:test_socket) do
14
+ Class.new(described_class) do
15
+ def read
16
+ fail options[:err]
17
+ end
18
+ end
14
19
  end
15
- end
16
- end
17
- let(:socket) { test_socket.new(url, ping: 42, logger: logger) }
18
- let(:driver) { WebSocket::Driver::Client }
19
- let(:ws) { double(driver) }
20
- subject { socket }
21
-
22
- describe '#connect!' do
23
- pending 'connects'
24
- pending 'pings every 30s'
25
- end
26
20
 
27
- context 'with a driver' do
28
- before do
29
- socket.instance_variable_set('@driver', ws)
30
- end
21
+ let(:socket) do
22
+ test_socket.new(url, ping: 42, logger: logger, err: err)
23
+ end
31
24
 
32
- describe '#disconnect!' do
33
- it 'closes and nils the websocket' do
34
- expect(ws).to receive(:close)
35
- socket.disconnect!
25
+ let(:driver) { WebSocket::Driver::Client }
26
+ let(:ws) { double(driver) }
27
+ subject { socket }
28
+
29
+ describe '#connect!' do
30
+ pending 'connects'
31
+ pending 'pings every 30s'
36
32
  end
37
- end
38
33
 
39
- describe '#run_loop' do
40
- it 'runs' do
41
- expect(ws).to receive(:emit)
42
- expect(ws).to receive(:start)
43
- socket.run_loop
34
+ context 'with a driver' do
35
+ before do
36
+ socket.instance_variable_set('@driver', ws)
37
+ end
38
+
39
+ describe '#disconnect!' do
40
+ it 'closes and nils the websocket' do
41
+ expect(ws).to receive(:close)
42
+ socket.disconnect!
43
+ end
44
+ end
45
+
46
+ context 'consumes data' do
47
+ it 'runs' do
48
+ expect(ws).to receive(:emit)
49
+ expect(ws).to receive(:start)
50
+ expect(logger).to receive(:debug).with("#{test_socket}#run_loop")
51
+ socket.run_loop
52
+ end
53
+ end
44
54
  end
55
+
56
+ pending 'send_data'
45
57
  end
46
58
  end
47
-
48
- pending 'send_data'
49
59
  end
50
60
  end
51
61
  rescue LoadError
@@ -0,0 +1,100 @@
1
+ # This file was auto-generated by lib/tasks/web.rake
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe Slack::Web::Api::Endpoints::Conversations do
6
+ let(:client) { Slack::Web::Client.new }
7
+ context 'conversations_archive' do
8
+ it 'requires channel' do
9
+ expect { client.conversations_archive }.to raise_error ArgumentError, /Required arguments :channel missing/
10
+ end
11
+ end
12
+ context 'conversations_close' do
13
+ it 'requires channel' do
14
+ expect { client.conversations_close }.to raise_error ArgumentError, /Required arguments :channel missing/
15
+ end
16
+ end
17
+ context 'conversations_create' do
18
+ it 'requires name' do
19
+ expect { client.conversations_create }.to raise_error ArgumentError, /Required arguments :name missing/
20
+ end
21
+ end
22
+ context 'conversations_history' do
23
+ it 'requires channel' do
24
+ expect { client.conversations_history }.to raise_error ArgumentError, /Required arguments :channel missing/
25
+ end
26
+ end
27
+ context 'conversations_info' do
28
+ it 'requires channel' do
29
+ expect { client.conversations_info }.to raise_error ArgumentError, /Required arguments :channel missing/
30
+ end
31
+ end
32
+ context 'conversations_invite' do
33
+ it 'requires channel' do
34
+ expect { client.conversations_invite(users: 'W1234567890,U2345678901,U3456789012') }.to raise_error ArgumentError, /Required arguments :channel missing/
35
+ end
36
+ it 'requires users' do
37
+ expect { client.conversations_invite(channel: 'C1234567890') }.to raise_error ArgumentError, /Required arguments :users missing/
38
+ end
39
+ end
40
+ context 'conversations_join' do
41
+ it 'requires channel' do
42
+ expect { client.conversations_join }.to raise_error ArgumentError, /Required arguments :channel missing/
43
+ end
44
+ end
45
+ context 'conversations_kick' do
46
+ it 'requires channel' do
47
+ expect { client.conversations_kick(user: 'W1234567890') }.to raise_error ArgumentError, /Required arguments :channel missing/
48
+ end
49
+ it 'requires user' do
50
+ expect { client.conversations_kick(channel: 'C1234567890') }.to raise_error ArgumentError, /Required arguments :user missing/
51
+ end
52
+ end
53
+ context 'conversations_leave' do
54
+ it 'requires channel' do
55
+ expect { client.conversations_leave }.to raise_error ArgumentError, /Required arguments :channel missing/
56
+ end
57
+ end
58
+ context 'conversations_members' do
59
+ it 'requires channel' do
60
+ expect { client.conversations_members }.to raise_error ArgumentError, /Required arguments :channel missing/
61
+ end
62
+ end
63
+ context 'conversations_rename' do
64
+ it 'requires channel' do
65
+ expect { client.conversations_rename(name: ' ') }.to raise_error ArgumentError, /Required arguments :channel missing/
66
+ end
67
+ it 'requires name' do
68
+ expect { client.conversations_rename(channel: 'C1234567890') }.to raise_error ArgumentError, /Required arguments :name missing/
69
+ end
70
+ end
71
+ context 'conversations_replies' do
72
+ it 'requires channel' do
73
+ expect { client.conversations_replies(ts: '1234567890.123456') }.to raise_error ArgumentError, /Required arguments :channel missing/
74
+ end
75
+ it 'requires ts' do
76
+ expect { client.conversations_replies(channel: 'C1234567890') }.to raise_error ArgumentError, /Required arguments :ts missing/
77
+ end
78
+ end
79
+ context 'conversations_setPurpose' do
80
+ it 'requires channel' do
81
+ expect { client.conversations_setPurpose(purpose: 'My More Special Purpose') }.to raise_error ArgumentError, /Required arguments :channel missing/
82
+ end
83
+ it 'requires purpose' do
84
+ expect { client.conversations_setPurpose(channel: 'C1234567890') }.to raise_error ArgumentError, /Required arguments :purpose missing/
85
+ end
86
+ end
87
+ context 'conversations_setTopic' do
88
+ it 'requires channel' do
89
+ expect { client.conversations_setTopic(topic: 'Apply topically for best effects') }.to raise_error ArgumentError, /Required arguments :channel missing/
90
+ end
91
+ it 'requires topic' do
92
+ expect { client.conversations_setTopic(channel: 'C1234567890') }.to raise_error ArgumentError, /Required arguments :topic missing/
93
+ end
94
+ end
95
+ context 'conversations_unarchive' do
96
+ it 'requires channel' do
97
+ expect { client.conversations_unarchive }.to raise_error ArgumentError, /Required arguments :channel missing/
98
+ end
99
+ end
100
+ end
@@ -9,6 +9,14 @@ RSpec.describe Slack::Web::Api::Endpoints::Users do
9
9
  expect(json.members.size).to eq 9
10
10
  expect(json.members.first.presence).to eq 'away'
11
11
  end
12
+ it 'list', vcr: { cassette_name: 'web/paginated_users_list' } do
13
+ members = []
14
+ client.users_list(presence: true, limit: 5) do |json|
15
+ expect(json.ok).to be true
16
+ members.concat json.members
17
+ end
18
+ expect(members.size).to eq 23
19
+ end
12
20
  it 'info', vcr: { cassette_name: 'web/users_info' } do
13
21
  json = client.users_info(user: '@aws')
14
22
  expect(json.user.name).to eq 'aws'
@@ -0,0 +1,70 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Slack::Web::Api::Pagination::Cursor do
4
+ let(:client) { Slack::Web::Client.new }
5
+ context 'default cursor' do
6
+ let(:cursor) { Slack::Web::Api::Pagination::Cursor.new(client, 'users_list', {}) }
7
+ it 'provides a default limit' do
8
+ expect(client).to receive(:users_list).with(limit: 100, cursor: nil)
9
+ cursor.first
10
+ end
11
+ it 'handles blank response metadata' do
12
+ expect(client).to receive(:users_list).once.and_return(Slack::Messages::Message.new)
13
+ cursor.to_a
14
+ end
15
+ it 'handles nil response metadata' do
16
+ expect(client).to receive(:users_list).once.and_return(Slack::Messages::Message.new(response_metadata: nil))
17
+ cursor.to_a
18
+ end
19
+ it 'paginates with a cursor inside response metadata' do
20
+ expect(client).to receive(:users_list).twice.and_return(
21
+ Slack::Messages::Message.new(response_metadata: { next_cursor: 'next' }),
22
+ Slack::Messages::Message.new
23
+ )
24
+ expect(cursor).not_to receive(:sleep)
25
+ cursor.to_a
26
+ end
27
+ context 'with rate limiting' do
28
+ let(:error) { Slack::Web::Api::Errors::TooManyRequestsError.new(nil) }
29
+ context 'with default max retries' do
30
+ it 'sleeps after a TooManyRequestsError' do
31
+ expect(client).to receive(:users_list).with(limit: 100, cursor: nil).ordered.and_return(Slack::Messages::Message.new(response_metadata: { next_cursor: 'next' }))
32
+ expect(client).to receive(:users_list).with(limit: 100, cursor: 'next').ordered.and_raise(error)
33
+ expect(error).to receive(:retry_after).once.ordered.and_return(9)
34
+ expect(cursor).to receive(:sleep).once.ordered.with(9)
35
+ expect(client).to receive(:users_list).with(limit: 100, cursor: 'next').ordered.and_return(Slack::Messages::Message.new)
36
+ cursor.to_a
37
+ end
38
+ end
39
+ context 'with a custom max_retries' do
40
+ let(:cursor) { Slack::Web::Api::Pagination::Cursor.new(client, 'users_list', max_retries: 4) }
41
+ it 'raises the error after hitting the max retries' do
42
+ expect(client).to receive(:users_list).with(limit: 100, cursor: nil).and_return(Slack::Messages::Message.new(response_metadata: { next_cursor: 'next' }))
43
+ expect(client).to receive(:users_list).with(limit: 100, cursor: 'next').exactly(5).times.and_raise(error)
44
+ expect(error).to receive(:retry_after).exactly(4).times.and_return(9)
45
+ expect(cursor).to receive(:sleep).exactly(4).times.with(9)
46
+ expect { cursor.to_a }.to raise_error(error)
47
+ end
48
+ end
49
+ end
50
+ end
51
+ context 'with a custom limit' do
52
+ let(:cursor) { Slack::Web::Api::Pagination::Cursor.new(client, 'users_list', limit: 42) }
53
+ it 'overrides default limit' do
54
+ expect(client).to receive(:users_list).with(limit: 42, cursor: nil)
55
+ cursor.first
56
+ end
57
+ end
58
+ context 'with a custom sleep_interval' do
59
+ let(:cursor) { Slack::Web::Api::Pagination::Cursor.new(client, 'users_list', sleep_interval: 3) }
60
+ it 'sleeps between requests' do
61
+ expect(client).to receive(:users_list).exactly(3).times.and_return(
62
+ Slack::Messages::Message.new(response_metadata: { next_cursor: 'next_a' }),
63
+ Slack::Messages::Message.new(response_metadata: { next_cursor: 'next_b' }),
64
+ Slack::Messages::Message.new
65
+ )
66
+ expect(cursor).to receive(:sleep).with(3).twice
67
+ cursor.to_a
68
+ end
69
+ end
70
+ end
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.9.1
4
+ version: 0.10.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: 2017-08-25 00:00:00.000000000 Z
11
+ date: 2017-09-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -235,6 +235,7 @@ files:
235
235
  - bin/commands/bots.rb
236
236
  - bin/commands/channels.rb
237
237
  - bin/commands/chat.rb
238
+ - bin/commands/conversations.rb
238
239
  - bin/commands/dnd.rb
239
240
  - bin/commands/emoji.rb
240
241
  - bin/commands/files.rb
@@ -311,6 +312,7 @@ files:
311
312
  - lib/slack/web/api/endpoints/bots.rb
312
313
  - lib/slack/web/api/endpoints/channels.rb
313
314
  - lib/slack/web/api/endpoints/chat.rb
315
+ - lib/slack/web/api/endpoints/conversations.rb
314
316
  - lib/slack/web/api/endpoints/dnd.rb
315
317
  - lib/slack/web/api/endpoints/emoji.rb
316
318
  - lib/slack/web/api/endpoints/files.rb
@@ -361,6 +363,7 @@ files:
361
363
  - lib/slack/web/faraday/connection.rb
362
364
  - lib/slack/web/faraday/request.rb
363
365
  - lib/slack/web/faraday/response/raise_error.rb
366
+ - lib/slack/web/pagination/cursor.rb
364
367
  - lib/slack_ruby_client.rb
365
368
  - lib/tasks/git.rake
366
369
  - lib/tasks/real_time.rake
@@ -374,6 +377,7 @@ files:
374
377
  - spec/fixtures/slack/web/auth_test_success.yml
375
378
  - spec/fixtures/slack/web/channels_info.yml
376
379
  - spec/fixtures/slack/web/groups_info.yml
380
+ - spec/fixtures/slack/web/paginated_users_list.yml
377
381
  - spec/fixtures/slack/web/rtm_connect.yml
378
382
  - spec/fixtures/slack/web/rtm_start.yml
379
383
  - spec/fixtures/slack/web/users_info.yml
@@ -403,6 +407,7 @@ files:
403
407
  - spec/slack/web/api/endpoints/api_spec.rb
404
408
  - spec/slack/web/api/endpoints/apps_permissions_spec.rb
405
409
  - spec/slack/web/api/endpoints/bots_spec.rb
410
+ - spec/slack/web/api/endpoints/conversations_spec.rb
406
411
  - spec/slack/web/api/endpoints/custom_specs/auth_spec.rb
407
412
  - spec/slack/web/api/endpoints/custom_specs/channels_spec.rb
408
413
  - spec/slack/web/api/endpoints/custom_specs/chat_spec.rb
@@ -431,6 +436,7 @@ files:
431
436
  - spec/slack/web/api/mixins/channels_spec.rb
432
437
  - spec/slack/web/api/mixins/groups_spec.rb
433
438
  - spec/slack/web/api/mixins/users_spec.rb
439
+ - spec/slack/web/api/pagination/cursor_spec.rb
434
440
  - spec/slack/web/client_spec.rb
435
441
  - spec/spec_helper.rb
436
442
  - spec/support/queue_with_timeout.rb
@@ -459,7 +465,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
459
465
  version: 1.3.6
460
466
  requirements: []
461
467
  rubyforge_project:
462
- rubygems_version: 2.6.12
468
+ rubygems_version: 2.6.11
463
469
  signing_key:
464
470
  specification_version: 4
465
471
  summary: Slack Web and RealTime API client.
@@ -469,6 +475,7 @@ test_files:
469
475
  - spec/fixtures/slack/web/auth_test_success.yml
470
476
  - spec/fixtures/slack/web/channels_info.yml
471
477
  - spec/fixtures/slack/web/groups_info.yml
478
+ - spec/fixtures/slack/web/paginated_users_list.yml
472
479
  - spec/fixtures/slack/web/rtm_connect.yml
473
480
  - spec/fixtures/slack/web/rtm_start.yml
474
481
  - spec/fixtures/slack/web/users_info.yml
@@ -498,6 +505,7 @@ test_files:
498
505
  - spec/slack/web/api/endpoints/api_spec.rb
499
506
  - spec/slack/web/api/endpoints/apps_permissions_spec.rb
500
507
  - spec/slack/web/api/endpoints/bots_spec.rb
508
+ - spec/slack/web/api/endpoints/conversations_spec.rb
501
509
  - spec/slack/web/api/endpoints/custom_specs/auth_spec.rb
502
510
  - spec/slack/web/api/endpoints/custom_specs/channels_spec.rb
503
511
  - spec/slack/web/api/endpoints/custom_specs/chat_spec.rb
@@ -526,6 +534,7 @@ test_files:
526
534
  - spec/slack/web/api/mixins/channels_spec.rb
527
535
  - spec/slack/web/api/mixins/groups_spec.rb
528
536
  - spec/slack/web/api/mixins/users_spec.rb
537
+ - spec/slack/web/api/pagination/cursor_spec.rb
529
538
  - spec/slack/web/client_spec.rb
530
539
  - spec/spec_helper.rb
531
540
  - spec/support/queue_with_timeout.rb