Skip to content

Commit d969dfb

Browse files
dblockCopilot
andcommitted
Expose response callbacks through request configuration blocks
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent b4ac50a commit d969dfb

99 files changed

Lines changed: 710 additions & 576 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
### 3.3.0 (Next)
22

3+
* [#605](https://github.com/slack-ruby/slack-ruby-client/pull/605): Add request configuration blocks with response callbacks to non-paginated generated API methods - [@dblock](https://github.com/dblock).
34
* [#603](https://github.com/slack-ruby/slack-ruby-client/pull/603): Enforce consistent exception messages with rubocop-exception_messages and run lint separately from the test matrix - [@dblock](https://github.com/dblock).
45
* [#602](https://github.com/slack-ruby/slack-ruby-client/pull/602): Make gli an optional dependency; only the `slack` command-line client needs it - [@corsonknowles](https://github.com/corsonknowles).
56
* [#599](https://github.com/slack-ruby/slack-ruby-client/pull/599): Set a default filename in `files_upload` so Slack displays image previews correctly when none is specified - [@ts-3156](https://github.com/ts-3156), [@dblock](https://github.com/dblock).

‎README.md‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,19 @@ You can also pass request options, including `timeout` and `open_timeout` into i
301301
client.conversations_list(request: { timeout: 180 })
302302
```
303303

304+
Non-paginated generated API methods accept a request-configuration block. Register a response callback to inspect headers without changing the method's parsed-body return value:
305+
306+
```ruby
307+
scopes = nil
308+
result = client.auth_test do |request|
309+
request.response do |response|
310+
scopes = response.headers['x-oauth-scopes']&.split(',')&.map(&:strip)
311+
end
312+
end
313+
```
314+
315+
The response is a `Faraday::Response` with the parsed body, headers, and status. Callbacks run after a successful request and propagate their own exceptions; they do not run when Slack or transport errors are raised. Multiple callbacks run in registration order. Request configuration runs before the HTTP call. Paginated methods retain their existing page-iteration blocks; handwritten helpers and mixins do not accept this configuration block. The low-level `get`, `post`, `put`, and `delete` methods also support it.
316+
304317
You can control what proxy options are used by modifying the `http_proxy` environment variable per [Net::HTTP's documentation](https://docs.ruby-lang.org/en/2.0.0/Net/HTTP.html#class-Net::HTTP-label-Proxies).
305318

306319
Note that Docker on OSX seems to incorrectly set the proxy, causing `Faraday::ConnectionFailed, ERROR -- : Failed to open TCP connection to : (getaddrinfo: Name or service not known)`. You might need to manually unset `http_proxy` in that case, eg. `http_proxy="" bundle exec ruby ./my_bot.rb`.

‎lib/slack/web/api/endpoints/admin_analytics.rb‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ module AdminAnalytics
1717
# Retrieve metadata for the type of analytics indicated. Can be used only with type set to public_channel analytics. See detail below. Omit the date parameter when using this argument.
1818
# @see https://api.slack.com/methods/admin.analytics.getFile
1919
# @see https://github.com/slack-ruby/slack-api-ref/blob/master/methods/admin.analytics/admin.analytics.getFile.json
20-
def admin_analytics_getFile(options = {})
20+
def admin_analytics_getFile(options = {}, &block)
2121
raise ArgumentError, 'Required arguments :type missing' if options[:type].nil?
22-
post('admin.analytics.getFile', options)
22+
post('admin.analytics.getFile', options, &block)
2323
end
2424
end
2525
end

‎lib/slack/web/api/endpoints/admin_apps.rb‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ module AdminApps
2525
# Bot scopes to approve for the app.
2626
# @see https://api.slack.com/methods/admin.apps.approve
2727
# @see https://github.com/slack-ruby/slack-api-ref/blob/master/methods/admin.apps/admin.apps.approve.json
28-
def admin_apps_approve(options = {})
29-
post('admin.apps.approve', options)
28+
def admin_apps_approve(options = {}, &block)
29+
post('admin.apps.approve', options, &block)
3030
end
3131

3232
#
@@ -40,9 +40,9 @@ def admin_apps_approve(options = {})
4040
# The enterprise to clear the app resolution from.
4141
# @see https://api.slack.com/methods/admin.apps.clearResolution
4242
# @see https://github.com/slack-ruby/slack-api-ref/blob/master/methods/admin.apps/admin.apps.clearResolution.json
43-
def admin_apps_clearResolution(options = {})
43+
def admin_apps_clearResolution(options = {}, &block)
4444
raise ArgumentError, 'Required arguments :app_id missing' if options[:app_id].nil?
45-
post('admin.apps.clearResolution', options)
45+
post('admin.apps.clearResolution', options, &block)
4646
end
4747

4848
#
@@ -58,8 +58,8 @@ def admin_apps_clearResolution(options = {})
5858
# The ID of the enterprise to approve the app on.
5959
# @see https://api.slack.com/methods/admin.apps.restrict
6060
# @see https://github.com/slack-ruby/slack-api-ref/blob/master/methods/admin.apps/admin.apps.restrict.json
61-
def admin_apps_restrict(options = {})
62-
post('admin.apps.restrict', options)
61+
def admin_apps_restrict(options = {}, &block)
62+
post('admin.apps.restrict', options, &block)
6363
end
6464

6565
#
@@ -73,9 +73,9 @@ def admin_apps_restrict(options = {})
7373
# The enterprise to completely uninstall the application from (across all workspaces). With an org-level token, this or team_ids is required.
7474
# @see https://api.slack.com/methods/admin.apps.uninstall
7575
# @see https://github.com/slack-ruby/slack-api-ref/blob/master/methods/admin.apps/admin.apps.uninstall.json
76-
def admin_apps_uninstall(options = {})
76+
def admin_apps_uninstall(options = {}, &block)
7777
raise ArgumentError, 'Required arguments :app_id missing' if options[:app_id].nil?
78-
post('admin.apps.uninstall', options)
78+
post('admin.apps.uninstall', options, &block)
7979
end
8080
end
8181
end

‎lib/slack/web/api/endpoints/admin_apps_config.rb‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ module AdminAppsConfig
1515
# return apps with the corresponding rich link preview layouts.
1616
# @see https://api.slack.com/methods/admin.apps.config.lookup
1717
# @see https://github.com/slack-ruby/slack-api-ref/blob/master/methods/admin.apps.config/admin.apps.config.lookup.json
18-
def admin_apps_config_lookup(options = {})
19-
post('admin.apps.config.lookup', options)
18+
def admin_apps_config_lookup(options = {}, &block)
19+
post('admin.apps.config.lookup', options, &block)
2020
end
2121

2222
#
@@ -32,9 +32,9 @@ def admin_apps_config_lookup(options = {})
3232
# Domain restrictions for the app. Should be an object with two properties: urls and emails. Each is an array of strings, and each sets the allowed URLs and emails for connector authorization, respectively.
3333
# @see https://api.slack.com/methods/admin.apps.config.set
3434
# @see https://github.com/slack-ruby/slack-api-ref/blob/master/methods/admin.apps.config/admin.apps.config.set.json
35-
def admin_apps_config_set(options = {})
35+
def admin_apps_config_set(options = {}, &block)
3636
raise ArgumentError, 'Required arguments :app_id missing' if options[:app_id].nil?
37-
post('admin.apps.config.set', options)
37+
post('admin.apps.config.set', options, &block)
3838
end
3939
end
4040
end

‎lib/slack/web/api/endpoints/admin_apps_mcp_servers_permissions.rb‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ module AdminAppsMcpServersPermissions
1313
# Encoded ID of the app.
1414
# @see https://api.slack.com/methods/admin.apps.mcp.servers.permissions.list
1515
# @see https://github.com/slack-ruby/slack-api-ref/blob/master/methods/admin.apps.mcp.servers.permissions/admin.apps.mcp.servers.permissions.list.json
16-
def admin_apps_mcp_servers_permissions_list(options = {})
16+
def admin_apps_mcp_servers_permissions_list(options = {}, &block)
1717
raise ArgumentError, 'Required arguments :app_id missing' if options[:app_id].nil?
18-
post('admin.apps.mcp.servers.permissions.list', options)
18+
post('admin.apps.mcp.servers.permissions.list', options, &block)
1919
end
2020

2121
#
@@ -33,11 +33,11 @@ def admin_apps_mcp_servers_permissions_list(options = {})
3333
# List of encoded usergroup IDs.
3434
# @see https://api.slack.com/methods/admin.apps.mcp.servers.permissions.set
3535
# @see https://github.com/slack-ruby/slack-api-ref/blob/master/methods/admin.apps.mcp.servers.permissions/admin.apps.mcp.servers.permissions.set.json
36-
def admin_apps_mcp_servers_permissions_set(options = {})
36+
def admin_apps_mcp_servers_permissions_set(options = {}, &block)
3737
raise ArgumentError, 'Required arguments :app_id missing' if options[:app_id].nil?
3838
raise ArgumentError, 'Required arguments :server_id missing' if options[:server_id].nil?
3939
raise ArgumentError, 'Required arguments :permission_type missing' if options[:permission_type].nil?
40-
post('admin.apps.mcp.servers.permissions.set', options)
40+
post('admin.apps.mcp.servers.permissions.set', options, &block)
4141
end
4242
end
4343
end

‎lib/slack/web/api/endpoints/admin_apps_permissions.rb‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ module AdminAppsPermissions
1919
# List of encoded channel IDs to add to the channel restriction list. Interpretation depends on the app's channel_restriction_mode, which is configured via the admin.apps.permissions.set method.
2020
# @see https://api.slack.com/methods/admin.apps.permissions.add
2121
# @see https://github.com/slack-ruby/slack-api-ref/blob/master/methods/admin.apps.permissions/admin.apps.permissions.add.json
22-
def admin_apps_permissions_add(options = {})
22+
def admin_apps_permissions_add(options = {}, &block)
2323
raise ArgumentError, 'Required arguments :app_id missing' if options[:app_id].nil?
24-
post('admin.apps.permissions.add', options)
24+
post('admin.apps.permissions.add', options, &block)
2525
end
2626

2727
#
@@ -31,9 +31,9 @@ def admin_apps_permissions_add(options = {})
3131
# Encoded ID of the app.
3232
# @see https://api.slack.com/methods/admin.apps.permissions.list
3333
# @see https://github.com/slack-ruby/slack-api-ref/blob/master/methods/admin.apps.permissions/admin.apps.permissions.list.json
34-
def admin_apps_permissions_list(options = {})
34+
def admin_apps_permissions_list(options = {}, &block)
3535
raise ArgumentError, 'Required arguments :app_id missing' if options[:app_id].nil?
36-
post('admin.apps.permissions.list', options)
36+
post('admin.apps.permissions.list', options, &block)
3737
end
3838

3939
#
@@ -49,9 +49,9 @@ def admin_apps_permissions_list(options = {})
4949
# List of encoded channel IDs to remove from the channel restriction list. Interpretation depends on the app's channel_restriction_mode, which is configured via the admin.apps.permissions.set method.
5050
# @see https://api.slack.com/methods/admin.apps.permissions.remove
5151
# @see https://github.com/slack-ruby/slack-api-ref/blob/master/methods/admin.apps.permissions/admin.apps.permissions.remove.json
52-
def admin_apps_permissions_remove(options = {})
52+
def admin_apps_permissions_remove(options = {}, &block)
5353
raise ArgumentError, 'Required arguments :app_id missing' if options[:app_id].nil?
54-
post('admin.apps.permissions.remove', options)
54+
post('admin.apps.permissions.remove', options, &block)
5555
end
5656

5757
#
@@ -71,10 +71,10 @@ def admin_apps_permissions_remove(options = {})
7171
# List of encoded channel IDs for channel restrictions. Semantics depend on channel_restriction_mode: allowlist for specific_channels, exclusion list for all_channels_except.
7272
# @see https://api.slack.com/methods/admin.apps.permissions.set
7373
# @see https://github.com/slack-ruby/slack-api-ref/blob/master/methods/admin.apps.permissions/admin.apps.permissions.set.json
74-
def admin_apps_permissions_set(options = {})
74+
def admin_apps_permissions_set(options = {}, &block)
7575
raise ArgumentError, 'Required arguments :app_id missing' if options[:app_id].nil?
7676
raise ArgumentError, 'Required arguments :permission_type missing' if options[:permission_type].nil?
77-
post('admin.apps.permissions.set', options)
77+
post('admin.apps.permissions.set', options, &block)
7878
end
7979
end
8080
end

‎lib/slack/web/api/endpoints/admin_apps_requests.rb‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ module AdminAppsRequests
1717
# The ID of the enterprise where this request belongs.
1818
# @see https://api.slack.com/methods/admin.apps.requests.cancel
1919
# @see https://github.com/slack-ruby/slack-api-ref/blob/master/methods/admin.apps.requests/admin.apps.requests.cancel.json
20-
def admin_apps_requests_cancel(options = {})
20+
def admin_apps_requests_cancel(options = {}, &block)
2121
raise ArgumentError, 'Required arguments :request_id missing' if options[:request_id].nil?
22-
post('admin.apps.requests.cancel', options)
22+
post('admin.apps.requests.cancel', options, &block)
2323
end
2424

2525
#

‎lib/slack/web/api/endpoints/admin_audit_anomaly_allow.rb‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ module AdminAuditAnomalyAllow
1111
#
1212
# @see https://api.slack.com/methods/admin.audit.anomaly.allow.getItem
1313
# @see https://github.com/slack-ruby/slack-api-ref/blob/master/methods/admin.audit.anomaly.allow/admin.audit.anomaly.allow.getItem.json
14-
def admin_audit_anomaly_allow_getItem(options = {})
15-
post('admin.audit.anomaly.allow.getItem', options)
14+
def admin_audit_anomaly_allow_getItem(options = {}, &block)
15+
post('admin.audit.anomaly.allow.getItem', options, &block)
1616
end
1717

1818
#
@@ -24,8 +24,8 @@ def admin_audit_anomaly_allow_getItem(options = {})
2424
# allow list of Autonomous System Numbers (ASN) in the Enterprise organization configuration.
2525
# @see https://api.slack.com/methods/admin.audit.anomaly.allow.updateItem
2626
# @see https://github.com/slack-ruby/slack-api-ref/blob/master/methods/admin.audit.anomaly.allow/admin.audit.anomaly.allow.updateItem.json
27-
def admin_audit_anomaly_allow_updateItem(options = {})
28-
post('admin.audit.anomaly.allow.updateItem', options)
27+
def admin_audit_anomaly_allow_updateItem(options = {}, &block)
28+
post('admin.audit.anomaly.allow.updateItem', options, &block)
2929
end
3030
end
3131
end

‎lib/slack/web/api/endpoints/admin_auth_policy.rb‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ module AdminAuthPolicy
1717
# Array of IDs to assign to the policy.
1818
# @see https://api.slack.com/methods/admin.auth.policy.assignEntities
1919
# @see https://github.com/slack-ruby/slack-api-ref/blob/master/methods/admin.auth.policy/admin.auth.policy.assignEntities.json
20-
def admin_auth_policy_assignEntities(options = {})
20+
def admin_auth_policy_assignEntities(options = {}, &block)
2121
raise ArgumentError, 'Required arguments :policy_name missing' if options[:policy_name].nil?
2222
raise ArgumentError, 'Required arguments :entity_type missing' if options[:entity_type].nil?
2323
raise ArgumentError, 'Required arguments :entity_ids missing' if options[:entity_ids].nil?
24-
post('admin.auth.policy.assignEntities', options)
24+
post('admin.auth.policy.assignEntities', options, &block)
2525
end
2626

2727
#
@@ -59,11 +59,11 @@ def admin_auth_policy_getEntities(options = {})
5959
# Encoded IDs of the entities you'd like to remove from the policy.
6060
# @see https://api.slack.com/methods/admin.auth.policy.removeEntities
6161
# @see https://github.com/slack-ruby/slack-api-ref/blob/master/methods/admin.auth.policy/admin.auth.policy.removeEntities.json
62-
def admin_auth_policy_removeEntities(options = {})
62+
def admin_auth_policy_removeEntities(options = {}, &block)
6363
raise ArgumentError, 'Required arguments :policy_name missing' if options[:policy_name].nil?
6464
raise ArgumentError, 'Required arguments :entity_type missing' if options[:entity_type].nil?
6565
raise ArgumentError, 'Required arguments :entity_ids missing' if options[:entity_ids].nil?
66-
post('admin.auth.policy.removeEntities', options)
66+
post('admin.auth.policy.removeEntities', options, &block)
6767
end
6868
end
6969
end

0 commit comments

Comments
 (0)