Skip to content

Commit 7d03f02

Browse files
algolia-botraed667millotpshortcuts
committed
feat(specs): add recommend batch rules endpoint (generated)
algolia/api-clients-automation#3782 Co-authored-by: algolia-bot <[email protected]> Co-authored-by: Raed <[email protected]> Co-authored-by: Pierre Millot <[email protected]> Co-authored-by: Clément Vannicatte <[email protected]>
1 parent 16ac3ca commit 7d03f02

File tree

4 files changed

+322
-1
lines changed

4 files changed

+322
-1
lines changed

algoliasearch/recommend/client.py

Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@
3838
)
3939
from algoliasearch.recommend.models.recommend_models import RecommendModels
4040
from algoliasearch.recommend.models.recommend_rule import RecommendRule
41+
from algoliasearch.recommend.models.recommend_updated_at_response import (
42+
RecommendUpdatedAtResponse,
43+
)
4144
from algoliasearch.recommend.models.search_recommend_rules_params import (
4245
SearchRecommendRulesParams,
4346
)
@@ -129,6 +132,98 @@ async def set_client_api_key(self, api_key: str) -> None:
129132
"""Sets a new API key to authenticate requests."""
130133
self._transporter._config.set_client_api_key(api_key)
131134

135+
async def batch_recommend_rules_with_http_info(
136+
self,
137+
index_name: Annotated[
138+
StrictStr,
139+
Field(description="Name of the index on which to perform the operation."),
140+
],
141+
model: Annotated[
142+
RecommendModels,
143+
Field(
144+
description="[Recommend model](https://www.algolia.com/doc/guides/algolia-recommend/overview/#recommend-models). "
145+
),
146+
],
147+
recommend_rule: Optional[List[RecommendRule]] = None,
148+
request_options: Optional[Union[dict, RequestOptions]] = None,
149+
) -> ApiResponse[str]:
150+
"""
151+
Create or update a batch of Recommend Rules Each Recommend Rule is created or updated, depending on whether a Recommend Rule with the same `objectID` already exists. You may also specify `true` for `clearExistingRules`, in which case the batch will atomically replace all the existing Recommend Rules. Recommend Rules are similar to Search Rules, except that the conditions and consequences apply to a [source item](/doc/guides/algolia-recommend/overview/#recommend-models) instead of a query. The main differences are the following: - Conditions `pattern` and `anchoring` are unavailable. - Condition `filters` triggers if the source item matches the specified filters. - Condition `filters` accepts numeric filters. - Consequence `params` only covers filtering parameters. - Consequence `automaticFacetFilters` doesn't require a facet value placeholder (it tries to match the data source item's attributes instead).
152+
153+
Required API Key ACLs:
154+
- editSettings
155+
156+
:param index_name: Name of the index on which to perform the operation. (required)
157+
:type index_name: str
158+
:param model: [Recommend model](https://www.algolia.com/doc/guides/algolia-recommend/overview/#recommend-models). (required)
159+
:type model: RecommendModels
160+
:param recommend_rule:
161+
:type recommend_rule: List[RecommendRule]
162+
: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)
163+
:return: Returns the raw algoliasearch 'APIResponse' object.
164+
"""
165+
166+
if index_name is None:
167+
raise ValueError(
168+
"Parameter `index_name` is required when calling `batch_recommend_rules`."
169+
)
170+
171+
if model is None:
172+
raise ValueError(
173+
"Parameter `model` is required when calling `batch_recommend_rules`."
174+
)
175+
176+
_data = {}
177+
if recommend_rule is not None:
178+
_data = recommend_rule
179+
180+
return await self._transporter.request(
181+
verb=Verb.POST,
182+
path="/1/indexes/{indexName}/{model}/recommend/rules/batch".replace(
183+
"{indexName}", quote(str(index_name), safe="")
184+
).replace("{model}", quote(str(model), safe="")),
185+
request_options=self._request_options.merge(
186+
data=dumps(bodySerializer(_data)),
187+
user_request_options=request_options,
188+
),
189+
use_read_transporter=False,
190+
)
191+
192+
async def batch_recommend_rules(
193+
self,
194+
index_name: Annotated[
195+
StrictStr,
196+
Field(description="Name of the index on which to perform the operation."),
197+
],
198+
model: Annotated[
199+
RecommendModels,
200+
Field(
201+
description="[Recommend model](https://www.algolia.com/doc/guides/algolia-recommend/overview/#recommend-models). "
202+
),
203+
],
204+
recommend_rule: Optional[List[RecommendRule]] = None,
205+
request_options: Optional[Union[dict, RequestOptions]] = None,
206+
) -> RecommendUpdatedAtResponse:
207+
"""
208+
Create or update a batch of Recommend Rules Each Recommend Rule is created or updated, depending on whether a Recommend Rule with the same `objectID` already exists. You may also specify `true` for `clearExistingRules`, in which case the batch will atomically replace all the existing Recommend Rules. Recommend Rules are similar to Search Rules, except that the conditions and consequences apply to a [source item](/doc/guides/algolia-recommend/overview/#recommend-models) instead of a query. The main differences are the following: - Conditions `pattern` and `anchoring` are unavailable. - Condition `filters` triggers if the source item matches the specified filters. - Condition `filters` accepts numeric filters. - Consequence `params` only covers filtering parameters. - Consequence `automaticFacetFilters` doesn't require a facet value placeholder (it tries to match the data source item's attributes instead).
209+
210+
Required API Key ACLs:
211+
- editSettings
212+
213+
:param index_name: Name of the index on which to perform the operation. (required)
214+
:type index_name: str
215+
:param model: [Recommend model](https://www.algolia.com/doc/guides/algolia-recommend/overview/#recommend-models). (required)
216+
:type model: RecommendModels
217+
:param recommend_rule:
218+
:type recommend_rule: List[RecommendRule]
219+
: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)
220+
:return: Returns the deserialized response in a 'RecommendUpdatedAtResponse' result object.
221+
"""
222+
resp = await self.batch_recommend_rules_with_http_info(
223+
index_name, model, recommend_rule, request_options
224+
)
225+
return resp.deserialize(RecommendUpdatedAtResponse, resp.raw_data)
226+
132227
async def custom_delete_with_http_info(
133228
self,
134229
path: Annotated[
@@ -977,6 +1072,98 @@ def set_client_api_key(self, api_key: str) -> None:
9771072
"""Sets a new API key to authenticate requests."""
9781073
self._transporter._config.set_client_api_key(api_key)
9791074

1075+
def batch_recommend_rules_with_http_info(
1076+
self,
1077+
index_name: Annotated[
1078+
StrictStr,
1079+
Field(description="Name of the index on which to perform the operation."),
1080+
],
1081+
model: Annotated[
1082+
RecommendModels,
1083+
Field(
1084+
description="[Recommend model](https://www.algolia.com/doc/guides/algolia-recommend/overview/#recommend-models). "
1085+
),
1086+
],
1087+
recommend_rule: Optional[List[RecommendRule]] = None,
1088+
request_options: Optional[Union[dict, RequestOptions]] = None,
1089+
) -> ApiResponse[str]:
1090+
"""
1091+
Create or update a batch of Recommend Rules Each Recommend Rule is created or updated, depending on whether a Recommend Rule with the same `objectID` already exists. You may also specify `true` for `clearExistingRules`, in which case the batch will atomically replace all the existing Recommend Rules. Recommend Rules are similar to Search Rules, except that the conditions and consequences apply to a [source item](/doc/guides/algolia-recommend/overview/#recommend-models) instead of a query. The main differences are the following: - Conditions `pattern` and `anchoring` are unavailable. - Condition `filters` triggers if the source item matches the specified filters. - Condition `filters` accepts numeric filters. - Consequence `params` only covers filtering parameters. - Consequence `automaticFacetFilters` doesn't require a facet value placeholder (it tries to match the data source item's attributes instead).
1092+
1093+
Required API Key ACLs:
1094+
- editSettings
1095+
1096+
:param index_name: Name of the index on which to perform the operation. (required)
1097+
:type index_name: str
1098+
:param model: [Recommend model](https://www.algolia.com/doc/guides/algolia-recommend/overview/#recommend-models). (required)
1099+
:type model: RecommendModels
1100+
:param recommend_rule:
1101+
:type recommend_rule: List[RecommendRule]
1102+
: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)
1103+
:return: Returns the raw algoliasearch 'APIResponse' object.
1104+
"""
1105+
1106+
if index_name is None:
1107+
raise ValueError(
1108+
"Parameter `index_name` is required when calling `batch_recommend_rules`."
1109+
)
1110+
1111+
if model is None:
1112+
raise ValueError(
1113+
"Parameter `model` is required when calling `batch_recommend_rules`."
1114+
)
1115+
1116+
_data = {}
1117+
if recommend_rule is not None:
1118+
_data = recommend_rule
1119+
1120+
return self._transporter.request(
1121+
verb=Verb.POST,
1122+
path="/1/indexes/{indexName}/{model}/recommend/rules/batch".replace(
1123+
"{indexName}", quote(str(index_name), safe="")
1124+
).replace("{model}", quote(str(model), safe="")),
1125+
request_options=self._request_options.merge(
1126+
data=dumps(bodySerializer(_data)),
1127+
user_request_options=request_options,
1128+
),
1129+
use_read_transporter=False,
1130+
)
1131+
1132+
def batch_recommend_rules(
1133+
self,
1134+
index_name: Annotated[
1135+
StrictStr,
1136+
Field(description="Name of the index on which to perform the operation."),
1137+
],
1138+
model: Annotated[
1139+
RecommendModels,
1140+
Field(
1141+
description="[Recommend model](https://www.algolia.com/doc/guides/algolia-recommend/overview/#recommend-models). "
1142+
),
1143+
],
1144+
recommend_rule: Optional[List[RecommendRule]] = None,
1145+
request_options: Optional[Union[dict, RequestOptions]] = None,
1146+
) -> RecommendUpdatedAtResponse:
1147+
"""
1148+
Create or update a batch of Recommend Rules Each Recommend Rule is created or updated, depending on whether a Recommend Rule with the same `objectID` already exists. You may also specify `true` for `clearExistingRules`, in which case the batch will atomically replace all the existing Recommend Rules. Recommend Rules are similar to Search Rules, except that the conditions and consequences apply to a [source item](/doc/guides/algolia-recommend/overview/#recommend-models) instead of a query. The main differences are the following: - Conditions `pattern` and `anchoring` are unavailable. - Condition `filters` triggers if the source item matches the specified filters. - Condition `filters` accepts numeric filters. - Consequence `params` only covers filtering parameters. - Consequence `automaticFacetFilters` doesn't require a facet value placeholder (it tries to match the data source item's attributes instead).
1149+
1150+
Required API Key ACLs:
1151+
- editSettings
1152+
1153+
:param index_name: Name of the index on which to perform the operation. (required)
1154+
:type index_name: str
1155+
:param model: [Recommend model](https://www.algolia.com/doc/guides/algolia-recommend/overview/#recommend-models). (required)
1156+
:type model: RecommendModels
1157+
:param recommend_rule:
1158+
:type recommend_rule: List[RecommendRule]
1159+
: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)
1160+
:return: Returns the deserialized response in a 'RecommendUpdatedAtResponse' result object.
1161+
"""
1162+
resp = self.batch_recommend_rules_with_http_info(
1163+
index_name, model, recommend_rule, request_options
1164+
)
1165+
return resp.deserialize(RecommendUpdatedAtResponse, resp.raw_data)
1166+
9801167
def custom_delete_with_http_info(
9811168
self,
9821169
path: Annotated[

algoliasearch/recommend/models/recommend_rule.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from json import loads
1010
from sys import version_info
11-
from typing import Any, Dict, Optional
11+
from typing import Any, Dict, List, Optional
1212

1313
from pydantic import BaseModel, ConfigDict, Field
1414

@@ -21,6 +21,7 @@
2121
from algoliasearch.recommend.models.condition import Condition
2222
from algoliasearch.recommend.models.consequence import Consequence
2323
from algoliasearch.recommend.models.rule_metadata import RuleMetadata
24+
from algoliasearch.recommend.models.time_range import TimeRange
2425

2526

2627
class RecommendRule(BaseModel):
@@ -37,6 +38,8 @@ class RecommendRule(BaseModel):
3738
""" Description of the rule's purpose. This can be helpful for display in the Algolia dashboard. """
3839
enabled: Optional[bool] = Field(default=None, alias="enabled")
3940
""" Indicates whether to enable the rule. If it isn't enabled, it isn't applied at query time. """
41+
validity: Optional[List[TimeRange]] = Field(default=None, alias="validity")
42+
""" Time periods when the rule is active. """
4043

4144
model_config = ConfigDict(
4245
use_enum_values=True,
@@ -85,5 +88,10 @@ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
8588
if obj.get("consequence") is not None
8689
else None
8790
)
91+
obj["validity"] = (
92+
[TimeRange.from_dict(_item) for _item in obj["validity"]]
93+
if obj.get("validity") is not None
94+
else None
95+
)
8896

8997
return cls.model_validate(obj)
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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 sys import version_info
11+
from typing import Any, Dict, Optional
12+
13+
from pydantic import BaseModel, ConfigDict, Field
14+
15+
if version_info >= (3, 11):
16+
from typing import Self
17+
else:
18+
from typing_extensions import Self
19+
20+
21+
class RecommendUpdatedAtResponse(BaseModel):
22+
"""
23+
Response, taskID, and update timestamp.
24+
"""
25+
26+
task_id: int = Field(alias="taskID")
27+
""" Unique identifier of a task. A successful API response means that a task was added to a queue. It might not run immediately. You can check the task's progress with the [`task` operation](#tag/Indices/operation/getTask) and this `taskID`. """
28+
updated_at: str = Field(alias="updatedAt")
29+
""" Date and time when the object was updated, in RFC 3339 format. """
30+
31+
model_config = ConfigDict(
32+
use_enum_values=True,
33+
populate_by_name=True,
34+
validate_assignment=True,
35+
protected_namespaces=(),
36+
)
37+
38+
def to_json(self) -> str:
39+
return self.model_dump_json(by_alias=True, exclude_unset=True)
40+
41+
@classmethod
42+
def from_json(cls, json_str: str) -> Optional[Self]:
43+
"""Create an instance of RecommendUpdatedAtResponse from a JSON string"""
44+
return cls.from_dict(loads(json_str))
45+
46+
def to_dict(self) -> Dict[str, Any]:
47+
"""Return the dictionary representation of the model using alias."""
48+
return self.model_dump(
49+
by_alias=True,
50+
exclude_none=True,
51+
exclude_unset=True,
52+
)
53+
54+
@classmethod
55+
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
56+
"""Create an instance of RecommendUpdatedAtResponse from a dict"""
57+
if obj is None:
58+
return None
59+
60+
if not isinstance(obj, dict):
61+
return cls.model_validate(obj)
62+
63+
return cls.model_validate(obj)
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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 sys import version_info
11+
from typing import Any, Dict, Optional
12+
13+
from pydantic import BaseModel, ConfigDict, Field
14+
15+
if version_info >= (3, 11):
16+
from typing import Self
17+
else:
18+
from typing_extensions import Self
19+
20+
21+
class TimeRange(BaseModel):
22+
"""
23+
TimeRange
24+
"""
25+
26+
var_from: int = Field(alias="from")
27+
""" When the rule should start to be active, in Unix epoch time. """
28+
until: int = Field(alias="until")
29+
""" When the rule should stop to be active, in Unix epoch time. """
30+
31+
model_config = ConfigDict(
32+
use_enum_values=True,
33+
populate_by_name=True,
34+
validate_assignment=True,
35+
protected_namespaces=(),
36+
)
37+
38+
def to_json(self) -> str:
39+
return self.model_dump_json(by_alias=True, exclude_unset=True)
40+
41+
@classmethod
42+
def from_json(cls, json_str: str) -> Optional[Self]:
43+
"""Create an instance of TimeRange from a JSON string"""
44+
return cls.from_dict(loads(json_str))
45+
46+
def to_dict(self) -> Dict[str, Any]:
47+
"""Return the dictionary representation of the model using alias."""
48+
return self.model_dump(
49+
by_alias=True,
50+
exclude_none=True,
51+
exclude_unset=True,
52+
)
53+
54+
@classmethod
55+
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
56+
"""Create an instance of TimeRange from a dict"""
57+
if obj is None:
58+
return None
59+
60+
if not isinstance(obj, dict):
61+
return cls.model_validate(obj)
62+
63+
return cls.model_validate(obj)

0 commit comments

Comments
 (0)