Skip to content

Commit 3d4ca53

Browse files
feat(specs): add v2 endpoints for ingestion
algolia/api-clients-automation#3416 Co-authored-by: algolia-bot <[email protected]> Co-authored-by: Clément Vannicatte <[email protected]>
1 parent befa44c commit 3d4ca53

File tree

4 files changed

+268
-0
lines changed

4 files changed

+268
-0
lines changed

algoliasearch/ingestion/client.py

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
from algoliasearch.ingestion.models.authentication_update_response import (
3535
AuthenticationUpdateResponse,
3636
)
37+
from algoliasearch.ingestion.models.batch_write_params import BatchWriteParams
3738
from algoliasearch.ingestion.models.delete_response import DeleteResponse
3839
from algoliasearch.ingestion.models.destination import Destination
3940
from algoliasearch.ingestion.models.destination_create import DestinationCreate
@@ -3220,6 +3221,95 @@ async def list_transformations(
32203221
await self.list_transformations_with_http_info(sort, order, request_options)
32213222
).deserialize(ListTransformationsResponse)
32223223

3224+
async def push_task_with_http_info(
3225+
self,
3226+
task_id: Annotated[
3227+
StrictStr, Field(description="Unique identifier of a task.")
3228+
],
3229+
batch_write_params: Annotated[
3230+
BatchWriteParams,
3231+
Field(
3232+
description="Request body of a Search API `batch` request that will be pushed in the Connectors pipeline."
3233+
),
3234+
],
3235+
request_options: Optional[Union[dict, RequestOptions]] = None,
3236+
) -> ApiResponse[str]:
3237+
"""
3238+
Push a `batch` request payload through the Pipeline. You can check the status of task pushes with the observability endpoints.
3239+
3240+
Required API Key ACLs:
3241+
- addObject
3242+
- deleteIndex
3243+
- editSettings
3244+
3245+
:param task_id: Unique identifier of a task. (required)
3246+
:type task_id: str
3247+
:param batch_write_params: Request body of a Search API `batch` request that will be pushed in the Connectors pipeline. (required)
3248+
:type batch_write_params: BatchWriteParams
3249+
:param request_options: The request options to send along with the query, they will be merged with the transporter base parameters (headers, query params, timeouts, etc.). (optional)
3250+
:return: Returns the raw algoliasearch 'APIResponse' object.
3251+
"""
3252+
3253+
if task_id is None:
3254+
raise ValueError(
3255+
"Parameter `task_id` is required when calling `push_task`."
3256+
)
3257+
3258+
if batch_write_params is None:
3259+
raise ValueError(
3260+
"Parameter `batch_write_params` is required when calling `push_task`."
3261+
)
3262+
3263+
_data = {}
3264+
if batch_write_params is not None:
3265+
_data = batch_write_params
3266+
3267+
return await self._transporter.request(
3268+
verb=Verb.POST,
3269+
path="/2/tasks/{taskID}/push".replace(
3270+
"{taskID}", quote(str(task_id), safe="")
3271+
),
3272+
request_options=self._request_options.merge(
3273+
data=dumps(bodySerializer(_data)),
3274+
user_request_options=request_options,
3275+
),
3276+
use_read_transporter=False,
3277+
)
3278+
3279+
async def push_task(
3280+
self,
3281+
task_id: Annotated[
3282+
StrictStr, Field(description="Unique identifier of a task.")
3283+
],
3284+
batch_write_params: Annotated[
3285+
BatchWriteParams,
3286+
Field(
3287+
description="Request body of a Search API `batch` request that will be pushed in the Connectors pipeline."
3288+
),
3289+
],
3290+
request_options: Optional[Union[dict, RequestOptions]] = None,
3291+
) -> RunResponse:
3292+
"""
3293+
Push a `batch` request payload through the Pipeline. You can check the status of task pushes with the observability endpoints.
3294+
3295+
Required API Key ACLs:
3296+
- addObject
3297+
- deleteIndex
3298+
- editSettings
3299+
3300+
:param task_id: Unique identifier of a task. (required)
3301+
:type task_id: str
3302+
:param batch_write_params: Request body of a Search API `batch` request that will be pushed in the Connectors pipeline. (required)
3303+
:type batch_write_params: BatchWriteParams
3304+
:param request_options: The request options to send along with the query, they will be merged with the transporter base parameters (headers, query params, timeouts, etc.). (optional)
3305+
:return: Returns the deserialized response in a 'RunResponse' result object.
3306+
"""
3307+
return (
3308+
await self.push_task_with_http_info(
3309+
task_id, batch_write_params, request_options
3310+
)
3311+
).deserialize(RunResponse)
3312+
32233313
async def run_task_with_http_info(
32243314
self,
32253315
task_id: Annotated[
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# coding: utf-8
2+
3+
"""
4+
Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT.
5+
"""
6+
7+
from __future__ import annotations
8+
9+
from enum import Enum
10+
from json import loads
11+
from typing import Self
12+
13+
14+
class Action(str, Enum):
15+
"""
16+
Type of indexing operation.
17+
"""
18+
19+
"""
20+
allowed enum values
21+
"""
22+
ADDOBJECT = "addObject"
23+
UPDATEOBJECT = "updateObject"
24+
PARTIALUPDATEOBJECT = "partialUpdateObject"
25+
PARTIALUPDATEOBJECTNOCREATE = "partialUpdateObjectNoCreate"
26+
DELETEOBJECT = "deleteObject"
27+
DELETE = "delete"
28+
CLEAR = "clear"
29+
30+
@classmethod
31+
def from_json(cls, json_str: str) -> Self:
32+
"""Create an instance of Action from a JSON string"""
33+
return cls(loads(json_str))
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# coding: utf-8
2+
3+
"""
4+
Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT.
5+
"""
6+
7+
from __future__ import annotations
8+
9+
from json import loads
10+
from typing import Any, Dict, Self
11+
12+
from pydantic import BaseModel, ConfigDict, Field
13+
14+
from algoliasearch.ingestion.models.action import Action
15+
16+
17+
class BatchRequest(BaseModel):
18+
"""
19+
BatchRequest
20+
"""
21+
22+
action: Action
23+
body: Dict[str, Any] = Field(
24+
description="Operation arguments (varies with specified `action`)."
25+
)
26+
27+
model_config = ConfigDict(
28+
use_enum_values=True, populate_by_name=True, validate_assignment=True
29+
)
30+
31+
def to_json(self) -> str:
32+
return self.model_dump_json(by_alias=True, exclude_unset=True)
33+
34+
@classmethod
35+
def from_json(cls, json_str: str) -> Self:
36+
"""Create an instance of BatchRequest from a JSON string"""
37+
return cls.from_dict(loads(json_str))
38+
39+
def to_dict(self) -> Dict[str, Any]:
40+
"""Return the dictionary representation of the model using alias.
41+
42+
This has the following differences from calling pydantic's
43+
`self.model_dump(by_alias=True)`:
44+
45+
* `None` is only added to the output dict for nullable fields that
46+
were set at model initialization. Other fields with value `None`
47+
are ignored.
48+
"""
49+
_dict = self.model_dump(
50+
by_alias=True,
51+
exclude={},
52+
exclude_none=True,
53+
)
54+
return _dict
55+
56+
@classmethod
57+
def from_dict(cls, obj: Dict) -> Self:
58+
"""Create an instance of BatchRequest from a dict"""
59+
if obj is None:
60+
return None
61+
62+
if not isinstance(obj, dict):
63+
return cls.model_validate(obj)
64+
65+
_obj = cls.model_validate(
66+
{"action": obj.get("action"), "body": obj.get("body")}
67+
)
68+
return _obj
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# coding: utf-8
2+
3+
"""
4+
Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT.
5+
"""
6+
7+
from __future__ import annotations
8+
9+
from json import loads
10+
from typing import Any, Dict, List, Self
11+
12+
from pydantic import BaseModel, ConfigDict
13+
14+
from algoliasearch.ingestion.models.batch_request import BatchRequest
15+
16+
17+
class BatchWriteParams(BaseModel):
18+
"""
19+
Batch parameters.
20+
"""
21+
22+
requests: List[BatchRequest]
23+
24+
model_config = ConfigDict(
25+
use_enum_values=True, populate_by_name=True, validate_assignment=True
26+
)
27+
28+
def to_json(self) -> str:
29+
return self.model_dump_json(by_alias=True, exclude_unset=True)
30+
31+
@classmethod
32+
def from_json(cls, json_str: str) -> Self:
33+
"""Create an instance of BatchWriteParams from a JSON string"""
34+
return cls.from_dict(loads(json_str))
35+
36+
def to_dict(self) -> Dict[str, Any]:
37+
"""Return the dictionary representation of the model using alias.
38+
39+
This has the following differences from calling pydantic's
40+
`self.model_dump(by_alias=True)`:
41+
42+
* `None` is only added to the output dict for nullable fields that
43+
were set at model initialization. Other fields with value `None`
44+
are ignored.
45+
"""
46+
_dict = self.model_dump(
47+
by_alias=True,
48+
exclude={},
49+
exclude_none=True,
50+
)
51+
_items = []
52+
if self.requests:
53+
for _item in self.requests:
54+
if _item:
55+
_items.append(_item.to_dict())
56+
_dict["requests"] = _items
57+
return _dict
58+
59+
@classmethod
60+
def from_dict(cls, obj: Dict) -> Self:
61+
"""Create an instance of BatchWriteParams from a dict"""
62+
if obj is None:
63+
return None
64+
65+
if not isinstance(obj, dict):
66+
return cls.model_validate(obj)
67+
68+
_obj = cls.model_validate(
69+
{
70+
"requests": (
71+
[BatchRequest.from_dict(_item) for _item in obj.get("requests")]
72+
if obj.get("requests") is not None
73+
else None
74+
)
75+
}
76+
)
77+
return _obj

0 commit comments

Comments
 (0)