|
6 | 6 | WebSearchParams, |
7 | 7 | WebSearchResponse, |
8 | 8 | ) |
9 | | -from ...response_utils import parse_response_model |
| 9 | +from ...web_operation_metadata import WEB_REQUEST_OPERATION_METADATA |
10 | 10 | from ...web_payload_utils import build_web_fetch_payload, build_web_search_payload |
| 11 | +from ...web_request_utils import start_web_job_async |
| 12 | +from ...web_route_constants import WEB_FETCH_ROUTE_PATH, WEB_SEARCH_ROUTE_PATH |
11 | 13 |
|
12 | 14 |
|
13 | 15 | class WebManager: |
| 16 | + _OPERATION_METADATA = WEB_REQUEST_OPERATION_METADATA |
| 17 | + _FETCH_ROUTE_PATH = WEB_FETCH_ROUTE_PATH |
| 18 | + _SEARCH_ROUTE_PATH = WEB_SEARCH_ROUTE_PATH |
| 19 | + |
14 | 20 | def __init__(self, client): |
15 | 21 | self._client = client |
16 | 22 | self.batch_fetch = BatchFetchManager(client) |
17 | 23 | self.crawl = WebCrawlManager(client) |
18 | 24 |
|
19 | 25 | async def fetch(self, params: FetchParams) -> FetchResponse: |
20 | 26 | payload = build_web_fetch_payload(params) |
21 | | - |
22 | | - response = await self._client.transport.post( |
23 | | - self._client._build_url("/web/fetch"), |
24 | | - data=payload, |
25 | | - ) |
26 | | - return parse_response_model( |
27 | | - response.data, |
| 27 | + return await start_web_job_async( |
| 28 | + client=self._client, |
| 29 | + route_prefix=self._FETCH_ROUTE_PATH, |
| 30 | + payload=payload, |
28 | 31 | model=FetchResponse, |
29 | | - operation_name="web fetch", |
| 32 | + operation_name=self._OPERATION_METADATA.fetch_operation_name, |
30 | 33 | ) |
31 | 34 |
|
32 | 35 | async def search(self, params: WebSearchParams) -> WebSearchResponse: |
33 | 36 | payload = build_web_search_payload(params) |
34 | | - response = await self._client.transport.post( |
35 | | - self._client._build_url("/web/search"), |
36 | | - data=payload, |
37 | | - ) |
38 | | - return parse_response_model( |
39 | | - response.data, |
| 37 | + return await start_web_job_async( |
| 38 | + client=self._client, |
| 39 | + route_prefix=self._SEARCH_ROUTE_PATH, |
| 40 | + payload=payload, |
40 | 41 | model=WebSearchResponse, |
41 | | - operation_name="web search", |
| 42 | + operation_name=self._OPERATION_METADATA.search_operation_name, |
42 | 43 | ) |
0 commit comments