slack-ruby-client 0.9.0 → 0.11.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 (142) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rubocop.yml +3 -0
  4. data/.rubocop_todo.yml +40 -39
  5. data/.travis.yml +1 -9
  6. data/CHANGELOG.md +24 -0
  7. data/CONTRIBUTING.md +2 -2
  8. data/Gemfile +3 -1
  9. data/README.md +40 -12
  10. data/Rakefile +1 -1
  11. data/UPGRADING.md +1 -1
  12. data/bin/commands/api.rb +2 -2
  13. data/bin/commands/apps_permissions.rb +22 -0
  14. data/bin/commands/auth.rb +4 -4
  15. data/bin/commands/bots.rb +2 -2
  16. data/bin/commands/channels.rb +52 -40
  17. data/bin/commands/chat.rb +63 -25
  18. data/bin/commands/conversations.rb +178 -0
  19. data/bin/commands/dialog.rb +14 -0
  20. data/bin/commands/dnd.rb +8 -8
  21. data/bin/commands/emoji.rb +2 -2
  22. data/bin/commands/files.rb +38 -17
  23. data/bin/commands/files_comments.rb +6 -6
  24. data/bin/commands/groups.rb +44 -51
  25. data/bin/commands/im.rb +16 -13
  26. data/bin/commands/migration.rb +14 -0
  27. data/bin/commands/mpim.rb +11 -11
  28. data/bin/commands/oauth.rb +15 -2
  29. data/bin/commands/pins.rb +6 -6
  30. data/bin/commands/reactions.rb +13 -13
  31. data/bin/commands/reminders.rb +10 -10
  32. data/bin/commands/rtm.rb +9 -6
  33. data/bin/commands/search.rb +9 -9
  34. data/bin/commands/stars.rb +8 -8
  35. data/bin/commands/team.rb +10 -10
  36. data/bin/commands/team_profile.rb +2 -2
  37. data/bin/commands/usergroups.rb +16 -16
  38. data/bin/commands/usergroups_users.rb +4 -4
  39. data/bin/commands/users.rb +40 -36
  40. data/bin/commands/users_admin.rb +28 -0
  41. data/bin/commands/users_prefs.rb +12 -0
  42. data/bin/commands/users_profile.rb +7 -7
  43. data/bin/commands.rb +7 -1
  44. data/bin/slack +1 -1
  45. data/examples/hi_real_time/hi.rb +1 -1
  46. data/examples/hi_real_time_and_web/hi.rb +1 -1
  47. data/examples/hi_real_time_async_celluloid/hi.rb +1 -1
  48. data/examples/hi_real_time_async_eventmachine/hi.rb +1 -1
  49. data/examples/hi_web/hi.rb +1 -1
  50. data/examples/new_ticket/new_ticket.rb +1 -1
  51. data/lib/slack/messages/formatting.rb +4 -4
  52. data/lib/slack/messages/message.rb +1 -2
  53. data/lib/slack/real_time/api/templates/event_handler.erb +1 -1
  54. data/lib/slack/real_time/client.rb +11 -10
  55. data/lib/slack/real_time/concurrency/celluloid.rb +6 -2
  56. data/lib/slack/real_time/config.rb +11 -11
  57. data/lib/slack/real_time/models/base.rb +1 -2
  58. data/lib/slack/real_time/socket.rb +2 -2
  59. data/lib/slack/real_time/stores/base.rb +1 -2
  60. data/lib/slack/real_time/stores/starter.rb +92 -72
  61. data/lib/slack/real_time/stores/store.rb +120 -90
  62. data/lib/slack/version.rb +1 -1
  63. data/lib/slack/web/api/endpoints/api.rb +2 -2
  64. data/lib/slack/web/api/endpoints/apps_permissions.rb +35 -0
  65. data/lib/slack/web/api/endpoints/auth.rb +4 -4
  66. data/lib/slack/web/api/endpoints/bots.rb +2 -2
  67. data/lib/slack/web/api/endpoints/channels.rb +57 -34
  68. data/lib/slack/web/api/endpoints/chat.rb +107 -37
  69. data/lib/slack/web/api/endpoints/conversations.rb +301 -0
  70. data/lib/slack/web/api/endpoints/dialog.rb +32 -0
  71. data/lib/slack/web/api/endpoints/dnd.rb +9 -9
  72. data/lib/slack/web/api/endpoints/emoji.rb +2 -2
  73. data/lib/slack/web/api/endpoints/files.rb +53 -23
  74. data/lib/slack/web/api/endpoints/files_comments.rb +11 -11
  75. data/lib/slack/web/api/endpoints/groups.rb +38 -50
  76. data/lib/slack/web/api/endpoints/im.rb +27 -17
  77. data/lib/slack/web/api/endpoints/migration.rb +25 -0
  78. data/lib/slack/web/api/endpoints/mpim.rb +13 -15
  79. data/lib/slack/web/api/endpoints/oauth.rb +24 -3
  80. data/lib/slack/web/api/endpoints/pins.rb +6 -8
  81. data/lib/slack/web/api/endpoints/presence.rb +1 -1
  82. data/lib/slack/web/api/endpoints/reactions.rb +18 -20
  83. data/lib/slack/web/api/endpoints/reminders.rb +10 -10
  84. data/lib/slack/web/api/endpoints/rtm.rb +14 -8
  85. data/lib/slack/web/api/endpoints/search.rb +12 -12
  86. data/lib/slack/web/api/endpoints/stars.rb +10 -12
  87. data/lib/slack/web/api/endpoints/team.rb +12 -13
  88. data/lib/slack/web/api/endpoints/team_profile.rb +2 -2
  89. data/lib/slack/web/api/endpoints/usergroups.rb +22 -22
  90. data/lib/slack/web/api/endpoints/usergroups_users.rb +4 -4
  91. data/lib/slack/web/api/endpoints/users.rb +34 -24
  92. data/lib/slack/web/api/endpoints/users_admin.rb +46 -0
  93. data/lib/slack/web/api/endpoints/users_prefs.rb +19 -0
  94. data/lib/slack/web/api/endpoints/users_profile.rb +10 -10
  95. data/lib/slack/web/api/endpoints.rb +14 -2
  96. data/lib/slack/web/api/mixins/ids.id.rb +1 -1
  97. data/lib/slack/web/api/mixins/users.search.rb +38 -36
  98. data/lib/slack/web/api/patches/chat.1.text-attachments-required.patch +1 -1
  99. data/lib/slack/web/api/patches/chat.3.update-attachments-support.patch +4 -3
  100. data/lib/slack/web/api/patches/chat.4.postEphemeral-attachments-support.patch +17 -0
  101. data/lib/slack/web/api/patches/dialog.1.open-json-support.patch +17 -0
  102. data/lib/slack/web/api/templates/command.erb +4 -3
  103. data/lib/slack/web/api/templates/commands.erb +1 -1
  104. data/lib/slack/web/api/templates/endpoints.erb +2 -2
  105. data/lib/slack/web/api/templates/method.erb +18 -3
  106. data/lib/slack/web/api/templates/method_spec.erb +1 -1
  107. data/lib/slack/web/config.rb +16 -12
  108. data/lib/slack/web/faraday/connection.rb +1 -1
  109. data/lib/slack/web/faraday/response/raise_error.rb +3 -3
  110. data/lib/slack/web/pagination/cursor.rb +48 -0
  111. data/lib/slack-ruby-client.rb +6 -0
  112. data/lib/tasks/git.rake +1 -1
  113. data/lib/tasks/real_time.rake +1 -1
  114. data/lib/tasks/web.rake +4 -1
  115. data/slack-ruby-client.gemspec +2 -3
  116. data/spec/fixtures/slack/web/paginated_users_list.yml +181 -0
  117. data/spec/integration/integration_spec.rb +1 -1
  118. data/spec/slack/messages/formatting_spec.rb +1 -1
  119. data/spec/slack/real_time/client_spec.rb +62 -63
  120. data/spec/slack/real_time/concurrency/celluloid_spec.rb +41 -31
  121. data/spec/slack/real_time/concurrency/it_behaves_like_a_realtime_socket.rb +1 -1
  122. data/spec/slack/real_time/event_handlers/bot_spec.rb +4 -2
  123. data/spec/slack/real_time/event_handlers/event_handlers_spec.rb +1 -1
  124. data/spec/slack/real_time/event_handlers/user_spec.rb +4 -2
  125. data/spec/slack/web/api/endpoints/apps_permissions_spec.rb +15 -0
  126. data/spec/slack/web/api/endpoints/conversations_spec.rb +100 -0
  127. data/spec/slack/web/api/endpoints/custom_specs/chat_spec.rb +37 -1
  128. data/spec/slack/web/api/endpoints/custom_specs/dialog_spec.rb +28 -0
  129. data/spec/slack/web/api/endpoints/custom_specs/users_spec.rb +16 -6
  130. data/spec/slack/web/api/endpoints/files_comments_spec.rb +8 -8
  131. data/spec/slack/web/api/endpoints/files_spec.rb +16 -5
  132. data/spec/slack/web/api/endpoints/migration_spec.rb +12 -0
  133. data/spec/slack/web/api/endpoints/oauth_spec.rb +11 -0
  134. data/spec/slack/web/api/endpoints/users_admin_spec.rb +17 -0
  135. data/spec/slack/web/api/endpoints/users_prefs_spec.rb +7 -0
  136. data/spec/slack/web/api/error_spec.rb +1 -1
  137. data/spec/slack/web/api/errors/slack_error_spec.rb +1 -1
  138. data/spec/slack/web/api/mixins/users_spec.rb +6 -4
  139. data/spec/slack/web/api/pagination/cursor_spec.rb +70 -0
  140. data/spec/support/queue_with_timeout.rb +1 -1
  141. data/spec/support/real_time/concurrency/mock.rb +1 -2
  142. metadata +47 -30
@@ -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
+ raise 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
@@ -10,7 +10,7 @@ RSpec.shared_examples_for 'a realtime socket' do
10
10
  end
11
11
  end
12
12
  describe 'api' do
13
- [:start_sync, :start_sync, :disconnect!, :connect!, :connected?, :send_data, :close].each do |m|
13
+ %i[start_sync start_sync disconnect! connect! connected? send_data close].each do |m|
14
14
  it m do
15
15
  expect(socket).to respond_to(m)
16
16
  end
@@ -17,7 +17,8 @@ RSpec.describe Slack::RealTime::Client, vcr: { cassette_name: 'web/rtm_start' }
17
17
  'icons' => {
18
18
  'image_48' => 'https:\/\/slack.com\/path\/to\/hugbot_48.png'
19
19
  }
20
- })
20
+ }
21
+ )
21
22
  client.send(:dispatch, event)
22
23
  end.to change(client.bots, :count).by(1)
23
24
  bot = client.bots['B024BE7LH']
@@ -32,7 +33,8 @@ RSpec.describe Slack::RealTime::Client, vcr: { cassette_name: 'web/rtm_start' }
32
33
  'bot' => {
33
34
  'id' => 'B0751JU2H',
34
35
  'name' => 'hugbot'
35
- })
36
+ }
37
+ )
36
38
  client.send(:dispatch, event)
37
39
  end.to_not change(client.bots, :count)
38
40
  bot = client.bots['B0751JU2H']
@@ -9,7 +9,7 @@ RSpec.describe Slack::RealTime::Client, vcr: { cassette_name: 'web/rtm_start' }
9
9
  'name' => 'push_sound',
10
10
  'value' => 'updated.mp3'
11
11
  )
12
- expect(client.self).to receive(:prefs) { fail ArgumentError }
12
+ expect(client.self).to receive(:prefs) { raise ArgumentError }
13
13
  expect { client.send(:dispatch, event) }.to_not raise_error
14
14
  end
15
15
  end
@@ -14,7 +14,8 @@ RSpec.describe Slack::RealTime::Client, vcr: { cassette_name: 'web/rtm_start' }
14
14
  'type' => 'user_change',
15
15
  'user' => {
16
16
  'id' => 'U07KECJ77', 'name' => 'renamed'
17
- })
17
+ }
18
+ )
18
19
  client.send(:dispatch, event)
19
20
  expect(client.users['U07KECJ77'].name).to eq 'renamed'
20
21
  end
@@ -24,7 +25,8 @@ RSpec.describe Slack::RealTime::Client, vcr: { cassette_name: 'web/rtm_start' }
24
25
  'type' => 'team_join',
25
26
  'user' => {
26
27
  'id' => 'DEADBEEF', 'name' => 'added'
27
- })
28
+ }
29
+ )
28
30
  client.send(:dispatch, event)
29
31
  end.to change(client.users, :count).by(1)
30
32
  expect(client.users['DEADBEEF'].name).to eq 'added'
@@ -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::AppsPermissions do
6
+ let(:client) { Slack::Web::Client.new }
7
+ context 'apps.permissions_request' do
8
+ it 'requires scopes' do
9
+ expect { client.apps_permissions_request(trigger_id: ' ') }.to raise_error ArgumentError, /Required arguments :scopes missing/
10
+ end
11
+ it 'requires trigger_id' do
12
+ expect { client.apps_permissions_request(scopes: ' ') }.to raise_error ArgumentError, /Required arguments :trigger_id missing/
13
+ end
14
+ end
15
+ end
@@ -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
@@ -2,6 +2,42 @@ require 'spec_helper'
2
2
 
3
3
  RSpec.describe Slack::Web::Api::Endpoints::Chat do
4
4
  let(:client) { Slack::Web::Client.new }
5
+ context 'chat_postEphemeral' do
6
+ let(:user) { OpenStruct.new(user: { id: '123' }) }
7
+ before(:each) do
8
+ allow(described_class).to receive(:users_id).and_return(user)
9
+ end
10
+
11
+ it 'automatically converts attachments into JSON' do
12
+ expect(client).to receive(:post).with(
13
+ 'chat.postEphemeral',
14
+ channel: 'channel',
15
+ text: 'text',
16
+ user: '123',
17
+ attachments: '[]'
18
+ )
19
+ client.chat_postEphemeral(channel: 'channel', text: 'text', user: '123', attachments: [])
20
+ end
21
+ context 'text and user arguments' do
22
+ it 'requires text' do
23
+ expect { client.chat_postEphemeral(channel: 'channel') }.to raise_error ArgumentError, /Required arguments :text missing/
24
+ end
25
+ it 'requires user' do
26
+ expect { client.chat_postEphemeral(channel: 'channel', text: 'text') }.to raise_error ArgumentError, /Required arguments :user missing/
27
+ end
28
+ it 'both text and user' do
29
+ expect(client).to receive(:post).with('chat.postEphemeral', hash_including(text: 'text', user: '123'))
30
+ expect { client.chat_postEphemeral(channel: 'channel', text: 'text', user: '123') }.to_not raise_error
31
+ end
32
+ end
33
+ context 'attachments argument' do
34
+ it 'optional attachments' do
35
+ expect(client).to receive(:post).with('chat.postEphemeral', hash_including(attachments: '[]'))
36
+ expect { client.chat_postEphemeral(channel: 'channel', text: 'text', user: '123', attachments: []) }.to_not raise_error
37
+ end
38
+ end
39
+ end
40
+
5
41
  context 'chat_postMessage' do
6
42
  it 'automatically converts attachments into JSON' do
7
43
  expect(client).to receive(:post).with(
@@ -45,7 +81,7 @@ RSpec.describe Slack::Web::Api::Endpoints::Chat do
45
81
  end
46
82
  context 'ts arguments' do
47
83
  it 'requires ts' do
48
- expect { client.chat_update(channel: 'channel') }.to raise_error ArgumentError, /Required arguments :ts missing>/
84
+ expect { client.chat_update(channel: 'channel', text: 'text') }.to raise_error ArgumentError, /Required arguments :ts missing>/
49
85
  end
50
86
  end
51
87
  context 'text and attachment arguments' do
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Slack::Web::Api::Endpoints::Dialog do
4
+ let(:client) { Slack::Web::Client.new }
5
+ context 'dialog_open' do
6
+ it 'automatically converts dialog into JSON' do
7
+ expect(client).to receive(:post).with(
8
+ 'dialog.open',
9
+ trigger_id: '12345.98765.abcd2358fdea',
10
+ dialog: '[]'
11
+ )
12
+ client.dialog_open(trigger_id: '12345.98765.abcd2358fdea', dialog: [])
13
+ end
14
+
15
+ context 'arguments' do
16
+ it 'requires dialog' do
17
+ expect { client.dialog_open(trigger_id: '123') }.to raise_error ArgumentError, /Required arguments :dialog missing/
18
+ end
19
+ it 'requires trigger_id' do
20
+ expect { client.dialog_open(dialog: []) }.to raise_error ArgumentError, /Required arguments :trigger_id missing/
21
+ end
22
+ it 'likes both dialog and trigger_id' do
23
+ expect(client).to receive(:post).with('dialog.open', hash_including(trigger_id: '123', dialog: '[]'))
24
+ expect { client.dialog_open(dialog: [], trigger_id: '123') }.to_not raise_error
25
+ end
26
+ end
27
+ end
28
+ end
@@ -9,15 +9,25 @@ 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'
15
23
  end
16
- it 'search', vcr: { cassette_name: 'web/users_info' } do
17
- json = client.users_search(user: 'aws')
18
- expect(json.ok).to be true
19
- expect(json.members.size).to eq 1
20
- expect(json.members.first.name).to eq 'aws'
21
- end if defined?(Picky)
24
+ if defined?(Picky)
25
+ it 'search', vcr: { cassette_name: 'web/users_info' } do
26
+ json = client.users_search(user: 'aws')
27
+ expect(json.ok).to be true
28
+ expect(json.members.size).to eq 1
29
+ expect(json.members.first.name).to eq 'aws'
30
+ end
31
+ end
22
32
  end
23
33
  end
@@ -5,12 +5,12 @@ require 'spec_helper'
5
5
  RSpec.describe Slack::Web::Api::Endpoints::FilesComments do
6
6
  let(:client) { Slack::Web::Client.new }
7
7
  context 'files.comments_add' do
8
- it 'requires file' do
9
- expect { client.files_comments_add(comment: 'Everyone should take a moment to read this file.') }.to raise_error ArgumentError, /Required arguments :file missing/
10
- end
11
8
  it 'requires comment' do
12
9
  expect { client.files_comments_add(file: 'F1234467890') }.to raise_error ArgumentError, /Required arguments :comment missing/
13
10
  end
11
+ it 'requires file' do
12
+ expect { client.files_comments_add(comment: 'Everyone should take a moment to read this file.') }.to raise_error ArgumentError, /Required arguments :file missing/
13
+ end
14
14
  end
15
15
  context 'files.comments_delete' do
16
16
  it 'requires file' do
@@ -21,14 +21,14 @@ RSpec.describe Slack::Web::Api::Endpoints::FilesComments do
21
21
  end
22
22
  end
23
23
  context 'files.comments_edit' do
24
+ it 'requires comment' do
25
+ expect { client.files_comments_edit(file: 'F1234567890', id: 'Fc1234567890') }.to raise_error ArgumentError, /Required arguments :comment missing/
26
+ end
24
27
  it 'requires file' do
25
- expect { client.files_comments_edit(id: 'Fc1234567890', comment: 'Everyone should take a moment to read this file, seriously.') }.to raise_error ArgumentError, /Required arguments :file missing/
28
+ expect { client.files_comments_edit(comment: 'Everyone should take a moment to read this file, seriously.', id: 'Fc1234567890') }.to raise_error ArgumentError, /Required arguments :file missing/
26
29
  end
27
30
  it 'requires id' do
28
- expect { client.files_comments_edit(file: 'F1234567890', comment: 'Everyone should take a moment to read this file, seriously.') }.to raise_error ArgumentError, /Required arguments :id missing/
29
- end
30
- it 'requires comment' do
31
- expect { client.files_comments_edit(file: 'F1234567890', id: 'Fc1234567890') }.to raise_error ArgumentError, /Required arguments :comment missing/
31
+ expect { client.files_comments_edit(comment: 'Everyone should take a moment to read this file, seriously.', file: 'F1234567890') }.to raise_error ArgumentError, /Required arguments :id missing/
32
32
  end
33
33
  end
34
34
  end
@@ -9,6 +9,14 @@ RSpec.describe Slack::Web::Api::Endpoints::Files do
9
9
  expect { client.files_delete }.to raise_error ArgumentError, /Required arguments :file missing/
10
10
  end
11
11
  end
12
+ context 'files_edit' do
13
+ it 'requires file' do
14
+ expect { client.files_edit(title: 'Brand new title') }.to raise_error ArgumentError, /Required arguments :file missing/
15
+ end
16
+ it 'requires title' do
17
+ expect { client.files_edit(file: 'F2147483862') }.to raise_error ArgumentError, /Required arguments :title missing/
18
+ end
19
+ end
12
20
  context 'files_info' do
13
21
  it 'requires file' do
14
22
  expect { client.files_info }.to raise_error ArgumentError, /Required arguments :file missing/
@@ -19,14 +27,17 @@ RSpec.describe Slack::Web::Api::Endpoints::Files do
19
27
  expect { client.files_revokePublicURL }.to raise_error ArgumentError, /Required arguments :file missing/
20
28
  end
21
29
  end
22
- context 'files_sharedPublicURL' do
30
+ context 'files_share' do
23
31
  it 'requires file' do
24
- expect { client.files_sharedPublicURL }.to raise_error ArgumentError, /Required arguments :file missing/
32
+ expect { client.files_share(channel: 'C1234567890') }.to raise_error ArgumentError, /Required arguments :file missing/
33
+ end
34
+ it 'requires channel' do
35
+ expect { client.files_share(file: 'F2147483862') }.to raise_error ArgumentError, /Required arguments :channel missing/
25
36
  end
26
37
  end
27
- context 'files_upload' do
28
- it 'requires filename' do
29
- expect { client.files_upload }.to raise_error ArgumentError, /Required arguments :filename missing/
38
+ context 'files_sharedPublicURL' do
39
+ it 'requires file' do
40
+ expect { client.files_sharedPublicURL }.to raise_error ArgumentError, /Required arguments :file missing/
30
41
  end
31
42
  end
32
43
  end
@@ -0,0 +1,12 @@
1
+ # This file was auto-generated by lib/tasks/web.rake
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe Slack::Web::Api::Endpoints::Migration do
6
+ let(:client) { Slack::Web::Client.new }
7
+ context 'migration_exchange' do
8
+ it 'requires users' do
9
+ expect { client.migration_exchange }.to raise_error ArgumentError, /Required arguments :users missing/
10
+ end
11
+ end
12
+ end
@@ -15,4 +15,15 @@ RSpec.describe Slack::Web::Api::Endpoints::Oauth do
15
15
  expect { client.oauth_access(client_id: '4b39e9-752c4', client_secret: '33fea0113f5b1') }.to raise_error ArgumentError, /Required arguments :code missing/
16
16
  end
17
17
  end
18
+ context 'oauth_token' do
19
+ it 'requires client_id' do
20
+ expect { client.oauth_token(client_secret: '33fea0113f5b1', code: 'ccdaa72ad') }.to raise_error ArgumentError, /Required arguments :client_id missing/
21
+ end
22
+ it 'requires client_secret' do
23
+ expect { client.oauth_token(client_id: '4b39e9-752c4', code: 'ccdaa72ad') }.to raise_error ArgumentError, /Required arguments :client_secret missing/
24
+ end
25
+ it 'requires code' do
26
+ expect { client.oauth_token(client_id: '4b39e9-752c4', client_secret: '33fea0113f5b1') }.to raise_error ArgumentError, /Required arguments :code missing/
27
+ end
28
+ end
18
29
  end
@@ -0,0 +1,17 @@
1
+ # This file was auto-generated by lib/tasks/web.rake
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe Slack::Web::Api::Endpoints::UsersAdmin do
6
+ let(:client) { Slack::Web::Client.new }
7
+ context 'users.admin_invite' do
8
+ it 'requires email' do
9
+ expect { client.users_admin_invite }.to raise_error ArgumentError, /Required arguments :email missing/
10
+ end
11
+ end
12
+ context 'users.admin_setInactive' do
13
+ it 'requires user' do
14
+ expect { client.users_admin_setInactive }.to raise_error ArgumentError, /Required arguments :user missing/
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,7 @@
1
+ # This file was auto-generated by lib/tasks/web.rake
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe Slack::Web::Api::Endpoints::UsersPrefs do
6
+ let(:client) { Slack::Web::Client.new }
7
+ end
@@ -5,7 +5,7 @@ RSpec.describe Slack::Web::Api::Error do
5
5
  it 'provides access to the response object', vcr: { cassette_name: 'web/auth_test_error' } do
6
6
  begin
7
7
  client.auth_test
8
- fail 'Expected to receive Slack::Web::Api::Error.'
8
+ raise 'Expected to receive Slack::Web::Api::Error.'
9
9
  rescue Slack::Web::Api::Error => e
10
10
  expect(e.response).to_not be_nil
11
11
  expect(e.response.status).to eq 200
@@ -5,7 +5,7 @@ RSpec.describe Slack::Web::Api::Errors::SlackError do
5
5
  it 'provides access to the response object', vcr: { cassette_name: 'web/auth_test_error' } do
6
6
  begin
7
7
  client.auth_test
8
- fail 'Expected to receive Slack::Web::Api::Errors::SlackError.'
8
+ raise 'Expected to receive Slack::Web::Api::Errors::SlackError.'
9
9
  rescue Slack::Web::Api::Errors::SlackError => e
10
10
  expect(e.response).to_not be_nil
11
11
  expect(e.response.status).to eq 200
@@ -29,9 +29,11 @@ RSpec.describe Slack::Web::Api::Mixins::Users do
29
29
  expect { subject.users_id(user: '@foo') }.to raise_error Slack::Web::Api::Errors::SlackError, 'user_not_found'
30
30
  end
31
31
  end
32
- context '#users_search' do
33
- it 'finds a user' do
34
- expect(subject.users_search(user: 'aws')).to eq('ok' => true, 'members' => [{ 'id' => 'UDEADBEEF', 'name' => 'aws', 'profile' => {} }])
32
+ if defined?(Picky)
33
+ context '#users_search' do
34
+ it 'finds a user' do
35
+ expect(subject.users_search(user: 'aws')).to eq('ok' => true, 'members' => [{ 'id' => 'UDEADBEEF', 'name' => 'aws', 'profile' => {} }])
36
+ end
35
37
  end
36
- end if defined?(Picky)
38
+ end
37
39
  end
@@ -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
@@ -26,7 +26,7 @@ class QueueWithTimeout
26
26
  if @queue.empty?
27
27
  @recieved.wait(@mutex, timeout) if timeout != 0
28
28
  # if we're still empty after the timeout, raise exception
29
- fail ThreadError, 'queue empty' if @queue.empty?
29
+ raise ThreadError, 'queue empty' if @queue.empty?
30
30
  end
31
31
  @queue.shift
32
32
  end
@@ -6,8 +6,7 @@ module Slack
6
6
  end
7
7
 
8
8
  class Socket < ::Slack::RealTime::Socket
9
- def self.close
10
- end
9
+ def self.close; end
11
10
 
12
11
  def start_async(client)
13
12
  reactor = Thread.new {}