Skip to content

Commit 5c91fe4

Browse files
committed
*_id methods may be supplied with all sensible options
1 parent cabf9d2 commit 5c91fe4

File tree

5 files changed

+35
-8
lines changed

5 files changed

+35
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
* [#554](https://github.com/slack-ruby/slack-ruby-client/pull/557): Require Faraday >= 2.0.1 - [@anrichvs](https://github.com/AnrichVS).
44
* [#559](https://github.com/slack-ruby/slack-ruby-client/pull/559): Enable name-to-id translation of non-public channels - [@eizengan](https://github.com/eizengan).
5+
* [#560](https://github.com/slack-ruby/slack-ruby-client/pull/560): Name-to-id translation can supply all sensible list options - [@eizengan](https://github.com/eizengan).
56
* Your contribution here.
67

78
### 2.6.0 (2025/05/24)

lib/slack/web/api/mixins/conversations.id.rb

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,18 @@ module Conversations
1212
#
1313
# @option options [channel] :channel
1414
# Channel to get ID for, prefixed with #.
15+
# @option options [string] :team_id
16+
# The team id to search for channels in, required if token belongs to org-wide app.
17+
# This field will be ignored if the API call is sent using a workspace-level token.
18+
# @option options [boolean] :id_exclude_archived
19+
# Set to true to exclude archived channels from the search
1520
# @option options [integer] :id_limit
1621
# The page size used for conversations_list calls required to find the channel's ID
1722
# @option options [string] :id_types
1823
# The types of conversations to use when searching for the ID. A comma-separated list
1924
# containing one or more of public_channel, private_channel, mpim, im
2025
def conversations_id(options = {})
2126
name = options[:channel]
22-
limit = options.fetch(:id_limit, Slack::Web.config.conversations_id_page_size)
23-
types = options.fetch(:id_types, nil)
24-
2527
raise ArgumentError, 'Required arguments :channel missing' if name.nil?
2628

2729
id_for(
@@ -30,7 +32,12 @@ def conversations_id(options = {})
3032
prefix: '#',
3133
enum_method: :conversations_list,
3234
list_method: :channels,
33-
options: { limit: limit, types: types }.compact
35+
options: {
36+
team_id: options.fetch(:team_id, nil),
37+
exclude_archived: options.fetch(:id_exclude_archived, nil),
38+
limit: options.fetch(:id_limit, Slack::Web.config.conversations_id_page_size),
39+
types: options.fetch(:id_types, nil)
40+
}.compact
3441
)
3542
end
3643
end

lib/slack/web/api/mixins/users.id.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@ module Users
1212
#
1313
# @option options [user] :user
1414
# User to get ID for, prefixed with '@'.
15+
# @option options [string] :team_id
16+
# The team id to search for users in, required if token belongs to org-wide app.
17+
# This field will be ignored if the API call is sent using a workspace-level token.
1518
# @option options [integer] :id_limit
1619
# The page size used for users_list calls required to find the user's ID
1720
def users_id(options = {})
1821
name = options[:user]
19-
limit = options.fetch(:id_limit, Slack::Web.config.users_id_page_size)
20-
2122
raise ArgumentError, 'Required arguments :user missing' if name.nil?
2223

2324
id_for(
@@ -26,7 +27,10 @@ def users_id(options = {})
2627
prefix: '@',
2728
enum_method: :users_list,
2829
list_method: :members,
29-
options: { limit: limit }.compact
30+
options: {
31+
team_id: options.fetch(:team_id, nil),
32+
limit: options.fetch(:id_limit, Slack::Web.config.users_id_page_size)
33+
}.compact
3034
)
3135
end
3236
end

spec/slack/web/api/mixins/conversations_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@
3737
)
3838
end
3939

40+
it 'forwards a provided team_id to the underlying conversations_list calls' do
41+
expect(conversations).to receive(:conversations_list).with(team_id: 'T1234567890')
42+
conversations.conversations_id(channel: '#general', team_id: 'T1234567890')
43+
end
44+
45+
it 'forwards a provided exclude_archived to the underlying conversations_list calls' do
46+
expect(conversations).to receive(:conversations_list).with(exclude_archived: true)
47+
conversations.conversations_id(channel: '#general', id_exclude_archived: true)
48+
end
49+
4050
it 'forwards the provided limit to the underlying conversations_list calls' do
4151
expect(conversations).to receive(:conversations_list).with(limit: 1234)
4252
conversations.conversations_id(channel: '#general', id_limit: 1234)

spec/slack/web/api/mixins/users_spec.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@
3434
expect(users.users_id(user: '@aws')).to eq('ok' => true, 'user' => { 'id' => 'UDEADBEEF' })
3535
end
3636

37+
it 'forwards a provided team_id to the underlying users_list calls' do
38+
expect(users).to receive(:users_list).with(team_id: 'T1234567890')
39+
users.users_id(user: '@aws', team_id: 'T1234567890')
40+
end
41+
3742
it 'forwards a provided limit to the underlying users_list calls' do
3843
expect(users).to receive(:users_list).with(limit: 1234)
3944
users.users_id(user: '@aws', id_limit: 1234)
@@ -45,7 +50,7 @@
4550
)
4651
end
4752

48-
context 'when a non-default conversations_id page size has been configured' do
53+
context 'when a non-default users_id page size has been configured' do
4954
before { Slack::Web.config.users_id_page_size = 500 }
5055

5156
after { Slack::Web.config.reset }

0 commit comments

Comments
 (0)