Skip to content

Commit

Permalink
feat(templates): add request_options to python helpers consistently (…
Browse files Browse the repository at this point in the history
…generated)

algolia/api-clients-automation#3868

Co-authored-by: algolia-bot <accounts+algolia-api-client-bot@algolia.com>
Co-authored-by: Kai Welke <kai.welke@algolia.com>
  • Loading branch information
algolia-bot and kai687 committed Oct 2, 2024
1 parent 57069aa commit aa1fffc
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions algoliasearch/search/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,9 @@ async def _func(_prev: SearchRulesResponse) -> SearchRulesResponse:
async def generate_secured_api_key(
self,
parent_api_key: str,
restrictions: Optional[SecuredApiKeyRestrictions] = SecuredApiKeyRestrictions(),
restrictions: Optional[
Union[dict, SecuredApiKeyRestrictions]
] = SecuredApiKeyRestrictions(),
) -> str:
"""
Helper: Generates a secured API key based on the given `parent_api_key` and given `restrictions`.
Expand Down Expand Up @@ -470,18 +472,23 @@ async def save_objects(
self,
index_name: str,
objects: List[Dict[str, Any]],
request_options: Optional[Union[dict, RequestOptions]] = None,
) -> List[BatchResponse]:
"""
Helper: Saves the given array of objects in the given index. The `chunked_batch` helper is used under the hood, which creates a `batch` requests with at most 1000 objects in it.
"""
return await self.chunked_batch(
index_name=index_name, objects=objects, action=Action.ADDOBJECT
index_name=index_name,
objects=objects,
action=Action.ADDOBJECT,
request_options=request_options,
)

async def delete_objects(
self,
index_name: str,
object_ids: List[str],
request_options: Optional[Union[dict, RequestOptions]] = None,
) -> List[BatchResponse]:
"""
Helper: Deletes every records for the given objectIDs. The `chunked_batch` helper is used under the hood, which creates a `batch` requests with at most 1000 objectIDs in it.
Expand All @@ -490,13 +497,15 @@ async def delete_objects(
index_name=index_name,
objects=[{"objectID": id} for id in object_ids],
action=Action.DELETEOBJECT,
request_options=request_options,
)

async def partial_update_objects(
self,
index_name: str,
objects: List[Dict[str, Any]],
create_if_not_exists: Optional[bool] = False,
request_options: Optional[Union[dict, RequestOptions]] = None,
) -> List[BatchResponse]:
"""
Helper: Replaces object content of all the given objects according to their respective `objectID` field. The `chunked_batch` helper is used under the hood, which creates a `batch` requests with at most 1000 objects in it.
Expand All @@ -507,6 +516,7 @@ async def partial_update_objects(
action=Action.PARTIALUPDATEOBJECT
if create_if_not_exists
else Action.PARTIALUPDATEOBJECTNOCREATE,
request_options=request_options,
)

async def chunked_batch(
Expand Down Expand Up @@ -5346,7 +5356,9 @@ def _func(_prev: SearchRulesResponse) -> SearchRulesResponse:
def generate_secured_api_key(
self,
parent_api_key: str,
restrictions: Optional[SecuredApiKeyRestrictions] = SecuredApiKeyRestrictions(),
restrictions: Optional[
Union[dict, SecuredApiKeyRestrictions]
] = SecuredApiKeyRestrictions(),
) -> str:
"""
Helper: Generates a secured API key based on the given `parent_api_key` and given `restrictions`.
Expand Down Expand Up @@ -5396,18 +5408,23 @@ def save_objects(
self,
index_name: str,
objects: List[Dict[str, Any]],
request_options: Optional[Union[dict, RequestOptions]] = None,
) -> List[BatchResponse]:
"""
Helper: Saves the given array of objects in the given index. The `chunked_batch` helper is used under the hood, which creates a `batch` requests with at most 1000 objects in it.
"""
return self.chunked_batch(
index_name=index_name, objects=objects, action=Action.ADDOBJECT
index_name=index_name,
objects=objects,
action=Action.ADDOBJECT,
request_options=request_options,
)

def delete_objects(
self,
index_name: str,
object_ids: List[str],
request_options: Optional[Union[dict, RequestOptions]] = None,
) -> List[BatchResponse]:
"""
Helper: Deletes every records for the given objectIDs. The `chunked_batch` helper is used under the hood, which creates a `batch` requests with at most 1000 objectIDs in it.
Expand All @@ -5416,13 +5433,15 @@ def delete_objects(
index_name=index_name,
objects=[{"objectID": id} for id in object_ids],
action=Action.DELETEOBJECT,
request_options=request_options,
)

def partial_update_objects(
self,
index_name: str,
objects: List[Dict[str, Any]],
create_if_not_exists: Optional[bool] = False,
request_options: Optional[Union[dict, RequestOptions]] = None,
) -> List[BatchResponse]:
"""
Helper: Replaces object content of all the given objects according to their respective `objectID` field. The `chunked_batch` helper is used under the hood, which creates a `batch` requests with at most 1000 objects in it.
Expand All @@ -5433,6 +5452,7 @@ def partial_update_objects(
action=Action.PARTIALUPDATEOBJECT
if create_if_not_exists
else Action.PARTIALUPDATEOBJECTNOCREATE,
request_options=request_options,
)

def chunked_batch(
Expand Down

0 comments on commit aa1fffc

Please sign in to comment.