Skip to content

Commit 5081e6c

Browse files
fix: python playground (generated)
Co-authored-by: shortcuts <[email protected]>
1 parent 966cba2 commit 5081e6c

File tree

2 files changed

+47
-17
lines changed

2 files changed

+47
-17
lines changed

clients/algoliasearch-client-python/algoliasearch/search/client.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,9 @@ async def browse_objects(
354354
"""
355355
Helper: Iterate on the `browse` method of the client to allow aggregating objects of an index.
356356
"""
357+
if isinstance(browse_params, dict):
358+
browse_params = BrowseParamsObject().from_dict(browse_params)
359+
357360
if browse_params is None:
358361
browse_params = BrowseParamsObject(hits_per_page=1000)
359362

@@ -385,6 +388,9 @@ async def browse_rules(
385388
"""
386389
Helper: Iterate on the `search_rules` method of the client to allow aggregating rules of an index.
387390
"""
391+
if isinstance(search_rules_params, dict):
392+
search_rules_params = SearchRulesParams().from_dict(search_rules_params)
393+
388394
if search_rules_params is None:
389395
search_rules_params = SearchRulesParams(hits_per_page=1000)
390396

@@ -418,6 +424,11 @@ async def browse_synonyms(
418424
"""
419425
Helper: Iterate on the `search_synonyms` method of the client to allow aggregating synonyms of an index.
420426
"""
427+
if isinstance(search_synonyms_params, dict):
428+
search_synonyms_params = SearchSynonymsParams().from_dict(
429+
search_synonyms_params
430+
)
431+
421432
if search_synonyms_params is None:
422433
search_synonyms_params = SearchSynonymsParams(hits_per_page=1000, page=0)
423434
hits_per_page = 1000
@@ -453,6 +464,7 @@ async def generate_secured_api_key(
453464
"""
454465
if restrictions is None:
455466
restrictions = SecuredApiKeyRestrictions()
467+
456468
restrictions_dict = {}
457469
if isinstance(restrictions, SecuredApiKeyRestrictions):
458470
restrictions_dict = restrictions.to_dict()
@@ -5384,6 +5396,9 @@ def browse_objects(
53845396
"""
53855397
Helper: Iterate on the `browse` method of the client to allow aggregating objects of an index.
53865398
"""
5399+
if isinstance(browse_params, dict):
5400+
browse_params = BrowseParamsObject().from_dict(browse_params)
5401+
53875402
if browse_params is None:
53885403
browse_params = BrowseParamsObject(hits_per_page=1000)
53895404

@@ -5415,6 +5430,9 @@ def browse_rules(
54155430
"""
54165431
Helper: Iterate on the `search_rules` method of the client to allow aggregating rules of an index.
54175432
"""
5433+
if isinstance(search_rules_params, dict):
5434+
search_rules_params = SearchRulesParams().from_dict(search_rules_params)
5435+
54185436
if search_rules_params is None:
54195437
search_rules_params = SearchRulesParams(hits_per_page=1000)
54205438

@@ -5448,6 +5466,11 @@ def browse_synonyms(
54485466
"""
54495467
Helper: Iterate on the `search_synonyms` method of the client to allow aggregating synonyms of an index.
54505468
"""
5469+
if isinstance(search_synonyms_params, dict):
5470+
search_synonyms_params = SearchSynonymsParams().from_dict(
5471+
search_synonyms_params
5472+
)
5473+
54515474
if search_synonyms_params is None:
54525475
search_synonyms_params = SearchSynonymsParams(hits_per_page=1000, page=0)
54535476
hits_per_page = 1000
@@ -5481,6 +5504,7 @@ def generate_secured_api_key(
54815504
"""
54825505
if restrictions is None:
54835506
restrictions = SecuredApiKeyRestrictions()
5507+
54845508
restrictions_dict = {}
54855509
if isinstance(restrictions, SecuredApiKeyRestrictions):
54865510
restrictions_dict = restrictions.to_dict()

clients/algoliasearch-client-ruby/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)