Skip to content

Commit 32d0e6a

Browse files
fix(clients): support dict in helpers (generated)
algolia/api-clients-automation#4254 Co-authored-by: algolia-bot <[email protected]> Co-authored-by: Clément Vannicatte <[email protected]>
1 parent ebae3c5 commit 32d0e6a

File tree

1 file changed

+23
-17
lines changed

1 file changed

+23
-17
lines changed

lib/algolia/api/search_client.rb

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3150,19 +3150,21 @@ def wait_for_app_task(
31503150
def wait_for_api_key(
31513151
key,
31523152
operation,
3153-
api_key = {},
3153+
api_key = Search::ApiKey.new,
31543154
max_retries = 50,
31553155
timeout = -> (retry_count) { [retry_count * 200, 5000].min },
31563156
request_options = {}
31573157
)
3158+
api_key = api_client.object_to_hash(api_key)
3159+
31583160
retries = 0
31593161
if operation == "update"
31603162
raise ArgumentError, "`api_key` is required when waiting for an `update` operation." if api_key.nil?
31613163
while retries < max_retries
31623164
updated_key = get_api_key(key, request_options)
31633165
updated_key_hash = updated_key.to_hash
31643166
equals = true
3165-
api_key.to_hash.each do |k, v|
3167+
api_key.each do |k, v|
31663168
equals &&= updated_key_hash[k] == v
31673169
end
31683170

@@ -3201,7 +3203,9 @@ def wait_for_api_key(
32013203
# @param request_options [Hash] the requestOptions to send along with the query, they will be forwarded to the `browse` method.
32023204
# @param block [Proc] the block to execute on each object of the index.
32033205
def browse_objects(index_name, browse_params = Search::BrowseParamsObject.new, request_options = {}, &block)
3204-
browse_params.hits_per_page ||= 1000
3206+
browse_params = api_client.object_to_hash(browse_params)
3207+
3208+
browse_params[:hitsPerPage] = 1000 unless browse_params.key?(:hitsPerPage)
32053209

32063210
hits = []
32073211
loop do
@@ -3214,8 +3218,8 @@ def browse_objects(index_name, browse_params = Search::BrowseParamsObject.new, r
32143218
hits.concat(res.hits)
32153219
end
32163220

3217-
browse_params.cursor = res.cursor
3218-
break if browse_params.cursor.nil?
3221+
browse_params[:cursor] = res.cursor
3222+
break if browse_params[:cursor].nil?
32193223
end
32203224

32213225
hits unless block_given?
@@ -3227,12 +3231,11 @@ def browse_objects(index_name, browse_params = Search::BrowseParamsObject.new, r
32273231
# @param search_rules_params [SearchRulesParams] the parameters to send along with the query, they will be forwarded to the `searchRules` method.
32283232
# @param request_options [Hash] the requestOptions to send along with the query, they will be forwarded to the `searchRules` method.
32293233
# @param block [Proc] the block to execute on each rule of the index.
3230-
def browse_rules(
3231-
index_name,
3232-
search_rules_params = Search::SearchRulesParams.new(hits_per_page: 1000, page: 0),
3233-
request_options = {},
3234-
&block
3235-
)
3234+
def browse_rules(index_name, search_rules_params = Search::SearchRulesParams.new, request_options = {}, &block)
3235+
search_rules_params = api_client.object_to_hash(search_rules_params)
3236+
3237+
search_rules_params[:hitsPerPage] = 1000 unless search_rules_params.key?(:hitsPerPage)
3238+
32363239
rules = []
32373240
loop do
32383241
res = search_rules(index_name, search_rules_params, request_options)
@@ -3244,8 +3247,8 @@ def browse_rules(
32443247
rules.concat(res.hits)
32453248
end
32463249

3247-
search_rules_params.page += 1
3248-
break if res.hits.length < search_rules_params.hits_per_page
3250+
search_rules_params[:page] += 1
3251+
break if res.hits.length < search_rules_params[:hitsPerPage]
32493252
end
32503253

32513254
rules unless block_given?
@@ -3259,10 +3262,14 @@ def browse_rules(
32593262
# @param block [Proc] the block to execute on each synonym of the index.
32603263
def browse_synonyms(
32613264
index_name,
3262-
search_synonyms_params = Search::SearchSynonymsParams.new(hits_per_page: 1000, page: 0),
3265+
search_synonyms_params = Search::SearchSynonymsParams.new,
32633266
request_options = {},
32643267
&block
32653268
)
3269+
search_synonyms_params = api_client.object_to_hash(search_synonyms_params)
3270+
3271+
search_synonyms_params[:hitsPerPage] = 1000 unless search_synonyms_params.key?(:hitsPerPage)
3272+
32663273
synonyms = []
32673274
loop do
32683275
res = search_synonyms(index_name, search_synonyms_params, request_options)
@@ -3274,8 +3281,8 @@ def browse_synonyms(
32743281
synonyms.concat(res.hits)
32753282
end
32763283

3277-
search_synonyms_params.page += 1
3278-
break if res.hits.length < search_synonyms_params.hits_per_page
3284+
search_synonyms_params[:page] += 1
3285+
break if res.hits.length < search_synonyms_params[:hitsPerPage]
32793286
end
32803287

32813288
synonyms unless block_given?
@@ -3543,6 +3550,5 @@ def index_exists?(index_name)
35433550

35443551
true
35453552
end
3546-
35473553
end
35483554
end

0 commit comments

Comments
 (0)