# Code generated by openapi-nexus. DO NOT EDIT.
#
# Multi Status API — 1.0.0
"""HTTP client wrapping httpx."""
from __future__ import annotations
from typing import Any
import httpx
from .auth import Authenticator
class Client:
"""Synchronous HTTP client for the generated SDK."""
def __init__(
self,
base_url: str,
*,
http_client: httpx.Client | None = None,
authenticator: Authenticator | None = None,
) -> None:
self._base_url = base_url.rstrip("/")
self._http_client = http_client or httpx.Client()
self._authenticator = authenticator
def request(
self,
method: str,
path: str,
*,
params: dict[str, str] | None = None,
json: Any = None,
headers: dict[str, str] | None = None,
) -> httpx.Response:
"""Send an HTTP request and return the raw response."""
url = f"{self._base_url}{path}"
req_headers: dict[str, str] = {"Accept": "application/json"}
if json is not None:
req_headers["Content-Type"] = "application/json"
if headers:
req_headers.update(headers)
if self._authenticator is not None:
req_headers.update(self._authenticator.auth_headers())
return self._http_client.request(
method,
url,
params=params,
json=json,
headers=req_headers,
)
def close(self) -> None:
"""Close the underlying HTTP client."""
self._http_client.close()
def __enter__(self) -> Client:
return self
def __exit__(self, *args: object) -> None:
self.close()