slack-ruby-client 2.4.0 → 2.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/update_api.yml +1 -1
- data/.rubocop_todo.yml +43 -13
- data/CHANGELOG.md +12 -0
- data/CONTRIBUTING.md +7 -7
- data/Gemfile +1 -0
- data/README.md +46 -28
- data/bin/commands/admin_conversations.rb +21 -0
- data/bin/commands/admin_users_session.rb +1 -1
- data/bin/commands/admin_workflows.rb +3 -1
- data/bin/commands/admin_workflows_triggers_types_permissions.rb +4 -4
- data/bin/commands/assistant_threads.rb +45 -0
- data/bin/commands/bookmarks.rb +1 -0
- data/bin/commands/canvases.rb +4 -4
- data/bin/commands/canvases_access.rb +3 -3
- data/bin/commands/chat.rb +7 -3
- data/bin/commands/conversations.rb +5 -5
- data/bin/commands/conversations_canvases.rb +2 -2
- data/bin/commands/conversations_requestSharedInvite.rb +48 -0
- data/bin/commands/files.rb +2 -1
- data/bin/commands/usergroups.rb +5 -0
- data/bin/commands/usergroups_users.rb +2 -0
- data/examples/files_upload_v2/.env.example +1 -0
- data/examples/files_upload_v2/Gemfile +5 -0
- data/examples/files_upload_v2/README.md +13 -0
- data/examples/files_upload_v2/files_upload_v2.rb +37 -0
- data/examples/oauth_v2/.env.example +4 -0
- data/examples/oauth_v2/Gemfile +7 -0
- data/examples/oauth_v2/README.md +33 -0
- data/examples/oauth_v2/oauth_v2.rb +60 -0
- data/lib/slack/messages/formatting.rb +1 -1
- data/lib/slack/version.rb +1 -1
- data/lib/slack/web/api/endpoints/admin_conversations.rb +35 -0
- data/lib/slack/web/api/endpoints/admin_users_session.rb +2 -3
- data/lib/slack/web/api/endpoints/admin_workflows.rb +5 -1
- data/lib/slack/web/api/endpoints/admin_workflows_triggers_types_permissions.rb +2 -2
- data/lib/slack/web/api/endpoints/assistant_threads.rb +68 -0
- data/lib/slack/web/api/endpoints/bookmarks.rb +2 -0
- data/lib/slack/web/api/endpoints/canvases.rb +2 -2
- data/lib/slack/web/api/endpoints/canvases_access.rb +4 -4
- data/lib/slack/web/api/endpoints/chat.rb +12 -3
- data/lib/slack/web/api/endpoints/conversations.rb +4 -4
- data/lib/slack/web/api/endpoints/conversations_canvases.rb +1 -1
- data/lib/slack/web/api/endpoints/conversations_requestSharedInvite.rb +73 -0
- data/lib/slack/web/api/endpoints/files.rb +3 -1
- data/lib/slack/web/api/endpoints/usergroups.rb +10 -0
- data/lib/slack/web/api/endpoints/usergroups_users.rb +4 -0
- data/lib/slack/web/api/endpoints.rb +4 -0
- data/lib/slack/web/api/errors.rb +48 -4
- data/lib/slack/web/api/helpers/files.rb +87 -0
- data/lib/slack/web/api/helpers.rb +13 -0
- data/lib/slack/web/api/templates/method_spec.erb +4 -3
- data/lib/slack/web/client.rb +1 -0
- data/lib/slack/web/faraday/connection.rb +13 -26
- data/lib/slack/web/faraday/options.rb +24 -0
- data/lib/slack/web/faraday/request.rb +2 -1
- data/lib/slack-ruby-client.rb +2 -0
- data/slack-ruby-client.gemspec +2 -1
- metadata +32 -154
- data/screenshots/create-app.png +0 -0
- data/spec/fixtures/slack/web/429_error.yml +0 -81
- data/spec/fixtures/slack/web/auth_test_error.yml +0 -81
- data/spec/fixtures/slack/web/auth_test_success.yml +0 -81
- data/spec/fixtures/slack/web/conversations_info.yml +0 -167
- data/spec/fixtures/slack/web/conversations_setTopic.yml +0 -84
- data/spec/fixtures/slack/web/conversations_setTopic_one_page.yml +0 -172
- data/spec/fixtures/slack/web/conversations_setTopic_paginated.yml +0 -253
- data/spec/fixtures/slack/web/paginated_users_list.yml +0 -613
- data/spec/fixtures/slack/web/rtm_connect.yml +0 -391
- data/spec/fixtures/slack/web/users_info.yml +0 -214
- data/spec/fixtures/slack/web/users_list.yml +0 -133
- data/spec/fixtures/slack/web/views_open_error.yml +0 -83
- data/spec/integration/integration_spec.rb +0 -207
- data/spec/slack/config_spec.rb +0 -16
- data/spec/slack/events/config_spec.rb +0 -35
- data/spec/slack/events/request_spec.rb +0 -199
- data/spec/slack/messages/formatting_spec.rb +0 -156
- data/spec/slack/real_time/api/message_spec.rb +0 -20
- data/spec/slack/real_time/api/ping_spec.rb +0 -17
- data/spec/slack/real_time/api/typing_spec.rb +0 -19
- data/spec/slack/real_time/client_spec.rb +0 -601
- data/spec/slack/real_time/concurrency/clients/async_spec.rb +0 -16
- data/spec/slack/real_time/concurrency/it_behaves_like_a_realtime_socket.rb +0 -21
- data/spec/slack/real_time/concurrency/with_concurrency_spec.rb +0 -10
- data/spec/slack/real_time/concurrency/without_concurrency_spec.rb +0 -10
- data/spec/slack/real_time/event_handlers/bot_spec.rb +0 -47
- data/spec/slack/real_time/event_handlers/event_handlers_spec.rb +0 -16
- data/spec/slack/real_time/event_handlers/im_spec.rb +0 -51
- data/spec/slack/real_time/event_handlers/private_channel_spec.rb +0 -99
- data/spec/slack/real_time/event_handlers/public_channel_spec.rb +0 -123
- data/spec/slack/real_time/event_handlers/team_spec.rb +0 -63
- data/spec/slack/real_time/event_handlers/user_spec.rb +0 -65
- data/spec/slack/real_time/rtm_connect_spec.rb +0 -14
- data/spec/slack/real_time/stores/store_spec.rb +0 -50
- data/spec/slack/slack_spec.rb +0 -93
- data/spec/slack/version_spec.rb +0 -8
- data/spec/slack/web/api/endpoints/admin_analytics_spec.rb +0 -13
- data/spec/slack/web/api/endpoints/admin_apps_activities_spec.rb +0 -8
- data/spec/slack/web/api/endpoints/admin_apps_approved_spec.rb +0 -8
- data/spec/slack/web/api/endpoints/admin_apps_config_spec.rb +0 -18
- data/spec/slack/web/api/endpoints/admin_apps_requests_spec.rb +0 -13
- data/spec/slack/web/api/endpoints/admin_apps_restricted_spec.rb +0 -8
- data/spec/slack/web/api/endpoints/admin_apps_spec.rb +0 -18
- data/spec/slack/web/api/endpoints/admin_audit_anomaly_allow_spec.rb +0 -8
- data/spec/slack/web/api/endpoints/admin_auth_policy_spec.rb +0 -35
- data/spec/slack/web/api/endpoints/admin_barriers_spec.rb +0 -38
- data/spec/slack/web/api/endpoints/admin_conversations_ekm_spec.rb +0 -8
- data/spec/slack/web/api/endpoints/admin_conversations_restrictAccess_spec.rb +0 -32
- data/spec/slack/web/api/endpoints/admin_conversations_spec.rb +0 -133
- data/spec/slack/web/api/endpoints/admin_emoji_spec.rb +0 -37
- data/spec/slack/web/api/endpoints/admin_functions_permissions_spec.rb +0 -21
- data/spec/slack/web/api/endpoints/admin_functions_spec.rb +0 -13
- data/spec/slack/web/api/endpoints/admin_inviteRequests_approved_spec.rb +0 -8
- data/spec/slack/web/api/endpoints/admin_inviteRequests_denied_spec.rb +0 -8
- data/spec/slack/web/api/endpoints/admin_inviteRequests_spec.rb +0 -18
- data/spec/slack/web/api/endpoints/admin_roles_spec.rb +0 -30
- data/spec/slack/web/api/endpoints/admin_teams_admins_spec.rb +0 -13
- data/spec/slack/web/api/endpoints/admin_teams_owners_spec.rb +0 -13
- data/spec/slack/web/api/endpoints/admin_teams_settings_spec.rb +0 -53
- data/spec/slack/web/api/endpoints/admin_teams_spec.rb +0 -16
- data/spec/slack/web/api/endpoints/admin_usergroups_spec.rb +0 -37
- data/spec/slack/web/api/endpoints/admin_users_session_spec.rb +0 -41
- data/spec/slack/web/api/endpoints/admin_users_spec.rb +0 -67
- data/spec/slack/web/api/endpoints/admin_users_unsupportedVersions_spec.rb +0 -8
- data/spec/slack/web/api/endpoints/admin_workflows_collaborators_spec.rb +0 -24
- data/spec/slack/web/api/endpoints/admin_workflows_permissions_spec.rb +0 -13
- data/spec/slack/web/api/endpoints/admin_workflows_spec.rb +0 -13
- data/spec/slack/web/api/endpoints/admin_workflows_triggers_types_permissions_spec.rb +0 -21
- data/spec/slack/web/api/endpoints/api_spec.rb +0 -8
- data/spec/slack/web/api/endpoints/apps_activities_spec.rb +0 -13
- data/spec/slack/web/api/endpoints/apps_auth_external_spec.rb +0 -13
- data/spec/slack/web/api/endpoints/apps_connections_spec.rb +0 -8
- data/spec/slack/web/api/endpoints/apps_datastore_spec.rb +0 -74
- data/spec/slack/web/api/endpoints/apps_event_authorizations_spec.rb +0 -13
- data/spec/slack/web/api/endpoints/apps_manifest_spec.rb +0 -44
- data/spec/slack/web/api/endpoints/apps_spec.rb +0 -16
- data/spec/slack/web/api/endpoints/auth_spec.rb +0 -8
- data/spec/slack/web/api/endpoints/auth_teams_spec.rb +0 -8
- data/spec/slack/web/api/endpoints/bookmarks_spec.rb +0 -40
- data/spec/slack/web/api/endpoints/bots_spec.rb +0 -8
- data/spec/slack/web/api/endpoints/calls_participants_spec.rb +0 -24
- data/spec/slack/web/api/endpoints/calls_spec.rb +0 -31
- data/spec/slack/web/api/endpoints/canvases_access_spec.rb +0 -21
- data/spec/slack/web/api/endpoints/canvases_sections_spec.rb +0 -16
- data/spec/slack/web/api/endpoints/canvases_spec.rb +0 -21
- data/spec/slack/web/api/endpoints/chat_scheduledMessages_spec.rb +0 -8
- data/spec/slack/web/api/endpoints/chat_spec.rb +0 -134
- data/spec/slack/web/api/endpoints/conversations_canvases_spec.rb +0 -13
- data/spec/slack/web/api/endpoints/conversations_externalInvitePermissions_spec.rb +0 -19
- data/spec/slack/web/api/endpoints/conversations_spec.rb +0 -8
- data/spec/slack/web/api/endpoints/custom_specs/auth_spec.rb +0 -27
- data/spec/slack/web/api/endpoints/custom_specs/chat_spec.rb +0 -206
- data/spec/slack/web/api/endpoints/custom_specs/conversations_spec.rb +0 -13
- data/spec/slack/web/api/endpoints/custom_specs/dialog_spec.rb +0 -40
- data/spec/slack/web/api/endpoints/custom_specs/users_spec.rb +0 -38
- data/spec/slack/web/api/endpoints/custom_specs/views_spec.rb +0 -112
- data/spec/slack/web/api/endpoints/dialog_spec.rb +0 -14
- data/spec/slack/web/api/endpoints/dnd_spec.rb +0 -18
- data/spec/slack/web/api/endpoints/emoji_spec.rb +0 -8
- data/spec/slack/web/api/endpoints/files_comments_spec.rb +0 -16
- data/spec/slack/web/api/endpoints/files_remote_spec.rb +0 -24
- data/spec/slack/web/api/endpoints/files_spec.rb +0 -57
- data/spec/slack/web/api/endpoints/functions_distributions_permissions_spec.rb +0 -10
- data/spec/slack/web/api/endpoints/functions_spec.rb +0 -28
- data/spec/slack/web/api/endpoints/functions_workflows_steps_responses_spec.rb +0 -13
- data/spec/slack/web/api/endpoints/functions_workflows_steps_spec.rb +0 -13
- data/spec/slack/web/api/endpoints/migration_spec.rb +0 -13
- data/spec/slack/web/api/endpoints/oauth_spec.rb +0 -8
- data/spec/slack/web/api/endpoints/oauth_v2_spec.rb +0 -16
- data/spec/slack/web/api/endpoints/openid_connect_spec.rb +0 -8
- data/spec/slack/web/api/endpoints/pins_spec.rb +0 -23
- data/spec/slack/web/api/endpoints/reactions_spec.rb +0 -24
- data/spec/slack/web/api/endpoints/reminders_spec.rb +0 -31
- data/spec/slack/web/api/endpoints/rtm_spec.rb +0 -8
- data/spec/slack/web/api/endpoints/search_spec.rb +0 -23
- data/spec/slack/web/api/endpoints/stars_spec.rb +0 -8
- data/spec/slack/web/api/endpoints/team_billing_spec.rb +0 -8
- data/spec/slack/web/api/endpoints/team_externalTeams_spec.rb +0 -13
- data/spec/slack/web/api/endpoints/team_preferences_spec.rb +0 -8
- data/spec/slack/web/api/endpoints/team_profile_spec.rb +0 -8
- data/spec/slack/web/api/endpoints/team_spec.rb +0 -8
- data/spec/slack/web/api/endpoints/tooling_tokens_spec.rb +0 -13
- data/spec/slack/web/api/endpoints/usergroups_spec.rb +0 -28
- data/spec/slack/web/api/endpoints/usergroups_users_spec.rb +0 -21
- data/spec/slack/web/api/endpoints/users_admin_spec.rb +0 -18
- data/spec/slack/web/api/endpoints/users_discoverableContacts_spec.rb +0 -13
- data/spec/slack/web/api/endpoints/users_prefs_spec.rb +0 -8
- data/spec/slack/web/api/endpoints/users_profile_spec.rb +0 -14
- data/spec/slack/web/api/endpoints/users_spec.rb +0 -8
- data/spec/slack/web/api/endpoints/views_spec.rb +0 -65
- data/spec/slack/web/api/endpoints/workflows_spec.rb +0 -34
- data/spec/slack/web/api/endpoints/workflows_triggers_permissions_spec.rb +0 -31
- data/spec/slack/web/api/error_spec.rb +0 -14
- data/spec/slack/web/api/errors/slack_error_spec.rb +0 -33
- data/spec/slack/web/api/mixins/conversations_list_spec.rb +0 -21
- data/spec/slack/web/api/mixins/conversations_spec.rb +0 -45
- data/spec/slack/web/api/mixins/users_spec.rb +0 -52
- data/spec/slack/web/api/options_spec.rb +0 -69
- data/spec/slack/web/api/pagination/cursor_spec.rb +0 -102
- data/spec/slack/web/client_spec.rb +0 -359
- data/spec/slack/web/faraday/request_spec.rb +0 -80
- data/spec/slack/web/faraday/response/raise_error_spec.rb +0 -86
- data/spec/spec_helper.rb +0 -30
- data/spec/support/queue_with_timeout.rb +0 -35
- data/spec/support/real_time/concurrency/mock.rb +0 -31
- data/spec/support/real_time/connected_client.rb +0 -21
- data/spec/support/real_time/event.rb +0 -12
- data/spec/support/real_time/loaded_client.rb +0 -120
- data/spec/support/token.rb +0 -11
- data/spec/support/vcr.rb +0 -45
@@ -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
|
@@ -1,31 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
module Slack
|
3
|
-
module RealTime
|
4
|
-
module Concurrency
|
5
|
-
module Mock
|
6
|
-
class WebSocket
|
7
|
-
end
|
8
|
-
|
9
|
-
class Socket < ::Slack::RealTime::Socket
|
10
|
-
def self.close; end
|
11
|
-
|
12
|
-
def start_async(client)
|
13
|
-
reactor = Thread.new {}
|
14
|
-
client.run_loop
|
15
|
-
reactor
|
16
|
-
end
|
17
|
-
|
18
|
-
def send_data(message)
|
19
|
-
driver.send(message)
|
20
|
-
end
|
21
|
-
|
22
|
-
protected
|
23
|
-
|
24
|
-
def connect
|
25
|
-
@driver = WebSocket.new(url, nil, options)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
RSpec.shared_context 'connected client' do |opts|
|
3
|
-
let(:client) { Slack::RealTime::Client.new(opts || {}) }
|
4
|
-
let(:ws) { double(Slack::RealTime::Concurrency::Mock::WebSocket) }
|
5
|
-
let(:url) { 'wss://cerberus-xxxx.lb.slack-msgs.com/websocket/uid' }
|
6
|
-
let(:socket) { double(Slack::RealTime::Socket, connected?: true) }
|
7
|
-
|
8
|
-
before do
|
9
|
-
Slack::RealTime.configure do |config|
|
10
|
-
config.concurrency = Slack::RealTime::Concurrency::Mock
|
11
|
-
config.store_class = (opts || {})[:store_class] || Slack::RealTime::Stores::Store
|
12
|
-
end
|
13
|
-
allow(Slack::RealTime::Socket).to(
|
14
|
-
receive(:new).with(url, { ping: 30, logger: Slack::Logger.default }).and_return(socket)
|
15
|
-
)
|
16
|
-
allow(socket).to receive(:start_sync)
|
17
|
-
allow(socket).to receive(:connect!)
|
18
|
-
allow(ws).to receive(:on)
|
19
|
-
client.start!
|
20
|
-
end
|
21
|
-
end
|