slack-ruby-client 0.7.2 → 1.0.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.
- checksums.yaml +5 -5
- data/.github/FUNDING.yml +1 -0
- data/.gitignore +2 -0
- data/.gitmodules +1 -1
- data/.rubocop.yml +37 -1
- data/.rubocop_todo.yml +130 -47
- data/.travis.yml +17 -13
- data/CHANGELOG.md +254 -43
- data/CONTRIBUTING.md +26 -15
- data/Dangerfile +3 -0
- data/Gemfile +13 -2
- data/LICENSE.md +1 -1
- data/README.md +287 -63
- data/RELEASING.md +22 -14
- data/Rakefile +2 -1
- data/UPGRADING.md +129 -5
- data/bin/commands/admin_analytics.rb +16 -0
- data/bin/commands/admin_apps.rb +51 -0
- data/bin/commands/admin_apps_approved.rb +17 -0
- data/bin/commands/admin_apps_requests.rb +17 -0
- data/bin/commands/admin_apps_restricted.rb +17 -0
- data/bin/commands/admin_auth_policy.rb +39 -0
- data/bin/commands/admin_barriers.rb +47 -0
- data/bin/commands/admin_conversations.rb +169 -0
- 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 +54 -0
- data/bin/commands/admin_inviteRequests.rb +36 -0
- data/bin/commands/admin_inviteRequests_approved.rb +16 -0
- data/bin/commands/admin_inviteRequests_denied.rb +16 -0
- data/bin/commands/admin_teams.rb +27 -0
- data/bin/commands/admin_teams_admins.rb +16 -0
- data/bin/commands/admin_teams_owners.rb +16 -0
- data/bin/commands/admin_teams_settings.rb +64 -0
- data/bin/commands/admin_usergroups.rb +48 -0
- data/bin/commands/admin_users.rb +98 -0
- data/bin/commands/admin_users_session.rb +78 -0
- data/bin/commands/api.rb +3 -3
- data/bin/commands/apps.rb +15 -0
- 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/apps_permissions.rb +23 -0
- data/bin/commands/apps_permissions_resources.rb +15 -0
- data/bin/commands/apps_permissions_scopes.rb +13 -0
- data/bin/commands/apps_permissions_users.rb +26 -0
- data/bin/commands/auth.rb +12 -2
- data/bin/commands/auth_teams.rb +16 -0
- data/bin/commands/bots.rb +15 -0
- data/bin/commands/calls.rb +52 -0
- data/bin/commands/calls_participants.rb +25 -0
- data/bin/commands/channels.rb +6 -132
- data/bin/commands/chat.rb +127 -20
- data/bin/commands/chat_scheduledMessages.rb +19 -0
- data/bin/commands/conversations.rb +253 -0
- data/bin/commands/dialog.rb +15 -0
- data/bin/commands/dnd.rb +12 -9
- data/bin/commands/emoji.rb +3 -2
- data/bin/commands/files.rb +47 -31
- data/bin/commands/files_comments.rb +3 -23
- data/bin/commands/files_remote.rb +78 -0
- data/bin/commands/groups.rb +1 -154
- data/bin/commands/im.rb +1 -48
- data/bin/commands/migration.rb +16 -0
- data/bin/commands/mpim.rb +1 -48
- data/bin/commands/oauth.rb +4 -2
- data/bin/commands/oauth_v2.rb +29 -0
- data/bin/commands/openid_connect.rb +27 -0
- data/bin/commands/pins.rb +9 -12
- data/bin/commands/reactions.rb +17 -15
- data/bin/commands/reminders.rb +17 -10
- data/bin/commands/rtm.rb +19 -4
- data/bin/commands/search.rb +17 -12
- data/bin/commands/stars.rb +12 -9
- data/bin/commands/team.rb +23 -8
- data/bin/commands/team_billing.rb +13 -0
- data/bin/commands/team_preferences.rb +13 -0
- data/bin/commands/team_profile.rb +14 -0
- data/bin/commands/tooling_tokens.rb +14 -0
- data/bin/commands/usergroups.rb +23 -17
- data/bin/commands/usergroups_users.rb +7 -4
- data/bin/commands/users.rb +83 -27
- data/bin/commands/users_admin.rb +29 -0
- data/bin/commands/users_prefs.rb +13 -0
- data/bin/commands/users_profile.rb +27 -0
- data/bin/commands/views.rb +48 -0
- data/bin/commands/workflows.rb +38 -0
- data/bin/commands.rb +47 -5
- data/bin/slack +3 -4
- data/examples/hi_real_time_and_web/Gemfile +1 -0
- data/examples/hi_real_time_and_web/hi.rb +8 -4
- data/examples/{hi_real_time_async_celluloid → hi_real_time_async_async}/Gemfile +2 -1
- data/examples/{hi_real_time_async_celluloid → hi_real_time_async_async}/Procfile +0 -0
- data/examples/{hi_real_time_async_celluloid → hi_real_time_async_async}/hi.rb +13 -8
- data/examples/hi_web/Gemfile +1 -0
- data/examples/hi_web/hi.rb +2 -1
- data/examples/new_ticket/Gemfile +1 -0
- data/examples/new_ticket/new_ticket.rb +3 -2
- data/lib/slack/config.rb +2 -2
- data/lib/slack/events/config.rb +32 -0
- data/lib/slack/events/request.rb +72 -0
- data/lib/slack/logger.rb +6 -5
- data/lib/slack/messages/formatting.rb +4 -4
- data/lib/slack/messages/message.rb +6 -4
- data/lib/slack/real_time/api/message.rb +3 -1
- data/lib/slack/real_time/api/message_id.rb +1 -0
- data/lib/slack/real_time/api/ping.rb +5 -2
- data/lib/slack/real_time/api/templates/event_handler.erb +1 -1
- data/lib/slack/real_time/api/typing.rb +3 -1
- data/lib/slack/real_time/client.rb +116 -36
- data/lib/slack/real_time/concurrency/async.rb +138 -0
- data/lib/slack/real_time/concurrency.rb +2 -2
- data/lib/slack/real_time/config.rb +17 -19
- data/lib/slack/real_time/models/base.rb +3 -3
- data/lib/slack/real_time/models/bot.rb +1 -0
- data/lib/slack/real_time/models/channel.rb +1 -0
- data/lib/slack/real_time/models/group.rb +1 -0
- data/lib/slack/real_time/models/im.rb +1 -0
- data/lib/slack/real_time/models/team.rb +1 -0
- data/lib/slack/real_time/models/user.rb +1 -0
- data/lib/slack/real_time/models.rb +8 -7
- data/lib/slack/real_time/socket.rb +51 -23
- data/lib/slack/real_time/stores/base.rb +6 -9
- data/lib/slack/real_time/stores/starter.rb +143 -69
- data/lib/slack/real_time/stores/store.rb +160 -82
- data/lib/slack/real_time/stores.rb +4 -3
- data/lib/slack/version.rb +2 -1
- data/lib/slack/web/api/endpoints/admin_analytics.rb +28 -0
- data/lib/slack/web/api/endpoints/admin_apps.rb +78 -0
- data/lib/slack/web/api/endpoints/admin_apps_approved.rb +35 -0
- data/lib/slack/web/api/endpoints/admin_apps_requests.rb +35 -0
- data/lib/slack/web/api/endpoints/admin_apps_restricted.rb +35 -0
- 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 +260 -0
- 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 +88 -0
- data/lib/slack/web/api/endpoints/admin_inviteRequests.rb +61 -0
- data/lib/slack/web/api/endpoints/admin_inviteRequests_approved.rb +33 -0
- data/lib/slack/web/api/endpoints/admin_inviteRequests_denied.rb +33 -0
- data/lib/slack/web/api/endpoints/admin_teams.rb +50 -0
- data/lib/slack/web/api/endpoints/admin_teams_admins.rb +34 -0
- data/lib/slack/web/api/endpoints/admin_teams_owners.rb +34 -0
- data/lib/slack/web/api/endpoints/admin_teams_settings.rb +99 -0
- data/lib/slack/web/api/endpoints/admin_usergroups.rb +77 -0
- data/lib/slack/web/api/endpoints/admin_users.rb +163 -0
- data/lib/slack/web/api/endpoints/admin_users_session.rb +122 -0
- data/lib/slack/web/api/endpoints/api.rb +4 -5
- data/lib/slack/web/api/endpoints/apps.rb +27 -0
- 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/apps_permissions.rb +36 -0
- data/lib/slack/web/api/endpoints/apps_permissions_resources.rb +31 -0
- data/lib/slack/web/api/endpoints/apps_permissions_scopes.rb +21 -0
- data/lib/slack/web/api/endpoints/apps_permissions_users.rb +50 -0
- data/lib/slack/web/api/endpoints/auth.rb +14 -2
- data/lib/slack/web/api/endpoints/auth_teams.rb +33 -0
- data/lib/slack/web/api/endpoints/bots.rb +25 -0
- 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 +8 -201
- data/lib/slack/web/api/endpoints/chat.rb +252 -42
- data/lib/slack/web/api/endpoints/chat_scheduledMessages.rb +40 -0
- data/lib/slack/web/api/endpoints/conversations.rb +422 -0
- data/lib/slack/web/api/endpoints/dialog.rb +33 -0
- data/lib/slack/web/api/endpoints/dnd.rb +17 -12
- data/lib/slack/web/api/endpoints/emoji.rb +3 -2
- data/lib/slack/web/api/endpoints/files.rb +82 -43
- data/lib/slack/web/api/endpoints/files_comments.rb +4 -36
- data/lib/slack/web/api/endpoints/files_remote.rb +127 -0
- data/lib/slack/web/api/endpoints/groups.rb +1 -235
- data/lib/slack/web/api/endpoints/im.rb +1 -73
- data/lib/slack/web/api/endpoints/migration.rb +28 -0
- data/lib/slack/web/api/endpoints/mpim.rb +1 -72
- data/lib/slack/web/api/endpoints/oauth.rb +9 -10
- data/lib/slack/web/api/endpoints/oauth_v2.rb +48 -0
- data/lib/slack/web/api/endpoints/openid_connect.rb +42 -0
- data/lib/slack/web/api/endpoints/pins.rb +14 -23
- data/lib/slack/web/api/endpoints/presence.rb +1 -1
- data/lib/slack/web/api/endpoints/reactions.rb +43 -34
- data/lib/slack/web/api/endpoints/reminders.rb +28 -15
- data/lib/slack/web/api/endpoints/rtm.rb +29 -8
- data/lib/slack/web/api/endpoints/search.rb +39 -24
- data/lib/slack/web/api/endpoints/stars.rb +30 -22
- data/lib/slack/web/api/endpoints/team.rb +34 -11
- 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 +23 -0
- data/lib/slack/web/api/endpoints/tooling_tokens.rb +24 -0
- data/lib/slack/web/api/endpoints/usergroups.rb +43 -32
- data/lib/slack/web/api/endpoints/usergroups_users.rb +14 -9
- data/lib/slack/web/api/endpoints/users.rb +104 -19
- data/lib/slack/web/api/endpoints/users_admin.rb +49 -0
- data/lib/slack/web/api/endpoints/users_prefs.rb +21 -0
- data/lib/slack/web/api/endpoints/users_profile.rb +44 -0
- data/lib/slack/web/api/endpoints/views.rb +97 -0
- data/lib/slack/web/api/endpoints/workflows.rb +61 -0
- data/lib/slack/web/api/endpoints.rb +111 -29
- data/lib/slack/web/api/error.rb +2 -8
- data/lib/slack/web/api/errors/server_error.rb +37 -0
- data/lib/slack/web/api/errors/slack_error.rb +29 -0
- data/lib/slack/web/api/errors/too_many_requests_error.rb +21 -0
- data/lib/slack/web/api/errors.rb +1040 -0
- data/lib/slack/web/api/mixins/conversations.id.rb +25 -0
- data/lib/slack/web/api/mixins/ids.id.rb +24 -0
- data/lib/slack/web/api/mixins/users.id.rb +6 -7
- data/lib/slack/web/api/mixins/users.search.rb +39 -36
- data/lib/slack/web/api/mixins.rb +4 -4
- data/lib/slack/web/api/patches/chat.1.patch +70 -0
- data/lib/slack/web/api/patches/dialog.1.open-json-support.patch +17 -0
- data/lib/slack/web/api/patches/views.1.view-json.patch +40 -0
- data/lib/slack/web/api/patches/views.1.views-published.patch +16 -0
- data/lib/slack/web/api/templates/command.erb +5 -3
- data/lib/slack/web/api/templates/commands.erb +2 -1
- data/lib/slack/web/api/templates/endpoints.erb +5 -5
- data/lib/slack/web/api/templates/errors.erb +20 -0
- data/lib/slack/web/api/templates/method.erb +26 -4
- data/lib/slack/web/api/templates/method_spec.erb +3 -2
- data/lib/slack/web/client.rb +2 -1
- data/lib/slack/web/config.rb +21 -10
- data/lib/slack/web/faraday/connection.rb +25 -16
- data/lib/slack/web/faraday/request.rb +4 -1
- data/lib/slack/web/faraday/response/raise_error.rb +19 -1
- data/lib/slack/web/faraday/response/wrap_error.rb +24 -0
- data/lib/slack/web/pagination/cursor.rb +48 -0
- data/lib/slack-ruby-client.rb +40 -26
- data/lib/slack.rb +1 -0
- data/lib/slack_ruby_client.rb +1 -0
- data/lib/tasks/git.rake +2 -1
- data/lib/tasks/real_time.rake +16 -6
- data/lib/tasks/update.rake +1 -0
- data/lib/tasks/web.rake +42 -10
- data/screenshots/create-app.png +0 -0
- data/slack-ruby-client.gemspec +11 -9
- data/spec/fixtures/slack/web/429_error.yml +50 -52
- 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 +613 -0
- data/spec/fixtures/slack/web/rtm_connect.yml +307 -0
- 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 +83 -0
- data/spec/integration/integration_spec.rb +116 -48
- data/spec/slack/config_spec.rb +2 -0
- data/spec/slack/events/config_spec.rb +33 -0
- data/spec/slack/events/request_spec.rb +184 -0
- data/spec/slack/messages/formatting_spec.rb +25 -14
- data/spec/slack/real_time/api/message_spec.rb +6 -1
- data/spec/slack/real_time/api/ping_spec.rb +2 -0
- data/spec/slack/real_time/api/typing_spec.rb +5 -1
- data/spec/slack/real_time/client_spec.rb +465 -141
- data/spec/slack/real_time/concurrency/it_behaves_like_a_realtime_socket.rb +21 -0
- 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 +7 -4
- data/spec/slack/real_time/event_handlers/channel_spec.rb +10 -7
- data/spec/slack/real_time/event_handlers/event_handlers_spec.rb +3 -2
- data/spec/slack/real_time/event_handlers/group_spec.rb +5 -4
- data/spec/slack/real_time/event_handlers/im_spec.rb +9 -8
- data/spec/slack/real_time/event_handlers/team_spec.rb +8 -4
- data/spec/slack/real_time/event_handlers/user_spec.rb +7 -4
- data/spec/slack/real_time/rtm_connect_spec.rb +14 -0
- data/spec/slack/real_time/rtm_start_spec.rb +2 -1
- data/spec/slack/real_time/store_spec.rb +2 -1
- data/spec/slack/slack_spec.rb +42 -8
- data/spec/slack/version_spec.rb +2 -1
- data/spec/slack/web/api/endpoints/admin_analytics_spec.rb +13 -0
- data/spec/slack/web/api/endpoints/admin_apps_approved_spec.rb +8 -0
- data/spec/slack/web/api/endpoints/admin_apps_requests_spec.rb +8 -0
- data/spec/slack/web/api/endpoints/admin_apps_restricted_spec.rb +8 -0
- data/spec/slack/web/api/endpoints/admin_apps_spec.rb +18 -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/admin_conversations_ekm_spec.rb +8 -0
- data/spec/slack/web/api/endpoints/admin_conversations_restrictAccess_spec.rb +32 -0
- data/spec/slack/web/api/endpoints/admin_conversations_spec.rb +98 -0
- data/spec/slack/web/api/endpoints/admin_emoji_spec.rb +37 -0
- data/spec/slack/web/api/endpoints/admin_inviteRequests_approved_spec.rb +8 -0
- data/spec/slack/web/api/endpoints/admin_inviteRequests_denied_spec.rb +8 -0
- data/spec/slack/web/api/endpoints/admin_inviteRequests_spec.rb +18 -0
- data/spec/slack/web/api/endpoints/admin_teams_admins_spec.rb +13 -0
- data/spec/slack/web/api/endpoints/admin_teams_owners_spec.rb +13 -0
- data/spec/slack/web/api/endpoints/admin_teams_settings_spec.rb +53 -0
- data/spec/slack/web/api/endpoints/admin_teams_spec.rb +16 -0
- data/spec/slack/web/api/endpoints/admin_usergroups_spec.rb +37 -0
- data/spec/slack/web/api/endpoints/admin_users_session_spec.rb +41 -0
- data/spec/slack/web/api/endpoints/admin_users_spec.rb +67 -0
- data/spec/slack/web/api/endpoints/api_spec.rb +1 -0
- data/spec/slack/web/api/endpoints/apps_connections_spec.rb +8 -0
- 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 +16 -0
- data/spec/slack/web/api/endpoints/auth_teams_spec.rb +8 -0
- data/spec/slack/web/api/endpoints/bots_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/chat_scheduledMessages_spec.rb +8 -0
- data/spec/slack/web/api/endpoints/custom_specs/auth_spec.rb +11 -4
- data/spec/slack/web/api/endpoints/custom_specs/chat_spec.rb +140 -24
- data/spec/slack/web/api/endpoints/custom_specs/conversations_spec.rb +13 -0
- data/spec/slack/web/api/endpoints/custom_specs/dialog_spec.rb +36 -0
- data/spec/slack/web/api/endpoints/custom_specs/users_spec.rb +22 -7
- data/spec/slack/web/api/endpoints/custom_specs/views_spec.rb +95 -0
- data/spec/slack/web/api/endpoints/dnd_spec.rb +4 -3
- data/spec/slack/web/api/endpoints/emoji_spec.rb +1 -0
- data/spec/slack/web/api/endpoints/files_comments_spec.rb +3 -21
- data/spec/slack/web/api/endpoints/files_remote_spec.rb +24 -0
- data/spec/slack/web/api/endpoints/files_spec.rb +17 -5
- data/spec/slack/web/api/endpoints/migration_spec.rb +13 -0
- data/spec/slack/web/api/endpoints/oauth_spec.rb +1 -11
- data/spec/slack/web/api/endpoints/oauth_v2_spec.rb +16 -0
- data/spec/slack/web/api/endpoints/openid_connect_spec.rb +8 -0
- data/spec/slack/web/api/endpoints/pins_spec.rb +1 -0
- data/spec/slack/web/api/endpoints/reactions_spec.rb +8 -1
- data/spec/slack/web/api/endpoints/reminders_spec.rb +3 -2
- data/spec/slack/web/api/endpoints/rtm_spec.rb +1 -0
- data/spec/slack/web/api/endpoints/search_spec.rb +1 -0
- data/spec/slack/web/api/endpoints/stars_spec.rb +1 -0
- 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/team_profile_spec.rb +8 -0
- data/spec/slack/web/api/endpoints/team_spec.rb +1 -0
- data/spec/slack/web/api/endpoints/tooling_tokens_spec.rb +13 -0
- data/spec/slack/web/api/endpoints/usergroups_spec.rb +1 -0
- data/spec/slack/web/api/endpoints/usergroups_users_spec.rb +3 -2
- data/spec/slack/web/api/endpoints/users_admin_spec.rb +18 -0
- data/spec/slack/web/api/endpoints/users_prefs_spec.rb +8 -0
- data/spec/slack/web/api/endpoints/users_profile_spec.rb +8 -0
- data/spec/slack/web/api/endpoints/workflows_spec.rb +26 -0
- data/spec/slack/web/api/error_spec.rb +7 -7
- data/spec/slack/web/api/errors/slack_error_spec.rb +33 -0
- data/spec/slack/web/api/mixins/conversations_list_spec.rb +21 -0
- data/spec/slack/web/api/mixins/conversations_spec.rb +43 -0
- data/spec/slack/web/api/mixins/users_spec.rb +30 -17
- data/spec/slack/web/api/pagination/cursor_spec.rb +98 -0
- data/spec/slack/web/client_spec.rb +211 -14
- data/spec/slack/web/faraday/request_spec.rb +80 -0
- data/spec/slack/web/faraday/response/raise_error_spec.rb +86 -0
- data/spec/spec_helper.rb +9 -2
- data/spec/support/queue_with_timeout.rb +6 -5
- data/spec/support/real_time/concurrency/mock.rb +2 -2
- data/spec/support/real_time/connected_client.rb +7 -2
- data/spec/support/real_time/event.rb +1 -0
- data/spec/support/token.rb +1 -0
- data/spec/support/vcr.rb +37 -1
- metadata +250 -130
- data/examples/hi_real_time/Gemfile +0 -5
- data/examples/hi_real_time/hi.gif +0 -0
- data/examples/hi_real_time/hi.rb +0 -37
- data/examples/hi_real_time_async/Gemfile +0 -5
- data/examples/hi_real_time_async/hi.rb +0 -29
- data/examples/hi_real_time_async_eventmachine/Gemfile +0 -6
- data/examples/hi_real_time_async_eventmachine/Procfile +0 -2
- data/examples/hi_real_time_async_eventmachine/hi.rb +0 -36
- data/lib/slack/real_time/concurrency/celluloid.rb +0 -100
- data/lib/slack/real_time/concurrency/eventmachine.rb +0 -60
- data/lib/slack/web/api/mixins/channels.id.json +0 -20
- data/lib/slack/web/api/mixins/channels.id.rb +0 -26
- data/lib/slack/web/api/mixins/groups.id.json +0 -20
- data/lib/slack/web/api/mixins/groups.id.rb +0 -26
- 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 -20
- data/screenshots/register-bot.png +0 -0
- 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 -35
- data/spec/slack/real_time/concurrency/eventmachine_spec.rb +0 -50
- data/spec/slack/web/api/endpoints/custom_specs/channels_spec.rb +0 -11
- data/spec/slack/web/api/endpoints/custom_specs/groups_spec.rb +0 -11
- data/spec/slack/web/api/endpoints/im_spec.rb +0 -30
- data/spec/slack/web/api/endpoints/mpim_spec.rb +0 -30
- data/spec/slack/web/api/mixins/channels_spec.rb +0 -31
- data/spec/slack/web/api/mixins/groups_spec.rb +0 -31
@@ -1,224 +1,468 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'spec_helper'
|
2
3
|
|
3
|
-
RSpec.describe Slack::RealTime::Client
|
4
|
+
RSpec.describe Slack::RealTime::Client do
|
4
5
|
let(:ws) { double(Slack::RealTime::Concurrency::Mock::WebSocket, on: true) }
|
5
|
-
|
6
|
+
|
6
7
|
before do
|
8
|
+
# supports passing tests in CI even with an actual SLACK_API_TOKEN set
|
7
9
|
@token = ENV.delete('SLACK_API_TOKEN')
|
8
10
|
Slack::Config.reset
|
9
11
|
Slack::RealTime::Config.reset
|
10
12
|
Slack::RealTime.configure do |config|
|
13
|
+
config.token = '<SLACK_API_TOKEN>'
|
11
14
|
config.concurrency = Slack::RealTime::Concurrency::Mock
|
12
15
|
end
|
13
16
|
end
|
17
|
+
|
14
18
|
after do
|
15
19
|
ENV['SLACK_API_TOKEN'] = @token if @token
|
16
20
|
end
|
21
|
+
|
17
22
|
context 'token' do
|
18
|
-
before do
|
19
|
-
Slack.configure do |config|
|
20
|
-
config.token = 'global default'
|
21
|
-
end
|
22
|
-
end
|
23
23
|
it 'defaults token to global default' do
|
24
|
-
client =
|
25
|
-
expect(client.token).to eq '
|
26
|
-
expect(client.web_client.token).to eq '
|
24
|
+
client = described_class.new
|
25
|
+
expect(client.token).to eq '<SLACK_API_TOKEN>'
|
26
|
+
expect(client.web_client.token).to eq '<SLACK_API_TOKEN>'
|
27
27
|
end
|
28
28
|
context 'with real time config' do
|
29
29
|
before do
|
30
|
-
|
30
|
+
described_class.configure do |config|
|
31
31
|
config.token = 'custom real time token'
|
32
32
|
end
|
33
33
|
end
|
34
|
+
|
34
35
|
it 'overrides token to real time config' do
|
35
|
-
client =
|
36
|
+
client = described_class.new
|
36
37
|
expect(client.token).to eq 'custom real time token'
|
37
38
|
expect(client.web_client.token).to eq 'custom real time token'
|
38
39
|
end
|
39
40
|
it 'overrides token to specific token' do
|
40
|
-
client =
|
41
|
+
client = described_class.new(token: 'local token')
|
41
42
|
expect(client.token).to eq 'local token'
|
42
43
|
expect(client.web_client.token).to eq 'local token'
|
43
44
|
end
|
44
45
|
end
|
45
46
|
end
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
47
|
+
|
48
|
+
context 'websocket_ping_timer' do
|
49
|
+
context 'with defaults' do
|
50
|
+
let(:client) { described_class.new }
|
51
|
+
|
52
|
+
it 'defaults to websocket_ping / 2' do
|
53
|
+
expect(client.websocket_ping_timer).to eq 15
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context 'with websocket_ping value changed' do
|
58
|
+
let(:client) { described_class.new(websocket_ping: 22) }
|
59
|
+
|
60
|
+
it 'defaults to websocket_ping / 2' do
|
61
|
+
expect(client.websocket_ping_timer).to eq 11
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
context 'client with a full store',
|
67
|
+
vcr: { cassette_name: 'web/rtm_start', allow_playback_repeats: true } do
|
68
|
+
let(:client) { described_class.new(store_class: Slack::RealTime::Stores::Store) }
|
69
|
+
let(:url) { 'wss://cerberus-xxxx.lb.slack-msgs.com/websocket/uid' }
|
70
|
+
|
71
|
+
describe '#start!' do
|
72
|
+
let(:socket) { double(Slack::RealTime::Socket, connected?: true) }
|
73
|
+
|
74
|
+
before do
|
75
|
+
allow(Slack::RealTime::Socket).to(
|
76
|
+
receive(:new).with(url, ping: 30, logger: Slack::Logger.default).and_return(socket)
|
77
|
+
)
|
78
|
+
allow(socket).to receive(:connect!)
|
79
|
+
allow(socket).to receive(:start_sync)
|
80
|
+
client.start!
|
81
|
+
end
|
82
|
+
|
83
|
+
describe 'properties provided upon connection' do
|
84
|
+
it 'sets url' do
|
85
|
+
expect(client.url).to eq url
|
56
86
|
end
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
end
|
71
|
-
it 'sets users' do
|
72
|
-
expect(client.users.count).to eq 18
|
73
|
-
expect(client.users.values.first['id']).to eq 'U07518DTL'
|
74
|
-
end
|
75
|
-
it 'sets channels' do
|
76
|
-
expect(client.channels.count).to eq 37
|
77
|
-
expect(client.channels.values.first['name']).to eq 'a1'
|
78
|
-
end
|
79
|
-
it 'sets ims' do
|
80
|
-
expect(client.ims.count).to eq 2
|
81
|
-
expect(client.ims.values.first['user']).to eq 'USLACKBOT'
|
82
|
-
end
|
83
|
-
it 'sets bots' do
|
84
|
-
expect(client.bots.count).to eq 16
|
85
|
-
expect(client.bots.values.first['name']).to eq 'bot'
|
86
|
-
end
|
87
|
-
it 'sets groups' do
|
88
|
-
expect(client.groups.count).to eq 1
|
89
|
-
end
|
87
|
+
it 'sets team' do
|
88
|
+
expect(client.team.domain).to eq 'dblockdotorg'
|
89
|
+
end
|
90
|
+
it 'sets teams' do
|
91
|
+
expect(client.teams.count).to eq 1
|
92
|
+
expect(client.teams.values.first).to eq client.team
|
93
|
+
end
|
94
|
+
it 'sets self' do
|
95
|
+
expect(client.self.id).to eq 'U0J1GAHN1'
|
96
|
+
end
|
97
|
+
it 'sets users' do
|
98
|
+
expect(client.users.count).to eq 35
|
99
|
+
expect(client.users.values.first['id']).to eq 'U0J1GAHN1'
|
90
100
|
end
|
91
|
-
it '
|
92
|
-
expect(client.
|
101
|
+
it 'sets channels' do
|
102
|
+
expect(client.channels.count).to eq 156
|
103
|
+
expect(client.channels.values.first['name']).to eq 'general'
|
93
104
|
end
|
94
|
-
it '
|
95
|
-
expect(client.
|
105
|
+
it 'sets ims' do
|
106
|
+
expect(client.ims.count).to eq 10
|
107
|
+
expect(client.ims.values.first['user']).to eq 'U04KB5WQR'
|
108
|
+
end
|
109
|
+
it 'sets bots' do
|
110
|
+
expect(client.bots.count).to eq 83
|
111
|
+
expect(client.bots.values.first['name']).to eq 'bot'
|
112
|
+
end
|
113
|
+
it 'sets groups' do
|
114
|
+
expect(client.groups.count).to eq 1
|
115
|
+
end
|
116
|
+
it 'includes team name in to_s' do
|
117
|
+
expect(client.to_s).to eq(
|
118
|
+
"id=#{client.team.id}, name=#{client.team.name}, domain=#{client.team.domain}"
|
119
|
+
)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
it 'uses web client to fetch url' do
|
124
|
+
expect(client.web_client).to be_a Slack::Web::Client
|
125
|
+
end
|
126
|
+
it 'remembers socket' do
|
127
|
+
expect(client.instance_variable_get('@socket')).to eq socket
|
128
|
+
end
|
129
|
+
it 'cannot be invoked twice' do
|
130
|
+
expect do
|
131
|
+
client.start!
|
132
|
+
end.to raise_error Slack::RealTime::Client::ClientAlreadyStartedError
|
133
|
+
end
|
134
|
+
describe '#stop!' do
|
135
|
+
before do
|
136
|
+
allow(socket).to receive(:disconnect!)
|
137
|
+
client.stop!
|
96
138
|
end
|
139
|
+
|
97
140
|
it 'cannot be invoked twice' do
|
141
|
+
client.instance_variable_set('@socket', nil) # caused by a :close callback
|
98
142
|
expect do
|
99
|
-
client.start!
|
100
|
-
end.to raise_error Slack::RealTime::Client::ClientAlreadyStartedError
|
101
|
-
end
|
102
|
-
describe '#stop!' do
|
103
|
-
before do
|
104
|
-
expect(socket).to receive(:disconnect!)
|
105
143
|
client.stop!
|
106
|
-
end
|
107
|
-
it 'cannot be invoked twice' do
|
108
|
-
client.instance_variable_set('@socket', nil) # caused by a :close callback
|
109
|
-
expect do
|
110
|
-
client.stop!
|
111
|
-
end.to raise_error Slack::RealTime::Client::ClientNotStartedError
|
112
|
-
end
|
144
|
+
end.to raise_error Slack::RealTime::Client::ClientNotStartedError
|
113
145
|
end
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
146
|
+
end
|
147
|
+
|
148
|
+
describe '#next_id' do
|
149
|
+
it 'increments' do
|
150
|
+
previous_id = client.send(:next_id)
|
151
|
+
expect(client.send(:next_id)).to eq previous_id + 1
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
context 'subclassed' do
|
156
|
+
it 'runs event handlers' do
|
157
|
+
event = Slack::RealTime::Event.new(
|
158
|
+
'type' => 'team_rename',
|
159
|
+
'name' => 'New Team Name Inc.'
|
160
|
+
)
|
161
|
+
client.send(:dispatch, event)
|
162
|
+
expect(client.store.team.name).to eq 'New Team Name Inc.'
|
119
163
|
end
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
164
|
+
end
|
165
|
+
|
166
|
+
describe '#run_handlers' do
|
167
|
+
describe 'empty events' do
|
168
|
+
before do
|
169
|
+
@e = client.store.class.events
|
170
|
+
client.store.class.events = nil
|
124
171
|
end
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
'name' => 'New Team Name Inc.'
|
129
|
-
)
|
130
|
-
expect(client).to_not receive(:run_handlers)
|
131
|
-
client.send(:dispatch, event)
|
172
|
+
|
173
|
+
after do
|
174
|
+
client.store.class.events = @e
|
132
175
|
end
|
133
|
-
|
134
|
-
|
176
|
+
|
177
|
+
it 'returns false when event is nil' do
|
178
|
+
expect(client.send(:run_handlers, 'example', {})).to be nil
|
135
179
|
end
|
136
|
-
|
137
|
-
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
describe '#start_async' do
|
185
|
+
let(:socket) { double(Slack::RealTime::Socket, connected?: true) }
|
186
|
+
|
187
|
+
before do
|
188
|
+
allow(Slack::RealTime::Socket).to(
|
189
|
+
receive(:new).with(url, ping: 30, logger: Slack::Logger.default).and_return(socket)
|
190
|
+
)
|
191
|
+
allow(socket).to receive(:connect!)
|
192
|
+
allow(socket).to receive(:start_async)
|
193
|
+
client.start_async
|
194
|
+
end
|
195
|
+
|
196
|
+
describe '#run_ping!' do
|
197
|
+
it 'sends ping messages when the websocket connection is idle' do
|
198
|
+
allow(socket).to receive(:time_since_last_message).and_return(30)
|
199
|
+
expect(socket).to receive(:send_data).with('{"type":"ping","id":1}')
|
200
|
+
client.run_ping!
|
201
|
+
end
|
202
|
+
it 'reconnects the websocket if it has been idle for too long' do
|
203
|
+
allow(socket).to receive(:time_since_last_message).and_return(75)
|
204
|
+
allow(socket).to receive(:connected?).and_return(true)
|
205
|
+
expect(socket).to receive(:close)
|
206
|
+
expect(socket).to receive(:restart_async)
|
207
|
+
client.run_ping!
|
208
|
+
end
|
209
|
+
[
|
210
|
+
EOFError,
|
211
|
+
Errno::ECONNRESET,
|
212
|
+
Errno::EPIPE,
|
213
|
+
Faraday::ClientError,
|
214
|
+
Slack::Web::Api::Errors::SlackError
|
215
|
+
].each do |err|
|
216
|
+
context "raising #{err}" do
|
217
|
+
it 'does not terminate the ping worker' do
|
218
|
+
allow(socket).to receive(:time_since_last_message) { raise err }
|
219
|
+
expect(socket).not_to receive(:send_data)
|
220
|
+
client.run_ping!
|
221
|
+
end
|
138
222
|
end
|
139
223
|
end
|
140
|
-
context '
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
224
|
+
context 'raising Slack::Web::Api::Errors::SlackError' do
|
225
|
+
%w[invalid_auth account_inactive].each do |code|
|
226
|
+
context code do
|
227
|
+
it 'does not terminate the ping worker' do
|
228
|
+
allow(socket).to receive(:time_since_last_message) {
|
229
|
+
raise Slack::Web::Api::Errors::SlackError, code
|
230
|
+
}
|
231
|
+
expect(socket).not_to receive(:send_data)
|
232
|
+
expect do
|
233
|
+
client.run_ping!
|
234
|
+
end.to raise_error Slack::Web::Api::Errors::SlackError, code
|
235
|
+
end
|
236
|
+
end
|
149
237
|
end
|
150
238
|
end
|
151
239
|
end
|
152
240
|
end
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
241
|
+
|
242
|
+
describe 'to_s' do
|
243
|
+
it 'defaults to class instance' do
|
244
|
+
expect(client.to_s).to match(/^#<Slack::RealTime::Client:0x\h+>$/)
|
245
|
+
end
|
246
|
+
end
|
247
|
+
end
|
248
|
+
|
249
|
+
context 'client with starter store', vcr: { cassette_name: 'web/rtm_connect' } do
|
250
|
+
let(:client) { described_class.new(store_class: Slack::RealTime::Stores::Starter) }
|
251
|
+
let(:url) { 'wss://cerberus-xxxx.lb.slack-msgs.com/websocket/uid' }
|
252
|
+
|
253
|
+
describe '#start!' do
|
254
|
+
let(:socket) { double(Slack::RealTime::Socket, connected?: true) }
|
255
|
+
|
256
|
+
before do
|
257
|
+
allow(Slack::RealTime::Socket).to(
|
258
|
+
receive(:new).with(url, ping: 30, logger: Slack::Logger.default).and_return(socket)
|
259
|
+
)
|
260
|
+
allow(socket).to receive(:connect!)
|
261
|
+
allow(socket).to receive(:start_sync)
|
262
|
+
client.start!
|
263
|
+
end
|
264
|
+
|
265
|
+
describe 'properties provided upon connection' do
|
266
|
+
it 'sets url' do
|
267
|
+
expect(client.url).to eq url
|
158
268
|
end
|
159
|
-
it
|
160
|
-
expect(client.
|
269
|
+
it 'sets team' do
|
270
|
+
expect(client.team.domain).to eq 'dblockdotorg'
|
161
271
|
end
|
162
|
-
it '
|
163
|
-
expect(client.
|
272
|
+
it 'sets self' do
|
273
|
+
expect(client.self.id).to eq 'U0J1GAHN1'
|
164
274
|
end
|
165
|
-
it '
|
166
|
-
expect(client.
|
275
|
+
it 'no users' do
|
276
|
+
expect(client.users).to be_nil
|
167
277
|
end
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
278
|
+
it 'no teams' do
|
279
|
+
expect(client.teams).to be_nil
|
280
|
+
end
|
281
|
+
it 'no channels' do
|
282
|
+
expect(client.channels).to be_nil
|
283
|
+
end
|
284
|
+
it 'no ims' do
|
285
|
+
expect(client.ims).to be_nil
|
172
286
|
end
|
287
|
+
it 'no bots' do
|
288
|
+
expect(client.bots).to be_nil
|
289
|
+
end
|
290
|
+
it 'no groups' do
|
291
|
+
expect(client.groups).to be_nil
|
292
|
+
end
|
293
|
+
it 'includes team name in to_s' do
|
294
|
+
expect(client.to_s).to eq(
|
295
|
+
"id=#{client.team.id}, name=#{client.team.name}, domain=#{client.team.domain}"
|
296
|
+
)
|
297
|
+
end
|
298
|
+
end
|
299
|
+
|
300
|
+
it 'uses web client to fetch url' do
|
301
|
+
expect(client.web_client).to be_a Slack::Web::Client
|
302
|
+
end
|
303
|
+
it 'remembers socket' do
|
304
|
+
expect(client.instance_variable_get('@socket')).to eq socket
|
305
|
+
end
|
306
|
+
it 'cannot be invoked twice' do
|
307
|
+
expect do
|
308
|
+
client.start!
|
309
|
+
end.to raise_error Slack::RealTime::Client::ClientAlreadyStartedError
|
310
|
+
end
|
311
|
+
describe '#stop!' do
|
312
|
+
before do
|
313
|
+
allow(socket).to receive(:disconnect!)
|
314
|
+
client.stop!
|
315
|
+
end
|
316
|
+
|
317
|
+
it 'cannot be invoked twice' do
|
318
|
+
client.instance_variable_set('@socket', nil) # caused by a :close callback
|
319
|
+
expect do
|
320
|
+
client.stop!
|
321
|
+
end.to raise_error Slack::RealTime::Client::ClientNotStartedError
|
322
|
+
end
|
323
|
+
end
|
324
|
+
|
325
|
+
describe '#next_id' do
|
326
|
+
it 'increments' do
|
327
|
+
previous_id = client.send(:next_id)
|
328
|
+
expect(client.send(:next_id)).to eq previous_id + 1
|
329
|
+
end
|
330
|
+
end
|
331
|
+
end
|
332
|
+
end
|
333
|
+
|
334
|
+
context 'client with nil store', vcr: { cassette_name: 'web/rtm_connect' } do
|
335
|
+
let(:client) { described_class.new(store_class: nil) }
|
336
|
+
let(:url) { 'wss://mpmulti-w5tz.slack-msgs.com/websocket/uid' }
|
337
|
+
|
338
|
+
it 'sets store to nil' do
|
339
|
+
expect(client.store).to be nil
|
340
|
+
end
|
341
|
+
it "doesn't handle events" do
|
342
|
+
event = Slack::RealTime::Event.new(
|
343
|
+
'type' => 'team_rename',
|
344
|
+
'name' => 'New Team Name Inc.'
|
345
|
+
)
|
346
|
+
expect(client).not_to receive(:run_handlers)
|
347
|
+
client.send(:dispatch, event)
|
348
|
+
end
|
349
|
+
it 'self' do
|
350
|
+
expect(client.self).to be nil
|
351
|
+
end
|
352
|
+
it 'team' do
|
353
|
+
expect(client.team).to be nil
|
354
|
+
end
|
355
|
+
describe 'to_s' do
|
356
|
+
it 'defaults to class instance' do
|
357
|
+
expect(client.to_s).to match(/^#<Slack::RealTime::Client:0x\h+>$/)
|
358
|
+
end
|
359
|
+
end
|
360
|
+
end
|
361
|
+
|
362
|
+
context 'client with defaults' do
|
363
|
+
let(:client) { described_class.new }
|
364
|
+
|
365
|
+
describe '#initialize' do
|
366
|
+
it 'sets ping' do
|
367
|
+
expect(client.websocket_ping).to eq 30
|
368
|
+
end
|
369
|
+
it "doesn't set proxy" do
|
370
|
+
expect(client.websocket_proxy).to be nil
|
371
|
+
end
|
372
|
+
it 'defaults logger' do
|
373
|
+
expect(client.send(:logger)).to be_a ::Logger
|
374
|
+
end
|
375
|
+
it 'sets default store_class' do
|
376
|
+
expect(client.send(:store_class)).to eq Slack::RealTime::Store
|
377
|
+
end
|
378
|
+
(Slack::RealTime::Config::ATTRIBUTES - %i[logger store_class token]).each do |key|
|
379
|
+
it "sets #{key}" do
|
380
|
+
expect(client.send(key)).to eq Slack::RealTime::Config.send(key)
|
381
|
+
end
|
382
|
+
end
|
383
|
+
end
|
384
|
+
|
385
|
+
describe '#run_ping?' do
|
386
|
+
it 'returns true when websocket_ping is greater than 0' do
|
387
|
+
client.websocket_ping = 30
|
388
|
+
expect(client.run_ping?).to be true
|
389
|
+
end
|
390
|
+
it 'returns false when websocket_ping is less than 1' do
|
391
|
+
client.websocket_ping = 0
|
392
|
+
expect(client.run_ping?).to be false
|
393
|
+
client.websocket_ping = nil
|
394
|
+
expect(client.run_ping?).to be false
|
173
395
|
end
|
174
396
|
end
|
175
397
|
end
|
398
|
+
|
176
399
|
context 'with custom settings' do
|
177
400
|
describe '#initialize' do
|
178
401
|
Slack::RealTime::Config::ATTRIBUTES.each do |key|
|
179
|
-
context key do
|
180
|
-
let(:client) {
|
402
|
+
context key.to_s do
|
403
|
+
let(:client) { described_class.new(key => 'custom') }
|
404
|
+
|
181
405
|
it "sets #{key}" do
|
182
|
-
expect(client.send(key)).
|
406
|
+
expect(client.send(key)).not_to eq Slack::RealTime::Config.send(key)
|
183
407
|
expect(client.send(key)).to eq 'custom'
|
184
408
|
end
|
185
409
|
end
|
186
410
|
end
|
187
411
|
end
|
412
|
+
|
413
|
+
describe 'logger accessor' do
|
414
|
+
let(:client) { described_class.new }
|
415
|
+
|
416
|
+
it 'exposes public logger' do
|
417
|
+
expect(client.logger).to be_a(::Logger)
|
418
|
+
end
|
419
|
+
it 'exposes public logger=' do
|
420
|
+
expect { client.logger = nil }.not_to raise_error(NoMethodError)
|
421
|
+
end
|
422
|
+
end
|
188
423
|
end
|
424
|
+
|
189
425
|
context 'global config' do
|
190
426
|
after do
|
191
|
-
|
427
|
+
described_class.config.reset
|
192
428
|
end
|
193
|
-
|
429
|
+
|
430
|
+
let(:url) { 'wss://cerberus-xxxx.lb.slack-msgs.com/websocket/uid' }
|
431
|
+
let(:client) { described_class.new }
|
432
|
+
|
194
433
|
context 'ping' do
|
195
434
|
before do
|
196
|
-
|
435
|
+
described_class.configure do |config|
|
197
436
|
config.websocket_ping = 15
|
198
437
|
end
|
199
438
|
end
|
439
|
+
|
200
440
|
describe '#initialize' do
|
201
441
|
it 'sets ping' do
|
202
442
|
expect(client.websocket_ping).to eq 15
|
203
443
|
end
|
204
|
-
it 'creates a connection with custom ping' do
|
205
|
-
expect(Slack::RealTime::Concurrency::Mock::WebSocket).to
|
444
|
+
it 'creates a connection with custom ping', vcr: { cassette_name: 'web/rtm_start' } do
|
445
|
+
expect(Slack::RealTime::Concurrency::Mock::WebSocket).to(
|
446
|
+
receive(:new).with(url, nil, ping: 15).and_return(ws)
|
447
|
+
)
|
206
448
|
client.start!
|
207
449
|
end
|
208
450
|
it 'sets start_options' do
|
209
|
-
expect(client.start_options).to eq({})
|
451
|
+
expect(client.start_options).to eq(request: { timeout: 180 })
|
210
452
|
end
|
211
453
|
end
|
212
454
|
end
|
455
|
+
|
213
456
|
context 'proxy' do
|
214
457
|
before do
|
215
|
-
|
458
|
+
described_class.configure do |config|
|
216
459
|
config.websocket_proxy = {
|
217
460
|
origin: 'http://username:password@proxy.example.com',
|
218
461
|
headers: { 'User-Agent' => 'ruby' }
|
219
462
|
}
|
220
463
|
end
|
221
464
|
end
|
465
|
+
|
222
466
|
describe '#initialize' do
|
223
467
|
it 'sets proxy' do
|
224
468
|
expect(client.websocket_proxy).to eq(
|
@@ -226,7 +470,7 @@ RSpec.describe Slack::RealTime::Client, vcr: { cassette_name: 'web/rtm_start' }
|
|
226
470
|
headers: { 'User-Agent' => 'ruby' }
|
227
471
|
)
|
228
472
|
end
|
229
|
-
it 'creates a connection with custom proxy' do
|
473
|
+
it 'creates a connection with custom proxy', vcr: { cassette_name: 'web/rtm_start' } do
|
230
474
|
expect(Slack::RealTime::Concurrency::Mock::WebSocket).to receive(:new).with(
|
231
475
|
url,
|
232
476
|
nil,
|
@@ -234,59 +478,139 @@ RSpec.describe Slack::RealTime::Client, vcr: { cassette_name: 'web/rtm_start' }
|
|
234
478
|
proxy: {
|
235
479
|
origin: 'http://username:password@proxy.example.com',
|
236
480
|
headers: { 'User-Agent' => 'ruby' }
|
237
|
-
}
|
481
|
+
}
|
482
|
+
).and_return(ws)
|
238
483
|
client.start!
|
239
484
|
end
|
240
485
|
end
|
241
486
|
end
|
487
|
+
|
242
488
|
context 'start_options' do
|
243
489
|
before do
|
244
|
-
|
490
|
+
described_class.configure do |config|
|
245
491
|
config.start_options = { simple_latest: true }
|
246
492
|
end
|
247
493
|
end
|
494
|
+
|
248
495
|
describe '#initialize' do
|
249
496
|
it 'sets start_options' do
|
250
497
|
expect(client.start_options).to eq(simple_latest: true)
|
251
498
|
end
|
252
499
|
context 'start!' do
|
253
500
|
let(:socket) { double(Slack::RealTime::Socket, connected?: true) }
|
501
|
+
|
254
502
|
before do
|
255
503
|
allow(Slack::RealTime::Socket).to receive(:new).and_return(socket)
|
256
504
|
allow(socket).to receive(:connect!)
|
257
505
|
allow(socket).to receive(:start_sync)
|
258
506
|
end
|
259
|
-
|
260
|
-
|
507
|
+
|
508
|
+
it 'calls rtm_start with start options', vcr: { cassette_name: 'web/rtm_start' } do
|
509
|
+
expect(client.web_client).to(
|
510
|
+
receive(:rtm_start).with(simple_latest: true).and_call_original
|
511
|
+
)
|
261
512
|
client.start!
|
262
513
|
end
|
263
514
|
end
|
264
515
|
end
|
265
516
|
end
|
517
|
+
|
266
518
|
context 'store_class' do
|
267
|
-
|
268
|
-
|
269
|
-
|
519
|
+
context 'starter' do
|
520
|
+
before do
|
521
|
+
described_class.configure do |config|
|
522
|
+
config.store_class = Slack::RealTime::Stores::Starter
|
523
|
+
end
|
524
|
+
end
|
525
|
+
|
526
|
+
describe '#initialize' do
|
527
|
+
it 'can be overriden explicitly' do
|
528
|
+
client = described_class.new(store_class: Slack::RealTime::Store)
|
529
|
+
expect(client.send(:store_class)).to eq Slack::RealTime::Store
|
530
|
+
end
|
531
|
+
it 'sets store_class' do
|
532
|
+
expect(client.send(:store_class)).to eq(Slack::RealTime::Stores::Starter)
|
533
|
+
end
|
534
|
+
context 'start!' do
|
535
|
+
let(:socket) { double(Slack::RealTime::Socket, connected?: true) }
|
536
|
+
|
537
|
+
before do
|
538
|
+
allow(Slack::RealTime::Socket).to receive(:new).and_return(socket)
|
539
|
+
allow(socket).to receive(:connect!)
|
540
|
+
allow(socket).to receive(:start_sync)
|
541
|
+
end
|
542
|
+
|
543
|
+
it 'instantiates the correct store class', vcr: { cassette_name: 'web/rtm_connect' } do
|
544
|
+
client.start!
|
545
|
+
expect(client.store).to be_a Slack::RealTime::Stores::Starter
|
546
|
+
end
|
547
|
+
end
|
548
|
+
end
|
549
|
+
end
|
550
|
+
|
551
|
+
context 'store' do
|
552
|
+
before do
|
553
|
+
described_class.configure do |config|
|
554
|
+
config.store_class = Slack::RealTime::Stores::Store
|
555
|
+
end
|
556
|
+
end
|
557
|
+
|
558
|
+
describe '#initialize' do
|
559
|
+
context 'start!' do
|
560
|
+
let(:socket) { double(Slack::RealTime::Socket, connected?: true) }
|
561
|
+
|
562
|
+
before do
|
563
|
+
allow(Slack::RealTime::Socket).to receive(:new).and_return(socket)
|
564
|
+
allow(socket).to receive(:connect!)
|
565
|
+
allow(socket).to receive(:start_sync)
|
566
|
+
end
|
567
|
+
|
568
|
+
it 'calls rtm_start and not rtm_connect', vcr: { cassette_name: 'web/rtm_start' } do
|
569
|
+
expect(client.web_client).to receive(:rtm_start).and_call_original
|
570
|
+
client.start!
|
571
|
+
end
|
572
|
+
end
|
270
573
|
end
|
271
574
|
end
|
575
|
+
end
|
576
|
+
|
577
|
+
context 'start_method' do
|
272
578
|
describe '#initialize' do
|
273
579
|
it 'can be overriden explicitly' do
|
274
|
-
client =
|
275
|
-
expect(client.send(:
|
580
|
+
client = described_class.new(start_method: :overriden)
|
581
|
+
expect(client.send(:start_method)).to eq :overriden
|
276
582
|
end
|
277
|
-
|
278
|
-
|
583
|
+
context 'with start_method' do
|
584
|
+
before do
|
585
|
+
described_class.configure do |config|
|
586
|
+
config.start_method = :overriden
|
587
|
+
end
|
588
|
+
end
|
589
|
+
|
590
|
+
it 'sets start_method' do
|
591
|
+
expect(client.send(:start_method)).to eq :overriden
|
592
|
+
end
|
593
|
+
it 'calls the overriden method' do
|
594
|
+
expect(client.web_client).to receive(:overriden).and_raise('overriden')
|
595
|
+
expect do
|
596
|
+
client.start!
|
597
|
+
end.to raise_error RuntimeError, 'overriden'
|
598
|
+
end
|
279
599
|
end
|
600
|
+
|
280
601
|
context 'start!' do
|
281
602
|
let(:socket) { double(Slack::RealTime::Socket, connected?: true) }
|
603
|
+
|
282
604
|
before do
|
283
605
|
allow(Slack::RealTime::Socket).to receive(:new).and_return(socket)
|
284
606
|
allow(socket).to receive(:connect!)
|
285
607
|
allow(socket).to receive(:start_sync)
|
286
608
|
end
|
287
|
-
|
609
|
+
|
610
|
+
it 'defaults to :rtm_start when using full store',
|
611
|
+
vcr: { cassette_name: 'web/rtm_start' } do
|
612
|
+
expect(client.web_client).to receive(:rtm_start).and_call_original
|
288
613
|
client.start!
|
289
|
-
expect(client.store).to be_a Slack::RealTime::Stores::Starter
|
290
614
|
end
|
291
615
|
end
|
292
616
|
end
|