inttegro.resources.file_links

Generated public typing surface. Do not edit by hand.

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