Skip to content

Commit 3ccf12a

Browse files
committed
добавлены новые endpoints категорий
1 parent 01c8134 commit 3ccf12a

16 files changed

Lines changed: 1231 additions & 162 deletions

chizhik_api/abstraction.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
class DeliveryMode:
3+
"""Я хз что это такое"""
4+
5+
STORE = "store"

chizhik_api/endpoints/catalog.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
from human_requests import ApiChild, ApiParent, api_child_field, autotest
1010
from human_requests.abstraction import FetchResponse, HttpMethod
1111

12+
from ..abstraction import DeliveryMode
13+
1214
if TYPE_CHECKING:
1315
from ..manager import ChizhikAPI # noqa: F401
1416

@@ -37,6 +39,32 @@ async def tree(self, city_id: Optional[str] = None) -> FetchResponse:
3739
if city_id:
3840
url += f"?city_id={city_id}"
3941
return await self._parent._request(HttpMethod.GET, url)
42+
43+
@autotest
44+
async def delivery_tree(self,
45+
store_id: str,
46+
mode: DeliveryMode = DeliveryMode.STORE,
47+
include_restrict: bool = True):
48+
url = f"{self._parent.DELIVERY_API_URL}/catalog/v3/stores/{store_id}/categories?mode={mode}&include_subcategories=1&include_restrict={str(include_restrict).lower()}"
49+
return await self._parent._request(HttpMethod.GET, url)
50+
51+
@autotest
52+
async def delivery_tree_extended(self,
53+
store_id: str,
54+
category_alias: str,
55+
mode: DeliveryMode = DeliveryMode.STORE,
56+
include_restrict: bool = True):
57+
url = f"{self._parent.DELIVERY_API_URL}/catalog/v2/stores/{store_id}/categories/{category_alias}/extended?mode={mode}&include_restrict={str(include_restrict).lower()}"
58+
return await self._parent._request(HttpMethod.GET, url)
59+
60+
@autotest
61+
async def delivery_tree_ancestors(self,
62+
store_id: str,
63+
category_alias: str,
64+
mode: DeliveryMode = DeliveryMode.STORE,
65+
include_restrict: bool = True):
66+
url = f"{self._parent.DELIVERY_API_URL}/catalog/v3/stores/{store_id}/categories/{category_alias}/ancestors?mode={mode}&include_restrict={str(include_restrict).lower()}"
67+
return await self._parent._request(HttpMethod.GET, url)
4068

4169
@autotest
4270
async def products_list(
@@ -56,6 +84,8 @@ async def products_list(
5684
url += f"&term={urllib.parse.quote(search)}"
5785
return await self._parent._request(HttpMethod.GET, url)
5886

87+
async def products_list_v2():
88+
url = "https://app.chizhik.club/delivery/api/catalog/v2/stores/HB55/categories/264C39153/products?mode=store&include_restrict=true&limit=499&offset=0"
5989

6090
class ProductService(ApiChild["ChizhikAPI"]):
6191
"""Сервис для работы с товарами в каталоге."""
@@ -78,3 +108,13 @@ async def info(
78108
if city_id:
79109
url += f"?city_id={city_id}"
80110
return await self._parent._request(HttpMethod.GET, url)
111+
112+
@autotest
113+
async def delivery_info(self,
114+
store_id: str,
115+
product_id: int,
116+
mode: DeliveryMode = DeliveryMode.STORE,
117+
include_restrict: bool = True):
118+
# TODO
119+
url = f"{self._parent.DELIVERY_API_URL}/catalog/v2/stores/{store_id}/products/{product_id}?mode={mode}&include_restrict={str(include_restrict).lower()}"
120+
return await self._parent._request(HttpMethod.GET, url)

chizhik_api/manager.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class ChizhikAPI(ApiParent):
4545
browser_opts: dict[str, Any] = field(default_factory=dict)
4646
"""Дополнительные опции для браузера (см. https://camoufox.com/python/installation/)"""
4747
API_URL: str = "https://app.chizhik.club/api"
48+
DELIVERY_API_URL: str = "https://app.chizhik.club/delivery/api"
4849
"""URL для работы с каталогом."""
4950
MAIN_SITE_URL: str = "https://chizhik.club/catalog/"
5051
"""URL главной страницы сайта."""

tests/__snapshots__/ClassAdvertising.active_inout.schema.json

Lines changed: 0 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,6 @@
66
],
77
"$schema": "https://json-schema.org/draft/2020-12/schema",
88
"properties": {
9-
"background": {
10-
"type": "string",
11-
"format": "uri"
12-
},
13-
"banner": {
14-
"type": "null"
15-
},
16-
"description": {
17-
"type": "string"
18-
},
199
"detail": {
2010
"type": "array",
2111
"items": {
@@ -38,74 +28,8 @@
3828
}
3929
}
4030
},
41-
"end_timestamp": {
42-
"type": "string",
43-
"format": "date-time"
44-
},
45-
"image": {
46-
"type": "string",
47-
"format": "uri"
48-
},
49-
"is_thematic": {
50-
"type": "boolean"
51-
},
52-
"logo": {
53-
"type": "string",
54-
"format": "uri"
55-
},
56-
"pdf": {
57-
"type": "string",
58-
"format": "uri"
59-
},
60-
"pdf_data": {
61-
"type": "object",
62-
"required": [
63-
"background_color",
64-
"banner",
65-
"file",
66-
"image",
67-
"subtitle",
68-
"text_color",
69-
"title"
70-
],
71-
"properties": {
72-
"background_color": {
73-
"type": "string"
74-
},
75-
"banner": {
76-
"type": "null"
77-
},
78-
"file": {
79-
"type": "string",
80-
"format": "uri"
81-
},
82-
"image": {
83-
"type": "string",
84-
"format": "uri"
85-
},
86-
"subtitle": {
87-
"type": "string"
88-
},
89-
"text_color": {
90-
"type": "string"
91-
},
92-
"title": {
93-
"type": "string"
94-
}
95-
}
96-
},
9731
"show": {
9832
"type": "boolean"
99-
},
100-
"start_timestamp": {
101-
"type": "string",
102-
"format": "date-time"
103-
},
104-
"title": {
105-
"type": "string"
106-
},
107-
"title_color": {
108-
"type": "string"
10933
}
11034
}
11135
}

0 commit comments

Comments
 (0)