From f2e0b8f91995213fc9fb3608d6e9f68a0c662bc6 Mon Sep 17 00:00:00 2001 From: Nate Eizenga Date: Tue, 29 Apr 2025 14:56:18 -0400 Subject: [PATCH 01/11] Configurable page size when calcualting conversations_id --- CHANGELOG.md | 1 + lib/slack/web/api/mixins/conversations.id.rb | 10 +++++++++- lib/slack/web/api/mixins/ids.id.rb | 4 ++-- lib/slack/web/config.rb | 2 ++ 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 855155cc..04f2b42c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ * [#549](https://github.com/slack-ruby/slack-ruby-client/pull/549): Add group ID formatting support for message mentions - [@n0h0](https://github.com/n0h0). * [#553](https://github.com/slack-ruby/slack-ruby-client/pull/553): Use `secure_compare` during signature verification - [@hieuk09](https://github.com/hieuk09). +* [#555](https://github.com/slack-ruby/slack-ruby-client/pull/555): Make page size in resolving conversation IDs configurable - [@eizengan](https://github.com/eizengan). * Your contribution here. ### 2.5.2 (2025/02/19) diff --git a/lib/slack/web/api/mixins/conversations.id.rb b/lib/slack/web/api/mixins/conversations.id.rb index b3b51cb0..552296f4 100644 --- a/lib/slack/web/api/mixins/conversations.id.rb +++ b/lib/slack/web/api/mixins/conversations.id.rb @@ -16,7 +16,15 @@ def conversations_id(options = {}) name = options[:channel] raise ArgumentError, 'Required arguments :channel missing' if name.nil? - id_for :channel, name, '#', :conversations_list, :channels, 'channel_not_found' + id_for( + :channel, + name, + '#', + :conversations_list, + :channels, + 'channel_not_found', + enum_method_options: { limit: conversations_id_page_size } + ) end end end diff --git a/lib/slack/web/api/mixins/ids.id.rb b/lib/slack/web/api/mixins/ids.id.rb index 50c2a495..251c93a9 100644 --- a/lib/slack/web/api/mixins/ids.id.rb +++ b/lib/slack/web/api/mixins/ids.id.rb @@ -6,10 +6,10 @@ module Mixins module Ids private - def id_for(key, name, prefix, enum_method, list_method, not_found_error) + def id_for(key, name, prefix, enum_method, list_method, not_found_error, enum_method_options: {}) # rubocop:disable Metrics/ParameterLists return { 'ok' => true, key.to_s => { 'id' => name } } unless name[0] == prefix - public_send enum_method do |list| + public_send(enum_method, **enum_method_options) do |list| list.public_send(list_method).each do |li| return Slack::Messages::Message.new('ok' => true, key.to_s => { 'id' => li.id }) if li.name == name[1..-1] end diff --git a/lib/slack/web/config.rb b/lib/slack/web/config.rb index 3c460d5e..e5bb77cf 100644 --- a/lib/slack/web/config.rb +++ b/lib/slack/web/config.rb @@ -15,6 +15,7 @@ module Config timeout open_timeout default_page_size + conversations_id_page_size default_max_retries adapter ].freeze @@ -32,6 +33,7 @@ def reset self.timeout = nil self.open_timeout = nil self.default_page_size = 100 + self.conversations_id_page_size = default_page_size self.default_max_retries = 100 self.adapter = ::Faraday.default_adapter end From 102a461d6ce06554dd4539eabfcbd6d0e14dd44d Mon Sep 17 00:00:00 2001 From: Nate Eizenga Date: Thu, 8 May 2025 12:09:47 -0400 Subject: [PATCH 02/11] Fix failing test --- spec/slack/web/api/mixins/conversations_spec.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/slack/web/api/mixins/conversations_spec.rb b/spec/slack/web/api/mixins/conversations_spec.rb index 4bdac52a..75c3b57c 100644 --- a/spec/slack/web/api/mixins/conversations_spec.rb +++ b/spec/slack/web/api/mixins/conversations_spec.rb @@ -13,6 +13,7 @@ end before do + allow(conversations).to receive(:conversations_id_page_size).and_return(100) allow(conversations).to receive(:conversations_list).and_yield( Slack::Messages::Message.new( 'channels' => [{ From 4a87569b5ae2fa1d2a5e1a7aafdb0ccfeeb3c0e7 Mon Sep 17 00:00:00 2001 From: Nate Eizenga Date: Thu, 8 May 2025 12:12:03 -0400 Subject: [PATCH 03/11] Add new config to docs --- README.md | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 2b705aa1..258cdc7c 100644 --- a/README.md +++ b/README.md @@ -179,7 +179,7 @@ client.files_upload_v2( # required options filename: 'results.pdf', # this is used for the file title, unless a :title option is provided content: File.read('/users/me/results.pdf'), # the string contents of the file - + # optional options channels: ['C000000', 'C000001'], # channel IDs to share the file in (:channel_id, :channel, or :channels are all supported) initial_comment: 'Sharing the Q1 results :tada:', # the message that is included with the file share thread @@ -281,20 +281,21 @@ client = Slack::Web::Client.new(user_agent: 'Slack Ruby Client/1.0') The following settings are supported. -setting | description ---------------------|------------------------------------------------------------------------------------------------- -token | Slack API token. -user_agent | User-agent, defaults to _Slack Ruby Client/version_. -proxy | Optional HTTP proxy. -ca_path | Optional SSL certificates path. -ca_file | Optional SSL certificates file. -endpoint | Slack endpoint, default is _https://slack.com/api_. -logger | Optional `Logger` instance that logs HTTP requests. -timeout | Optional open/read timeout in seconds. -open_timeout | Optional connection open timeout in seconds. -default_page_size | Optional page size for paginated requests, default is _100_. -default_max_retries | Optional number of retries for paginated requests, default is _100_. -adapter | Optional HTTP adapter to use, defaults to `Faraday.default_adapter`. +setting | description +-----------------------------|------------------------------------------------------------------------------------------------- +token | Slack API token. +user_agent | User-agent, defaults to _Slack Ruby Client/version_. +proxy | Optional HTTP proxy. +ca_path | Optional SSL certificates path. +ca_file | Optional SSL certificates file. +endpoint | Slack endpoint, default is _https://slack.com/api_. +logger | Optional `Logger` instance that logs HTTP requests. +timeout | Optional open/read timeout in seconds. +open_timeout | Optional connection open timeout in seconds. +default_page_size | Optional page size for paginated requests, default is _100_. +conversations_id_page_size | Optional page size for conversations_list requests made when calculating conversation id from a conversation name, default is _equal to default_page_size_. +default_max_retries | Optional number of retries for paginated requests, default is _100_. +adapter | Optional HTTP adapter to use, defaults to `Faraday.default_adapter`. You can also pass request options, including `timeout` and `open_timeout` into individual calls. From b116415eefac4883aba75f6032b0d4dcd0e42567 Mon Sep 17 00:00:00 2001 From: Nate Eizenga Date: Thu, 8 May 2025 12:32:01 -0400 Subject: [PATCH 04/11] Allow overriding conversations_id limit with an argument --- lib/slack/web/api/mixins/conversations.id.rb | 6 +++++- spec/slack/web/api/mixins/conversations_spec.rb | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/slack/web/api/mixins/conversations.id.rb b/lib/slack/web/api/mixins/conversations.id.rb index 552296f4..2619bc02 100644 --- a/lib/slack/web/api/mixins/conversations.id.rb +++ b/lib/slack/web/api/mixins/conversations.id.rb @@ -12,8 +12,12 @@ module Conversations # # @option options [channel] :channel # Channel to get ID for, prefixed with #. + # @option options [integer] :limit + # The page size used for conversations_list calls required to find the channel's ID def conversations_id(options = {}) name = options[:channel] + limit = options.fetch(:limit, conversations_id_page_size) + raise ArgumentError, 'Required arguments :channel missing' if name.nil? id_for( @@ -23,7 +27,7 @@ def conversations_id(options = {}) :conversations_list, :channels, 'channel_not_found', - enum_method_options: { limit: conversations_id_page_size } + enum_method_options: { limit: limit } ) end end diff --git a/spec/slack/web/api/mixins/conversations_spec.rb b/spec/slack/web/api/mixins/conversations_spec.rb index 75c3b57c..93365ecf 100644 --- a/spec/slack/web/api/mixins/conversations_spec.rb +++ b/spec/slack/web/api/mixins/conversations_spec.rb @@ -37,6 +37,11 @@ ) end + it 'forwards a provided limit to the underlying conversations_list calls' do + expect(conversations).to receive(:conversations_list).with(limit: 1234) + conversations.conversations_id(channel: '#general', limit: 1234) + end + it 'fails with an exception' do expect { conversations.conversations_id(channel: '#invalid') }.to( raise_error(Slack::Web::Api::Errors::SlackError, 'channel_not_found') From a6a86d1999b72f5d30a4ff2100ff0eb8985a9c6b Mon Sep 17 00:00:00 2001 From: Nate Eizenga Date: Thu, 8 May 2025 12:32:19 -0400 Subject: [PATCH 05/11] Extend id_for page size config to users_id --- CHANGELOG.md | 2 +- README.md | 1 + lib/slack/web/api/mixins/users.id.rb | 14 +++++++++++++- lib/slack/web/config.rb | 2 ++ spec/slack/web/api/mixins/users_spec.rb | 6 ++++++ 5 files changed, 23 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 04f2b42c..33913754 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ * [#549](https://github.com/slack-ruby/slack-ruby-client/pull/549): Add group ID formatting support for message mentions - [@n0h0](https://github.com/n0h0). * [#553](https://github.com/slack-ruby/slack-ruby-client/pull/553): Use `secure_compare` during signature verification - [@hieuk09](https://github.com/hieuk09). -* [#555](https://github.com/slack-ruby/slack-ruby-client/pull/555): Make page size in resolving conversation IDs configurable - [@eizengan](https://github.com/eizengan). +* [#555](https://github.com/slack-ruby/slack-ruby-client/pull/555): Make page size in resolving IDs configurable - [@eizengan](https://github.com/eizengan). * Your contribution here. ### 2.5.2 (2025/02/19) diff --git a/README.md b/README.md index 258cdc7c..22bb1d87 100644 --- a/README.md +++ b/README.md @@ -294,6 +294,7 @@ timeout | Optional open/read timeout in seconds. open_timeout | Optional connection open timeout in seconds. default_page_size | Optional page size for paginated requests, default is _100_. conversations_id_page_size | Optional page size for conversations_list requests made when calculating conversation id from a conversation name, default is _equal to default_page_size_. +users_id_page_size | Optional page size for users_list requests made when calculating user id from a user name, default is _equal to default_page_size_. default_max_retries | Optional number of retries for paginated requests, default is _100_. adapter | Optional HTTP adapter to use, defaults to `Faraday.default_adapter`. diff --git a/lib/slack/web/api/mixins/users.id.rb b/lib/slack/web/api/mixins/users.id.rb index 15aaa36b..cd6d2f2f 100644 --- a/lib/slack/web/api/mixins/users.id.rb +++ b/lib/slack/web/api/mixins/users.id.rb @@ -12,11 +12,23 @@ module Users # # @option options [user] :user # User to get ID for, prefixed with '@'. + # @option options [integer] :limit + # The page size used for users_list calls required to find the user's ID def users_id(options = {}) name = options[:user] + limit = options.fetch(:limit, users_id_page_size) + raise ArgumentError, 'Required arguments :user missing' if name.nil? - id_for :user, name, '@', :users_list, :members, 'user_not_found' + id_for( + :user, + name, + '@', + :users_list, + :members, + 'user_not_found', + enum_method_options: { limit: limit } + ) end end end diff --git a/lib/slack/web/config.rb b/lib/slack/web/config.rb index e5bb77cf..6eb45790 100644 --- a/lib/slack/web/config.rb +++ b/lib/slack/web/config.rb @@ -16,6 +16,7 @@ module Config open_timeout default_page_size conversations_id_page_size + users_id_page_size default_max_retries adapter ].freeze @@ -34,6 +35,7 @@ def reset self.open_timeout = nil self.default_page_size = 100 self.conversations_id_page_size = default_page_size + self.users_id_page_size = default_page_size self.default_max_retries = 100 self.adapter = ::Faraday.default_adapter end diff --git a/spec/slack/web/api/mixins/users_spec.rb b/spec/slack/web/api/mixins/users_spec.rb index 5ee3063d..f396eccf 100644 --- a/spec/slack/web/api/mixins/users_spec.rb +++ b/spec/slack/web/api/mixins/users_spec.rb @@ -13,6 +13,7 @@ end before do + allow(users).to receive(:users_id_page_size).and_return(100) allow(users).to receive(:users_list).and_yield( Slack::Messages::Message.new( 'members' => [{ @@ -33,6 +34,11 @@ expect(users.users_id(user: '@aws')).to eq('ok' => true, 'user' => { 'id' => 'UDEADBEEF' }) end + it 'forwards a provided limit to the underlying users_list calls' do + expect(users).to receive(:users_list).with(limit: 1234) + users.users_id(user: '@aws', limit: 1234) + end + it 'fails with an exception' do expect { users.users_id(user: '@foo') }.to( raise_error(Slack::Web::Api::Errors::SlackError, 'user_not_found') From 8d73e213cb1b2b4955abecc75feb20df97d7f54e Mon Sep 17 00:00:00 2001 From: Nate Eizenga Date: Mon, 12 May 2025 11:52:25 -0400 Subject: [PATCH 06/11] Tests for default id_for page sizes --- .../web/api/mixins/conversations_spec.rb | 21 ++++++++++++++++++- spec/slack/web/api/mixins/users_spec.rb | 19 ++++++++++++++++- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/spec/slack/web/api/mixins/conversations_spec.rb b/spec/slack/web/api/mixins/conversations_spec.rb index 93365ecf..a621b1ce 100644 --- a/spec/slack/web/api/mixins/conversations_spec.rb +++ b/spec/slack/web/api/mixins/conversations_spec.rb @@ -13,7 +13,7 @@ end before do - allow(conversations).to receive(:conversations_id_page_size).and_return(100) + allow(conversations).to receive(:conversations_id_page_size) { Slack::Web.config.conversations_id_page_size } allow(conversations).to receive(:conversations_list).and_yield( Slack::Messages::Message.new( 'channels' => [{ @@ -32,6 +32,7 @@ end it 'translates a channel that starts with a #' do + expect(conversations).to receive(:conversations_list).with(limit: 100) expect(conversations.conversations_id(channel: '#general')).to( eq('ok' => true, 'channel' => { 'id' => 'CDEADBEEF' }) ) @@ -47,5 +48,23 @@ raise_error(Slack::Web::Api::Errors::SlackError, 'channel_not_found') ) end + + context 'when a non-default conversations_id page size has been configured' do + before { Slack::Web.config.conversations_id_page_size = 500 } + + after { Slack::Web.config.reset } + + it 'translates a channel that starts with a #' do + expect(conversations).to receive(:conversations_list).with(limit: 500) + expect(conversations.conversations_id(channel: '#general')).to( + eq('ok' => true, 'channel' => { 'id' => 'CDEADBEEF' }) + ) + end + + it 'forwards a provided limit to the underlying conversations_list calls' do + expect(conversations).to receive(:conversations_list).with(limit: 1234) + conversations.conversations_id(channel: '#general', limit: 1234) + end + end end end diff --git a/spec/slack/web/api/mixins/users_spec.rb b/spec/slack/web/api/mixins/users_spec.rb index f396eccf..9724c746 100644 --- a/spec/slack/web/api/mixins/users_spec.rb +++ b/spec/slack/web/api/mixins/users_spec.rb @@ -13,7 +13,7 @@ end before do - allow(users).to receive(:users_id_page_size).and_return(100) + allow(users).to receive(:users_id_page_size) { Slack::Web.config.users_id_page_size } allow(users).to receive(:users_list).and_yield( Slack::Messages::Message.new( 'members' => [{ @@ -31,6 +31,7 @@ end it 'translates a user that starts with a @' do + expect(users).to receive(:users_list).with(limit: 100) expect(users.users_id(user: '@aws')).to eq('ok' => true, 'user' => { 'id' => 'UDEADBEEF' }) end @@ -44,6 +45,22 @@ raise_error(Slack::Web::Api::Errors::SlackError, 'user_not_found') ) end + + context 'when a non-default conversations_id page size has been configured' do + before { Slack::Web.config.users_id_page_size = 500 } + + after { Slack::Web.config.reset } + + it 'translates a user that starts with a @' do + expect(users).to receive(:users_list).with(limit: 500) + expect(users.users_id(user: '@aws')).to eq('ok' => true, 'user' => { 'id' => 'UDEADBEEF' }) + end + + it 'forwards a provided limit to the underlying users_list calls' do + expect(users).to receive(:users_list).with(limit: 1234) + users.users_id(user: '@aws', limit: 1234) + end + end end if defined?(Picky) From 1f777a963caeb5329e12d47cbfea1197c4e865bf Mon Sep 17 00:00:00 2001 From: Nate Eizenga Date: Mon, 12 May 2025 12:55:15 -0400 Subject: [PATCH 07/11] id_for enhancements - avoid unintentional parameter forwarding via limit -> id_limit - switch to keyword parameters - deduce error text instead of using argument - enum_method_options -> options --- lib/slack/web/api/mixins/conversations.id.rb | 17 ++++++++--------- lib/slack/web/api/mixins/ids.id.rb | 5 +++-- lib/slack/web/api/mixins/users.id.rb | 17 ++++++++--------- spec/slack/web/api/mixins/conversations_spec.rb | 4 ++-- spec/slack/web/api/mixins/users_spec.rb | 4 ++-- 5 files changed, 23 insertions(+), 24 deletions(-) diff --git a/lib/slack/web/api/mixins/conversations.id.rb b/lib/slack/web/api/mixins/conversations.id.rb index 2619bc02..8f3caab5 100644 --- a/lib/slack/web/api/mixins/conversations.id.rb +++ b/lib/slack/web/api/mixins/conversations.id.rb @@ -12,22 +12,21 @@ module Conversations # # @option options [channel] :channel # Channel to get ID for, prefixed with #. - # @option options [integer] :limit + # @option options [integer] :id_limit # The page size used for conversations_list calls required to find the channel's ID def conversations_id(options = {}) name = options[:channel] - limit = options.fetch(:limit, conversations_id_page_size) + limit = options.fetch(:id_limit, conversations_id_page_size) raise ArgumentError, 'Required arguments :channel missing' if name.nil? id_for( - :channel, - name, - '#', - :conversations_list, - :channels, - 'channel_not_found', - enum_method_options: { limit: limit } + key: :channel, + name: name, + prefix: '#', + enum_method: :conversations_list, + list_method: :channels, + options: { limit: limit } ) end end diff --git a/lib/slack/web/api/mixins/ids.id.rb b/lib/slack/web/api/mixins/ids.id.rb index 251c93a9..4f0c10ab 100644 --- a/lib/slack/web/api/mixins/ids.id.rb +++ b/lib/slack/web/api/mixins/ids.id.rb @@ -6,15 +6,16 @@ module Mixins module Ids private - def id_for(key, name, prefix, enum_method, list_method, not_found_error, enum_method_options: {}) # rubocop:disable Metrics/ParameterLists + def id_for(key:, name:, prefix:, enum_method:, list_method:, options: {}) return { 'ok' => true, key.to_s => { 'id' => name } } unless name[0] == prefix - public_send(enum_method, **enum_method_options) do |list| + public_send(enum_method, **options) do |list| list.public_send(list_method).each do |li| return Slack::Messages::Message.new('ok' => true, key.to_s => { 'id' => li.id }) if li.name == name[1..-1] end end + not_found_error = "#{key}_not_found" raise Slack::Web::Api::Errors::SlackError, not_found_error end end diff --git a/lib/slack/web/api/mixins/users.id.rb b/lib/slack/web/api/mixins/users.id.rb index cd6d2f2f..78508b09 100644 --- a/lib/slack/web/api/mixins/users.id.rb +++ b/lib/slack/web/api/mixins/users.id.rb @@ -12,22 +12,21 @@ module Users # # @option options [user] :user # User to get ID for, prefixed with '@'. - # @option options [integer] :limit + # @option options [integer] :id_limit # The page size used for users_list calls required to find the user's ID def users_id(options = {}) name = options[:user] - limit = options.fetch(:limit, users_id_page_size) + limit = options.fetch(:id_limit, users_id_page_size) raise ArgumentError, 'Required arguments :user missing' if name.nil? id_for( - :user, - name, - '@', - :users_list, - :members, - 'user_not_found', - enum_method_options: { limit: limit } + key: :user, + name: name, + prefix: '@', + enum_method: :users_list, + list_method: :members, + options: { limit: limit } ) end end diff --git a/spec/slack/web/api/mixins/conversations_spec.rb b/spec/slack/web/api/mixins/conversations_spec.rb index a621b1ce..5ca37d30 100644 --- a/spec/slack/web/api/mixins/conversations_spec.rb +++ b/spec/slack/web/api/mixins/conversations_spec.rb @@ -40,7 +40,7 @@ it 'forwards a provided limit to the underlying conversations_list calls' do expect(conversations).to receive(:conversations_list).with(limit: 1234) - conversations.conversations_id(channel: '#general', limit: 1234) + conversations.conversations_id(channel: '#general', id_limit: 1234) end it 'fails with an exception' do @@ -63,7 +63,7 @@ it 'forwards a provided limit to the underlying conversations_list calls' do expect(conversations).to receive(:conversations_list).with(limit: 1234) - conversations.conversations_id(channel: '#general', limit: 1234) + conversations.conversations_id(channel: '#general', id_limit: 1234) end end end diff --git a/spec/slack/web/api/mixins/users_spec.rb b/spec/slack/web/api/mixins/users_spec.rb index 9724c746..9efc3257 100644 --- a/spec/slack/web/api/mixins/users_spec.rb +++ b/spec/slack/web/api/mixins/users_spec.rb @@ -37,7 +37,7 @@ it 'forwards a provided limit to the underlying users_list calls' do expect(users).to receive(:users_list).with(limit: 1234) - users.users_id(user: '@aws', limit: 1234) + users.users_id(user: '@aws', id_limit: 1234) end it 'fails with an exception' do @@ -58,7 +58,7 @@ it 'forwards a provided limit to the underlying users_list calls' do expect(users).to receive(:users_list).with(limit: 1234) - users.users_id(user: '@aws', limit: 1234) + users.users_id(user: '@aws', id_limit: 1234) end end end From 9bc08a7e02452cb17f74e70e7d66b5dc61335d46 Mon Sep 17 00:00:00 2001 From: Nate Eizenga Date: Mon, 12 May 2025 13:23:07 -0400 Subject: [PATCH 08/11] Avoid cross-module references --- lib/slack/web/api/mixins/conversations.id.rb | 2 +- lib/slack/web/api/mixins/users.id.rb | 2 +- spec/slack/web/api/mixins/conversations_spec.rb | 1 - spec/slack/web/api/mixins/users_spec.rb | 1 - 4 files changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/slack/web/api/mixins/conversations.id.rb b/lib/slack/web/api/mixins/conversations.id.rb index 8f3caab5..8c80c0c2 100644 --- a/lib/slack/web/api/mixins/conversations.id.rb +++ b/lib/slack/web/api/mixins/conversations.id.rb @@ -16,7 +16,7 @@ module Conversations # The page size used for conversations_list calls required to find the channel's ID def conversations_id(options = {}) name = options[:channel] - limit = options.fetch(:id_limit, conversations_id_page_size) + limit = options.fetch(:id_limit, Slack::Web.config.conversations_id_page_size) raise ArgumentError, 'Required arguments :channel missing' if name.nil? diff --git a/lib/slack/web/api/mixins/users.id.rb b/lib/slack/web/api/mixins/users.id.rb index 78508b09..a070f4fb 100644 --- a/lib/slack/web/api/mixins/users.id.rb +++ b/lib/slack/web/api/mixins/users.id.rb @@ -16,7 +16,7 @@ module Users # The page size used for users_list calls required to find the user's ID def users_id(options = {}) name = options[:user] - limit = options.fetch(:id_limit, users_id_page_size) + limit = options.fetch(:id_limit, Slack::Web.config.users_id_page_size) raise ArgumentError, 'Required arguments :user missing' if name.nil? diff --git a/spec/slack/web/api/mixins/conversations_spec.rb b/spec/slack/web/api/mixins/conversations_spec.rb index 5ca37d30..2bc2b987 100644 --- a/spec/slack/web/api/mixins/conversations_spec.rb +++ b/spec/slack/web/api/mixins/conversations_spec.rb @@ -13,7 +13,6 @@ end before do - allow(conversations).to receive(:conversations_id_page_size) { Slack::Web.config.conversations_id_page_size } allow(conversations).to receive(:conversations_list).and_yield( Slack::Messages::Message.new( 'channels' => [{ diff --git a/spec/slack/web/api/mixins/users_spec.rb b/spec/slack/web/api/mixins/users_spec.rb index 9efc3257..c15d95ea 100644 --- a/spec/slack/web/api/mixins/users_spec.rb +++ b/spec/slack/web/api/mixins/users_spec.rb @@ -13,7 +13,6 @@ end before do - allow(users).to receive(:users_id_page_size) { Slack::Web.config.users_id_page_size } allow(users).to receive(:users_list).and_yield( Slack::Messages::Message.new( 'members' => [{ From 6681fdaab52e647232948c3db579e85b98091110 Mon Sep 17 00:00:00 2001 From: Nate Eizenga Date: Tue, 13 May 2025 14:23:26 -0400 Subject: [PATCH 09/11] Remove single-use variable --- lib/slack/web/api/mixins/ids.id.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/slack/web/api/mixins/ids.id.rb b/lib/slack/web/api/mixins/ids.id.rb index 4f0c10ab..40f8dd1d 100644 --- a/lib/slack/web/api/mixins/ids.id.rb +++ b/lib/slack/web/api/mixins/ids.id.rb @@ -15,8 +15,7 @@ def id_for(key:, name:, prefix:, enum_method:, list_method:, options: {}) end end - not_found_error = "#{key}_not_found" - raise Slack::Web::Api::Errors::SlackError, not_found_error + raise Slack::Web::Api::Errors::SlackError, "#{key}_not_found" end end end From e4c2fdc48982a51bc07833089575ec04f321ae5c Mon Sep 17 00:00:00 2001 From: Nate Eizenga Date: Tue, 13 May 2025 14:27:48 -0400 Subject: [PATCH 10/11] Revise *_id_page_size handling --- README.md | 4 ++-- lib/slack/web/api/mixins/conversations.id.rb | 2 +- lib/slack/web/api/mixins/users.id.rb | 2 +- lib/slack/web/config.rb | 4 ++-- spec/slack/web/api/mixins/conversations_spec.rb | 2 +- spec/slack/web/api/mixins/users_spec.rb | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 22bb1d87..7a24519b 100644 --- a/README.md +++ b/README.md @@ -293,8 +293,8 @@ logger | Optional `Logger` instance that logs HTTP request timeout | Optional open/read timeout in seconds. open_timeout | Optional connection open timeout in seconds. default_page_size | Optional page size for paginated requests, default is _100_. -conversations_id_page_size | Optional page size for conversations_list requests made when calculating conversation id from a conversation name, default is _equal to default_page_size_. -users_id_page_size | Optional page size for users_list requests made when calculating user id from a user name, default is _equal to default_page_size_. +conversations_id_page_size | Optional page size for conversations_list requests made when calculating conversation id from a conversation name, default is _nil_, which will use the default_page_size. +users_id_page_size | Optional page size for users_list requests made when calculating user id from a user name, default is _nil_, which will use the default_page_size. default_max_retries | Optional number of retries for paginated requests, default is _100_. adapter | Optional HTTP adapter to use, defaults to `Faraday.default_adapter`. diff --git a/lib/slack/web/api/mixins/conversations.id.rb b/lib/slack/web/api/mixins/conversations.id.rb index 8c80c0c2..51789c84 100644 --- a/lib/slack/web/api/mixins/conversations.id.rb +++ b/lib/slack/web/api/mixins/conversations.id.rb @@ -26,7 +26,7 @@ def conversations_id(options = {}) prefix: '#', enum_method: :conversations_list, list_method: :channels, - options: { limit: limit } + options: { limit: limit }.compact ) end end diff --git a/lib/slack/web/api/mixins/users.id.rb b/lib/slack/web/api/mixins/users.id.rb index a070f4fb..94fc98a1 100644 --- a/lib/slack/web/api/mixins/users.id.rb +++ b/lib/slack/web/api/mixins/users.id.rb @@ -26,7 +26,7 @@ def users_id(options = {}) prefix: '@', enum_method: :users_list, list_method: :members, - options: { limit: limit } + options: { limit: limit }.compact ) end end diff --git a/lib/slack/web/config.rb b/lib/slack/web/config.rb index 6eb45790..ef8052ba 100644 --- a/lib/slack/web/config.rb +++ b/lib/slack/web/config.rb @@ -34,8 +34,8 @@ def reset self.timeout = nil self.open_timeout = nil self.default_page_size = 100 - self.conversations_id_page_size = default_page_size - self.users_id_page_size = default_page_size + self.conversations_id_page_size = nil + self.users_id_page_size = nil self.default_max_retries = 100 self.adapter = ::Faraday.default_adapter end diff --git a/spec/slack/web/api/mixins/conversations_spec.rb b/spec/slack/web/api/mixins/conversations_spec.rb index 2bc2b987..56cd270e 100644 --- a/spec/slack/web/api/mixins/conversations_spec.rb +++ b/spec/slack/web/api/mixins/conversations_spec.rb @@ -31,7 +31,7 @@ end it 'translates a channel that starts with a #' do - expect(conversations).to receive(:conversations_list).with(limit: 100) + expect(conversations).to receive(:conversations_list) expect(conversations.conversations_id(channel: '#general')).to( eq('ok' => true, 'channel' => { 'id' => 'CDEADBEEF' }) ) diff --git a/spec/slack/web/api/mixins/users_spec.rb b/spec/slack/web/api/mixins/users_spec.rb index c15d95ea..054d791a 100644 --- a/spec/slack/web/api/mixins/users_spec.rb +++ b/spec/slack/web/api/mixins/users_spec.rb @@ -30,7 +30,7 @@ end it 'translates a user that starts with a @' do - expect(users).to receive(:users_list).with(limit: 100) + expect(users).to receive(:users_list) expect(users.users_id(user: '@aws')).to eq('ok' => true, 'user' => { 'id' => 'UDEADBEEF' }) end From c6e0869999d029f0c26c0b717f2411b177813e6d Mon Sep 17 00:00:00 2001 From: Nate Eizenga Date: Wed, 14 May 2025 10:52:42 -0400 Subject: [PATCH 11/11] ignorable test failures don't un-ignorably fail coveralls --- .github/workflows/test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 25e54622..72438d23 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -41,6 +41,7 @@ jobs: parallel: true github-token: ${{ secrets.GITHUB_TOKEN }} flag-name: run-${{ matrix.entry.ruby }}${{ matrix.entry.concurrency && '-'}}${{ matrix.entry.concurrency }} + allow-empty: ${{ matrix.entry.ignore || false }} finish: name: coveralls