slack-ruby-client 1.0.0 → 2.1.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/.github/workflows/integration_test.yml +45 -0
- data/.github/workflows/lint.yml +14 -0
- data/.github/workflows/pr_lint.yml +21 -0
- data/.github/workflows/test.yml +37 -0
- data/.gitignore +4 -3
- data/.rubocop.yml +6 -1
- data/.rubocop_todo.yml +88 -34
- data/.ruby-version +1 -0
- data/CHANGELOG.md +36 -0
- data/CONTRIBUTING.md +6 -5
- data/Gemfile +13 -1
- data/Gemfile.danger +6 -0
- data/README.md +78 -76
- data/RELEASING.md +2 -2
- data/SECURITY.md +9 -0
- data/UPGRADING.md +28 -0
- data/bin/commands/admin_analytics.rb +16 -10
- data/bin/commands/admin_apps.rb +48 -42
- data/bin/commands/admin_apps_approved.rb +17 -11
- data/bin/commands/admin_apps_requests.rb +28 -11
- data/bin/commands/admin_apps_restricted.rb +17 -11
- data/bin/commands/admin_audit_anomaly_allow.rb +29 -0
- data/bin/commands/admin_auth_policy.rb +37 -31
- data/bin/commands/admin_barriers.rb +44 -38
- data/bin/commands/admin_conversations.rb +221 -163
- data/bin/commands/admin_conversations_ekm.rb +17 -11
- data/bin/commands/admin_conversations_restrictAccess.rb +35 -29
- data/bin/commands/admin_emoji.rb +50 -44
- data/bin/commands/admin_inviteRequests.rb +34 -28
- data/bin/commands/admin_inviteRequests_approved.rb +16 -10
- data/bin/commands/admin_inviteRequests_denied.rb +16 -10
- data/bin/commands/admin_roles.rb +46 -0
- data/bin/commands/admin_teams.rb +26 -20
- data/bin/commands/admin_teams_admins.rb +16 -10
- data/bin/commands/admin_teams_owners.rb +16 -10
- data/bin/commands/admin_teams_settings.rb +59 -53
- data/bin/commands/admin_usergroups.rb +45 -39
- data/bin/commands/admin_users.rb +91 -85
- data/bin/commands/admin_users_session.rb +72 -66
- data/bin/commands/admin_users_unsupportedVersions.rb +21 -0
- data/bin/commands/api.rb +14 -8
- data/bin/commands/apps.rb +15 -9
- data/bin/commands/apps_connections.rb +13 -7
- data/bin/commands/apps_event_authorizations.rb +16 -10
- data/bin/commands/apps_manifest.rb +48 -41
- data/bin/commands/auth.rb +21 -15
- data/bin/commands/auth_teams.rb +16 -10
- data/bin/commands/bookmarks.rb +59 -0
- data/bin/commands/bots.rb +15 -9
- data/bin/commands/calls.rb +49 -43
- data/bin/commands/calls_participants.rb +24 -18
- data/bin/commands/chat.rb +150 -141
- data/bin/commands/chat_scheduledMessages.rb +19 -13
- data/bin/commands/conversations.rb +233 -225
- data/bin/commands/dialog.rb +15 -9
- data/bin/commands/dnd.rb +46 -40
- data/bin/commands/emoji.rb +14 -7
- data/bin/commands/files.rb +112 -83
- data/bin/commands/files_comments.rb +15 -9
- data/bin/commands/files_remote.rb +73 -67
- data/bin/commands/functions_workflows_steps.rb +22 -0
- data/bin/commands/functions_workflows_steps_responses.rb +22 -0
- data/bin/commands/migration.rb +16 -10
- data/bin/commands/oauth.rb +18 -12
- data/bin/commands/oauth_v2.rb +28 -22
- data/bin/commands/openid_connect.rb +26 -20
- data/bin/commands/pins.rb +33 -26
- data/bin/commands/reactions.rb +52 -46
- data/bin/commands/reminders.rb +53 -47
- data/bin/commands/rtm.rb +15 -24
- data/bin/commands/search.rb +43 -37
- data/bin/commands/stars.rb +38 -32
- data/bin/commands/team.rb +47 -38
- data/bin/commands/team_billing.rb +13 -7
- data/bin/commands/team_preferences.rb +13 -7
- data/bin/commands/team_profile.rb +14 -8
- data/bin/commands/tooling_tokens.rb +14 -8
- data/bin/commands/usergroups.rb +64 -58
- data/bin/commands/usergroups_users.rb +27 -21
- data/bin/commands/users.rb +111 -105
- data/bin/commands/users_admin.rb +28 -22
- data/bin/commands/users_prefs.rb +13 -7
- data/bin/commands/users_profile.rb +26 -20
- data/bin/commands/views.rb +47 -39
- data/bin/commands/workflows.rb +36 -30
- data/bin/slack +48 -43
- data/lib/slack/real_time/api/message.rb +3 -2
- data/lib/slack/real_time/api/templates/event_handler.erb +5 -1
- data/lib/slack/real_time/api/typing.rb +2 -1
- data/lib/slack/real_time/client.rb +10 -28
- data/lib/slack/real_time/config.rb +3 -3
- data/lib/slack/real_time/models/channel.rb +4 -0
- data/lib/slack/real_time/models/{group.rb → mpim.rb} +1 -1
- data/lib/slack/real_time/models.rb +2 -1
- data/lib/slack/real_time/stores/base.rb +25 -9
- data/lib/slack/real_time/stores/starter.rb +323 -309
- data/lib/slack/real_time/stores/store.rb +265 -198
- data/lib/slack/real_time/stores.rb +1 -7
- data/lib/slack/version.rb +1 -1
- data/lib/slack/web/api/endpoints/admin_analytics.rb +2 -2
- data/lib/slack/web/api/endpoints/admin_apps.rb +2 -2
- data/lib/slack/web/api/endpoints/admin_apps_requests.rb +16 -0
- data/lib/slack/web/api/endpoints/admin_audit_anomaly_allow.rb +34 -0
- data/lib/slack/web/api/endpoints/admin_auth_policy.rb +7 -7
- data/lib/slack/web/api/endpoints/admin_barriers.rb +8 -8
- data/lib/slack/web/api/endpoints/admin_conversations.rb +110 -28
- data/lib/slack/web/api/endpoints/admin_conversations_restrictAccess.rb +6 -6
- data/lib/slack/web/api/endpoints/admin_emoji.rb +9 -9
- data/lib/slack/web/api/endpoints/admin_inviteRequests.rb +2 -2
- data/lib/slack/web/api/endpoints/admin_roles.rb +73 -0
- data/lib/slack/web/api/endpoints/admin_teams.rb +2 -2
- data/lib/slack/web/api/endpoints/admin_teams_admins.rb +1 -1
- data/lib/slack/web/api/endpoints/admin_teams_owners.rb +1 -1
- data/lib/slack/web/api/endpoints/admin_teams_settings.rb +11 -11
- data/lib/slack/web/api/endpoints/admin_usergroups.rb +7 -7
- data/lib/slack/web/api/endpoints/admin_users.rb +16 -16
- data/lib/slack/web/api/endpoints/admin_users_session.rb +8 -8
- data/lib/slack/web/api/endpoints/admin_users_unsupportedVersions.rb +25 -0
- data/lib/slack/web/api/endpoints/apps.rb +2 -2
- data/lib/slack/web/api/endpoints/apps_connections.rb +1 -1
- data/lib/slack/web/api/endpoints/apps_event_authorizations.rb +1 -1
- data/lib/slack/web/api/endpoints/apps_manifest.rb +8 -6
- data/lib/slack/web/api/endpoints/bookmarks.rb +88 -0
- data/lib/slack/web/api/endpoints/bots.rb +1 -1
- data/lib/slack/web/api/endpoints/calls.rb +5 -5
- data/lib/slack/web/api/endpoints/calls_participants.rb +4 -4
- data/lib/slack/web/api/endpoints/chat.rb +37 -31
- data/lib/slack/web/api/endpoints/conversations.rb +38 -34
- data/lib/slack/web/api/endpoints/dialog.rb +2 -2
- data/lib/slack/web/api/endpoints/dnd.rb +1 -1
- data/lib/slack/web/api/endpoints/emoji.rb +2 -0
- data/lib/slack/web/api/endpoints/files.rb +45 -10
- data/lib/slack/web/api/endpoints/files_comments.rb +2 -2
- data/lib/slack/web/api/endpoints/files_remote.rb +8 -8
- data/lib/slack/web/api/endpoints/functions_workflows_steps.rb +28 -0
- data/lib/slack/web/api/endpoints/functions_workflows_steps_responses.rb +28 -0
- data/lib/slack/web/api/endpoints/migration.rb +1 -1
- data/lib/slack/web/api/endpoints/oauth_v2.rb +2 -2
- data/lib/slack/web/api/endpoints/pins.rb +5 -3
- data/lib/slack/web/api/endpoints/reactions.rb +4 -4
- data/lib/slack/web/api/endpoints/reminders.rb +5 -5
- data/lib/slack/web/api/endpoints/rtm.rb +0 -23
- data/lib/slack/web/api/endpoints/search.rb +3 -3
- data/lib/slack/web/api/endpoints/team.rb +13 -1
- data/lib/slack/web/api/endpoints/tooling_tokens.rb +1 -1
- data/lib/slack/web/api/endpoints/usergroups.rb +5 -5
- data/lib/slack/web/api/endpoints/usergroups_users.rb +3 -3
- data/lib/slack/web/api/endpoints/users.rb +4 -4
- data/lib/slack/web/api/endpoints/users_admin.rb +2 -2
- data/lib/slack/web/api/endpoints/users_profile.rb +1 -1
- data/lib/slack/web/api/endpoints/views.rb +16 -11
- data/lib/slack/web/api/endpoints/workflows.rb +4 -4
- data/lib/slack/web/api/endpoints.rb +12 -0
- data/lib/slack/web/api/errors.rb +146 -8
- data/lib/slack/web/api/mixins/conversations.id.rb +1 -1
- data/lib/slack/web/api/mixins/users.id.rb +1 -1
- data/lib/slack/web/api/mixins/users.search.rb +2 -1
- data/lib/slack/web/api/patches/{chat.1.patch → chat.attachments-blocks.patch} +13 -14
- data/lib/slack/web/api/patches/{dialog.1.open-json-support.patch → dialog.encoded-json.patch} +4 -4
- data/lib/slack/web/api/patches/views.view-json.patch +55 -0
- data/lib/slack/web/api/templates/command.erb +18 -12
- data/lib/slack/web/api/templates/method.erb +1 -1
- data/lib/slack/web/config.rb +2 -2
- data/lib/slack/web/faraday/connection.rb +4 -4
- data/lib/slack/web/faraday/request.rb +2 -0
- data/lib/slack/web/faraday/response/raise_error.rb +2 -10
- data/lib/slack/web/faraday/response/wrap_error.rb +1 -1
- data/lib/slack-ruby-client.rb +2 -1
- data/lib/tasks/real_time.rake +44 -24
- data/lib/tasks/web.rake +9 -8
- data/slack-ruby-client.gemspec +5 -14
- data/spec/fixtures/slack/web/rtm_connect.yml +85 -1
- data/spec/integration/integration_spec.rb +1 -1
- data/spec/slack/events/config_spec.rb +2 -0
- data/spec/slack/events/request_spec.rb +5 -1
- data/spec/slack/messages/formatting_spec.rb +10 -0
- data/spec/slack/real_time/api/message_spec.rb +1 -1
- data/spec/slack/real_time/api/ping_spec.rb +1 -1
- data/spec/slack/real_time/api/typing_spec.rb +1 -1
- data/spec/slack/real_time/client_spec.rb +91 -127
- data/spec/slack/real_time/event_handlers/bot_spec.rb +19 -17
- data/spec/slack/real_time/event_handlers/event_handlers_spec.rb +1 -1
- data/spec/slack/real_time/event_handlers/im_spec.rb +30 -27
- data/spec/slack/real_time/event_handlers/{group_spec.rb → private_channel_spec.rb} +35 -27
- data/spec/slack/real_time/event_handlers/{channel_spec.rb → public_channel_spec.rb} +27 -23
- data/spec/slack/real_time/event_handlers/team_spec.rb +7 -8
- data/spec/slack/real_time/event_handlers/user_spec.rb +6 -5
- data/spec/slack/real_time/stores/store_spec.rb +50 -0
- data/spec/slack/slack_spec.rb +5 -4
- data/spec/slack/version_spec.rb +1 -1
- data/spec/slack/web/api/endpoints/admin_apps_requests_spec.rb +5 -0
- data/spec/slack/web/api/endpoints/admin_audit_anomaly_allow_spec.rb +8 -0
- data/spec/slack/web/api/endpoints/admin_conversations_spec.rb +31 -0
- data/spec/slack/web/api/endpoints/admin_roles_spec.rb +30 -0
- data/spec/slack/web/api/endpoints/admin_users_unsupportedVersions_spec.rb +8 -0
- data/spec/slack/web/api/endpoints/bookmarks_spec.rb +40 -0
- data/spec/slack/web/api/endpoints/custom_specs/chat_spec.rb +45 -17
- data/spec/slack/web/api/endpoints/custom_specs/dialog_spec.rb +6 -2
- data/spec/slack/web/api/endpoints/custom_specs/views_spec.rb +33 -16
- data/spec/slack/web/api/endpoints/files_spec.rb +13 -0
- data/spec/slack/web/api/endpoints/functions_workflows_steps_responses_spec.rb +13 -0
- data/spec/slack/web/api/endpoints/functions_workflows_steps_spec.rb +13 -0
- data/spec/slack/web/api/mixins/conversations_spec.rb +2 -0
- data/spec/slack/web/api/mixins/users_spec.rb +2 -0
- data/spec/slack/web/api/pagination/cursor_spec.rb +11 -7
- data/spec/slack/web/client_spec.rb +39 -11
- data/spec/slack/web/faraday/response/raise_error_spec.rb +1 -1
- data/spec/support/real_time/connected_client.rb +1 -1
- data/spec/support/real_time/loaded_client.rb +120 -0
- metadata +45 -197
- data/.travis.yml +0 -29
- data/bin/commands/admin_conversations_whitelist.rb +0 -37
- data/bin/commands/apps_permissions.rb +0 -23
- data/bin/commands/apps_permissions_resources.rb +0 -15
- data/bin/commands/apps_permissions_scopes.rb +0 -13
- data/bin/commands/apps_permissions_users.rb +0 -26
- data/bin/commands/channels.rb +0 -23
- data/bin/commands/groups.rb +0 -14
- data/bin/commands/im.rb +0 -6
- data/bin/commands/mpim.rb +0 -6
- data/bin/commands.rb +0 -66
- data/lib/slack/web/api/endpoints/admin_conversations_whitelist.rb +0 -64
- data/lib/slack/web/api/endpoints/apps_permissions.rb +0 -36
- data/lib/slack/web/api/endpoints/apps_permissions_resources.rb +0 -31
- data/lib/slack/web/api/endpoints/apps_permissions_scopes.rb +0 -21
- data/lib/slack/web/api/endpoints/apps_permissions_users.rb +0 -50
- data/lib/slack/web/api/endpoints/channels.rb +0 -25
- data/lib/slack/web/api/endpoints/groups.rb +0 -13
- data/lib/slack/web/api/endpoints/im.rb +0 -13
- data/lib/slack/web/api/endpoints/mpim.rb +0 -13
- data/lib/slack/web/api/endpoints/presence.rb +0 -23
- data/lib/slack/web/api/patches/views.1.view-json.patch +0 -40
- data/lib/slack/web/api/patches/views.1.views-published.patch +0 -16
- data/lib/slack/web/api/templates/commands.erb +0 -6
- data/spec/fixtures/slack/web/rtm_start.yml +0 -815
- data/spec/slack/real_time/rtm_start_spec.rb +0 -14
- data/spec/slack/real_time/store_spec.rb +0 -12
@@ -14,7 +14,7 @@ module Slack
|
|
14
14
|
# Channel to get ID for, prefixed with #.
|
15
15
|
def conversations_id(options = {})
|
16
16
|
name = options[:channel]
|
17
|
-
|
17
|
+
raise ArgumentError, 'Required arguments :channel missing' if name.nil?
|
18
18
|
|
19
19
|
id_for :channel, name, '#', :conversations_list, :channels, 'channel_not_found'
|
20
20
|
end
|
@@ -14,7 +14,7 @@ module Slack
|
|
14
14
|
# User to get ID for, prefixed with '@'.
|
15
15
|
def users_id(options = {})
|
16
16
|
name = options[:user]
|
17
|
-
|
17
|
+
raise ArgumentError, 'Required arguments :user missing' if name.nil?
|
18
18
|
|
19
19
|
id_for :user, name, '@', :users_list, :members, 'user_not_found'
|
20
20
|
end
|
@@ -14,7 +14,8 @@ if defined?(Picky)
|
|
14
14
|
# Free-formed text to search for.
|
15
15
|
def users_search(options = {})
|
16
16
|
query = options[:user]
|
17
|
-
|
17
|
+
raise ArgumentError, 'Required arguments :user missing' if query.nil?
|
18
|
+
|
18
19
|
index = Picky::Index.new(:users) do
|
19
20
|
category :name
|
20
21
|
category :first_name
|
@@ -1,15 +1,14 @@
|
|
1
1
|
diff --git a/lib/slack/web/api/endpoints/chat.rb b/lib/slack/web/api/endpoints/chat.rb
|
2
|
-
index
|
2
|
+
index 701cd1e..07acc40 100644
|
3
3
|
--- a/lib/slack/web/api/endpoints/chat.rb
|
4
4
|
+++ b/lib/slack/web/api/endpoints/chat.rb
|
5
|
-
@@ -
|
6
|
-
# @see https://api.slack.com/methods/chat.postEphemeral
|
5
|
+
@@ -122,9 +122,21 @@ module Slack
|
7
6
|
# @see https://github.com/slack-ruby/slack-api-ref/blob/master/methods/chat/chat.postEphemeral.json
|
8
7
|
def chat_postEphemeral(options = {})
|
9
|
-
|
10
|
-
-
|
11
|
-
+
|
12
|
-
|
8
|
+
raise ArgumentError, 'Required arguments :channel missing' if options[:channel].nil?
|
9
|
+
- raise ArgumentError, 'Required arguments :text missing' if options[:text].nil?
|
10
|
+
+ raise ArgumentError, 'Required arguments :text, :attachments or :blocks missing' if options[:text].nil? && options[:attachments].nil? && options[:blocks].nil?
|
11
|
+
raise ArgumentError, 'Required arguments :user missing' if options[:user].nil?
|
13
12
|
options = options.merge(user: users_id(options)['user']['id']) if options[:user]
|
14
13
|
+ # attachments must be passed as an encoded JSON string
|
15
14
|
+ if options.key?(:attachments)
|
@@ -26,11 +25,11 @@ index d090ae2..50186d5 100644
|
|
26
25
|
post('chat.postEphemeral', options)
|
27
26
|
end
|
28
27
|
|
29
|
-
@@ -
|
28
|
+
@@ -167,6 +179,19 @@ module Slack
|
30
29
|
# @see https://github.com/slack-ruby/slack-api-ref/blob/master/methods/chat/chat.postMessage.json
|
31
30
|
def chat_postMessage(options = {})
|
32
|
-
|
33
|
-
+
|
31
|
+
raise ArgumentError, 'Required arguments :channel missing' if options[:channel].nil?
|
32
|
+
+ raise ArgumentError, 'Required arguments :text, :attachments or :blocks missing' if options[:text].nil? && options[:attachments].nil? && options[:blocks].nil?
|
34
33
|
+ # attachments must be passed as an encoded JSON string
|
35
34
|
+ if options.key?(:attachments)
|
36
35
|
+ attachments = options[:attachments]
|
@@ -46,12 +45,12 @@ index d090ae2..50186d5 100644
|
|
46
45
|
post('chat.postMessage', options)
|
47
46
|
end
|
48
47
|
|
49
|
-
@@ -
|
48
|
+
@@ -268,8 +293,21 @@ module Slack
|
50
49
|
# @see https://github.com/slack-ruby/slack-api-ref/blob/master/methods/chat/chat.update.json
|
51
50
|
def chat_update(options = {})
|
52
|
-
|
53
|
-
+
|
54
|
-
|
51
|
+
raise ArgumentError, 'Required arguments :channel missing' if options[:channel].nil?
|
52
|
+
+ raise ArgumentError, 'Required arguments :text, :attachments, :blocks or :reply_broadcast missing' if options[:text].nil? && options[:attachments].nil? && options[:blocks].nil? && options[:reply_broadcast].nil?
|
53
|
+
raise ArgumentError, 'Required arguments :ts missing' if options[:ts].nil?
|
55
54
|
options = options.merge(channel: conversations_id(options)['channel']['id']) if options[:channel]
|
56
55
|
+ # attachments must be passed as an encoded JSON string
|
57
56
|
+ if options.key?(:attachments)
|
data/lib/slack/web/api/patches/{dialog.1.open-json-support.patch → dialog.encoded-json.patch}
RENAMED
@@ -1,11 +1,11 @@
|
|
1
1
|
diff --git a/lib/slack/web/api/endpoints/dialog.rb b/lib/slack/web/api/endpoints/dialog.rb
|
2
|
-
index
|
2
|
+
index 05475c8..a4ff4ff 100644
|
3
3
|
--- a/lib/slack/web/api/endpoints/dialog.rb
|
4
4
|
+++ b/lib/slack/web/api/endpoints/dialog.rb
|
5
|
-
@@ -
|
5
|
+
@@ -18,6 +18,12 @@ module Slack
|
6
6
|
def dialog_open(options = {})
|
7
|
-
|
8
|
-
|
7
|
+
raise ArgumentError, 'Required arguments :dialog missing' if options[:dialog].nil?
|
8
|
+
raise ArgumentError, 'Required arguments :trigger_id missing' if options[:trigger_id].nil?
|
9
9
|
+ # dialog must be passed as an encoded JSON string
|
10
10
|
+ if options.key?(:dialog)
|
11
11
|
+ dialog = options[:dialog]
|
@@ -0,0 +1,55 @@
|
|
1
|
+
diff --git a/lib/slack/web/api/endpoints/views.rb b/lib/slack/web/api/endpoints/views.rb
|
2
|
+
index cfa83a5..038c5f0 100644
|
3
|
+
--- a/lib/slack/web/api/endpoints/views.rb
|
4
|
+
+++ b/lib/slack/web/api/endpoints/views.rb
|
5
|
+
@@ -19,6 +19,12 @@ module Slack
|
6
|
+
# @see https://github.com/slack-ruby/slack-api-ref/blob/master/methods/views/views.open.json
|
7
|
+
def views_open(options = {})
|
8
|
+
raise ArgumentError, 'Required arguments :view missing' if options[:view].nil?
|
9
|
+
+ raise ArgumentError, 'One of :trigger_id, :interactivity_pointer is required' unless options[:trigger_id].nil? ^ options[:interactivity_pointer].nil?
|
10
|
+
+ if options.key?(:view)
|
11
|
+
+ view = options[:view]
|
12
|
+
+ view = JSON.dump(view) unless view.is_a?(String)
|
13
|
+
+ options = options.merge(view: view)
|
14
|
+
+ end
|
15
|
+
post('views.open', options)
|
16
|
+
end
|
17
|
+
|
18
|
+
@@ -36,6 +42,11 @@ module Slack
|
19
|
+
def views_publish(options = {})
|
20
|
+
raise ArgumentError, 'Required arguments :user_id missing' if options[:user_id].nil?
|
21
|
+
raise ArgumentError, 'Required arguments :view missing' if options[:view].nil?
|
22
|
+
+ if options.key?(:view)
|
23
|
+
+ view = options[:view]
|
24
|
+
+ view = JSON.dump(view) unless view.is_a?(String)
|
25
|
+
+ options = options.merge(view: view)
|
26
|
+
+ end
|
27
|
+
post('views.publish', options)
|
28
|
+
end
|
29
|
+
|
30
|
+
@@ -52,6 +63,12 @@ module Slack
|
31
|
+
# @see https://github.com/slack-ruby/slack-api-ref/blob/master/methods/views/views.push.json
|
32
|
+
def views_push(options = {})
|
33
|
+
raise ArgumentError, 'Required arguments :view missing' if options[:view].nil?
|
34
|
+
+ raise ArgumentError, 'One of :trigger_id, :interactivity_pointer is required' unless options[:trigger_id].nil? ^ options[:interactivity_pointer].nil?
|
35
|
+
+ if options.key?(:view)
|
36
|
+
+ view = options[:view]
|
37
|
+
+ view = JSON.dump(view) unless view.is_a?(String)
|
38
|
+
+ options = options.merge(view: view)
|
39
|
+
+ end
|
40
|
+
post('views.push', options)
|
41
|
+
end
|
42
|
+
|
43
|
+
@@ -70,6 +87,12 @@ module Slack
|
44
|
+
# @see https://github.com/slack-ruby/slack-api-ref/blob/master/methods/views/views.update.json
|
45
|
+
def views_update(options = {})
|
46
|
+
raise ArgumentError, 'Required arguments :view missing' if options[:view].nil?
|
47
|
+
+ raise ArgumentError, 'One of :external_id, :view_id is required' unless options[:external_id].nil? ^ options[:view_id].nil?
|
48
|
+
+ if options.key?(:view)
|
49
|
+
+ view = options[:view]
|
50
|
+
+ view = JSON.dump(view) unless view.is_a?(String)
|
51
|
+
+ options = options.merge(view: view)
|
52
|
+
+ end
|
53
|
+
post('views.update', options)
|
54
|
+
end
|
55
|
+
end
|
@@ -1,13 +1,16 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
# This file was auto-generated by lib/tasks/web.rake
|
3
3
|
|
4
|
+
module Slack
|
5
|
+
module Cli
|
6
|
+
class App
|
4
7
|
<% desc = group['desc'] || "#{group['name'].gsub(".", "_").camelize} methods." %>
|
5
8
|
<% if desc.include?("'") %>
|
6
|
-
desc "<%= desc %>"
|
9
|
+
desc "<%= desc %>"
|
7
10
|
<% else %>
|
8
|
-
desc '<%= desc %>'
|
11
|
+
desc '<%= desc %>'
|
9
12
|
<% end %>
|
10
|
-
command '<%= group['name'].gsub(".", "_") %>' do |g|
|
13
|
+
command '<%= group['name'].gsub(".", "_") %>' do |g|
|
11
14
|
<% names.sort.each_with_index do |(name, data), index| %>
|
12
15
|
<% if index > 0 %>
|
13
16
|
|
@@ -15,22 +18,25 @@ command '<%= group['name'].gsub(".", "_") %>' do |g|
|
|
15
18
|
<% short_desc = data["desc"].split("\n").first %>
|
16
19
|
<% short_desc += ' (undocumented)' if data['undocumented'] %>
|
17
20
|
<% if short_desc.include?("'") %>
|
18
|
-
|
21
|
+
g.desc "<%= short_desc %>"
|
19
22
|
<% else %>
|
20
|
-
|
23
|
+
g.desc '<%= short_desc %>'
|
21
24
|
<% end %>
|
22
|
-
|
23
|
-
|
25
|
+
g.long_desc %( <%= data["desc"].split("\n").join(" ") %> )
|
26
|
+
g.command '<%= name %>' do |c|
|
24
27
|
<% data["args"].each do |arg_name, arg_v| %>
|
25
28
|
<% if arg_v["desc"].include?("'") %>
|
26
|
-
|
29
|
+
c.flag '<%= arg_name %>', desc: "<%= arg_v["desc"].gsub('"', '\'') %>"
|
27
30
|
<% else %>
|
28
|
-
|
31
|
+
c.flag '<%= arg_name %>', desc: '<%= arg_v["desc"] %>'
|
29
32
|
<% end %>
|
30
33
|
<% end %>
|
31
|
-
|
32
|
-
|
34
|
+
c.action do |_global_options, options, _args|
|
35
|
+
puts JSON.dump(@client.<%=group['name'].gsub(".", "_") %>_<%= name %>(options))
|
36
|
+
end
|
37
|
+
end
|
38
|
+
<% end %>
|
39
|
+
end
|
33
40
|
end
|
34
41
|
end
|
35
|
-
<% end %>
|
36
42
|
end
|
@@ -35,7 +35,7 @@ module Slack
|
|
35
35
|
<% end %>
|
36
36
|
def <%= group.gsub(".", "_") %>_<%= name %>(options = {})
|
37
37
|
<% data['args'].select{ |k, v| v['required'] }.each do |arg_name, arg_v| %>
|
38
|
-
|
38
|
+
raise ArgumentError, 'Required arguments :<%= arg_name %> missing' if options[:<%= arg_name %>].nil?
|
39
39
|
<% end %>
|
40
40
|
<% if data['group'] == 'groups' && data['args']['channel'] && !data['args']['channel']['desc'].include?('Can be an encoded ID, or a name.') %>
|
41
41
|
options = options.merge(channel: groups_id(options)['group']['id']) if options[:channel]
|
data/lib/slack/web/config.rb
CHANGED
@@ -24,8 +24,8 @@ module Slack
|
|
24
24
|
def reset
|
25
25
|
self.endpoint = 'https://slack.com/api/'
|
26
26
|
self.user_agent = "Slack Ruby Client/#{Slack::VERSION}"
|
27
|
-
self.ca_path =
|
28
|
-
self.ca_file =
|
27
|
+
self.ca_path = nil
|
28
|
+
self.ca_file = nil
|
29
29
|
self.token = nil
|
30
30
|
self.proxy = nil
|
31
31
|
self.logger = nil
|
@@ -22,11 +22,11 @@ module Slack
|
|
22
22
|
options[:request] = request_options if request_options.any?
|
23
23
|
|
24
24
|
::Faraday::Connection.new(endpoint, options) do |connection|
|
25
|
-
connection.
|
26
|
-
connection.
|
25
|
+
connection.request :multipart
|
26
|
+
connection.request :url_encoded
|
27
27
|
connection.use ::Slack::Web::Faraday::Response::RaiseError
|
28
|
-
connection.
|
29
|
-
connection.
|
28
|
+
connection.response :mashify, mash_class: Slack::Messages::Message
|
29
|
+
connection.response :json, content_type: /\b*$/
|
30
30
|
connection.use ::Slack::Web::Faraday::Response::WrapError
|
31
31
|
connection.response :logger, logger if logger
|
32
32
|
connection.adapter adapter
|
@@ -3,7 +3,7 @@ module Slack
|
|
3
3
|
module Web
|
4
4
|
module Faraday
|
5
5
|
module Response
|
6
|
-
class RaiseError < ::Faraday::
|
6
|
+
class RaiseError < ::Faraday::Middleware
|
7
7
|
def on_complete(env)
|
8
8
|
raise Slack::Web::Api::Errors::TooManyRequestsError, env.response if env.status == 429
|
9
9
|
|
@@ -13,19 +13,11 @@ module Slack
|
|
13
13
|
return unless body
|
14
14
|
return if body['ok']
|
15
15
|
|
16
|
-
error_message =
|
17
|
-
body['error'] || body['errors'].map { |message| message['error'] }.join(',')
|
18
|
-
|
16
|
+
error_message = body['error'] || body['errors'].map { |message| message['error'] }.join(',')
|
19
17
|
error_class = Slack::Web::Api::Errors::ERROR_CLASSES[error_message]
|
20
18
|
error_class ||= Slack::Web::Api::Errors::SlackError
|
21
19
|
raise error_class.new(error_message, env.response)
|
22
20
|
end
|
23
|
-
|
24
|
-
def call(env)
|
25
|
-
super
|
26
|
-
rescue ::Faraday::ParsingError
|
27
|
-
raise Slack::Web::Api::Errors::ParsingError, env.response
|
28
|
-
end
|
29
21
|
end
|
30
22
|
end
|
31
23
|
end
|
data/lib/slack-ruby-client.rb
CHANGED
data/lib/tasks/real_time.rake
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
|
2
|
+
|
3
3
|
require 'json-schema'
|
4
4
|
require 'erubis'
|
5
5
|
|
6
|
+
# largely from https://github.com/aki017/slack-ruby-gem
|
6
7
|
namespace :slack do
|
7
8
|
namespace :real_time do
|
8
9
|
namespace :api do
|
@@ -16,43 +17,62 @@ namespace :slack do
|
|
16
17
|
name = File.basename(path, '.json')
|
17
18
|
parsed = JSON.parse(File.read(path))
|
18
19
|
JSON::Validator.validate(event_schema, parsed, insert_defaults: true)
|
19
|
-
next if
|
20
|
+
next if name == 'message'
|
20
21
|
|
21
22
|
result[name] = parsed
|
22
23
|
end
|
23
24
|
|
24
|
-
|
25
|
-
Erubis::Eruby.new(File.read('lib/slack/real_time/api/templates/event_handler.erb'))
|
25
|
+
hook_template = Erubis::Eruby.new(File.read('lib/slack/real_time/api/templates/event_handler.erb'))
|
26
26
|
Dir.glob('lib/slack/real_time/stores/**/*.rb').each do |store_file|
|
27
27
|
next if File.basename(store_file) == 'base.rb'
|
28
28
|
|
29
|
-
STDOUT.write "#{File.basename(store_file)}:"
|
29
|
+
STDOUT.write "#{File.basename(store_file)}: "
|
30
30
|
|
31
31
|
store_file_contents = File.read(store_file)
|
32
32
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
else
|
37
|
-
STDOUT.write('x')
|
38
|
-
rendered_event_handler = event_handler_template.result(
|
39
|
-
name: event_data['name'],
|
40
|
-
desc: event_data['desc']
|
41
|
-
)
|
42
|
-
|
43
|
-
store_file_contents.gsub!(
|
44
|
-
REAL_TIME_EVENTS_MARKER,
|
45
|
-
REAL_TIME_EVENTS_MARKER +
|
46
|
-
"\n\n" +
|
47
|
-
rendered_event_handler.rstrip
|
48
|
-
)
|
49
|
-
end
|
33
|
+
unless store_file_contents.include?(REAL_TIME_EVENTS_MARKER)
|
34
|
+
puts "missing '#{REAL_TIME_EVENTS_MARKER}' line; skipping."
|
35
|
+
next
|
50
36
|
end
|
51
37
|
|
52
|
-
|
53
|
-
|
38
|
+
# Extract current hook implementations from the store class
|
39
|
+
hooks = {}
|
40
|
+
hook_matcher = /
|
41
|
+
(?:^[[:blank:]]*\R)+ # At least one blank line
|
42
|
+
(?:^[[:blank:]]*\#.*\R)* # Optional preceding comments
|
43
|
+
(?<hook> # on :event do |data|
|
44
|
+
^(?<padding>[[:blank:]]+)\#\ *on\ :(?<event>\w+)\ do\ \|[\w, ]+\|\ *\R # Commented hook
|
45
|
+
(?>^\k<padding>\#.*\R)* # Extra comments
|
46
|
+
|
|
47
|
+
^(?<padding>[[:blank:]]+)on\ :(?<event>\w+)\ do\ \|[\w, ]+\|\ *\R # Active hook
|
48
|
+
[\s\S]*? # Inside block
|
49
|
+
(?>^\k<padding>end[[:blank:]]*\R) # End of block
|
50
|
+
)
|
51
|
+
/x
|
52
|
+
store_file_contents.gsub!(hook_matcher) do
|
53
|
+
hook, event = Regexp.last_match.values_at(:hook, :event)
|
54
|
+
hooks[event] = hook
|
55
|
+
nil
|
54
56
|
end
|
55
57
|
|
58
|
+
# Render latest event documentation with current hook implementations
|
59
|
+
rendered_hooks = events.sort.map do |event_name, event_data|
|
60
|
+
STDOUT.write(hooks.key?(event_name) ? '.' : 'x')
|
61
|
+
|
62
|
+
hook_template.result(
|
63
|
+
name: event_data['name'],
|
64
|
+
desc: event_data['desc'],
|
65
|
+
hook: hooks[event_name]
|
66
|
+
).rstrip
|
67
|
+
end
|
68
|
+
|
69
|
+
# Insert updated event hooks under RealTime Events marker
|
70
|
+
store_file_contents.gsub!(
|
71
|
+
REAL_TIME_EVENTS_MARKER,
|
72
|
+
[REAL_TIME_EVENTS_MARKER, *rendered_hooks].join("\n\n")
|
73
|
+
)
|
74
|
+
File.write(store_file, store_file_contents)
|
75
|
+
|
56
76
|
puts ' done.'
|
57
77
|
end
|
58
78
|
end
|
data/lib/tasks/web.rake
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
|
2
|
+
|
3
3
|
require 'json-schema'
|
4
4
|
require 'erubis'
|
5
5
|
require 'active_support'
|
6
6
|
require 'active_support/core_ext'
|
7
7
|
|
8
|
+
# largely from https://github.com/aki017/slack-ruby-gem
|
8
9
|
namespace :slack do
|
9
10
|
namespace :web do
|
10
11
|
namespace :api do
|
@@ -39,11 +40,17 @@ namespace :slack do
|
|
39
40
|
result[prefix][name] = parsed
|
40
41
|
end
|
41
42
|
|
43
|
+
# Start with a fresh slate
|
44
|
+
Dir.glob('lib/slack/web/api/endpoints/*.rb').each { |file| File.delete(file) }
|
45
|
+
Dir.glob('spec/slack/web/api/endpoints/*_spec.rb').each { |file| File.delete(file) }
|
46
|
+
Dir.glob('bin/commands/*.rb').each { |file| File.delete(file) }
|
47
|
+
|
42
48
|
method_template = Erubis::Eruby.new(File.read('lib/slack/web/api/templates/method.erb'))
|
43
49
|
method_spec_template =
|
44
50
|
Erubis::Eruby.new(File.read('lib/slack/web/api/templates/method_spec.erb'))
|
45
51
|
command_template = Erubis::Eruby.new(File.read('lib/slack/web/api/templates/command.erb'))
|
46
|
-
|
52
|
+
|
53
|
+
data.each.with_index(1) do |(group, names), index|
|
47
54
|
printf "%2d/%2d %10s %s\n", index, data.size, group, names.keys
|
48
55
|
# method
|
49
56
|
snaked_group = group.tr('.', '_')
|
@@ -77,12 +84,6 @@ namespace :slack do
|
|
77
84
|
endpoints_template.result(files: data.keys.map { |key| key.tr('.', '_') })
|
78
85
|
)
|
79
86
|
|
80
|
-
commands_template = Erubis::Eruby.new(File.read('lib/slack/web/api/templates/commands.erb'))
|
81
|
-
File.write(
|
82
|
-
'bin/commands.rb',
|
83
|
-
commands_template.result(files: data.keys.map { |key| key.tr('.', '_') })
|
84
|
-
)
|
85
|
-
|
86
87
|
errors_template = Erubis::Eruby.new(File.read('lib/slack/web/api/templates/errors.erb'))
|
87
88
|
errors = data.values.map do |names|
|
88
89
|
names.values.map do |d|
|
data/slack-ruby-client.gemspec
CHANGED
@@ -10,26 +10,17 @@ Gem::Specification.new do |s|
|
|
10
10
|
s.authors = ['Daniel Doubrovkine']
|
11
11
|
s.email = 'dblock@dblock.org'
|
12
12
|
s.platform = Gem::Platform::RUBY
|
13
|
+
s.required_ruby_version = '>= 2.7'
|
13
14
|
s.required_rubygems_version = '>= 1.3.6'
|
14
15
|
s.files = `git ls-files`.split("\n")
|
15
16
|
s.require_paths = ['lib']
|
16
17
|
s.homepage = 'http://github.com/slack-ruby/slack-ruby-client'
|
17
18
|
s.licenses = ['MIT']
|
18
19
|
s.summary = 'Slack Web and RealTime API client.'
|
19
|
-
s.add_dependency 'faraday', '>=
|
20
|
-
s.add_dependency '
|
20
|
+
s.add_dependency 'faraday', '>= 2.0'
|
21
|
+
s.add_dependency 'faraday-mashify'
|
22
|
+
s.add_dependency 'faraday-multipart'
|
21
23
|
s.add_dependency 'gli'
|
22
24
|
s.add_dependency 'hashie'
|
23
|
-
s.
|
24
|
-
s.add_development_dependency 'activesupport'
|
25
|
-
s.add_development_dependency 'erubis'
|
26
|
-
s.add_development_dependency 'json-schema'
|
27
|
-
s.add_development_dependency 'rake', '~> 13'
|
28
|
-
s.add_development_dependency 'rspec'
|
29
|
-
s.add_development_dependency 'rubocop', '~> 0.93.1'
|
30
|
-
s.add_development_dependency 'rubocop-performance', '~> 1.5.2'
|
31
|
-
s.add_development_dependency 'rubocop-rspec', '~> 1.39.0'
|
32
|
-
s.add_development_dependency 'timecop'
|
33
|
-
s.add_development_dependency 'vcr'
|
34
|
-
s.add_development_dependency 'webmock'
|
25
|
+
s.metadata['rubygems_mfa_required'] = 'true'
|
35
26
|
end
|
@@ -304,4 +304,88 @@ http_interactions:
|
|
304
304
|
encoding: UTF-8
|
305
305
|
string: '{"ok":false,"error":"invalid_array_arg"}'
|
306
306
|
recorded_at: Sat, 19 Jan 2019 21:25:48 GMT
|
307
|
-
|
307
|
+
- request:
|
308
|
+
method: post
|
309
|
+
uri: https://slack.com/api/rtm.connect
|
310
|
+
body:
|
311
|
+
encoding: UTF-8
|
312
|
+
string: presence_sub=true
|
313
|
+
headers:
|
314
|
+
Accept:
|
315
|
+
- application/json; charset=utf-8
|
316
|
+
User-Agent:
|
317
|
+
- Slack Ruby Client/2.0.0
|
318
|
+
Authorization:
|
319
|
+
- Bearer <SLACK_API_TOKEN>
|
320
|
+
Content-Type:
|
321
|
+
- application/x-www-form-urlencoded
|
322
|
+
Accept-Encoding:
|
323
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
324
|
+
response:
|
325
|
+
status:
|
326
|
+
code: 200
|
327
|
+
message: OK
|
328
|
+
headers:
|
329
|
+
Date:
|
330
|
+
- Sun, 25 Sep 2022 22:32:50 GMT
|
331
|
+
Server:
|
332
|
+
- Apache
|
333
|
+
X-Powered-By:
|
334
|
+
- HHVM/4.153.1
|
335
|
+
Access-Control-Allow-Origin:
|
336
|
+
- "*"
|
337
|
+
Referrer-Policy:
|
338
|
+
- no-referrer
|
339
|
+
X-Slack-Backend:
|
340
|
+
- r
|
341
|
+
X-Slack-Unique-Id:
|
342
|
+
- YzDXEnlUBjX0uWkT8kmCzwAAABM
|
343
|
+
Strict-Transport-Security:
|
344
|
+
- max-age=31536000; includeSubDomains; preload
|
345
|
+
Access-Control-Allow-Headers:
|
346
|
+
- slack-route, x-slack-version-ts, x-b3-traceid, x-b3-spanid, x-b3-parentspanid,
|
347
|
+
x-b3-sampled, x-b3-flags
|
348
|
+
Access-Control-Expose-Headers:
|
349
|
+
- x-slack-req-id, retry-after
|
350
|
+
X-Oauth-Scopes:
|
351
|
+
- identify,bot:basic
|
352
|
+
X-Accepted-Oauth-Scopes:
|
353
|
+
- rtm:stream,client
|
354
|
+
Expires:
|
355
|
+
- Mon, 26 Jul 1997 05:00:00 GMT
|
356
|
+
Cache-Control:
|
357
|
+
- private, no-cache, no-store, must-revalidate
|
358
|
+
Pragma:
|
359
|
+
- no-cache
|
360
|
+
X-Xss-Protection:
|
361
|
+
- '0'
|
362
|
+
X-Content-Type-Options:
|
363
|
+
- nosniff
|
364
|
+
X-Slack-Req-Id:
|
365
|
+
- 20417f9da55172a329704fca8e35f683
|
366
|
+
Vary:
|
367
|
+
- Accept-Encoding
|
368
|
+
Content-Length:
|
369
|
+
- '275'
|
370
|
+
Content-Type:
|
371
|
+
- application/json; charset=utf-8
|
372
|
+
X-Envoy-Upstream-Service-Time:
|
373
|
+
- '116'
|
374
|
+
X-Backend:
|
375
|
+
- main_normal main_bedrock_normal_with_overflow main_canary_with_overflow main_bedrock_canary_with_overflow
|
376
|
+
main_control_with_overflow main_bedrock_control_with_overflow
|
377
|
+
X-Server:
|
378
|
+
- slack-www-hhvm-main-iad-fbwt
|
379
|
+
X-Slack-Shared-Secret-Outcome:
|
380
|
+
- no-match
|
381
|
+
Via:
|
382
|
+
- envoy-www-iad-twh3, envoy-edge-pdx-hvfy
|
383
|
+
X-Edge-Backend:
|
384
|
+
- envoy-www
|
385
|
+
X-Slack-Edge-Shared-Secret-Outcome:
|
386
|
+
- no-match
|
387
|
+
body:
|
388
|
+
encoding: UTF-8
|
389
|
+
string: '{"ok":true,"url":"wss:\/\/wss-primary.slack.com\/websocket\/IDugmjBU5vPyDN1rGavpMHB1CdAznuJDyHl3pqAHz_DSflTYmCyuPIxH1vwqvz3aIXhyarUZMxyWiJD7zako2Wqc_poO8uiP3i6teabXYTA4vx4Hu2pa9k9PACV1apgYJFRU_iw4g2c5qeo=\/2","team":{"id":"T04KB5WQH","name":"dblock","domain":"dblockdotorg"},"self":{"id":"U0J1GAHN1","name":"travis-ci"}}'
|
390
|
+
recorded_at: Sun, 25 Sep 2022 22:32:50 GMT
|
391
|
+
recorded_with: VCR 6.1.0
|
@@ -14,9 +14,11 @@ RSpec.describe Slack::Events::Config do
|
|
14
14
|
it 'defaults signing secret to ENV[SLACK_SIGNING_SECRET]' do
|
15
15
|
expect(Slack::Events.config.signing_secret).to eq 'secret'
|
16
16
|
end
|
17
|
+
|
17
18
|
it 'defaults signature expiration to 5 minutes' do
|
18
19
|
expect(Slack::Events.config.signature_expires_in).to eq 5 * 60
|
19
20
|
end
|
21
|
+
|
20
22
|
context 'configured' do
|
21
23
|
before do
|
22
24
|
Slack::Events.configure do |config|
|
@@ -18,7 +18,7 @@ RSpec.describe Slack::Events::Request do
|
|
18
18
|
let(:timestamp) { '1547933148' }
|
19
19
|
let(:body) do
|
20
20
|
'{"token":"X34FAqCu8tmGEkEEpoDncnja","challenge":' \
|
21
|
-
|
21
|
+
'"P7sFXA4o3HV2hTx4zb4zcQ9yrvuQs8pDh6EacOxmMRj0tJaXfQFF","type":"url_verification"}'
|
22
22
|
end
|
23
23
|
let(:http_request) do
|
24
24
|
request_double = double(
|
@@ -101,6 +101,7 @@ RSpec.describe Slack::Events::Request do
|
|
101
101
|
expect(request).to be_valid
|
102
102
|
expect(request).not_to be_expired
|
103
103
|
end
|
104
|
+
|
104
105
|
it 'does not raise an error and returns true' do
|
105
106
|
expect(request.verify!).to be true
|
106
107
|
end
|
@@ -115,6 +116,7 @@ RSpec.describe Slack::Events::Request do
|
|
115
116
|
expect(request).to be_valid
|
116
117
|
expect(request).to be_expired
|
117
118
|
end
|
119
|
+
|
118
120
|
it 'raises an error on verify!' do
|
119
121
|
expect { request.verify! }.to raise_error Slack::Events::Request::TimestampExpired
|
120
122
|
end
|
@@ -129,6 +131,7 @@ RSpec.describe Slack::Events::Request do
|
|
129
131
|
expect(request).to be_valid
|
130
132
|
expect(request).not_to be_expired
|
131
133
|
end
|
134
|
+
|
132
135
|
it 'does not raise an error on verify!' do
|
133
136
|
expect(request.verify!).to be true
|
134
137
|
end
|
@@ -143,6 +146,7 @@ RSpec.describe Slack::Events::Request do
|
|
143
146
|
expect(request).to be_valid
|
144
147
|
expect(request).to be_expired
|
145
148
|
end
|
149
|
+
|
146
150
|
it 'raises an error on verify!' do
|
147
151
|
expect { request.verify! }.to raise_error Slack::Events::Request::TimestampExpired
|
148
152
|
end
|