slack-ruby-client 0.14.6 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/FUNDING.yml +1 -0
- data/.rubocop.yml +15 -3
- data/.rubocop_todo.yml +110 -38
- data/.travis.yml +2 -5
- data/CHANGELOG.md +42 -0
- data/CONTRIBUTING.md +19 -8
- data/Dangerfile +1 -1
- data/Gemfile +1 -2
- data/LICENSE.md +1 -1
- data/README.md +38 -36
- data/RELEASING.md +1 -1
- data/UPGRADING.md +62 -2
- data/bin/commands/admin_analytics.rb +16 -0
- data/bin/commands/admin_apps.rb +26 -2
- data/bin/commands/admin_apps_requests.rb +1 -0
- data/bin/commands/admin_auth_policy.rb +39 -0
- data/bin/commands/admin_barriers.rb +47 -0
- data/bin/commands/admin_conversations.rb +155 -3
- data/bin/commands/admin_conversations_ekm.rb +17 -0
- data/bin/commands/admin_conversations_restrictAccess.rb +37 -0
- data/bin/commands/admin_conversations_whitelist.rb +37 -0
- data/bin/commands/admin_emoji.rb +1 -1
- data/bin/commands/admin_teams.rb +1 -1
- data/bin/commands/admin_usergroups.rb +48 -0
- data/bin/commands/admin_users.rb +3 -2
- data/bin/commands/admin_users_session.rb +62 -0
- data/bin/commands/api.rb +0 -1
- data/bin/commands/apps_connections.rb +13 -0
- data/bin/commands/apps_event_authorizations.rb +16 -0
- data/bin/commands/apps_manifest.rb +51 -0
- data/bin/commands/auth_teams.rb +16 -0
- data/bin/commands/bots.rb +1 -0
- data/bin/commands/calls.rb +52 -0
- data/bin/commands/calls_participants.rb +25 -0
- data/bin/commands/channels.rb +1 -155
- data/bin/commands/chat.rb +17 -12
- data/bin/commands/chat_scheduledMessages.rb +1 -0
- data/bin/commands/conversations.rb +71 -3
- data/bin/commands/dnd.rb +2 -0
- data/bin/commands/files.rb +6 -4
- data/bin/commands/files_remote.rb +2 -2
- data/bin/commands/groups.rb +1 -162
- data/bin/commands/im.rb +1 -63
- data/bin/commands/migration.rb +1 -0
- data/bin/commands/mpim.rb +1 -61
- data/bin/commands/oauth.rb +0 -13
- data/bin/commands/oauth_v2.rb +13 -1
- data/bin/commands/openid_connect.rb +27 -0
- data/bin/commands/pins.rb +2 -4
- data/bin/commands/reactions.rb +1 -0
- data/bin/commands/reminders.rb +6 -0
- data/bin/commands/rtm.rb +2 -2
- data/bin/commands/search.rb +4 -0
- data/bin/commands/stars.rb +7 -6
- data/bin/commands/team.rb +3 -0
- data/bin/commands/team_billing.rb +13 -0
- data/bin/commands/team_preferences.rb +13 -0
- data/bin/commands/tooling_tokens.rb +14 -0
- data/bin/commands/usergroups.rb +5 -0
- data/bin/commands/usergroups_users.rb +2 -0
- data/bin/commands/users.rb +4 -2
- data/bin/commands/users_profile.rb +5 -5
- data/bin/commands/views.rb +2 -2
- data/bin/commands/workflows.rb +38 -0
- data/bin/commands.rb +17 -8
- data/lib/slack/config.rb +1 -2
- data/lib/slack/events/request.rb +10 -4
- data/lib/slack/messages/message.rb +0 -4
- data/lib/slack/real_time/client.rb +6 -6
- data/lib/slack/real_time/concurrency/async.rb +7 -11
- data/lib/slack/real_time/concurrency.rb +0 -2
- data/lib/slack/real_time/config.rb +5 -14
- data/lib/slack/real_time/models/base.rb +0 -4
- data/lib/slack/real_time/socket.rb +3 -4
- data/lib/slack/real_time/stores/base.rb +4 -7
- data/lib/slack/real_time/stores/starter.rb +6 -3
- data/lib/slack/real_time/stores/store.rb +5 -0
- data/lib/slack/version.rb +1 -1
- data/lib/slack/web/api/endpoints/admin_analytics.rb +28 -0
- data/lib/slack/web/api/endpoints/admin_apps.rb +42 -6
- data/lib/slack/web/api/endpoints/admin_apps_approved.rb +2 -2
- data/lib/slack/web/api/endpoints/admin_apps_requests.rb +4 -2
- data/lib/slack/web/api/endpoints/admin_apps_restricted.rb +2 -2
- data/lib/slack/web/api/endpoints/admin_auth_policy.rb +72 -0
- data/lib/slack/web/api/endpoints/admin_barriers.rb +82 -0
- data/lib/slack/web/api/endpoints/admin_conversations.rb +234 -4
- data/lib/slack/web/api/endpoints/admin_conversations_ekm.rb +35 -0
- data/lib/slack/web/api/endpoints/admin_conversations_restrictAccess.rb +61 -0
- data/lib/slack/web/api/endpoints/admin_conversations_whitelist.rb +64 -0
- data/lib/slack/web/api/endpoints/admin_emoji.rb +10 -10
- data/lib/slack/web/api/endpoints/admin_inviteRequests.rb +7 -7
- data/lib/slack/web/api/endpoints/admin_inviteRequests_approved.rb +3 -3
- data/lib/slack/web/api/endpoints/admin_inviteRequests_denied.rb +2 -2
- data/lib/slack/web/api/endpoints/admin_teams.rb +7 -7
- data/lib/slack/web/api/endpoints/admin_teams_admins.rb +2 -2
- data/lib/slack/web/api/endpoints/admin_teams_owners.rb +2 -2
- data/lib/slack/web/api/endpoints/admin_teams_settings.rb +5 -5
- data/lib/slack/web/api/endpoints/admin_usergroups.rb +77 -0
- data/lib/slack/web/api/endpoints/admin_users.rb +23 -23
- data/lib/slack/web/api/endpoints/admin_users_session.rb +97 -3
- data/lib/slack/web/api/endpoints/api.rb +1 -3
- data/lib/slack/web/api/endpoints/apps.rb +2 -2
- data/lib/slack/web/api/endpoints/apps_connections.rb +21 -0
- data/lib/slack/web/api/endpoints/apps_event_authorizations.rb +34 -0
- data/lib/slack/web/api/endpoints/apps_manifest.rb +75 -0
- data/lib/slack/web/api/endpoints/auth.rb +1 -1
- data/lib/slack/web/api/endpoints/auth_teams.rb +33 -0
- data/lib/slack/web/api/endpoints/bots.rb +3 -1
- data/lib/slack/web/api/endpoints/calls.rb +83 -0
- data/lib/slack/web/api/endpoints/calls_participants.rb +42 -0
- data/lib/slack/web/api/endpoints/channels.rb +1 -245
- data/lib/slack/web/api/endpoints/chat.rb +76 -66
- data/lib/slack/web/api/endpoints/chat_scheduledMessages.rb +5 -3
- data/lib/slack/web/api/endpoints/conversations.rb +149 -41
- data/lib/slack/web/api/endpoints/dialog.rb +2 -2
- data/lib/slack/web/api/endpoints/dnd.rb +6 -3
- data/lib/slack/web/api/endpoints/files.rb +21 -17
- data/lib/slack/web/api/endpoints/files_comments.rb +1 -1
- data/lib/slack/web/api/endpoints/files_remote.rb +23 -23
- data/lib/slack/web/api/endpoints/groups.rb +0 -253
- data/lib/slack/web/api/endpoints/im.rb +0 -101
- data/lib/slack/web/api/endpoints/migration.rb +4 -2
- data/lib/slack/web/api/endpoints/mpim.rb +0 -96
- data/lib/slack/web/api/endpoints/oauth.rb +5 -30
- data/lib/slack/web/api/endpoints/oauth_v2.rb +24 -6
- data/lib/slack/web/api/endpoints/openid_connect.rb +42 -0
- data/lib/slack/web/api/endpoints/pins.rb +7 -12
- data/lib/slack/web/api/endpoints/reactions.rb +16 -14
- data/lib/slack/web/api/endpoints/reminders.rb +17 -5
- data/lib/slack/web/api/endpoints/rtm.rb +10 -10
- data/lib/slack/web/api/endpoints/search.rb +27 -13
- data/lib/slack/web/api/endpoints/stars.rb +13 -11
- data/lib/slack/web/api/endpoints/team.rb +11 -5
- data/lib/slack/web/api/endpoints/team_billing.rb +21 -0
- data/lib/slack/web/api/endpoints/team_preferences.rb +21 -0
- data/lib/slack/web/api/endpoints/team_profile.rb +1 -1
- data/lib/slack/web/api/endpoints/tooling_tokens.rb +24 -0
- data/lib/slack/web/api/endpoints/usergroups.rb +26 -16
- data/lib/slack/web/api/endpoints/usergroups_users.rb +9 -5
- data/lib/slack/web/api/endpoints/users.rb +20 -18
- data/lib/slack/web/api/endpoints/users_profile.rb +7 -7
- data/lib/slack/web/api/endpoints/views.rb +13 -13
- data/lib/slack/web/api/endpoints/workflows.rb +61 -0
- data/lib/slack/web/api/endpoints.rb +35 -18
- data/lib/slack/web/api/errors/server_error.rb +37 -0
- data/lib/slack/web/api/errors/too_many_requests_error.rb +1 -4
- data/lib/slack/web/api/errors.rb +486 -12
- data/lib/slack/web/api/mixins/{channels.id.rb → conversations.id.rb} +3 -5
- data/lib/slack/web/api/mixins/ids.id.rb +3 -5
- data/lib/slack/web/api/mixins/users.id.rb +1 -3
- data/lib/slack/web/api/mixins.rb +1 -2
- data/lib/slack/web/api/patches/{chat.6.block-kit-support.patch → chat.1.patch} +25 -24
- data/lib/slack/web/api/templates/endpoints.erb +1 -2
- data/lib/slack/web/api/templates/method.erb +4 -1
- data/lib/slack/web/api/templates/method_spec.erb +1 -1
- data/lib/slack/web/config.rb +2 -0
- data/lib/slack/web/faraday/connection.rb +23 -20
- data/lib/slack/web/faraday/request.rb +2 -1
- data/lib/slack/web/faraday/response/raise_error.rb +12 -1
- data/lib/slack/web/faraday/response/wrap_error.rb +24 -0
- data/lib/slack/web/pagination/cursor.rb +3 -7
- data/lib/slack-ruby-client.rb +4 -4
- data/lib/tasks/web.rake +11 -3
- data/slack-ruby-client.gemspec +6 -7
- data/spec/fixtures/slack/web/429_error.yml +50 -54
- data/spec/fixtures/slack/web/auth_test_error.yml +51 -18
- data/spec/fixtures/slack/web/auth_test_success.yml +50 -26
- data/spec/fixtures/slack/web/conversations_info.yml +167 -0
- data/spec/fixtures/slack/web/conversations_setTopic.yml +84 -0
- data/spec/fixtures/slack/web/conversations_setTopic_one_page.yml +172 -0
- data/spec/fixtures/slack/web/conversations_setTopic_paginated.yml +253 -0
- data/spec/fixtures/slack/web/paginated_users_list.yml +501 -69
- data/spec/fixtures/slack/web/rtm_connect.yml +267 -30
- data/spec/fixtures/slack/web/rtm_start.yml +771 -60
- data/spec/fixtures/slack/web/users_info.yml +153 -69
- data/spec/fixtures/slack/web/users_list.yml +102 -41
- data/spec/fixtures/slack/web/views_open_error.yml +49 -42
- data/spec/slack/events/request_spec.rb +13 -8
- data/spec/slack/real_time/client_spec.rb +35 -22
- data/spec/slack/real_time/concurrency/with_concurrency_spec.rb +10 -0
- data/spec/slack/real_time/concurrency/without_concurrency_spec.rb +10 -0
- data/spec/slack/real_time/event_handlers/bot_spec.rb +1 -1
- data/spec/slack/real_time/event_handlers/channel_spec.rb +1 -1
- data/spec/slack/real_time/event_handlers/im_spec.rb +5 -5
- data/spec/slack/real_time/event_handlers/user_spec.rb +2 -2
- data/spec/slack/real_time/rtm_connect_spec.rb +1 -1
- data/spec/slack/real_time/rtm_start_spec.rb +1 -1
- data/spec/slack/slack_spec.rb +3 -1
- data/spec/slack/web/api/endpoints/admin_analytics_spec.rb +13 -0
- data/spec/slack/web/api/endpoints/admin_apps_spec.rb +10 -0
- data/spec/slack/web/api/endpoints/admin_auth_policy_spec.rb +35 -0
- data/spec/slack/web/api/endpoints/admin_barriers_spec.rb +38 -0
- data/spec/slack/web/api/endpoints/{apps_permissions_scopes_spec.rb → admin_conversations_ekm_spec.rb} +1 -1
- data/spec/slack/web/api/endpoints/admin_conversations_restrictAccess_spec.rb +32 -0
- data/spec/slack/web/api/endpoints/admin_conversations_spec.rb +85 -0
- data/spec/slack/web/api/endpoints/admin_emoji_spec.rb +6 -6
- data/spec/slack/web/api/endpoints/admin_teams_settings_spec.rb +10 -10
- data/spec/slack/web/api/endpoints/admin_teams_spec.rb +2 -2
- data/spec/slack/web/api/endpoints/admin_usergroups_spec.rb +37 -0
- data/spec/slack/web/api/endpoints/admin_users_session_spec.rb +28 -0
- data/spec/slack/web/api/endpoints/admin_users_spec.rb +15 -23
- data/spec/slack/web/api/endpoints/{apps_permissions_resources_spec.rb → apps_connections_spec.rb} +1 -1
- data/spec/slack/web/api/endpoints/apps_event_authorizations_spec.rb +13 -0
- data/spec/slack/web/api/endpoints/apps_manifest_spec.rb +36 -0
- data/spec/slack/web/api/endpoints/apps_spec.rb +2 -2
- data/spec/slack/web/api/endpoints/auth_teams_spec.rb +8 -0
- data/spec/slack/web/api/endpoints/calls_participants_spec.rb +24 -0
- data/spec/slack/web/api/endpoints/calls_spec.rb +31 -0
- data/spec/slack/web/api/endpoints/custom_specs/auth_spec.rb +4 -6
- data/spec/slack/web/api/endpoints/custom_specs/conversations_spec.rb +13 -0
- data/spec/slack/web/api/endpoints/custom_specs/users_spec.rb +2 -2
- data/spec/slack/web/api/endpoints/dnd_spec.rb +0 -5
- data/spec/slack/web/api/endpoints/files_comments_spec.rb +2 -2
- data/spec/slack/web/api/endpoints/files_remote_spec.rb +3 -3
- data/spec/slack/web/api/endpoints/files_spec.rb +4 -4
- data/spec/slack/web/api/endpoints/oauth_spec.rb +0 -22
- data/spec/slack/web/api/endpoints/oauth_v2_spec.rb +6 -3
- data/spec/slack/web/api/endpoints/openid_connect_spec.rb +8 -0
- data/spec/slack/web/api/endpoints/pins_spec.rb +1 -4
- data/spec/slack/web/api/endpoints/reactions_spec.rb +3 -3
- data/spec/slack/web/api/endpoints/reminders_spec.rb +2 -2
- data/spec/slack/web/api/endpoints/team_billing_spec.rb +8 -0
- data/spec/slack/web/api/endpoints/team_preferences_spec.rb +8 -0
- data/spec/slack/web/api/endpoints/tooling_tokens_spec.rb +13 -0
- data/spec/slack/web/api/endpoints/usergroups_users_spec.rb +2 -2
- data/spec/slack/web/api/endpoints/workflows_spec.rb +26 -0
- data/spec/slack/web/api/error_spec.rb +5 -7
- data/spec/slack/web/api/errors/slack_error_spec.rb +21 -26
- data/spec/slack/web/api/mixins/conversations_list_spec.rb +21 -0
- data/spec/slack/web/api/mixins/{channels_spec.rb → conversations_spec.rb} +8 -8
- data/spec/slack/web/api/mixins/users_spec.rb +1 -1
- data/spec/slack/web/api/pagination/cursor_spec.rb +1 -3
- data/spec/slack/web/client_spec.rb +123 -1
- data/spec/slack/web/faraday/request_spec.rb +80 -0
- data/spec/slack/web/faraday/response/raise_error_spec.rb +8 -6
- data/spec/spec_helper.rb +1 -1
- data/spec/support/real_time/connected_client.rb +1 -7
- data/spec/support/vcr.rb +36 -1
- metadata +95 -173
- data/examples/hi_real_time/Gemfile +0 -6
- data/examples/hi_real_time/hi.gif +0 -0
- data/examples/hi_real_time/hi.rb +0 -41
- data/examples/hi_real_time_async_celluloid/Gemfile +0 -7
- data/examples/hi_real_time_async_celluloid/Procfile +0 -2
- data/examples/hi_real_time_async_celluloid/hi.rb +0 -39
- data/examples/hi_real_time_async_eventmachine/Gemfile +0 -7
- data/examples/hi_real_time_async_eventmachine/Procfile +0 -2
- data/examples/hi_real_time_async_eventmachine/hi.rb +0 -39
- data/lib/slack/real_time/concurrency/celluloid.rb +0 -142
- data/lib/slack/real_time/concurrency/eventmachine.rb +0 -85
- data/lib/slack/web/api/mixins/channels.id.json +0 -20
- data/lib/slack/web/api/mixins/groups.id.json +0 -20
- data/lib/slack/web/api/mixins/groups.id.rb +0 -27
- data/lib/slack/web/api/patches/chat.1.text-attachments-required.patch +0 -13
- data/lib/slack/web/api/patches/chat.2.attachments-json.patch +0 -17
- data/lib/slack/web/api/patches/chat.3.update-attachments-support.patch +0 -21
- data/lib/slack/web/api/patches/chat.4.postEphemeral-attachments-support.patch +0 -17
- data/lib/slack/web/api/patches/chat.5.postEphemeral-text-or-attachments.patch +0 -15
- data/spec/fixtures/slack/web/503_error.yml +0 -14
- data/spec/fixtures/slack/web/channels_info.yml +0 -46
- data/spec/fixtures/slack/web/groups_info.yml +0 -43
- data/spec/slack/real_time/concurrency/celluloid_spec.rb +0 -116
- data/spec/slack/real_time/concurrency/eventmachine_spec.rb +0 -57
- data/spec/slack/web/api/endpoints/apps_permissions_spec.rb +0 -16
- data/spec/slack/web/api/endpoints/apps_permissions_users_spec.rb +0 -19
- data/spec/slack/web/api/endpoints/conversations_spec.rb +0 -101
- data/spec/slack/web/api/endpoints/custom_specs/channels_spec.rb +0 -13
- data/spec/slack/web/api/endpoints/custom_specs/groups_spec.rb +0 -13
- data/spec/slack/web/api/endpoints/im_spec.rb +0 -39
- data/spec/slack/web/api/endpoints/mpim_spec.rb +0 -39
- data/spec/slack/web/api/endpoints/views_spec.rb +0 -29
- data/spec/slack/web/api/errors/service_unavailable_spec.rb +0 -17
- data/spec/slack/web/api/mixins/groups_spec.rb +0 -43
@@ -5,34 +5,29 @@ RSpec.describe Slack::Web::Api::Errors::SlackError do
|
|
5
5
|
let(:client) { Slack::Web::Client.new }
|
6
6
|
|
7
7
|
it 'provides access to the response object', vcr: { cassette_name: 'web/auth_test_error' } do
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
expect(e.response_metadata).to be_nil
|
17
|
-
end
|
8
|
+
client.auth_test
|
9
|
+
raise 'Expected to receive Slack::Web::Api::Errors::SlackError.'
|
10
|
+
rescue described_class => e
|
11
|
+
expect(e.response).not_to be_nil
|
12
|
+
expect(e.response.status).to eq 200
|
13
|
+
expect(e.message).to eql 'not_authed'
|
14
|
+
expect(e.error).to eql 'not_authed'
|
15
|
+
expect(e.response_metadata).to be_nil
|
18
16
|
end
|
19
17
|
|
20
18
|
it 'provides access to any response_metadata', vcr: { cassette_name: 'web/views_open_error' } do
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
'
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
]
|
35
|
-
)
|
36
|
-
end
|
19
|
+
client.views_open(trigger_id: 'trigger_id', view: {})
|
20
|
+
raise 'Expected to receive Slack::Web::Api::Errors::SlackError.'
|
21
|
+
rescue described_class => e
|
22
|
+
expect(e.response).not_to be_nil
|
23
|
+
expect(e.response.status).to eq 200
|
24
|
+
expect(e.message).to eql 'invalid_arguments'
|
25
|
+
expect(e.error).to eql 'invalid_arguments'
|
26
|
+
expect(e.response_metadata).to eq(
|
27
|
+
'messages' => [
|
28
|
+
'[ERROR] failed to match all allowed schemas [json-pointer:/view]',
|
29
|
+
'[ERROR] missing required field: type [json-pointer:/view]'
|
30
|
+
]
|
31
|
+
)
|
37
32
|
end
|
38
33
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
RSpec.describe Slack::Web::Client do
|
5
|
+
context 'conversations_setTopic' do
|
6
|
+
it 'does not invoke conversations_list', vcr: { cassette_name: 'web/conversations_setTopic' } do
|
7
|
+
rc = subject.conversations_setTopic({ channel: 'C019CV63UTC', topic: 'new topic' })
|
8
|
+
expect(rc.channel.topic.value).to eq 'new topic'
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'resolves IDs via conversations_list', vcr: { cassette_name: 'web/conversations_setTopic_one_page' } do
|
12
|
+
rc = subject.conversations_setTopic({ channel: '#1', topic: 'new topic' })
|
13
|
+
expect(rc.channel.topic.value).to eq 'new topic'
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'paginates to resolve IDs', vcr: { cassette_name: 'web/conversations_setTopic_paginated' } do
|
17
|
+
rc = subject.conversations_setTopic({ channel: '#topic', topic: 'new topic' })
|
18
|
+
expect(rc.channel.topic.value).to eq 'new topic'
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -1,19 +1,19 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
|
-
RSpec.describe Slack::Web::Api::Mixins::
|
5
|
-
subject(:
|
4
|
+
RSpec.describe Slack::Web::Api::Mixins::Conversations do
|
5
|
+
subject(:conversations) do
|
6
6
|
klass.new
|
7
7
|
end
|
8
8
|
|
9
9
|
let(:klass) do
|
10
10
|
Class.new do
|
11
|
-
include Slack::Web::Api::Mixins::
|
11
|
+
include Slack::Web::Api::Mixins::Conversations
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
15
|
before do
|
16
|
-
allow(
|
16
|
+
allow(conversations).to receive(:conversations_list).and_yield(
|
17
17
|
Slack::Messages::Message.new(
|
18
18
|
'channels' => [{
|
19
19
|
'id' => 'CDEADBEEF',
|
@@ -23,19 +23,19 @@ RSpec.describe Slack::Web::Api::Mixins::Channels do
|
|
23
23
|
)
|
24
24
|
end
|
25
25
|
|
26
|
-
|
26
|
+
describe '#conversations_id' do
|
27
27
|
it 'leaves channels specified by ID alone' do
|
28
|
-
expect(
|
28
|
+
expect(conversations.conversations_id(channel: 'C123456')).to(
|
29
29
|
eq('ok' => true, 'channel' => { 'id' => 'C123456' })
|
30
30
|
)
|
31
31
|
end
|
32
32
|
it 'translates a channel that starts with a #' do
|
33
|
-
expect(
|
33
|
+
expect(conversations.conversations_id(channel: '#general')).to(
|
34
34
|
eq('ok' => true, 'channel' => { 'id' => 'CDEADBEEF' })
|
35
35
|
)
|
36
36
|
end
|
37
37
|
it 'fails with an exception' do
|
38
|
-
expect {
|
38
|
+
expect { conversations.conversations_id(channel: '#invalid') }.to(
|
39
39
|
raise_error(Slack::Web::Api::Errors::SlackError, 'channel_not_found')
|
40
40
|
)
|
41
41
|
end
|
@@ -30,7 +30,7 @@ RSpec.describe Slack::Web::Api::Pagination::Cursor do
|
|
30
30
|
cursor.to_a
|
31
31
|
end
|
32
32
|
context 'with rate limiting' do
|
33
|
-
let(:error) { Slack::Web::Api::Errors::TooManyRequestsError.new(
|
33
|
+
let(:error) { Slack::Web::Api::Errors::TooManyRequestsError.new(OpenStruct.new(headers: { 'retry-after' => 9 })) }
|
34
34
|
|
35
35
|
context 'with default max retries' do
|
36
36
|
it 'sleeps after a TooManyRequestsError' do
|
@@ -43,7 +43,6 @@ RSpec.describe Slack::Web::Api::Pagination::Cursor do
|
|
43
43
|
expect(client).to(
|
44
44
|
receive(:users_list).with(limit: 100, cursor: 'next').ordered.and_raise(error)
|
45
45
|
)
|
46
|
-
expect(error).to receive(:retry_after).once.ordered.and_return(9)
|
47
46
|
expect(cursor).to receive(:sleep).once.ordered.with(9)
|
48
47
|
expect(client).to(
|
49
48
|
receive(:users_list)
|
@@ -67,7 +66,6 @@ RSpec.describe Slack::Web::Api::Pagination::Cursor do
|
|
67
66
|
expect(client).to(
|
68
67
|
receive(:users_list).with(limit: 100, cursor: 'next').exactly(5).times.and_raise(error)
|
69
68
|
)
|
70
|
-
expect(error).to receive(:retry_after).exactly(4).times.and_return(9)
|
71
69
|
expect(cursor).to receive(:sleep).exactly(4).times.with(9)
|
72
70
|
expect { cursor.to_a }.to raise_error(error)
|
73
71
|
end
|
@@ -150,6 +150,50 @@ RSpec.describe Slack::Web::Client do
|
|
150
150
|
end
|
151
151
|
end
|
152
152
|
|
153
|
+
context 'adapter option' do
|
154
|
+
let(:adapter) { Faraday.default_adapter }
|
155
|
+
let(:adapter_class) { Faraday::Adapter::NetHttp }
|
156
|
+
|
157
|
+
around do |ex|
|
158
|
+
previous_adapter = Faraday.default_adapter
|
159
|
+
# ensure default adapter is set for this spec
|
160
|
+
Faraday.default_adapter = :net_http
|
161
|
+
ex.run
|
162
|
+
Faraday.default_adapter = previous_adapter
|
163
|
+
end
|
164
|
+
|
165
|
+
context 'default adapter' do
|
166
|
+
describe '#initialize' do
|
167
|
+
it 'sets adapter' do
|
168
|
+
expect(client.adapter).to eq adapter
|
169
|
+
end
|
170
|
+
it 'creates a connection with an adapter' do
|
171
|
+
expect(client.send(:connection).adapter).to eq adapter_class
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
context 'non default adapter' do
|
177
|
+
let(:adapter) { :typhoeus }
|
178
|
+
let(:adapter_class) { Faraday::Adapter::Typhoeus }
|
179
|
+
|
180
|
+
before do
|
181
|
+
described_class.configure do |config|
|
182
|
+
config.adapter = adapter
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
describe '#initialize' do
|
187
|
+
it 'sets adapter' do
|
188
|
+
expect(client.adapter).to eq adapter
|
189
|
+
end
|
190
|
+
it 'creates a connection with an adapter' do
|
191
|
+
expect(client.send(:connection).adapter).to eq adapter_class
|
192
|
+
end
|
193
|
+
end
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
153
197
|
context 'timeout options' do
|
154
198
|
before do
|
155
199
|
described_class.configure do |config|
|
@@ -182,7 +226,10 @@ RSpec.describe Slack::Web::Client do
|
|
182
226
|
request = nil
|
183
227
|
response = conn.post do |r|
|
184
228
|
r.path = 'rtm.start'
|
185
|
-
r.
|
229
|
+
r.headers = {
|
230
|
+
'Accept' => ['application/json; charset=utf-8'],
|
231
|
+
'Authorization' => ['Bearer <SLACK_API_TOKEN>']
|
232
|
+
}
|
186
233
|
request = r
|
187
234
|
end
|
188
235
|
|
@@ -205,5 +252,80 @@ RSpec.describe Slack::Web::Client do
|
|
205
252
|
client.users_admin_setInactive(user: 'U092BDCLV')
|
206
253
|
end
|
207
254
|
end
|
255
|
+
|
256
|
+
context 'persistent capability' do
|
257
|
+
describe '#initialize' do
|
258
|
+
it 'caches the Faraday connection to allow persistent adapters' do
|
259
|
+
first = client.send(:connection)
|
260
|
+
second = client.send(:connection)
|
261
|
+
|
262
|
+
expect(first).to equal second
|
263
|
+
end
|
264
|
+
end
|
265
|
+
end
|
266
|
+
|
267
|
+
context 'server failures' do
|
268
|
+
subject(:request) { client.api_test }
|
269
|
+
|
270
|
+
let(:stub_slack_request) { stub_request(:post, 'https://slack.com/api/api.test') }
|
271
|
+
let(:exception) do
|
272
|
+
request
|
273
|
+
rescue Slack::Web::Api::Errors::ServerError => e
|
274
|
+
return e
|
275
|
+
end
|
276
|
+
|
277
|
+
context 'parsing error' do
|
278
|
+
before { stub_slack_request.to_return(body: '<html></html>') }
|
279
|
+
|
280
|
+
it 'raises ParsingError' do
|
281
|
+
expect { request }.to raise_error(Slack::Web::Api::Errors::ParsingError).with_message('parsing_error')
|
282
|
+
expect(exception.response.body).to eq('<html></html>')
|
283
|
+
expect(exception.cause).to be_a(Faraday::ParsingError)
|
284
|
+
expect(exception.cause.cause.cause).to be_a(JSON::ParserError)
|
285
|
+
end
|
286
|
+
end
|
287
|
+
|
288
|
+
context 'timeout' do
|
289
|
+
context 'open timeout' do
|
290
|
+
before { stub_slack_request.to_timeout }
|
291
|
+
|
292
|
+
it 'raises TimoutError' do
|
293
|
+
expect { request }.to raise_error(Slack::Web::Api::Errors::TimeoutError).with_message('timeout_error')
|
294
|
+
expect(exception.cause).to be_a(Faraday::ConnectionFailed)
|
295
|
+
expect(exception.cause.cause).to be_a(Net::OpenTimeout)
|
296
|
+
end
|
297
|
+
end
|
298
|
+
|
299
|
+
context 'read timeout' do
|
300
|
+
before { stub_slack_request.to_raise(Net::ReadTimeout) }
|
301
|
+
|
302
|
+
it 'raises TimeoutError' do
|
303
|
+
expect { request }.to raise_error(Slack::Web::Api::Errors::TimeoutError).with_message('timeout_error')
|
304
|
+
expect(exception.cause).to be_a(Faraday::TimeoutError)
|
305
|
+
expect(exception.cause.cause).to be_a(Net::ReadTimeout)
|
306
|
+
end
|
307
|
+
end
|
308
|
+
end
|
309
|
+
|
310
|
+
context '5xx response' do
|
311
|
+
context 'with a JSON body' do
|
312
|
+
before { stub_slack_request.to_return(status: 500, body: '{}') }
|
313
|
+
|
314
|
+
it 'raises UnavailableError' do
|
315
|
+
expect { request }.to raise_error(Slack::Web::Api::Errors::UnavailableError).with_message('unavailable_error')
|
316
|
+
expect(exception.response.status).to eq(500)
|
317
|
+
end
|
318
|
+
end
|
319
|
+
|
320
|
+
context 'with a HTML response' do
|
321
|
+
before { stub_slack_request.to_return(status: 500, body: '<html></html>') }
|
322
|
+
|
323
|
+
it 'raises UnavailableError' do
|
324
|
+
expect { request }.to raise_error(Slack::Web::Api::Errors::UnavailableError).with_message('unavailable_error')
|
325
|
+
expect(exception.response.status).to eq(500)
|
326
|
+
end
|
327
|
+
end
|
328
|
+
end
|
329
|
+
end
|
208
330
|
end
|
209
331
|
end
|
@@ -0,0 +1,80 @@
|
|
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
|
@@ -2,16 +2,18 @@
|
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
4
|
RSpec.describe Slack::Web::Faraday::Response::RaiseError do
|
5
|
-
subject(:raise_error_obj) { described_class.new }
|
5
|
+
subject(:raise_error_obj) { described_class.new(app) }
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
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
12
|
|
13
|
+
describe '#on_complete' do
|
13
14
|
context 'with status of 429' do
|
14
15
|
let(:status) { 429 }
|
16
|
+
let(:response) { OpenStruct.new(headers: { 'retry-after' => 10 }) }
|
15
17
|
|
16
18
|
it 'raises a TooManyRequestsError' do
|
17
19
|
expect { raise_error_obj.on_complete(env) }.to(
|
data/spec/spec_helper.rb
CHANGED
@@ -12,7 +12,7 @@ Dir[File.join(File.dirname(__FILE__), 'support', '**/*.rb')].each do |file|
|
|
12
12
|
end
|
13
13
|
|
14
14
|
Slack.configure do |config|
|
15
|
-
config.token = ENV['SLACK_API_TOKEN']
|
15
|
+
config.token = '<SLACK_API_TOKEN>' # ENV['SLACK_API_TOKEN']
|
16
16
|
end
|
17
17
|
|
18
18
|
RSpec.configure do |config|
|
@@ -2,13 +2,7 @@
|
|
2
2
|
RSpec.shared_context 'connected client' do |opts|
|
3
3
|
let(:client) { Slack::RealTime::Client.new(opts || {}) }
|
4
4
|
let(:ws) { double(Slack::RealTime::Concurrency::Mock::WebSocket) }
|
5
|
-
let(:url)
|
6
|
-
if Slack::RealTime.config.store_class == Slack::RealTime::Stores::Store
|
7
|
-
'wss://ms173.slack-msgs.com/websocket/lqcUiAvrKTP-uuid='
|
8
|
-
else
|
9
|
-
'wss://mpmulti-w5tz.slack-msgs.com/websocket/uid'
|
10
|
-
end
|
11
|
-
end
|
5
|
+
let(:url) { 'wss://cerberus-xxxx.lb.slack-msgs.com/websocket/uid' }
|
12
6
|
let(:socket) { double(Slack::RealTime::Socket, connected?: true) }
|
13
7
|
|
14
8
|
before do
|
data/spec/support/vcr.rb
CHANGED
@@ -5,6 +5,41 @@ require 'webmock/rspec'
|
|
5
5
|
VCR.configure do |config|
|
6
6
|
config.cassette_library_dir = 'spec/fixtures/slack'
|
7
7
|
config.hook_into :webmock
|
8
|
-
# config.default_cassette_options = { record: :new_episodes }
|
9
8
|
config.configure_rspec_metadata!
|
9
|
+
if ENV.key?('SLACK_API_TOKEN')
|
10
|
+
config.filter_sensitive_data('<SLACK_API_TOKEN>') do
|
11
|
+
ENV['SLACK_API_TOKEN']
|
12
|
+
end
|
13
|
+
end
|
14
|
+
config.before_record do |i|
|
15
|
+
i.response.body.force_encoding('UTF-8')
|
16
|
+
end
|
17
|
+
config.register_request_matcher :client_headers do |recorded, actual|
|
18
|
+
authorizations = ENV.key?('SLACK_API_TOKEN') ? actual.headers['Authorization'].map do |auth|
|
19
|
+
auth.gsub(ENV['SLACK_API_TOKEN'], '<SLACK_API_TOKEN>')
|
20
|
+
end : actual.headers['Authorization']
|
21
|
+
actual.headers['Accept'] == recorded.headers['Accept'] &&
|
22
|
+
authorizations == recorded.headers['Authorization']
|
23
|
+
end
|
24
|
+
config.default_cassette_options = {
|
25
|
+
match_requests_on: %i[method uri body client_headers]
|
26
|
+
# record: :new_episodes
|
27
|
+
}
|
28
|
+
end
|
29
|
+
|
30
|
+
module VCR
|
31
|
+
module Errors
|
32
|
+
class UnhandledHTTPRequestError
|
33
|
+
private
|
34
|
+
|
35
|
+
# Force unhandled HTTP error reports to include the headers
|
36
|
+
# for our custom matcher `client_headers`.
|
37
|
+
#
|
38
|
+
# This patch can be removed if https://github.com/vcr/vcr/issues/912
|
39
|
+
# is ever resolved.
|
40
|
+
def match_request_on_headers?
|
41
|
+
true
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
10
45
|
end
|