Skip to content

Commit 9195f09

Browse files
algolia-botfebeckmillotp
committed
feat(specs): add /schedule endpoint (generated)
algolia/api-clients-automation#3350 Co-authored-by: algolia-bot <[email protected]> Co-authored-by: Fernando Beck <[email protected]> Co-authored-by: Pierre Millot <[email protected]>
1 parent b8794d4 commit 9195f09

File tree

3 files changed

+221
-0
lines changed

3 files changed

+221
-0
lines changed

algoliasearch/abtesting/client.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@
1717
from algoliasearch.abtesting.models.ab_test_response import ABTestResponse
1818
from algoliasearch.abtesting.models.add_ab_tests_request import AddABTestsRequest
1919
from algoliasearch.abtesting.models.list_ab_tests_response import ListABTestsResponse
20+
from algoliasearch.abtesting.models.schedule_ab_test_response import (
21+
ScheduleABTestResponse,
22+
)
23+
from algoliasearch.abtesting.models.schedule_ab_tests_request import (
24+
ScheduleABTestsRequest,
25+
)
2026
from algoliasearch.http.api_response import ApiResponse
2127
from algoliasearch.http.request_options import RequestOptions
2228
from algoliasearch.http.serializer import bodySerializer
@@ -706,6 +712,64 @@ async def list_ab_tests(
706712
)
707713
).deserialize(ListABTestsResponse)
708714

715+
async def schedule_ab_test_with_http_info(
716+
self,
717+
schedule_ab_tests_request: ScheduleABTestsRequest,
718+
request_options: Optional[Union[dict, RequestOptions]] = None,
719+
) -> ApiResponse[str]:
720+
"""
721+
Schedule an A/B test to be started at a later time.
722+
723+
Required API Key ACLs:
724+
- editSettings
725+
726+
:param schedule_ab_tests_request: (required)
727+
:type schedule_ab_tests_request: ScheduleABTestsRequest
728+
: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)
729+
:return: Returns the raw algoliasearch 'APIResponse' object.
730+
"""
731+
732+
if schedule_ab_tests_request is None:
733+
raise ValueError(
734+
"Parameter `schedule_ab_tests_request` is required when calling `schedule_ab_test`."
735+
)
736+
737+
_data = {}
738+
if schedule_ab_tests_request is not None:
739+
_data = schedule_ab_tests_request
740+
741+
return await self._transporter.request(
742+
verb=Verb.POST,
743+
path="/2/abtests/schedule",
744+
request_options=self._request_options.merge(
745+
data=dumps(bodySerializer(_data)),
746+
user_request_options=request_options,
747+
),
748+
use_read_transporter=False,
749+
)
750+
751+
async def schedule_ab_test(
752+
self,
753+
schedule_ab_tests_request: ScheduleABTestsRequest,
754+
request_options: Optional[Union[dict, RequestOptions]] = None,
755+
) -> ScheduleABTestResponse:
756+
"""
757+
Schedule an A/B test to be started at a later time.
758+
759+
Required API Key ACLs:
760+
- editSettings
761+
762+
:param schedule_ab_tests_request: (required)
763+
:type schedule_ab_tests_request: ScheduleABTestsRequest
764+
: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)
765+
:return: Returns the deserialized response in a 'ScheduleABTestResponse' result object.
766+
"""
767+
return (
768+
await self.schedule_ab_test_with_http_info(
769+
schedule_ab_tests_request, request_options
770+
)
771+
).deserialize(ScheduleABTestResponse)
772+
709773
async def stop_ab_test_with_http_info(
710774
self,
711775
id: Annotated[StrictInt, Field(description="Unique A/B test identifier.")],
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 typing import Any, Dict, Self
11+
12+
from pydantic import BaseModel, ConfigDict, Field, StrictInt
13+
14+
15+
class ScheduleABTestResponse(BaseModel):
16+
"""
17+
ScheduleABTestResponse
18+
"""
19+
20+
ab_test_schedule_id: StrictInt = Field(
21+
description="Unique scheduled A/B test identifier.", alias="abTestScheduleID"
22+
)
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 ScheduleABTestResponse 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+
return _dict
52+
53+
@classmethod
54+
def from_dict(cls, obj: Dict) -> Self:
55+
"""Create an instance of ScheduleABTestResponse from a dict"""
56+
if obj is None:
57+
return None
58+
59+
if not isinstance(obj, dict):
60+
return cls.model_validate(obj)
61+
62+
_obj = cls.model_validate({"abTestScheduleID": obj.get("abTestScheduleID")})
63+
return _obj
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
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 Annotated, Any, Dict, List, Self
11+
12+
from pydantic import BaseModel, ConfigDict, Field, StrictStr
13+
14+
from algoliasearch.abtesting.models.add_ab_tests_variant import AddABTestsVariant
15+
16+
17+
class ScheduleABTestsRequest(BaseModel):
18+
"""
19+
ScheduleABTestsRequest
20+
"""
21+
22+
name: StrictStr = Field(description="A/B test name.")
23+
variants: Annotated[List[AddABTestsVariant], Field(min_length=2, max_length=2)] = (
24+
Field(description="A/B test variants.")
25+
)
26+
scheduled_at: StrictStr = Field(
27+
description="Date and time when the A/B test is scheduled to start, in RFC 3339 format.",
28+
alias="scheduledAt",
29+
)
30+
end_at: StrictStr = Field(
31+
description="End date and time of the A/B test, in RFC 3339 format.",
32+
alias="endAt",
33+
)
34+
35+
model_config = ConfigDict(
36+
use_enum_values=True, populate_by_name=True, validate_assignment=True
37+
)
38+
39+
def to_json(self) -> str:
40+
return self.model_dump_json(by_alias=True, exclude_unset=True)
41+
42+
@classmethod
43+
def from_json(cls, json_str: str) -> Self:
44+
"""Create an instance of ScheduleABTestsRequest from a JSON string"""
45+
return cls.from_dict(loads(json_str))
46+
47+
def to_dict(self) -> Dict[str, Any]:
48+
"""Return the dictionary representation of the model using alias.
49+
50+
This has the following differences from calling pydantic's
51+
`self.model_dump(by_alias=True)`:
52+
53+
* `None` is only added to the output dict for nullable fields that
54+
were set at model initialization. Other fields with value `None`
55+
are ignored.
56+
"""
57+
_dict = self.model_dump(
58+
by_alias=True,
59+
exclude={},
60+
exclude_none=True,
61+
)
62+
_items = []
63+
if self.variants:
64+
for _item in self.variants:
65+
if _item:
66+
_items.append(_item.to_dict())
67+
_dict["variants"] = _items
68+
return _dict
69+
70+
@classmethod
71+
def from_dict(cls, obj: Dict) -> Self:
72+
"""Create an instance of ScheduleABTestsRequest from a dict"""
73+
if obj is None:
74+
return None
75+
76+
if not isinstance(obj, dict):
77+
return cls.model_validate(obj)
78+
79+
_obj = cls.model_validate(
80+
{
81+
"name": obj.get("name"),
82+
"variants": (
83+
[
84+
AddABTestsVariant.from_dict(_item)
85+
for _item in obj.get("variants")
86+
]
87+
if obj.get("variants") is not None
88+
else None
89+
),
90+
"scheduledAt": obj.get("scheduledAt"),
91+
"endAt": obj.get("endAt"),
92+
}
93+
)
94+
return _obj

0 commit comments

Comments
 (0)