slack-ruby-client 2.3.0 → 2.5.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 (228) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/test.yml +22 -12
  3. data/.github/workflows/update_api.yml +1 -1
  4. data/.gitignore +1 -0
  5. data/.rubocop_todo.yml +43 -13
  6. data/CHANGELOG.md +19 -0
  7. data/CONTRIBUTING.md +7 -7
  8. data/Gemfile +1 -0
  9. data/README.md +68 -25
  10. data/bin/commands/admin_conversations.rb +21 -0
  11. data/bin/commands/admin_emoji.rb +1 -1
  12. data/bin/commands/admin_users.rb +4 -4
  13. data/bin/commands/admin_users_session.rb +1 -1
  14. data/bin/commands/admin_workflows.rb +6 -2
  15. data/bin/commands/admin_workflows_triggers_types_permissions.rb +31 -0
  16. data/bin/commands/apps_datastore.rb +46 -0
  17. data/bin/commands/assistant_threads.rb +45 -0
  18. data/bin/commands/bookmarks.rb +1 -0
  19. data/bin/commands/canvases.rb +40 -0
  20. data/bin/commands/canvases_access.rb +34 -0
  21. data/bin/commands/canvases_sections.rb +21 -0
  22. data/bin/commands/chat.rb +7 -3
  23. data/bin/commands/conversations.rb +6 -6
  24. data/bin/commands/conversations_canvases.rb +21 -0
  25. data/bin/commands/conversations_externalInvitePermissions.rb +22 -0
  26. data/bin/commands/conversations_requestSharedInvite.rb +48 -0
  27. data/bin/commands/files.rb +2 -1
  28. data/bin/commands/functions_distributions_permissions.rb +59 -0
  29. data/bin/commands/oauth.rb +2 -2
  30. data/bin/commands/oauth_v2.rb +2 -2
  31. data/bin/commands/reminders.rb +1 -1
  32. data/bin/commands/team_externalTeams.rb +35 -0
  33. data/bin/commands/usergroups.rb +5 -0
  34. data/bin/commands/usergroups_users.rb +2 -0
  35. data/bin/commands/users_discoverableContacts.rb +20 -0
  36. data/bin/commands/workflows_triggers_permissions.rb +60 -0
  37. data/examples/files_upload_v2/.env.example +1 -0
  38. data/examples/files_upload_v2/Gemfile +5 -0
  39. data/examples/files_upload_v2/README.md +13 -0
  40. data/examples/files_upload_v2/files_upload_v2.rb +37 -0
  41. data/examples/oauth_v2/.env.example +4 -0
  42. data/examples/oauth_v2/Gemfile +7 -0
  43. data/examples/oauth_v2/README.md +33 -0
  44. data/examples/oauth_v2/oauth_v2.rb +60 -0
  45. data/lib/slack/messages/formatting.rb +13 -0
  46. data/lib/slack/version.rb +1 -1
  47. data/lib/slack/web/api/endpoints/admin_conversations.rb +35 -0
  48. data/lib/slack/web/api/endpoints/admin_emoji.rb +1 -1
  49. data/lib/slack/web/api/endpoints/admin_users.rb +2 -2
  50. data/lib/slack/web/api/endpoints/admin_users_session.rb +2 -3
  51. data/lib/slack/web/api/endpoints/admin_workflows.rb +10 -2
  52. data/lib/slack/web/api/endpoints/admin_workflows_triggers_types_permissions.rb +41 -0
  53. data/lib/slack/web/api/endpoints/apps_datastore.rb +71 -0
  54. data/lib/slack/web/api/endpoints/assistant_threads.rb +68 -0
  55. data/lib/slack/web/api/endpoints/bookmarks.rb +2 -0
  56. data/lib/slack/web/api/endpoints/canvases.rb +52 -0
  57. data/lib/slack/web/api/endpoints/canvases_access.rb +47 -0
  58. data/lib/slack/web/api/endpoints/canvases_sections.rb +27 -0
  59. data/lib/slack/web/api/endpoints/chat.rb +12 -3
  60. data/lib/slack/web/api/endpoints/conversations.rb +5 -5
  61. data/lib/slack/web/api/endpoints/conversations_canvases.rb +26 -0
  62. data/lib/slack/web/api/endpoints/conversations_externalInvitePermissions.rb +31 -0
  63. data/lib/slack/web/api/endpoints/conversations_requestSharedInvite.rb +73 -0
  64. data/lib/slack/web/api/endpoints/dnd.rb +1 -0
  65. data/lib/slack/web/api/endpoints/files.rb +3 -1
  66. data/lib/slack/web/api/endpoints/functions_distributions_permissions.rb +80 -0
  67. data/lib/slack/web/api/endpoints/oauth.rb +2 -2
  68. data/lib/slack/web/api/endpoints/oauth_v2.rb +2 -2
  69. data/lib/slack/web/api/endpoints/reminders.rb +1 -1
  70. data/lib/slack/web/api/endpoints/team_externalTeams.rb +53 -0
  71. data/lib/slack/web/api/endpoints/usergroups.rb +10 -0
  72. data/lib/slack/web/api/endpoints/usergroups_users.rb +4 -0
  73. data/lib/slack/web/api/endpoints/users_discoverableContacts.rb +24 -0
  74. data/lib/slack/web/api/endpoints/workflows_triggers_permissions.rb +87 -0
  75. data/lib/slack/web/api/endpoints.rb +24 -0
  76. data/lib/slack/web/api/errors.rb +118 -8
  77. data/lib/slack/web/api/helpers/files.rb +87 -0
  78. data/lib/slack/web/api/helpers.rb +13 -0
  79. data/lib/slack/web/api/templates/method.erb +1 -0
  80. data/lib/slack/web/api/templates/method_spec.erb +6 -4
  81. data/lib/slack/web/client.rb +1 -0
  82. data/lib/slack/web/faraday/connection.rb +13 -26
  83. data/lib/slack/web/faraday/options.rb +24 -0
  84. data/lib/slack/web/faraday/request.rb +2 -1
  85. data/lib/slack-ruby-client.rb +2 -0
  86. data/slack-ruby-client.gemspec +2 -1
  87. metadata +52 -144
  88. data/screenshots/create-app.png +0 -0
  89. data/spec/fixtures/slack/web/429_error.yml +0 -81
  90. data/spec/fixtures/slack/web/auth_test_error.yml +0 -81
  91. data/spec/fixtures/slack/web/auth_test_success.yml +0 -81
  92. data/spec/fixtures/slack/web/conversations_info.yml +0 -167
  93. data/spec/fixtures/slack/web/conversations_setTopic.yml +0 -84
  94. data/spec/fixtures/slack/web/conversations_setTopic_one_page.yml +0 -172
  95. data/spec/fixtures/slack/web/conversations_setTopic_paginated.yml +0 -253
  96. data/spec/fixtures/slack/web/paginated_users_list.yml +0 -613
  97. data/spec/fixtures/slack/web/rtm_connect.yml +0 -391
  98. data/spec/fixtures/slack/web/users_info.yml +0 -214
  99. data/spec/fixtures/slack/web/users_list.yml +0 -133
  100. data/spec/fixtures/slack/web/views_open_error.yml +0 -83
  101. data/spec/integration/integration_spec.rb +0 -207
  102. data/spec/slack/config_spec.rb +0 -16
  103. data/spec/slack/events/config_spec.rb +0 -35
  104. data/spec/slack/events/request_spec.rb +0 -199
  105. data/spec/slack/messages/formatting_spec.rb +0 -124
  106. data/spec/slack/real_time/api/message_spec.rb +0 -20
  107. data/spec/slack/real_time/api/ping_spec.rb +0 -17
  108. data/spec/slack/real_time/api/typing_spec.rb +0 -19
  109. data/spec/slack/real_time/client_spec.rb +0 -601
  110. data/spec/slack/real_time/concurrency/clients/async_spec.rb +0 -16
  111. data/spec/slack/real_time/concurrency/it_behaves_like_a_realtime_socket.rb +0 -21
  112. data/spec/slack/real_time/concurrency/with_concurrency_spec.rb +0 -10
  113. data/spec/slack/real_time/concurrency/without_concurrency_spec.rb +0 -10
  114. data/spec/slack/real_time/event_handlers/bot_spec.rb +0 -47
  115. data/spec/slack/real_time/event_handlers/event_handlers_spec.rb +0 -16
  116. data/spec/slack/real_time/event_handlers/im_spec.rb +0 -51
  117. data/spec/slack/real_time/event_handlers/private_channel_spec.rb +0 -99
  118. data/spec/slack/real_time/event_handlers/public_channel_spec.rb +0 -123
  119. data/spec/slack/real_time/event_handlers/team_spec.rb +0 -63
  120. data/spec/slack/real_time/event_handlers/user_spec.rb +0 -65
  121. data/spec/slack/real_time/rtm_connect_spec.rb +0 -14
  122. data/spec/slack/real_time/stores/store_spec.rb +0 -50
  123. data/spec/slack/slack_spec.rb +0 -93
  124. data/spec/slack/version_spec.rb +0 -8
  125. data/spec/slack/web/api/endpoints/admin_analytics_spec.rb +0 -13
  126. data/spec/slack/web/api/endpoints/admin_apps_activities_spec.rb +0 -8
  127. data/spec/slack/web/api/endpoints/admin_apps_approved_spec.rb +0 -8
  128. data/spec/slack/web/api/endpoints/admin_apps_config_spec.rb +0 -18
  129. data/spec/slack/web/api/endpoints/admin_apps_requests_spec.rb +0 -13
  130. data/spec/slack/web/api/endpoints/admin_apps_restricted_spec.rb +0 -8
  131. data/spec/slack/web/api/endpoints/admin_apps_spec.rb +0 -18
  132. data/spec/slack/web/api/endpoints/admin_audit_anomaly_allow_spec.rb +0 -8
  133. data/spec/slack/web/api/endpoints/admin_auth_policy_spec.rb +0 -35
  134. data/spec/slack/web/api/endpoints/admin_barriers_spec.rb +0 -38
  135. data/spec/slack/web/api/endpoints/admin_conversations_ekm_spec.rb +0 -8
  136. data/spec/slack/web/api/endpoints/admin_conversations_restrictAccess_spec.rb +0 -32
  137. data/spec/slack/web/api/endpoints/admin_conversations_spec.rb +0 -133
  138. data/spec/slack/web/api/endpoints/admin_emoji_spec.rb +0 -37
  139. data/spec/slack/web/api/endpoints/admin_functions_permissions_spec.rb +0 -21
  140. data/spec/slack/web/api/endpoints/admin_functions_spec.rb +0 -13
  141. data/spec/slack/web/api/endpoints/admin_inviteRequests_approved_spec.rb +0 -8
  142. data/spec/slack/web/api/endpoints/admin_inviteRequests_denied_spec.rb +0 -8
  143. data/spec/slack/web/api/endpoints/admin_inviteRequests_spec.rb +0 -18
  144. data/spec/slack/web/api/endpoints/admin_roles_spec.rb +0 -30
  145. data/spec/slack/web/api/endpoints/admin_teams_admins_spec.rb +0 -13
  146. data/spec/slack/web/api/endpoints/admin_teams_owners_spec.rb +0 -13
  147. data/spec/slack/web/api/endpoints/admin_teams_settings_spec.rb +0 -53
  148. data/spec/slack/web/api/endpoints/admin_teams_spec.rb +0 -16
  149. data/spec/slack/web/api/endpoints/admin_usergroups_spec.rb +0 -37
  150. data/spec/slack/web/api/endpoints/admin_users_session_spec.rb +0 -41
  151. data/spec/slack/web/api/endpoints/admin_users_spec.rb +0 -67
  152. data/spec/slack/web/api/endpoints/admin_users_unsupportedVersions_spec.rb +0 -8
  153. data/spec/slack/web/api/endpoints/admin_workflows_collaborators_spec.rb +0 -24
  154. data/spec/slack/web/api/endpoints/admin_workflows_permissions_spec.rb +0 -13
  155. data/spec/slack/web/api/endpoints/admin_workflows_spec.rb +0 -13
  156. data/spec/slack/web/api/endpoints/api_spec.rb +0 -8
  157. data/spec/slack/web/api/endpoints/apps_activities_spec.rb +0 -13
  158. data/spec/slack/web/api/endpoints/apps_auth_external_spec.rb +0 -13
  159. data/spec/slack/web/api/endpoints/apps_connections_spec.rb +0 -8
  160. data/spec/slack/web/api/endpoints/apps_datastore_spec.rb +0 -45
  161. data/spec/slack/web/api/endpoints/apps_event_authorizations_spec.rb +0 -13
  162. data/spec/slack/web/api/endpoints/apps_manifest_spec.rb +0 -44
  163. data/spec/slack/web/api/endpoints/apps_spec.rb +0 -16
  164. data/spec/slack/web/api/endpoints/auth_spec.rb +0 -8
  165. data/spec/slack/web/api/endpoints/auth_teams_spec.rb +0 -8
  166. data/spec/slack/web/api/endpoints/bookmarks_spec.rb +0 -40
  167. data/spec/slack/web/api/endpoints/bots_spec.rb +0 -8
  168. data/spec/slack/web/api/endpoints/calls_participants_spec.rb +0 -24
  169. data/spec/slack/web/api/endpoints/calls_spec.rb +0 -31
  170. data/spec/slack/web/api/endpoints/chat_scheduledMessages_spec.rb +0 -8
  171. data/spec/slack/web/api/endpoints/chat_spec.rb +0 -134
  172. data/spec/slack/web/api/endpoints/conversations_spec.rb +0 -8
  173. data/spec/slack/web/api/endpoints/custom_specs/auth_spec.rb +0 -27
  174. data/spec/slack/web/api/endpoints/custom_specs/chat_spec.rb +0 -206
  175. data/spec/slack/web/api/endpoints/custom_specs/conversations_spec.rb +0 -13
  176. data/spec/slack/web/api/endpoints/custom_specs/dialog_spec.rb +0 -40
  177. data/spec/slack/web/api/endpoints/custom_specs/users_spec.rb +0 -38
  178. data/spec/slack/web/api/endpoints/custom_specs/views_spec.rb +0 -112
  179. data/spec/slack/web/api/endpoints/dialog_spec.rb +0 -14
  180. data/spec/slack/web/api/endpoints/dnd_spec.rb +0 -13
  181. data/spec/slack/web/api/endpoints/emoji_spec.rb +0 -8
  182. data/spec/slack/web/api/endpoints/files_comments_spec.rb +0 -16
  183. data/spec/slack/web/api/endpoints/files_remote_spec.rb +0 -24
  184. data/spec/slack/web/api/endpoints/files_spec.rb +0 -57
  185. data/spec/slack/web/api/endpoints/functions_spec.rb +0 -28
  186. data/spec/slack/web/api/endpoints/functions_workflows_steps_responses_spec.rb +0 -13
  187. data/spec/slack/web/api/endpoints/functions_workflows_steps_spec.rb +0 -13
  188. data/spec/slack/web/api/endpoints/migration_spec.rb +0 -13
  189. data/spec/slack/web/api/endpoints/oauth_spec.rb +0 -8
  190. data/spec/slack/web/api/endpoints/oauth_v2_spec.rb +0 -16
  191. data/spec/slack/web/api/endpoints/openid_connect_spec.rb +0 -8
  192. data/spec/slack/web/api/endpoints/pins_spec.rb +0 -23
  193. data/spec/slack/web/api/endpoints/reactions_spec.rb +0 -24
  194. data/spec/slack/web/api/endpoints/reminders_spec.rb +0 -31
  195. data/spec/slack/web/api/endpoints/rtm_spec.rb +0 -8
  196. data/spec/slack/web/api/endpoints/search_spec.rb +0 -23
  197. data/spec/slack/web/api/endpoints/stars_spec.rb +0 -8
  198. data/spec/slack/web/api/endpoints/team_billing_spec.rb +0 -8
  199. data/spec/slack/web/api/endpoints/team_preferences_spec.rb +0 -8
  200. data/spec/slack/web/api/endpoints/team_profile_spec.rb +0 -8
  201. data/spec/slack/web/api/endpoints/team_spec.rb +0 -8
  202. data/spec/slack/web/api/endpoints/tooling_tokens_spec.rb +0 -13
  203. data/spec/slack/web/api/endpoints/usergroups_spec.rb +0 -28
  204. data/spec/slack/web/api/endpoints/usergroups_users_spec.rb +0 -21
  205. data/spec/slack/web/api/endpoints/users_admin_spec.rb +0 -18
  206. data/spec/slack/web/api/endpoints/users_prefs_spec.rb +0 -8
  207. data/spec/slack/web/api/endpoints/users_profile_spec.rb +0 -14
  208. data/spec/slack/web/api/endpoints/users_spec.rb +0 -8
  209. data/spec/slack/web/api/endpoints/views_spec.rb +0 -65
  210. data/spec/slack/web/api/endpoints/workflows_spec.rb +0 -34
  211. data/spec/slack/web/api/error_spec.rb +0 -14
  212. data/spec/slack/web/api/errors/slack_error_spec.rb +0 -33
  213. data/spec/slack/web/api/mixins/conversations_list_spec.rb +0 -21
  214. data/spec/slack/web/api/mixins/conversations_spec.rb +0 -45
  215. data/spec/slack/web/api/mixins/users_spec.rb +0 -52
  216. data/spec/slack/web/api/options_spec.rb +0 -69
  217. data/spec/slack/web/api/pagination/cursor_spec.rb +0 -102
  218. data/spec/slack/web/client_spec.rb +0 -359
  219. data/spec/slack/web/faraday/request_spec.rb +0 -80
  220. data/spec/slack/web/faraday/response/raise_error_spec.rb +0 -86
  221. data/spec/spec_helper.rb +0 -30
  222. data/spec/support/queue_with_timeout.rb +0 -35
  223. data/spec/support/real_time/concurrency/mock.rb +0 -31
  224. data/spec/support/real_time/connected_client.rb +0 -21
  225. data/spec/support/real_time/event.rb +0 -12
  226. data/spec/support/real_time/loaded_client.rb +0 -120
  227. data/spec/support/token.rb +0 -11
  228. data/spec/support/vcr.rb +0 -45
@@ -1,102 +0,0 @@
1
- # frozen_string_literal: true
2
- require 'spec_helper'
3
-
4
- RSpec.describe Slack::Web::Api::Pagination::Cursor do
5
- let(:client) { Slack::Web::Client.new }
6
-
7
- context 'default cursor' do
8
- let(:cursor) { described_class.new(client, 'users_list', {}) }
9
-
10
- it 'provides a default limit' do
11
- expect(client).to receive(:users_list).with({ limit: 100, cursor: nil })
12
- cursor.first
13
- end
14
-
15
- it 'handles blank response metadata' do
16
- expect(client).to receive(:users_list).once.and_return(Slack::Messages::Message.new)
17
- cursor.to_a
18
- end
19
-
20
- it 'handles nil response metadata' do
21
- expect(client).to(
22
- receive(:users_list).once.and_return(Slack::Messages::Message.new(response_metadata: nil))
23
- )
24
- cursor.to_a
25
- end
26
-
27
- it 'paginates with a cursor inside response metadata' do
28
- expect(client).to receive(:users_list).twice.and_return(
29
- Slack::Messages::Message.new(response_metadata: { next_cursor: 'next' }),
30
- Slack::Messages::Message.new
31
- )
32
- expect(cursor).not_to receive(:sleep)
33
- cursor.to_a
34
- end
35
-
36
- context 'with rate limiting' do
37
- let(:error) { Slack::Web::Api::Errors::TooManyRequestsError.new(OpenStruct.new(headers: { 'retry-after' => 9 })) }
38
-
39
- context 'with default max retries' do
40
- it 'sleeps after a TooManyRequestsError' do
41
- expect(client).to(
42
- receive(:users_list)
43
- .with({ limit: 100, cursor: nil })
44
- .ordered
45
- .and_return(Slack::Messages::Message.new(response_metadata: { next_cursor: 'next' }))
46
- )
47
- expect(client).to(
48
- receive(:users_list).with({ limit: 100, cursor: 'next' }).ordered.and_raise(error)
49
- )
50
- expect(cursor).to receive(:sleep).once.ordered.with(9)
51
- expect(client).to(
52
- receive(:users_list)
53
- .with({ limit: 100, cursor: 'next' })
54
- .ordered
55
- .and_return(Slack::Messages::Message.new)
56
- )
57
- cursor.to_a
58
- end
59
- end
60
-
61
- context 'with a custom max_retries' do
62
- let(:cursor) { described_class.new(client, 'users_list', max_retries: 4) }
63
-
64
- it 'raises the error after hitting the max retries' do
65
- expect(client).to(
66
- receive(:users_list)
67
- .with({ limit: 100, cursor: nil })
68
- .and_return(Slack::Messages::Message.new(response_metadata: { next_cursor: 'next' }))
69
- )
70
- expect(client).to(
71
- receive(:users_list).with({ limit: 100, cursor: 'next' }).exactly(5).times.and_raise(error)
72
- )
73
- expect(cursor).to receive(:sleep).exactly(4).times.with(9)
74
- expect { cursor.to_a }.to raise_error(error)
75
- end
76
- end
77
- end
78
- end
79
-
80
- context 'with a custom limit' do
81
- let(:cursor) { described_class.new(client, 'users_list', limit: 42) }
82
-
83
- it 'overrides default limit' do
84
- expect(client).to receive(:users_list).with({ limit: 42, cursor: nil })
85
- cursor.first
86
- end
87
- end
88
-
89
- context 'with a custom sleep_interval' do
90
- let(:cursor) { described_class.new(client, 'users_list', sleep_interval: 3) }
91
-
92
- it 'sleeps between requests' do
93
- expect(client).to receive(:users_list).exactly(3).times.and_return(
94
- Slack::Messages::Message.new(response_metadata: { next_cursor: 'next_a' }),
95
- Slack::Messages::Message.new(response_metadata: { next_cursor: 'next_b' }),
96
- Slack::Messages::Message.new
97
- )
98
- expect(cursor).to receive(:sleep).with(3).twice
99
- cursor.to_a
100
- end
101
- end
102
- end
@@ -1,359 +0,0 @@
1
- # frozen_string_literal: true
2
- require 'spec_helper'
3
- require 'faraday/typhoeus'
4
-
5
- RSpec.describe Slack::Web::Client do
6
- before do
7
- Slack::Config.reset
8
- end
9
-
10
- context 'with defaults' do
11
- let(:client) { described_class.new }
12
-
13
- describe '#initialize' do
14
- it 'sets user-agent' do
15
- expect(client.user_agent).to eq Slack::Web::Config.user_agent
16
- expect(client.user_agent).to include Slack::VERSION
17
- end
18
-
19
- (Slack::Web::Config::ATTRIBUTES - [:logger]).each do |key|
20
- it "sets #{key}" do
21
- expect(client.send(key)).to eq Slack::Web::Config.send(key)
22
- end
23
- end
24
- end
25
- end
26
-
27
- context 'with custom settings' do
28
- describe '#initialize' do
29
- Slack::Web::Config::ATTRIBUTES.each do |key|
30
- context key.to_s do
31
- let(:client) { described_class.new(key => 'custom') }
32
-
33
- it "sets #{key}" do
34
- expect(client.send(key)).not_to eq Slack::Web::Config.send(key)
35
- expect(client.send(key)).to eq 'custom'
36
- end
37
- end
38
- end
39
- end
40
- end
41
-
42
- context 'global config' do
43
- after do
44
- described_class.config.reset
45
- end
46
-
47
- let(:client) { described_class.new }
48
-
49
- context 'user-agent' do
50
- before do
51
- described_class.configure do |config|
52
- config.user_agent = 'custom/user-agent'
53
- end
54
- end
55
-
56
- describe '#initialize' do
57
- it 'sets user-agent' do
58
- expect(client.user_agent).to eq 'custom/user-agent'
59
- end
60
-
61
- it 'creates a connection with the custom user-agent' do
62
- expect(client.send(:connection).headers).to eq(
63
- 'Accept' => 'application/json; charset=utf-8',
64
- 'User-Agent' => 'custom/user-agent'
65
- )
66
- end
67
- end
68
- end
69
-
70
- context 'token' do
71
- before do
72
- Slack.configure do |config|
73
- config.token = 'global default'
74
- end
75
- end
76
-
77
- it 'defaults token to global default' do
78
- client = described_class.new
79
- expect(client.token).to eq 'global default'
80
- end
81
-
82
- context 'with web config' do
83
- before do
84
- described_class.configure do |config|
85
- config.token = 'custom web token'
86
- end
87
- end
88
-
89
- it 'overrides token to web config' do
90
- client = described_class.new
91
- expect(client.token).to eq 'custom web token'
92
- end
93
-
94
- it 'overrides token to specific token' do
95
- client = described_class.new(token: 'local token')
96
- expect(client.token).to eq 'local token'
97
- end
98
- end
99
- end
100
-
101
- context 'proxy' do
102
- before do
103
- described_class.configure do |config|
104
- config.proxy = 'http://localhost:8080'
105
- end
106
- end
107
-
108
- describe '#initialize' do
109
- it 'sets proxy' do
110
- expect(client.proxy).to eq 'http://localhost:8080'
111
- end
112
-
113
- it 'creates a connection with the proxy' do
114
- expect(client.send(:connection).proxy.uri.to_s).to eq 'http://localhost:8080'
115
- end
116
- end
117
- end
118
-
119
- context 'SSL options' do
120
- before do
121
- described_class.configure do |config|
122
- config.ca_path = '/ca_path'
123
- config.ca_file = '/ca_file'
124
- end
125
- end
126
-
127
- describe '#initialize' do
128
- it 'sets ca_path and ca_file' do
129
- expect(client.ca_path).to eq '/ca_path'
130
- expect(client.ca_file).to eq '/ca_file'
131
- end
132
-
133
- it 'creates a connection with ssl options' do
134
- ssl = client.send(:connection).ssl
135
- expect(ssl.ca_path).to eq '/ca_path'
136
- expect(ssl.ca_file).to eq '/ca_file'
137
- end
138
- end
139
- end
140
-
141
- context 'logger option' do
142
- let(:logger) { Logger.new(STDOUT) }
143
-
144
- before do
145
- described_class.configure do |config|
146
- config.logger = logger
147
- end
148
- end
149
-
150
- describe '#initialize' do
151
- it 'sets logger' do
152
- expect(client.logger).to eq logger
153
- end
154
-
155
- it 'creates a connection with a logger' do
156
- expect(client.send(:connection).builder.handlers).to include ::Faraday::Response::Logger
157
- end
158
- end
159
- end
160
-
161
- context 'adapter option' do
162
- let(:adapter) { Faraday.default_adapter }
163
- let(:adapter_class) { Faraday::Adapter::NetHttp }
164
-
165
- around do |ex|
166
- previous_adapter = Faraday.default_adapter
167
- # ensure default adapter is set for this spec
168
- Faraday.default_adapter = :net_http
169
- ex.run
170
- Faraday.default_adapter = previous_adapter
171
- end
172
-
173
- context 'default adapter' do
174
- describe '#initialize' do
175
- it 'sets adapter' do
176
- expect(client.adapter).to eq adapter
177
- end
178
-
179
- it 'creates a connection with an adapter' do
180
- expect(client.send(:connection).adapter).to eq adapter_class
181
- end
182
- end
183
- end
184
-
185
- context 'non default adapter' do
186
- let(:adapter) { :typhoeus }
187
- let(:adapter_class) { Faraday::Adapter::Typhoeus }
188
-
189
- before do
190
- described_class.configure do |config|
191
- config.adapter = adapter
192
- end
193
- end
194
-
195
- describe '#initialize' do
196
- it 'sets adapter' do
197
- expect(client.adapter).to eq adapter
198
- end
199
-
200
- it 'creates a connection with an adapter' do
201
- expect(client.send(:connection).adapter).to eq adapter_class
202
- end
203
- end
204
- end
205
- end
206
-
207
- context 'timeout options' do
208
- before do
209
- described_class.configure do |config|
210
- config.timeout = 10
211
- config.open_timeout = 15
212
- end
213
- end
214
-
215
- describe '#initialize' do
216
- it 'sets timeout and open_timeout' do
217
- expect(client.timeout).to eq 10
218
- expect(client.open_timeout).to eq 15
219
- end
220
-
221
- it 'creates a connection with timeout options' do
222
- conn = client.send(:connection)
223
- expect(conn.options.timeout).to eq 10
224
- expect(conn.options.open_timeout).to eq 15
225
- end
226
- end
227
- end
228
-
229
- context 'per-request options' do
230
- it 'applies timeout', vcr: { cassette_name: 'web/rtm_connect', allow_playback_repeats: true } do
231
- # reuse the same connection for the test, otherwise it creates a new one every time
232
- conn = client.send(:connection)
233
- expect(client).to receive(:connection).and_return(conn)
234
-
235
- # get the yielded request to reuse in the next call to
236
- # rtm.connect so that we can examine request.options later
237
- request = nil
238
- response = conn.post do |r|
239
- r.path = 'rtm.connect'
240
- r.headers = {
241
- 'Accept' => ['application/json; charset=utf-8'],
242
- 'Authorization' => ['Bearer <SLACK_API_TOKEN>']
243
- }
244
- request = r
245
- end
246
-
247
- expect(conn).to receive(:post).and_yield(request).and_return(response)
248
-
249
- client.rtm_connect(request: { timeout: 3 })
250
-
251
- expect(request.options.timeout).to eq 3
252
- end
253
- end
254
-
255
- context 'calling undocumented methods' do
256
- let(:client) { described_class.new }
257
-
258
- it 'produces a warning' do
259
- expect(client.logger).to(
260
- receive(:warn).with('The users.admin.setInactive method is undocumented.')
261
- )
262
- expect(client).to receive(:post)
263
- client.users_admin_setInactive(user: 'U092BDCLV')
264
- end
265
- end
266
-
267
- context 'persistent capability' do
268
- describe '#initialize' do
269
- it 'caches the Faraday connection to allow persistent adapters' do
270
- first = client.send(:connection)
271
- second = client.send(:connection)
272
-
273
- expect(first).to equal second
274
- end
275
- end
276
- end
277
-
278
- context 'server failures' do
279
- subject(:request) { client.api_test }
280
-
281
- let(:stub_slack_request) { stub_request(:post, 'https://slack.com/api/api.test') }
282
- let(:exception) do
283
- request
284
- rescue Slack::Web::Api::Errors::ServerError => e
285
- return e
286
- end
287
-
288
- context 'parsing error' do
289
- context 'when the response is not JSON' do
290
- before do
291
- stub_slack_request.to_return(body: '<html></html>', headers: { 'Content-Type' => 'text/html' })
292
- end
293
-
294
- it 'raises ParsingError' do
295
- expect { request }.to raise_error(Slack::Web::Api::Errors::ParsingError).with_message('parsing_error')
296
- expect(exception.response.body).to eq('<html></html>')
297
- expect(exception.cause).to be_a(Faraday::ParsingError)
298
- expect(exception.cause.cause).to be_a(JSON::ParserError)
299
- end
300
- end
301
-
302
- context 'when the response is malformed JSON' do
303
- before { stub_slack_request.to_return(body: '{') }
304
-
305
- it 'raises ParsingError' do
306
- expect { request }.to raise_error(Slack::Web::Api::Errors::ParsingError).with_message('parsing_error')
307
- expect(exception.response.body).to eq('{')
308
- expect(exception.cause).to be_a(Faraday::ParsingError)
309
- expect(exception.cause.cause).to be_a(JSON::ParserError)
310
- end
311
- end
312
- end
313
-
314
- context 'timeout' do
315
- context 'open timeout' do
316
- before { stub_slack_request.to_timeout }
317
-
318
- it 'raises TimoutError' do
319
- expect { request }.to raise_error(Slack::Web::Api::Errors::TimeoutError).with_message('timeout_error')
320
- expect(exception.cause).to be_a(Faraday::ConnectionFailed)
321
- expect(exception.cause.cause).to be_a(Net::OpenTimeout)
322
- end
323
- end
324
-
325
- context 'read timeout' do
326
- before { stub_slack_request.to_raise(Net::ReadTimeout) }
327
-
328
- it 'raises TimeoutError' do
329
- expect { request }.to raise_error(Slack::Web::Api::Errors::TimeoutError).with_message('timeout_error')
330
- expect(exception.cause).to be_a(Faraday::TimeoutError)
331
- expect(exception.cause.cause).to be_a(Net::ReadTimeout)
332
- end
333
- end
334
- end
335
-
336
- context '5xx response' do
337
- context 'with a JSON body' do
338
- before { stub_slack_request.to_return(status: 500, body: '{}') }
339
-
340
- it 'raises UnavailableError' do
341
- expect { request }.to raise_error(Slack::Web::Api::Errors::UnavailableError).with_message('unavailable_error')
342
- expect(exception.response.status).to eq(500)
343
- end
344
- end
345
-
346
- context 'with a HTML response' do
347
- before do
348
- stub_slack_request.to_return(status: 500, body: '<html></html>', headers: { 'Content-Type' => 'text/html' })
349
- end
350
-
351
- it 'raises UnavailableError' do
352
- expect { request }.to raise_error(Slack::Web::Api::Errors::UnavailableError).with_message('unavailable_error')
353
- expect(exception.response.status).to eq(500)
354
- end
355
- end
356
- end
357
- end
358
- end
359
- end
@@ -1,80 +0,0 @@
1
- # frozen_string_literal: true
2
- require 'spec_helper'
3
-
4
- class DummyClient
5
- include Slack::Web::Faraday::Connection
6
- include Slack::Web::Faraday::Request
7
-
8
- attr_reader :token
9
-
10
- def initialize(token)
11
- @token = token
12
- end
13
- end
14
-
15
- RSpec.describe Slack::Web::Faraday::Request do
16
- let(:token) { 'by-the-power-of-grayskull' }
17
- let(:client) { DummyClient.new(token) }
18
-
19
- before do
20
- Slack::Config.reset
21
- end
22
-
23
- context 'authorization' do
24
- let(:path) { '/any-path' }
25
- let(:options) { {} }
26
- let(:connection) { instance_double('Faraday::Connection') }
27
- let(:request) { instance_double('Faraday::Request') }
28
- let(:headers) { instance_double('Faraday::Utils::Headers') }
29
- let(:response) { instance_double('Faraday::Response', body: '') }
30
-
31
- before do
32
- allow(client).to receive(:connection).and_return(connection)
33
- allow(request).to receive(:url).with(path, options)
34
- allow(request).to receive(:path=).with(path)
35
- allow(request).to receive(:headers).and_return(headers)
36
- allow(connection).to receive(:send)
37
- .with(method).and_yield(request).and_return(response)
38
- end
39
-
40
- describe '#get' do
41
- let(:method) { :get }
42
-
43
- it 'sets authorization header' do
44
- expect(headers).to receive(:[]=)
45
- .with('Authorization', "Bearer #{token}")
46
- client.send(method, path, options)
47
- end
48
- end
49
-
50
- describe '#post' do
51
- let(:method) { :post }
52
-
53
- it 'sets authorization header' do
54
- expect(headers).to receive(:[]=)
55
- .with('Authorization', "Bearer #{token}")
56
- client.send(method, path, options)
57
- end
58
- end
59
-
60
- describe '#put' do
61
- let(:method) { :put }
62
-
63
- it 'sets authorization header' do
64
- expect(headers).to receive(:[]=)
65
- .with('Authorization', "Bearer #{token}")
66
- client.send(method, path, options)
67
- end
68
- end
69
-
70
- describe '#delete' do
71
- let(:method) { :delete }
72
-
73
- it 'sets authorization header' do
74
- expect(headers).to receive(:[]=)
75
- .with('Authorization', "Bearer #{token}")
76
- client.send(method, path, options)
77
- end
78
- end
79
- end
80
- end
@@ -1,86 +0,0 @@
1
- # frozen_string_literal: true
2
- require 'spec_helper'
3
-
4
- RSpec.describe Slack::Web::Faraday::Response::RaiseError do
5
- subject(:raise_error_obj) { described_class.new(app) }
6
-
7
- let(:app) { proc {} }
8
- let(:status) { 200 }
9
- let(:response) { nil }
10
- let(:body) { {} }
11
- let(:env) { double status: status, response: response, body: body, success?: true }
12
-
13
- describe '#on_complete' do
14
- context 'with status of 429' do
15
- let(:status) { 429 }
16
- let(:response) { OpenStruct.new(headers: { 'retry-after' => 10 }) }
17
-
18
- it 'raises a TooManyRequestsError' do
19
- expect { raise_error_obj.on_complete(env) }.to(
20
- raise_error(Slack::Web::Api::Errors::TooManyRequestsError)
21
- )
22
- end
23
- end
24
-
25
- context 'with an ok payload in the body' do
26
- let(:body) { { 'ok' => 'true' } }
27
-
28
- it 'is nil' do
29
- expect(raise_error_obj.on_complete(env)).to be_nil
30
- end
31
- end
32
-
33
- context 'with a single known error in the body' do
34
- let(:body) do
35
- {
36
- 'ok' => false,
37
- 'error' => 'already_in_channel',
38
- 'response_metadata' => { 'messages' => [] }
39
- }
40
- end
41
-
42
- it 'raises an error of the matching type with the error message' do
43
- expect { raise_error_obj.on_complete(env) }.to(
44
- raise_error(Slack::Web::Api::Errors::AlreadyInChannel, 'already_in_channel')
45
- )
46
- end
47
- end
48
-
49
- context 'with a single unknown error in the body' do
50
- let(:body) do
51
- {
52
- 'ok' => false,
53
- 'error' => 'unknown_error',
54
- 'response_metadata' => { 'messages' => [] }
55
- }
56
- end
57
-
58
- it 'raises a SlackError with the error message' do
59
- expect { raise_error_obj.on_complete(env) }.to(
60
- raise_error(Slack::Web::Api::Errors::SlackError, 'unknown_error')
61
- )
62
- end
63
- end
64
-
65
- context 'with multiple errors in the body' do
66
- let(:body) do
67
- {
68
- 'ok' => false,
69
- 'errors' => [
70
- { 'error' => 'already_in_channel' },
71
- { 'error' => 'something_else_terrible' }
72
- ]
73
- }
74
- end
75
-
76
- it 'raises a SlackError with the concatenated error messages' do
77
- expect { raise_error_obj.on_complete(env) }.to(
78
- raise_error(
79
- Slack::Web::Api::Errors::SlackError,
80
- 'already_in_channel,something_else_terrible'
81
- )
82
- )
83
- end
84
- end
85
- end
86
- end
data/spec/spec_helper.rb DELETED
@@ -1,30 +0,0 @@
1
- # frozen_string_literal: true
2
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..'))
3
-
4
- require 'rubygems'
5
- require 'rspec'
6
- require 'timecop'
7
-
8
- require 'simplecov'
9
- require 'simplecov-lcov'
10
- SimpleCov::Formatter::LcovFormatter.config do |c|
11
- c.report_with_single_file = true
12
- c.single_report_path = 'coverage/lcov.info'
13
- end
14
- SimpleCov.formatter = SimpleCov::Formatter::LcovFormatter
15
- SimpleCov.start
16
-
17
- require 'slack_ruby_client'
18
-
19
- Dir[File.join(File.dirname(__FILE__), 'support', '**/*.rb')].each do |file|
20
- require file
21
- end
22
-
23
- Slack.configure do |config|
24
- config.token = '<SLACK_API_TOKEN>' # ENV['SLACK_API_TOKEN']
25
- end
26
-
27
- RSpec.configure do |config|
28
- # Enable flags like --only-failures and --next-failure
29
- config.example_status_persistence_file_path = '.rspec_status'
30
- end
@@ -1,35 +0,0 @@
1
- # frozen_string_literal: true
2
- # http://spin.atomicobject.com/2014/07/07/ruby-queue-pop-timeout/
3
- class QueueWithTimeout
4
- def initialize
5
- @mutex = Mutex.new
6
- @queue = []
7
- @recieved = ConditionVariable.new
8
- end
9
-
10
- def push(item)
11
- @mutex.synchronize do
12
- @queue << item
13
- @recieved.signal
14
- end
15
- end
16
-
17
- def <<(item)
18
- push(item)
19
- end
20
-
21
- def pop(non_block = false)
22
- pop_with_timeout(non_block ? 0 : nil)
23
- end
24
-
25
- def pop_with_timeout(timeout = nil)
26
- @mutex.synchronize do
27
- if @queue.empty?
28
- @recieved.wait(@mutex, timeout) if timeout != 0
29
- # if we're still empty after the timeout, raise exception
30
- raise ThreadError, 'queue empty' if @queue.empty?
31
- end
32
- @queue.shift
33
- end
34
- end
35
- end