inttegro.async_resources.file_links

Generated public typing surface. Do not edit by hand.

  1# Generated by scripts/generate_async_resources.py; do not edit by hand.
  2"""Controlled-link operations for serving managed Inttegro files."""
  3from __future__ import annotations
  4from inttegro.file_link.file_link import FileLink
  5from inttegro.file_link.creation import Creation
  6from inttegro.file_link.page import Page
  7from ..async_http_client import AsyncHttpClient
  8from inttegro.file_link.create_request import CreateRequest
  9from inttegro.file_link.page_request import PageRequest
 10from inttegro.file_link.revoke_request import RevokeRequest
 11from .files import FileDownload
 12
 13class AsyncFileLinks:
 14    """Create and manage controlled links to managed file content.
 15
 16    Access this service as ``AsyncInttegroClient.file_links``. Methods use the client's shared transport and return the typed resource shapes documented below.
 17    """
 18
 19    def __init__(self, http: AsyncHttpClient):
 20        """Bind file-link operations to the client's shared HTTP transport."""
 21        self.http = http
 22
 23    async def create(self, payload: CreateRequest, idempotency_key: str | None=None) -> Creation:
 24        """Create a controlled file link and return its one-time creation data.
 25
 26        API endpoint: ``/file_links/create``.
 27
 28        Args:
 29            payload (CreateRequest): Typed request object or equivalent request mapping for this operation.
 30            idempotency_key (str | None): Optional stable key to reuse when retrying the same logical write.
 31
 32        Returns:
 33            ``Creation`` decoded from the documented response shape.
 34
 35        Raises:
 36            APIError: The API rejected the request or could not complete it.
 37            NetworkError: The request could not reach the Inttegro API.
 38            TimeoutError: The configured request deadline elapsed.
 39        """
 40        headers = {'Idempotency-Key': idempotency_key} if idempotency_key else {}
 41        return await self.http.post_with_headers('/file_links/create', payload, headers)
 42
 43    async def lookup(self, id: str) -> FileLink:
 44        """Return the file link identified by ``id``.
 45
 46        API endpoint: ``/file_links/lookup``.
 47
 48        Args:
 49            id (str): Unique identifier of the id.
 50
 51        Returns:
 52            ``FileLink`` decoded from the documented response shape.
 53
 54        Raises:
 55            APIError: The API rejected the request or could not complete it.
 56            NetworkError: The request could not reach the Inttegro API.
 57            TimeoutError: The configured request deadline elapsed.
 58        """
 59        return await self.http.post('/file_links/lookup', {'id': id})
 60
 61    async def page(self, payload: PageRequest | None=None) -> Page:
 62        """Return a page of file links for the authenticated application.
 63
 64        API endpoint: ``/file_links/page``.
 65
 66        Args:
 67            payload (PageRequest | None): Typed request object or equivalent request mapping for this operation.
 68
 69        Returns:
 70            ``Page`` decoded from the documented response shape.
 71
 72        Raises:
 73            APIError: The API rejected the request or could not complete it.
 74            NetworkError: The request could not reach the Inttegro API.
 75            TimeoutError: The configured request deadline elapsed.
 76        """
 77        return await self.http.post('/file_links/page', payload or {})
 78
 79    async def revoke(self, payload: RevokeRequest, idempotency_key: str | None=None) -> FileLink:
 80        """Revoke a file link so future attempts cannot use it.
 81
 82        API endpoint: ``/file_links/revoke``.
 83
 84        Args:
 85            payload (RevokeRequest): Typed request object or equivalent request mapping for this operation.
 86            idempotency_key (str | None): Optional stable key to reuse when retrying the same logical write.
 87
 88        Returns:
 89            ``FileLink`` decoded from the documented response shape.
 90
 91        Raises:
 92            APIError: The API rejected the request or could not complete it.
 93            NetworkError: The request could not reach the Inttegro API.
 94            TimeoutError: The configured request deadline elapsed.
 95        """
 96        headers = {'Idempotency-Key': idempotency_key} if idempotency_key else {}
 97        return await self.http.post_with_headers('/file_links/revoke', payload, headers)
 98
 99    async def open(self, url: str, save_to: str | None=None) -> FileDownload:
100        """Download a public file-link ``url`` and optionally save it to ``save_to``.
101
102        Args:
103            url (str): Inttegro-issued public URL; credentials are not attached to this request.
104            save_to (str | None): Optional local path where the downloaded bytes are written.
105
106        Returns:
107            ``FileDownload`` decoded from the documented response shape.
108        """
109        (data, headers) = await self.http.get_binary_public(url)
110        download = FileDownload(data, headers)
111        if save_to:
112            download.save_to(save_to)
113        return download