From d89b79fabfcfdc3b4ae5b82190f2845d0f2f2c92 Mon Sep 17 00:00:00 2001 From: guilbera Date: Fri, 14 Jul 2023 10:25:10 +0200 Subject: [PATCH 1/2] feat: create job id export --- priceloop_api/api/export_api/job_id_export.py | 114 ++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 priceloop_api/api/export_api/job_id_export.py diff --git a/priceloop_api/api/export_api/job_id_export.py b/priceloop_api/api/export_api/job_id_export.py new file mode 100644 index 0000000..db5c098 --- /dev/null +++ b/priceloop_api/api/export_api/job_id_export.py @@ -0,0 +1,114 @@ +from http import HTTPStatus +from typing import Any, Dict, Optional + +import httpx +from ... import errors +from ...client import AuthenticatedClient, Client +from ...models.export_info import ExportInfo +from ...types import Response + + +def _get_kwargs( + workspace: str, + export_job_id: int, + *, + client: AuthenticatedClient, +) -> Dict[str, Any]: + url = "{}/api/v1.0/workspaces/{workspace}/exports/{export_job_id}".format( + client.base_url, workspace=workspace, export_job_id=export_job_id + ) + + headers: Dict[str, str] = client.get_headers() + cookies: Dict[str, Any] = client.get_cookies() + + return { + "method": "get", + "url": url, + "headers": headers, + "cookies": cookies, + "timeout": client.get_timeout(), + "follow_redirects": client.follow_redirects, + } + + +def _parse_response(*, client: Client, response: httpx.Response) -> Optional["ExportInfo"]: + if response.status_code == HTTPStatus.OK: + response_200 = ExportInfo.from_dict(response.json()) + return response_200 + if client.raise_on_unexpected_status: + raise errors.UnexpectedStatus(response.status_code, response.content) + else: + return None + + +def _build_response(*, client: Client, response: httpx.Response) -> Response["ExportInfo"]: + return Response( + status_code=HTTPStatus(response.status_code), + content=response.content, + headers=response.headers, + parsed=_parse_response(client=client, response=response), + ) + + +def sync_detailed( + workspace: str, + export_job_id: int, + *, + client: AuthenticatedClient, +) -> Response["ExportInfo"]: + """This API endpoint returns a url from which the published table can be donwloaded. + + Args: + workspace (str): Example: workspace-name. + export_job_id (int): Example: 5. + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[List['ExportJob']] + """ + + kwargs = _get_kwargs( + workspace=workspace, + export_job_id=export_job_id, + client=client, + ) + + response = httpx.request( + verify=client.verify_ssl, + **kwargs, + ) + + return _build_response(client=client, response=response) + + +def sync( + workspace: str, + export_job_id: int, + *, + client: AuthenticatedClient, +) -> Optional["ExportInfo"]: + """List all table exports + + This API endpoint returns a list of all available exports for a table. Exported files are kept + available until `.availableUntil`. + + Args: + workspace (str): Example: workspace-name. + table (str): Example: table-name. + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + List['ExportJob'] + """ + + return sync_detailed( + workspace=workspace, + export_job_id=export_job_id, + client=client, + ).parsed From 42bb909a280e7cc53f5767dfbb229dc64f223805 Mon Sep 17 00:00:00 2001 From: guilbera Date: Fri, 14 Jul 2023 10:36:23 +0200 Subject: [PATCH 2/2] chore: correct description --- priceloop_api/api/export_api/job_id_export.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/priceloop_api/api/export_api/job_id_export.py b/priceloop_api/api/export_api/job_id_export.py index db5c098..2c9bbeb 100644 --- a/priceloop_api/api/export_api/job_id_export.py +++ b/priceloop_api/api/export_api/job_id_export.py @@ -67,7 +67,7 @@ def sync_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[List['ExportJob']] + Response['ExportInfo'] """ kwargs = _get_kwargs( @@ -90,21 +90,18 @@ def sync( *, client: AuthenticatedClient, ) -> Optional["ExportInfo"]: - """List all table exports - - This API endpoint returns a list of all available exports for a table. Exported files are kept - available until `.availableUntil`. + """This API endpoint returns a url from which the published table can be donwloaded. Args: workspace (str): Example: workspace-name. - table (str): Example: table-name. + export_job_id (int): Example: 5. Raises: errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - List['ExportJob'] + Response['ExportInfo'] """ return sync_detailed(