inttegro.async_resources.files
Generated public typing surface. Do not edit by hand.
1# Generated by scripts/generate_async_resources.py; do not edit by hand. 2"""Managed file operations and binary download helpers.""" 3from __future__ import annotations 4from pathlib import Path 5from inttegro.file.file import File 6from inttegro.file.page import Page 7from ..async_http_client import AsyncHttpClient 8from inttegro.file.page_request import PageRequest 9 10class FileDownload: 11 """Binary file content and the response headers needed to save it safely. 12 13 This local helper never performs an API request by itself. 14 """ 15 data: bytes 16 'Raw response bytes exactly as returned by the file content endpoint.' 17 headers: dict[str, str] 18 'Response headers normalized by the HTTP transport.' 19 20 def __init__(self, data: bytes, headers: dict[str, str] | None=None) -> None: 21 """Create a download value from response ``data`` and optional ``headers``.""" 22 self.data = data 23 self.headers = headers or {} 24 25 def save_to(self, path: str) -> None: 26 """Write the downloaded bytes to ``path``. 27 28 Args: 29 path (str): Documented path value for this operation. 30 31 Returns: 32 ``None`` after the local operation completes. 33 """ 34 Path(path).write_bytes(self.data) 35 36class AsyncFiles: 37 """Create, inspect, download, page, and delete managed file resources. 38 39 Access this service as ``AsyncInttegroClient.files``. Methods use the client's shared transport and return the typed resource shapes documented below. 40 """ 41 42 def __init__(self, http: AsyncHttpClient): 43 """Bind file operations to the client's shared HTTP transport.""" 44 self.http = http 45 46 async def create(self, *, file: str, purpose: str, title: str | None=None, custom_data: dict[str, str] | None=None, idempotency_key: str | None=None) -> File: 47 """Upload ``file`` and create a managed file for the stated ``purpose``. 48 49 ``custom_data`` contains merchant-defined string metadata. Reuse 50 ``idempotency_key`` when retrying the same logical upload. 51 """ 52 headers = {'Idempotency-Key': idempotency_key} if idempotency_key else {} 53 return await self.http.post_multipart('/files/create', {'purpose': purpose, 'title': title, 'custom_data': custom_data}, {'file': file}, headers=headers) 54 55 async def lookup(self, file_id: str) -> File: 56 """Return the file identified by ``file_id``. 57 58 API endpoint: ``/files/lookup``. 59 60 Args: 61 file_id (str): Unique identifier of the file. 62 63 Returns: 64 ``File`` decoded from the documented response shape. 65 66 Raises: 67 APIError: The API rejected the request or could not complete it. 68 NetworkError: The request could not reach the Inttegro API. 69 TimeoutError: The configured request deadline elapsed. 70 """ 71 return await self.http.post('/files/lookup', {'file_id': file_id}) 72 73 async def page(self, payload: PageRequest | None=None) -> Page: 74 """Return a page of files visible to the authenticated application. 75 76 API endpoint: ``/files/page``. 77 78 Args: 79 payload (PageRequest | None): Typed request object or equivalent request mapping for this operation. 80 81 Returns: 82 ``Page`` decoded from the documented response shape. 83 84 Raises: 85 APIError: The API rejected the request or could not complete it. 86 NetworkError: The request could not reach the Inttegro API. 87 TimeoutError: The configured request deadline elapsed. 88 """ 89 return await self.http.post('/files/page', payload or {}) 90 91 async def contents(self, *, file_id: str, disposition: str='attachment') -> FileDownload: 92 """Download ``file_id`` with the requested content ``disposition``. 93 94 API endpoint: ``/files/contents``. 95 96 Args: 97 file_id (str): Unique identifier of the file. 98 disposition (str): Requested content disposition for the download response. 99 100 Returns: 101 ``FileDownload`` decoded from the documented response shape. 102 103 Raises: 104 APIError: The API rejected the request or could not complete it. 105 NetworkError: The request could not reach the Inttegro API. 106 TimeoutError: The configured request deadline elapsed. 107 """ 108 (data, headers) = await self.http.post_binary_json('/files/contents', {'file_id': file_id, 'disposition': disposition}) 109 return FileDownload(data, headers) 110 111 async def delete(self, file_id: str) -> File: 112 """Delete ``file_id`` and return its final typed file state. 113 114 API endpoint: ``/files/delete``. 115 116 Args: 117 file_id (str): Unique identifier of the file. 118 119 Returns: 120 ``File`` decoded from the documented response shape. 121 122 Raises: 123 APIError: The API rejected the request or could not complete it. 124 NetworkError: The request could not reach the Inttegro API. 125 TimeoutError: The configured request deadline elapsed. 126 """ 127 return await self.http.post('/files/delete', {'file_id': file_id})
11class FileDownload: 12 """Binary file content and the response headers needed to save it safely. 13 14 This local helper never performs an API request by itself. 15 """ 16 data: bytes 17 'Raw response bytes exactly as returned by the file content endpoint.' 18 headers: dict[str, str] 19 'Response headers normalized by the HTTP transport.' 20 21 def __init__(self, data: bytes, headers: dict[str, str] | None=None) -> None: 22 """Create a download value from response ``data`` and optional ``headers``.""" 23 self.data = data 24 self.headers = headers or {} 25 26 def save_to(self, path: str) -> None: 27 """Write the downloaded bytes to ``path``. 28 29 Args: 30 path (str): Documented path value for this operation. 31 32 Returns: 33 ``None`` after the local operation completes. 34 """ 35 Path(path).write_bytes(self.data)
Binary file content and the response headers needed to save it safely.
This local helper never performs an API request by itself.
26 def save_to(self, path: str) -> None: 27 """Write the downloaded bytes to ``path``. 28 29 Args: 30 path (str): Documented path value for this operation. 31 32 Returns: 33 ``None`` after the local operation completes. 34 """ 35 Path(path).write_bytes(self.data)
Write the downloaded bytes to path.
Arguments:
- path (str): Documented path value for this operation.
Returns:
Noneafter the local operation completes.
37class AsyncFiles: 38 """Create, inspect, download, page, and delete managed file resources. 39 40 Access this service as ``AsyncInttegroClient.files``. Methods use the client's shared transport and return the typed resource shapes documented below. 41 """ 42 43 def __init__(self, http: AsyncHttpClient): 44 """Bind file operations to the client's shared HTTP transport.""" 45 self.http = http 46 47 async def create(self, *, file: str, purpose: str, title: str | None=None, custom_data: dict[str, str] | None=None, idempotency_key: str | None=None) -> File: 48 """Upload ``file`` and create a managed file for the stated ``purpose``. 49 50 ``custom_data`` contains merchant-defined string metadata. Reuse 51 ``idempotency_key`` when retrying the same logical upload. 52 """ 53 headers = {'Idempotency-Key': idempotency_key} if idempotency_key else {} 54 return await self.http.post_multipart('/files/create', {'purpose': purpose, 'title': title, 'custom_data': custom_data}, {'file': file}, headers=headers) 55 56 async def lookup(self, file_id: str) -> File: 57 """Return the file identified by ``file_id``. 58 59 API endpoint: ``/files/lookup``. 60 61 Args: 62 file_id (str): Unique identifier of the file. 63 64 Returns: 65 ``File`` decoded from the documented response shape. 66 67 Raises: 68 APIError: The API rejected the request or could not complete it. 69 NetworkError: The request could not reach the Inttegro API. 70 TimeoutError: The configured request deadline elapsed. 71 """ 72 return await self.http.post('/files/lookup', {'file_id': file_id}) 73 74 async def page(self, payload: PageRequest | None=None) -> Page: 75 """Return a page of files visible to the authenticated application. 76 77 API endpoint: ``/files/page``. 78 79 Args: 80 payload (PageRequest | None): Typed request object or equivalent request mapping for this operation. 81 82 Returns: 83 ``Page`` decoded from the documented response shape. 84 85 Raises: 86 APIError: The API rejected the request or could not complete it. 87 NetworkError: The request could not reach the Inttegro API. 88 TimeoutError: The configured request deadline elapsed. 89 """ 90 return await self.http.post('/files/page', payload or {}) 91 92 async def contents(self, *, file_id: str, disposition: str='attachment') -> FileDownload: 93 """Download ``file_id`` with the requested content ``disposition``. 94 95 API endpoint: ``/files/contents``. 96 97 Args: 98 file_id (str): Unique identifier of the file. 99 disposition (str): Requested content disposition for the download response. 100 101 Returns: 102 ``FileDownload`` decoded from the documented response shape. 103 104 Raises: 105 APIError: The API rejected the request or could not complete it. 106 NetworkError: The request could not reach the Inttegro API. 107 TimeoutError: The configured request deadline elapsed. 108 """ 109 (data, headers) = await self.http.post_binary_json('/files/contents', {'file_id': file_id, 'disposition': disposition}) 110 return FileDownload(data, headers) 111 112 async def delete(self, file_id: str) -> File: 113 """Delete ``file_id`` and return its final typed file state. 114 115 API endpoint: ``/files/delete``. 116 117 Args: 118 file_id (str): Unique identifier of the file. 119 120 Returns: 121 ``File`` decoded from the documented response shape. 122 123 Raises: 124 APIError: The API rejected the request or could not complete it. 125 NetworkError: The request could not reach the Inttegro API. 126 TimeoutError: The configured request deadline elapsed. 127 """ 128 return await self.http.post('/files/delete', {'file_id': file_id})
Create, inspect, download, page, and delete managed file resources.
Access this service as AsyncInttegroClient.files. Methods use the client's shared transport and return the typed resource shapes documented below.
43 def __init__(self, http: AsyncHttpClient): 44 """Bind file operations to the client's shared HTTP transport.""" 45 self.http = http
Bind file operations to the client's shared HTTP transport.
47 async def create(self, *, file: str, purpose: str, title: str | None=None, custom_data: dict[str, str] | None=None, idempotency_key: str | None=None) -> File: 48 """Upload ``file`` and create a managed file for the stated ``purpose``. 49 50 ``custom_data`` contains merchant-defined string metadata. Reuse 51 ``idempotency_key`` when retrying the same logical upload. 52 """ 53 headers = {'Idempotency-Key': idempotency_key} if idempotency_key else {} 54 return await self.http.post_multipart('/files/create', {'purpose': purpose, 'title': title, 'custom_data': custom_data}, {'file': file}, headers=headers)
Upload file and create a managed file for the stated purpose.
custom_data contains merchant-defined string metadata. Reuse
idempotency_key when retrying the same logical upload.
56 async def lookup(self, file_id: str) -> File: 57 """Return the file identified by ``file_id``. 58 59 API endpoint: ``/files/lookup``. 60 61 Args: 62 file_id (str): Unique identifier of the file. 63 64 Returns: 65 ``File`` decoded from the documented response shape. 66 67 Raises: 68 APIError: The API rejected the request or could not complete it. 69 NetworkError: The request could not reach the Inttegro API. 70 TimeoutError: The configured request deadline elapsed. 71 """ 72 return await self.http.post('/files/lookup', {'file_id': file_id})
Return the file identified by file_id.
API endpoint: /files/lookup.
Arguments:
- file_id (str): Unique identifier of the file.
Returns:
Filedecoded from the documented response shape.
Raises:
- APIError: The API rejected the request or could not complete it.
- NetworkError: The request could not reach the Inttegro API.
- TimeoutError: The configured request deadline elapsed.
74 async def page(self, payload: PageRequest | None=None) -> Page: 75 """Return a page of files visible to the authenticated application. 76 77 API endpoint: ``/files/page``. 78 79 Args: 80 payload (PageRequest | None): Typed request object or equivalent request mapping for this operation. 81 82 Returns: 83 ``Page`` decoded from the documented response shape. 84 85 Raises: 86 APIError: The API rejected the request or could not complete it. 87 NetworkError: The request could not reach the Inttegro API. 88 TimeoutError: The configured request deadline elapsed. 89 """ 90 return await self.http.post('/files/page', payload or {})
Return a page of files visible to the authenticated application.
API endpoint: /files/page.
Arguments:
- payload (PageRequest | None): Typed request object or equivalent request mapping for this operation.
Returns:
Pagedecoded from the documented response shape.
Raises:
- APIError: The API rejected the request or could not complete it.
- NetworkError: The request could not reach the Inttegro API.
- TimeoutError: The configured request deadline elapsed.
92 async def contents(self, *, file_id: str, disposition: str='attachment') -> FileDownload: 93 """Download ``file_id`` with the requested content ``disposition``. 94 95 API endpoint: ``/files/contents``. 96 97 Args: 98 file_id (str): Unique identifier of the file. 99 disposition (str): Requested content disposition for the download response. 100 101 Returns: 102 ``FileDownload`` decoded from the documented response shape. 103 104 Raises: 105 APIError: The API rejected the request or could not complete it. 106 NetworkError: The request could not reach the Inttegro API. 107 TimeoutError: The configured request deadline elapsed. 108 """ 109 (data, headers) = await self.http.post_binary_json('/files/contents', {'file_id': file_id, 'disposition': disposition}) 110 return FileDownload(data, headers)
Download file_id with the requested content disposition.
API endpoint: /files/contents.
Arguments:
- file_id (str): Unique identifier of the file.
- disposition (str): Requested content disposition for the download response.
Returns:
FileDownloaddecoded from the documented response shape.
Raises:
- APIError: The API rejected the request or could not complete it.
- NetworkError: The request could not reach the Inttegro API.
- TimeoutError: The configured request deadline elapsed.
112 async def delete(self, file_id: str) -> File: 113 """Delete ``file_id`` and return its final typed file state. 114 115 API endpoint: ``/files/delete``. 116 117 Args: 118 file_id (str): Unique identifier of the file. 119 120 Returns: 121 ``File`` decoded from the documented response shape. 122 123 Raises: 124 APIError: The API rejected the request or could not complete it. 125 NetworkError: The request could not reach the Inttegro API. 126 TimeoutError: The configured request deadline elapsed. 127 """ 128 return await self.http.post('/files/delete', {'file_id': file_id})
Delete file_id and return its final typed file state.
API endpoint: /files/delete.
Arguments:
- file_id (str): Unique identifier of the file.
Returns:
Filedecoded from the documented response shape.
Raises:
- APIError: The API rejected the request or could not complete it.
- NetworkError: The request could not reach the Inttegro API.
- TimeoutError: The configured request deadline elapsed.