|
| 1 | +# This file was auto-generated by Fern from our API Definition. |
| 2 | + |
| 3 | +import typing |
| 4 | +from json.decoder import JSONDecodeError |
| 5 | + |
| 6 | +from ..core.api_error import ApiError |
| 7 | +from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper |
| 8 | +from ..core.http_response import AsyncHttpResponse, HttpResponse |
| 9 | +from ..core.jsonable_encoder import jsonable_encoder |
| 10 | +from ..core.pydantic_utilities import parse_obj_as |
| 11 | +from ..core.request_options import RequestOptions |
| 12 | +from ..errors.too_many_requests_error import TooManyRequestsError |
| 13 | + |
| 14 | + |
| 15 | +class RawFileStashClient: |
| 16 | + def __init__(self, *, client_wrapper: SyncClientWrapper): |
| 17 | + self._client_wrapper = client_wrapper |
| 18 | + |
| 19 | + def download_file( |
| 20 | + self, *, s_3_key: str, request_options: typing.Optional[RequestOptions] = None |
| 21 | + ) -> HttpResponse[None]: |
| 22 | + """ |
| 23 | + Download a file from File Stash |
| 24 | +
|
| 25 | + Parameters |
| 26 | + ---------- |
| 27 | + s_3_key : str |
| 28 | +
|
| 29 | + request_options : typing.Optional[RequestOptions] |
| 30 | + Request-specific configuration. |
| 31 | +
|
| 32 | + Returns |
| 33 | + ------- |
| 34 | + HttpResponse[None] |
| 35 | + """ |
| 36 | + _response = self._client_wrapper.httpx_client.request( |
| 37 | + f"v1/connect/{jsonable_encoder(self._client_wrapper._project_id)}/file_stash/download", |
| 38 | + method="GET", |
| 39 | + params={ |
| 40 | + "s3_key": s_3_key, |
| 41 | + }, |
| 42 | + request_options=request_options, |
| 43 | + ) |
| 44 | + try: |
| 45 | + if 200 <= _response.status_code < 300: |
| 46 | + return HttpResponse(response=_response, data=None) |
| 47 | + if _response.status_code == 429: |
| 48 | + raise TooManyRequestsError( |
| 49 | + headers=dict(_response.headers), |
| 50 | + body=typing.cast( |
| 51 | + typing.Optional[typing.Any], |
| 52 | + parse_obj_as( |
| 53 | + type_=typing.Optional[typing.Any], # type: ignore |
| 54 | + object_=_response.json(), |
| 55 | + ), |
| 56 | + ), |
| 57 | + ) |
| 58 | + _response_json = _response.json() |
| 59 | + except JSONDecodeError: |
| 60 | + raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) |
| 61 | + raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) |
| 62 | + |
| 63 | + |
| 64 | +class AsyncRawFileStashClient: |
| 65 | + def __init__(self, *, client_wrapper: AsyncClientWrapper): |
| 66 | + self._client_wrapper = client_wrapper |
| 67 | + |
| 68 | + async def download_file( |
| 69 | + self, *, s_3_key: str, request_options: typing.Optional[RequestOptions] = None |
| 70 | + ) -> AsyncHttpResponse[None]: |
| 71 | + """ |
| 72 | + Download a file from File Stash |
| 73 | +
|
| 74 | + Parameters |
| 75 | + ---------- |
| 76 | + s_3_key : str |
| 77 | +
|
| 78 | + request_options : typing.Optional[RequestOptions] |
| 79 | + Request-specific configuration. |
| 80 | +
|
| 81 | + Returns |
| 82 | + ------- |
| 83 | + AsyncHttpResponse[None] |
| 84 | + """ |
| 85 | + _response = await self._client_wrapper.httpx_client.request( |
| 86 | + f"v1/connect/{jsonable_encoder(self._client_wrapper._project_id)}/file_stash/download", |
| 87 | + method="GET", |
| 88 | + params={ |
| 89 | + "s3_key": s_3_key, |
| 90 | + }, |
| 91 | + request_options=request_options, |
| 92 | + ) |
| 93 | + try: |
| 94 | + if 200 <= _response.status_code < 300: |
| 95 | + return AsyncHttpResponse(response=_response, data=None) |
| 96 | + if _response.status_code == 429: |
| 97 | + raise TooManyRequestsError( |
| 98 | + headers=dict(_response.headers), |
| 99 | + body=typing.cast( |
| 100 | + typing.Optional[typing.Any], |
| 101 | + parse_obj_as( |
| 102 | + type_=typing.Optional[typing.Any], # type: ignore |
| 103 | + object_=_response.json(), |
| 104 | + ), |
| 105 | + ), |
| 106 | + ) |
| 107 | + _response_json = _response.json() |
| 108 | + except JSONDecodeError: |
| 109 | + raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) |
| 110 | + raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) |
0 commit comments