From b2c0717cfe0c2bb898ccd3866ccdff9abf6b7d70 Mon Sep 17 00:00:00 2001 From: Ihar Hrachyshka Date: Sun, 2 Jun 2024 14:09:55 -0400 Subject: [PATCH] Embed letsrolld-client for python into the repo Closes #81 Closes #44 Closes #76 Closes #86 --- Makefile | 5 +- letsrolld-api-client/.gitignore | 23 ++ letsrolld-api-client/README.md | 124 ++++++++ .../letsrolld_api_client/__init__.py | 8 + .../letsrolld_api_client/api/__init__.py | 1 + .../api/default/__init__.py | 0 .../api/default/get_directors.py | 165 +++++++++++ .../api/default/get_directors_id.py | 146 ++++++++++ .../api/default/get_films.py | 210 ++++++++++++++ .../api/default/get_films_id.py | 146 ++++++++++ .../letsrolld_api_client/client.py | 268 ++++++++++++++++++ .../letsrolld_api_client/errors.py | 16 ++ .../letsrolld_api_client/models/__init__.py | 45 +++ .../models/array_of_directors_item.py | 87 ++++++ .../array_of_directors_item_films_item.py | 258 +++++++++++++++++ ...irectors_item_films_item_countries_item.py | 80 ++++++ ...irectors_item_films_item_directors_item.py | 77 +++++ ...f_directors_item_films_item_offers_item.py | 72 +++++ .../models/array_of_directors_item_info.py | 77 +++++ .../models/array_of_films_item.py | 254 +++++++++++++++++ .../array_of_films_item_countries_item.py | 80 ++++++ .../array_of_films_item_directors_item.py | 77 +++++ .../models/array_of_films_item_offers_item.py | 72 +++++ .../letsrolld_api_client/models/director.py | 87 ++++++ .../models/director_films_item.py | 254 +++++++++++++++++ .../director_films_item_countries_item.py | 80 ++++++ .../director_films_item_directors_item.py | 77 +++++ .../models/director_films_item_offers_item.py | 72 +++++ .../models/director_info.py | 77 +++++ .../letsrolld_api_client/models/film.py | 254 +++++++++++++++++ .../models/film_countries_item.py | 80 ++++++ .../models/film_directors_item.py | 77 +++++ .../models/film_offers_item.py | 72 +++++ .../letsrolld_api_client/py.typed | 1 + .../letsrolld_api_client/types.py | 45 +++ letsrolld-api-client/pyproject.toml | 27 ++ pdm.lock | 5 +- pyproject.toml | 2 +- sanity-check.sh | 18 +- .../webcli/templates/director.template | 2 +- 40 files changed, 3513 insertions(+), 8 deletions(-) create mode 100644 letsrolld-api-client/.gitignore create mode 100644 letsrolld-api-client/README.md create mode 100644 letsrolld-api-client/letsrolld_api_client/__init__.py create mode 100644 letsrolld-api-client/letsrolld_api_client/api/__init__.py create mode 100644 letsrolld-api-client/letsrolld_api_client/api/default/__init__.py create mode 100644 letsrolld-api-client/letsrolld_api_client/api/default/get_directors.py create mode 100644 letsrolld-api-client/letsrolld_api_client/api/default/get_directors_id.py create mode 100644 letsrolld-api-client/letsrolld_api_client/api/default/get_films.py create mode 100644 letsrolld-api-client/letsrolld_api_client/api/default/get_films_id.py create mode 100644 letsrolld-api-client/letsrolld_api_client/client.py create mode 100644 letsrolld-api-client/letsrolld_api_client/errors.py create mode 100644 letsrolld-api-client/letsrolld_api_client/models/__init__.py create mode 100644 letsrolld-api-client/letsrolld_api_client/models/array_of_directors_item.py create mode 100644 letsrolld-api-client/letsrolld_api_client/models/array_of_directors_item_films_item.py create mode 100644 letsrolld-api-client/letsrolld_api_client/models/array_of_directors_item_films_item_countries_item.py create mode 100644 letsrolld-api-client/letsrolld_api_client/models/array_of_directors_item_films_item_directors_item.py create mode 100644 letsrolld-api-client/letsrolld_api_client/models/array_of_directors_item_films_item_offers_item.py create mode 100644 letsrolld-api-client/letsrolld_api_client/models/array_of_directors_item_info.py create mode 100644 letsrolld-api-client/letsrolld_api_client/models/array_of_films_item.py create mode 100644 letsrolld-api-client/letsrolld_api_client/models/array_of_films_item_countries_item.py create mode 100644 letsrolld-api-client/letsrolld_api_client/models/array_of_films_item_directors_item.py create mode 100644 letsrolld-api-client/letsrolld_api_client/models/array_of_films_item_offers_item.py create mode 100644 letsrolld-api-client/letsrolld_api_client/models/director.py create mode 100644 letsrolld-api-client/letsrolld_api_client/models/director_films_item.py create mode 100644 letsrolld-api-client/letsrolld_api_client/models/director_films_item_countries_item.py create mode 100644 letsrolld-api-client/letsrolld_api_client/models/director_films_item_directors_item.py create mode 100644 letsrolld-api-client/letsrolld_api_client/models/director_films_item_offers_item.py create mode 100644 letsrolld-api-client/letsrolld_api_client/models/director_info.py create mode 100644 letsrolld-api-client/letsrolld_api_client/models/film.py create mode 100644 letsrolld-api-client/letsrolld_api_client/models/film_countries_item.py create mode 100644 letsrolld-api-client/letsrolld_api_client/models/film_directors_item.py create mode 100644 letsrolld-api-client/letsrolld_api_client/models/film_offers_item.py create mode 100644 letsrolld-api-client/letsrolld_api_client/py.typed create mode 100644 letsrolld-api-client/letsrolld_api_client/types.py create mode 100644 letsrolld-api-client/pyproject.toml diff --git a/Makefile b/Makefile index fd41d94..bdbc8b5 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ DIRECTORS_FILE?=directors.csv RUN_LOG?=run.log RUN_LOG_CMD?=ts | tee -a $(RUN_LOG) -.PHONY: install lint test populate run-update-directors run-update-films run-update-offers run-cleanup run-all run-db-upgrade webapp ui swagger get-dirs get-films +.PHONY: install lint test populate run-update-directors run-update-films run-update-offers run-cleanup run-all run-db-upgrade webapp ui swagger swagger_py get-dirs get-films install: pdm install -v @@ -44,6 +44,9 @@ swagger: pdm run swagger > swagger.json openapi-generator-cli validate -i swagger.json +swagger_py: swagger + pdm run openapi-python-client generate --path swagger.json + ui: cd ui && http-server --port 8081 -c-1 -o diff --git a/letsrolld-api-client/.gitignore b/letsrolld-api-client/.gitignore new file mode 100644 index 0000000..79a2c3d --- /dev/null +++ b/letsrolld-api-client/.gitignore @@ -0,0 +1,23 @@ +__pycache__/ +build/ +dist/ +*.egg-info/ +.pytest_cache/ + +# pyenv +.python-version + +# Environments +.env +.venv + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# JetBrains +.idea/ + +/coverage.xml +/.coverage diff --git a/letsrolld-api-client/README.md b/letsrolld-api-client/README.md new file mode 100644 index 0000000..10b2ce5 --- /dev/null +++ b/letsrolld-api-client/README.md @@ -0,0 +1,124 @@ +# letsrolld-api-client +A client library for accessing letsrolld API + +## Usage +First, create a client: + +```python +from letsrolld_api_client import Client + +client = Client(base_url="https://api.example.com") +``` + +If the endpoints you're going to hit require authentication, use `AuthenticatedClient` instead: + +```python +from letsrolld_api_client import AuthenticatedClient + +client = AuthenticatedClient(base_url="https://api.example.com", token="SuperSecretToken") +``` + +Now call your endpoint and use your models: + +```python +from letsrolld_api_client.models import MyDataModel +from letsrolld_api_client.api.my_tag import get_my_data_model +from letsrolld_api_client.types import Response + +with client as client: + my_data: MyDataModel = get_my_data_model.sync(client=client) + # or if you need more info (e.g. status_code) + response: Response[MyDataModel] = get_my_data_model.sync_detailed(client=client) +``` + +Or do the same thing with an async version: + +```python +from letsrolld_api_client.models import MyDataModel +from letsrolld_api_client.api.my_tag import get_my_data_model +from letsrolld_api_client.types import Response + +async with client as client: + my_data: MyDataModel = await get_my_data_model.asyncio(client=client) + response: Response[MyDataModel] = await get_my_data_model.asyncio_detailed(client=client) +``` + +By default, when you're calling an HTTPS API it will attempt to verify that SSL is working correctly. Using certificate verification is highly recommended most of the time, but sometimes you may need to authenticate to a server (especially an internal server) using a custom certificate bundle. + +```python +client = AuthenticatedClient( + base_url="https://internal_api.example.com", + token="SuperSecretToken", + verify_ssl="/path/to/certificate_bundle.pem", +) +``` + +You can also disable certificate validation altogether, but beware that **this is a security risk**. + +```python +client = AuthenticatedClient( + base_url="https://internal_api.example.com", + token="SuperSecretToken", + verify_ssl=False +) +``` + +Things to know: +1. Every path/method combo becomes a Python module with four functions: + 1. `sync`: Blocking request that returns parsed data (if successful) or `None` + 1. `sync_detailed`: Blocking request that always returns a `Request`, optionally with `parsed` set if the request was successful. + 1. `asyncio`: Like `sync` but async instead of blocking + 1. `asyncio_detailed`: Like `sync_detailed` but async instead of blocking + +1. All path/query params, and bodies become method arguments. +1. If your endpoint had any tags on it, the first tag will be used as a module name for the function (my_tag above) +1. Any endpoint which did not have a tag will be in `letsrolld_api_client.api.default` + +## Advanced customizations + +There are more settings on the generated `Client` class which let you control more runtime behavior, check out the docstring on that class for more info. You can also customize the underlying `httpx.Client` or `httpx.AsyncClient` (depending on your use-case): + +```python +from letsrolld_api_client import Client + +def log_request(request): + print(f"Request event hook: {request.method} {request.url} - Waiting for response") + +def log_response(response): + request = response.request + print(f"Response event hook: {request.method} {request.url} - Status {response.status_code}") + +client = Client( + base_url="https://api.example.com", + httpx_args={"event_hooks": {"request": [log_request], "response": [log_response]}}, +) + +# Or get the underlying httpx client to modify directly with client.get_httpx_client() or client.get_async_httpx_client() +``` + +You can even set the httpx client directly, but beware that this will override any existing settings (e.g., base_url): + +```python +import httpx +from letsrolld_api_client import Client + +client = Client( + base_url="https://api.example.com", +) +# Note that base_url needs to be re-set, as would any shared cookies, headers, etc. +client.set_httpx_client(httpx.Client(base_url="https://api.example.com", proxies="http://localhost:8030")) +``` + +## Building / publishing this package +This project uses [Poetry](https://python-poetry.org/) to manage dependencies and packaging. Here are the basics: +1. Update the metadata in pyproject.toml (e.g. authors, version) +1. If you're using a private repository, configure it with Poetry + 1. `poetry config repositories. ` + 1. `poetry config http-basic. ` +1. Publish the client with `poetry publish --build -r ` or, if for public PyPI, just `poetry publish --build` + +If you want to install this client into another project without publishing it (e.g. for development) then: +1. If that project **is using Poetry**, you can simply do `poetry add ` from that project +1. If that project is not using Poetry: + 1. Build a wheel with `poetry build -f wheel` + 1. Install that wheel from the other project `pip install ` diff --git a/letsrolld-api-client/letsrolld_api_client/__init__.py b/letsrolld-api-client/letsrolld_api_client/__init__.py new file mode 100644 index 0000000..20aa79a --- /dev/null +++ b/letsrolld-api-client/letsrolld_api_client/__init__.py @@ -0,0 +1,8 @@ +"""A client library for accessing letsrolld API""" + +from .client import AuthenticatedClient, Client + +__all__ = ( + "AuthenticatedClient", + "Client", +) diff --git a/letsrolld-api-client/letsrolld_api_client/api/__init__.py b/letsrolld-api-client/letsrolld_api_client/api/__init__.py new file mode 100644 index 0000000..81f9fa2 --- /dev/null +++ b/letsrolld-api-client/letsrolld_api_client/api/__init__.py @@ -0,0 +1 @@ +"""Contains methods for accessing the API""" diff --git a/letsrolld-api-client/letsrolld_api_client/api/default/__init__.py b/letsrolld-api-client/letsrolld_api_client/api/default/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/letsrolld-api-client/letsrolld_api_client/api/default/get_directors.py b/letsrolld-api-client/letsrolld_api_client/api/default/get_directors.py new file mode 100644 index 0000000..2c6a033 --- /dev/null +++ b/letsrolld-api-client/letsrolld_api_client/api/default/get_directors.py @@ -0,0 +1,165 @@ +from http import HTTPStatus +from typing import Any, Dict, List, Optional, Union + +import httpx + +from ... import errors +from ...client import AuthenticatedClient, Client +from ...models.array_of_directors_item import ArrayOfDirectorsItem +from ...types import UNSET, Response, Unset + + +def _get_kwargs( + *, + limit: Union[Unset, int] = 10, +) -> Dict[str, Any]: + params: Dict[str, Any] = {} + + params["limit"] = limit + + params = {k: v for k, v in params.items() if v is not UNSET and v is not None} + + _kwargs: Dict[str, Any] = { + "method": "get", + "url": "/directors", + "params": params, + } + + return _kwargs + + +def _parse_response( + *, client: Union[AuthenticatedClient, Client], response: httpx.Response +) -> Optional[List["ArrayOfDirectorsItem"]]: + if response.status_code == HTTPStatus.OK: + response_200 = [] + _response_200 = response.json() + for componentsschemas_array_of_directors_item_data in _response_200: + componentsschemas_array_of_directors_item = ArrayOfDirectorsItem.from_dict( + componentsschemas_array_of_directors_item_data + ) + + response_200.append(componentsschemas_array_of_directors_item) + + return response_200 + if client.raise_on_unexpected_status: + raise errors.UnexpectedStatus(response.status_code, response.content) + else: + return None + + +def _build_response( + *, client: Union[AuthenticatedClient, Client], response: httpx.Response +) -> Response[List["ArrayOfDirectorsItem"]]: + return Response( + status_code=HTTPStatus(response.status_code), + content=response.content, + headers=response.headers, + parsed=_parse_response(client=client, response=response), + ) + + +def sync_detailed( + *, + client: Union[AuthenticatedClient, Client], + limit: Union[Unset, int] = 10, +) -> Response[List["ArrayOfDirectorsItem"]]: + """Get Directors + + Args: + limit (Union[Unset, int]): Default: 10. + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[List['ArrayOfDirectorsItem']] + """ + + kwargs = _get_kwargs( + limit=limit, + ) + + response = client.get_httpx_client().request( + **kwargs, + ) + + return _build_response(client=client, response=response) + + +def sync( + *, + client: Union[AuthenticatedClient, Client], + limit: Union[Unset, int] = 10, +) -> Optional[List["ArrayOfDirectorsItem"]]: + """Get Directors + + Args: + limit (Union[Unset, int]): Default: 10. + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + List['ArrayOfDirectorsItem'] + """ + + return sync_detailed( + client=client, + limit=limit, + ).parsed + + +async def asyncio_detailed( + *, + client: Union[AuthenticatedClient, Client], + limit: Union[Unset, int] = 10, +) -> Response[List["ArrayOfDirectorsItem"]]: + """Get Directors + + Args: + limit (Union[Unset, int]): Default: 10. + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[List['ArrayOfDirectorsItem']] + """ + + kwargs = _get_kwargs( + limit=limit, + ) + + response = await client.get_async_httpx_client().request(**kwargs) + + return _build_response(client=client, response=response) + + +async def asyncio( + *, + client: Union[AuthenticatedClient, Client], + limit: Union[Unset, int] = 10, +) -> Optional[List["ArrayOfDirectorsItem"]]: + """Get Directors + + Args: + limit (Union[Unset, int]): Default: 10. + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + List['ArrayOfDirectorsItem'] + """ + + return ( + await asyncio_detailed( + client=client, + limit=limit, + ) + ).parsed diff --git a/letsrolld-api-client/letsrolld_api_client/api/default/get_directors_id.py b/letsrolld-api-client/letsrolld_api_client/api/default/get_directors_id.py new file mode 100644 index 0000000..2930b04 --- /dev/null +++ b/letsrolld-api-client/letsrolld_api_client/api/default/get_directors_id.py @@ -0,0 +1,146 @@ +from http import HTTPStatus +from typing import Any, Dict, Optional, Union + +import httpx + +from ... import errors +from ...client import AuthenticatedClient, Client +from ...models.director import Director +from ...types import Response + + +def _get_kwargs( + id: int, +) -> Dict[str, Any]: + _kwargs: Dict[str, Any] = { + "method": "get", + "url": f"/directors/{id}", + } + + return _kwargs + + +def _parse_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Optional[Director]: + if response.status_code == HTTPStatus.OK: + response_200 = Director.from_dict(response.json()) + + return response_200 + if client.raise_on_unexpected_status: + raise errors.UnexpectedStatus(response.status_code, response.content) + else: + return None + + +def _build_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Response[Director]: + return Response( + status_code=HTTPStatus(response.status_code), + content=response.content, + headers=response.headers, + parsed=_parse_response(client=client, response=response), + ) + + +def sync_detailed( + id: int, + *, + client: Union[AuthenticatedClient, Client], +) -> Response[Director]: + """Get Director + + Args: + id (int): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Director] + """ + + kwargs = _get_kwargs( + id=id, + ) + + response = client.get_httpx_client().request( + **kwargs, + ) + + return _build_response(client=client, response=response) + + +def sync( + id: int, + *, + client: Union[AuthenticatedClient, Client], +) -> Optional[Director]: + """Get Director + + Args: + id (int): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Director + """ + + return sync_detailed( + id=id, + client=client, + ).parsed + + +async def asyncio_detailed( + id: int, + *, + client: Union[AuthenticatedClient, Client], +) -> Response[Director]: + """Get Director + + Args: + id (int): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Director] + """ + + kwargs = _get_kwargs( + id=id, + ) + + response = await client.get_async_httpx_client().request(**kwargs) + + return _build_response(client=client, response=response) + + +async def asyncio( + id: int, + *, + client: Union[AuthenticatedClient, Client], +) -> Optional[Director]: + """Get Director + + Args: + id (int): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Director + """ + + return ( + await asyncio_detailed( + id=id, + client=client, + ) + ).parsed diff --git a/letsrolld-api-client/letsrolld_api_client/api/default/get_films.py b/letsrolld-api-client/letsrolld_api_client/api/default/get_films.py new file mode 100644 index 0000000..484025f --- /dev/null +++ b/letsrolld-api-client/letsrolld_api_client/api/default/get_films.py @@ -0,0 +1,210 @@ +from http import HTTPStatus +from typing import Any, Dict, List, Optional, Union + +import httpx + +from ... import errors +from ...client import AuthenticatedClient, Client +from ...models.array_of_films_item import ArrayOfFilmsItem +from ...types import UNSET, Response, Unset + + +def _get_kwargs( + *, + limit: Union[Unset, int] = 10, + genre: Union[Unset, str] = UNSET, + country: Union[Unset, str] = UNSET, + offer: Union[Unset, str] = UNSET, +) -> Dict[str, Any]: + params: Dict[str, Any] = {} + + params["limit"] = limit + + params["genre"] = genre + + params["country"] = country + + params["offer"] = offer + + params = {k: v for k, v in params.items() if v is not UNSET and v is not None} + + _kwargs: Dict[str, Any] = { + "method": "get", + "url": "/films", + "params": params, + } + + return _kwargs + + +def _parse_response( + *, client: Union[AuthenticatedClient, Client], response: httpx.Response +) -> Optional[List["ArrayOfFilmsItem"]]: + if response.status_code == HTTPStatus.OK: + response_200 = [] + _response_200 = response.json() + for componentsschemas_array_of_films_item_data in _response_200: + componentsschemas_array_of_films_item = ArrayOfFilmsItem.from_dict( + componentsschemas_array_of_films_item_data + ) + + response_200.append(componentsschemas_array_of_films_item) + + return response_200 + if client.raise_on_unexpected_status: + raise errors.UnexpectedStatus(response.status_code, response.content) + else: + return None + + +def _build_response( + *, client: Union[AuthenticatedClient, Client], response: httpx.Response +) -> Response[List["ArrayOfFilmsItem"]]: + return Response( + status_code=HTTPStatus(response.status_code), + content=response.content, + headers=response.headers, + parsed=_parse_response(client=client, response=response), + ) + + +def sync_detailed( + *, + client: Union[AuthenticatedClient, Client], + limit: Union[Unset, int] = 10, + genre: Union[Unset, str] = UNSET, + country: Union[Unset, str] = UNSET, + offer: Union[Unset, str] = UNSET, +) -> Response[List["ArrayOfFilmsItem"]]: + """Get Films + + Args: + limit (Union[Unset, int]): Default: 10. + genre (Union[Unset, str]): + country (Union[Unset, str]): + offer (Union[Unset, str]): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[List['ArrayOfFilmsItem']] + """ + + kwargs = _get_kwargs( + limit=limit, + genre=genre, + country=country, + offer=offer, + ) + + response = client.get_httpx_client().request( + **kwargs, + ) + + return _build_response(client=client, response=response) + + +def sync( + *, + client: Union[AuthenticatedClient, Client], + limit: Union[Unset, int] = 10, + genre: Union[Unset, str] = UNSET, + country: Union[Unset, str] = UNSET, + offer: Union[Unset, str] = UNSET, +) -> Optional[List["ArrayOfFilmsItem"]]: + """Get Films + + Args: + limit (Union[Unset, int]): Default: 10. + genre (Union[Unset, str]): + country (Union[Unset, str]): + offer (Union[Unset, str]): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + List['ArrayOfFilmsItem'] + """ + + return sync_detailed( + client=client, + limit=limit, + genre=genre, + country=country, + offer=offer, + ).parsed + + +async def asyncio_detailed( + *, + client: Union[AuthenticatedClient, Client], + limit: Union[Unset, int] = 10, + genre: Union[Unset, str] = UNSET, + country: Union[Unset, str] = UNSET, + offer: Union[Unset, str] = UNSET, +) -> Response[List["ArrayOfFilmsItem"]]: + """Get Films + + Args: + limit (Union[Unset, int]): Default: 10. + genre (Union[Unset, str]): + country (Union[Unset, str]): + offer (Union[Unset, str]): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[List['ArrayOfFilmsItem']] + """ + + kwargs = _get_kwargs( + limit=limit, + genre=genre, + country=country, + offer=offer, + ) + + response = await client.get_async_httpx_client().request(**kwargs) + + return _build_response(client=client, response=response) + + +async def asyncio( + *, + client: Union[AuthenticatedClient, Client], + limit: Union[Unset, int] = 10, + genre: Union[Unset, str] = UNSET, + country: Union[Unset, str] = UNSET, + offer: Union[Unset, str] = UNSET, +) -> Optional[List["ArrayOfFilmsItem"]]: + """Get Films + + Args: + limit (Union[Unset, int]): Default: 10. + genre (Union[Unset, str]): + country (Union[Unset, str]): + offer (Union[Unset, str]): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + List['ArrayOfFilmsItem'] + """ + + return ( + await asyncio_detailed( + client=client, + limit=limit, + genre=genre, + country=country, + offer=offer, + ) + ).parsed diff --git a/letsrolld-api-client/letsrolld_api_client/api/default/get_films_id.py b/letsrolld-api-client/letsrolld_api_client/api/default/get_films_id.py new file mode 100644 index 0000000..383c679 --- /dev/null +++ b/letsrolld-api-client/letsrolld_api_client/api/default/get_films_id.py @@ -0,0 +1,146 @@ +from http import HTTPStatus +from typing import Any, Dict, Optional, Union + +import httpx + +from ... import errors +from ...client import AuthenticatedClient, Client +from ...models.film import Film +from ...types import Response + + +def _get_kwargs( + id: int, +) -> Dict[str, Any]: + _kwargs: Dict[str, Any] = { + "method": "get", + "url": f"/films/{id}", + } + + return _kwargs + + +def _parse_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Optional[Film]: + if response.status_code == HTTPStatus.OK: + response_200 = Film.from_dict(response.json()) + + return response_200 + if client.raise_on_unexpected_status: + raise errors.UnexpectedStatus(response.status_code, response.content) + else: + return None + + +def _build_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Response[Film]: + return Response( + status_code=HTTPStatus(response.status_code), + content=response.content, + headers=response.headers, + parsed=_parse_response(client=client, response=response), + ) + + +def sync_detailed( + id: int, + *, + client: Union[AuthenticatedClient, Client], +) -> Response[Film]: + """Get Film + + Args: + id (int): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Film] + """ + + kwargs = _get_kwargs( + id=id, + ) + + response = client.get_httpx_client().request( + **kwargs, + ) + + return _build_response(client=client, response=response) + + +def sync( + id: int, + *, + client: Union[AuthenticatedClient, Client], +) -> Optional[Film]: + """Get Film + + Args: + id (int): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Film + """ + + return sync_detailed( + id=id, + client=client, + ).parsed + + +async def asyncio_detailed( + id: int, + *, + client: Union[AuthenticatedClient, Client], +) -> Response[Film]: + """Get Film + + Args: + id (int): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Film] + """ + + kwargs = _get_kwargs( + id=id, + ) + + response = await client.get_async_httpx_client().request(**kwargs) + + return _build_response(client=client, response=response) + + +async def asyncio( + id: int, + *, + client: Union[AuthenticatedClient, Client], +) -> Optional[Film]: + """Get Film + + Args: + id (int): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Film + """ + + return ( + await asyncio_detailed( + id=id, + client=client, + ) + ).parsed diff --git a/letsrolld-api-client/letsrolld_api_client/client.py b/letsrolld-api-client/letsrolld_api_client/client.py new file mode 100644 index 0000000..63a2493 --- /dev/null +++ b/letsrolld-api-client/letsrolld_api_client/client.py @@ -0,0 +1,268 @@ +import ssl +from typing import Any, Dict, Optional, Union + +import httpx +from attrs import define, evolve, field + + +@define +class Client: + """A class for keeping track of data related to the API + + The following are accepted as keyword arguments and will be used to construct httpx Clients internally: + + ``base_url``: The base URL for the API, all requests are made to a relative path to this URL + + ``cookies``: A dictionary of cookies to be sent with every request + + ``headers``: A dictionary of headers to be sent with every request + + ``timeout``: The maximum amount of a time a request can take. API functions will raise + httpx.TimeoutException if this is exceeded. + + ``verify_ssl``: Whether or not to verify the SSL certificate of the API server. This should be True in production, + but can be set to False for testing purposes. + + ``follow_redirects``: Whether or not to follow redirects. Default value is False. + + ``httpx_args``: A dictionary of additional arguments to be passed to the ``httpx.Client`` and ``httpx.AsyncClient`` constructor. + + + Attributes: + raise_on_unexpected_status: Whether or not to raise an errors.UnexpectedStatus if the API returns a + status code that was not documented in the source OpenAPI document. Can also be provided as a keyword + argument to the constructor. + """ + + raise_on_unexpected_status: bool = field(default=False, kw_only=True) + _base_url: str = field(alias="base_url") + _cookies: Dict[str, str] = field(factory=dict, kw_only=True, alias="cookies") + _headers: Dict[str, str] = field(factory=dict, kw_only=True, alias="headers") + _timeout: Optional[httpx.Timeout] = field(default=None, kw_only=True, alias="timeout") + _verify_ssl: Union[str, bool, ssl.SSLContext] = field(default=True, kw_only=True, alias="verify_ssl") + _follow_redirects: bool = field(default=False, kw_only=True, alias="follow_redirects") + _httpx_args: Dict[str, Any] = field(factory=dict, kw_only=True, alias="httpx_args") + _client: Optional[httpx.Client] = field(default=None, init=False) + _async_client: Optional[httpx.AsyncClient] = field(default=None, init=False) + + def with_headers(self, headers: Dict[str, str]) -> "Client": + """Get a new client matching this one with additional headers""" + if self._client is not None: + self._client.headers.update(headers) + if self._async_client is not None: + self._async_client.headers.update(headers) + return evolve(self, headers={**self._headers, **headers}) + + def with_cookies(self, cookies: Dict[str, str]) -> "Client": + """Get a new client matching this one with additional cookies""" + if self._client is not None: + self._client.cookies.update(cookies) + if self._async_client is not None: + self._async_client.cookies.update(cookies) + return evolve(self, cookies={**self._cookies, **cookies}) + + def with_timeout(self, timeout: httpx.Timeout) -> "Client": + """Get a new client matching this one with a new timeout (in seconds)""" + if self._client is not None: + self._client.timeout = timeout + if self._async_client is not None: + self._async_client.timeout = timeout + return evolve(self, timeout=timeout) + + def set_httpx_client(self, client: httpx.Client) -> "Client": + """Manually the underlying httpx.Client + + **NOTE**: This will override any other settings on the client, including cookies, headers, and timeout. + """ + self._client = client + return self + + def get_httpx_client(self) -> httpx.Client: + """Get the underlying httpx.Client, constructing a new one if not previously set""" + if self._client is None: + self._client = httpx.Client( + base_url=self._base_url, + cookies=self._cookies, + headers=self._headers, + timeout=self._timeout, + verify=self._verify_ssl, + follow_redirects=self._follow_redirects, + **self._httpx_args, + ) + return self._client + + def __enter__(self) -> "Client": + """Enter a context manager for self.client—you cannot enter twice (see httpx docs)""" + self.get_httpx_client().__enter__() + return self + + def __exit__(self, *args: Any, **kwargs: Any) -> None: + """Exit a context manager for internal httpx.Client (see httpx docs)""" + self.get_httpx_client().__exit__(*args, **kwargs) + + def set_async_httpx_client(self, async_client: httpx.AsyncClient) -> "Client": + """Manually the underlying httpx.AsyncClient + + **NOTE**: This will override any other settings on the client, including cookies, headers, and timeout. + """ + self._async_client = async_client + return self + + def get_async_httpx_client(self) -> httpx.AsyncClient: + """Get the underlying httpx.AsyncClient, constructing a new one if not previously set""" + if self._async_client is None: + self._async_client = httpx.AsyncClient( + base_url=self._base_url, + cookies=self._cookies, + headers=self._headers, + timeout=self._timeout, + verify=self._verify_ssl, + follow_redirects=self._follow_redirects, + **self._httpx_args, + ) + return self._async_client + + async def __aenter__(self) -> "Client": + """Enter a context manager for underlying httpx.AsyncClient—you cannot enter twice (see httpx docs)""" + await self.get_async_httpx_client().__aenter__() + return self + + async def __aexit__(self, *args: Any, **kwargs: Any) -> None: + """Exit a context manager for underlying httpx.AsyncClient (see httpx docs)""" + await self.get_async_httpx_client().__aexit__(*args, **kwargs) + + +@define +class AuthenticatedClient: + """A Client which has been authenticated for use on secured endpoints + + The following are accepted as keyword arguments and will be used to construct httpx Clients internally: + + ``base_url``: The base URL for the API, all requests are made to a relative path to this URL + + ``cookies``: A dictionary of cookies to be sent with every request + + ``headers``: A dictionary of headers to be sent with every request + + ``timeout``: The maximum amount of a time a request can take. API functions will raise + httpx.TimeoutException if this is exceeded. + + ``verify_ssl``: Whether or not to verify the SSL certificate of the API server. This should be True in production, + but can be set to False for testing purposes. + + ``follow_redirects``: Whether or not to follow redirects. Default value is False. + + ``httpx_args``: A dictionary of additional arguments to be passed to the ``httpx.Client`` and ``httpx.AsyncClient`` constructor. + + + Attributes: + raise_on_unexpected_status: Whether or not to raise an errors.UnexpectedStatus if the API returns a + status code that was not documented in the source OpenAPI document. Can also be provided as a keyword + argument to the constructor. + token: The token to use for authentication + prefix: The prefix to use for the Authorization header + auth_header_name: The name of the Authorization header + """ + + raise_on_unexpected_status: bool = field(default=False, kw_only=True) + _base_url: str = field(alias="base_url") + _cookies: Dict[str, str] = field(factory=dict, kw_only=True, alias="cookies") + _headers: Dict[str, str] = field(factory=dict, kw_only=True, alias="headers") + _timeout: Optional[httpx.Timeout] = field(default=None, kw_only=True, alias="timeout") + _verify_ssl: Union[str, bool, ssl.SSLContext] = field(default=True, kw_only=True, alias="verify_ssl") + _follow_redirects: bool = field(default=False, kw_only=True, alias="follow_redirects") + _httpx_args: Dict[str, Any] = field(factory=dict, kw_only=True, alias="httpx_args") + _client: Optional[httpx.Client] = field(default=None, init=False) + _async_client: Optional[httpx.AsyncClient] = field(default=None, init=False) + + token: str + prefix: str = "Bearer" + auth_header_name: str = "Authorization" + + def with_headers(self, headers: Dict[str, str]) -> "AuthenticatedClient": + """Get a new client matching this one with additional headers""" + if self._client is not None: + self._client.headers.update(headers) + if self._async_client is not None: + self._async_client.headers.update(headers) + return evolve(self, headers={**self._headers, **headers}) + + def with_cookies(self, cookies: Dict[str, str]) -> "AuthenticatedClient": + """Get a new client matching this one with additional cookies""" + if self._client is not None: + self._client.cookies.update(cookies) + if self._async_client is not None: + self._async_client.cookies.update(cookies) + return evolve(self, cookies={**self._cookies, **cookies}) + + def with_timeout(self, timeout: httpx.Timeout) -> "AuthenticatedClient": + """Get a new client matching this one with a new timeout (in seconds)""" + if self._client is not None: + self._client.timeout = timeout + if self._async_client is not None: + self._async_client.timeout = timeout + return evolve(self, timeout=timeout) + + def set_httpx_client(self, client: httpx.Client) -> "AuthenticatedClient": + """Manually the underlying httpx.Client + + **NOTE**: This will override any other settings on the client, including cookies, headers, and timeout. + """ + self._client = client + return self + + def get_httpx_client(self) -> httpx.Client: + """Get the underlying httpx.Client, constructing a new one if not previously set""" + if self._client is None: + self._headers[self.auth_header_name] = f"{self.prefix} {self.token}" if self.prefix else self.token + self._client = httpx.Client( + base_url=self._base_url, + cookies=self._cookies, + headers=self._headers, + timeout=self._timeout, + verify=self._verify_ssl, + follow_redirects=self._follow_redirects, + **self._httpx_args, + ) + return self._client + + def __enter__(self) -> "AuthenticatedClient": + """Enter a context manager for self.client—you cannot enter twice (see httpx docs)""" + self.get_httpx_client().__enter__() + return self + + def __exit__(self, *args: Any, **kwargs: Any) -> None: + """Exit a context manager for internal httpx.Client (see httpx docs)""" + self.get_httpx_client().__exit__(*args, **kwargs) + + def set_async_httpx_client(self, async_client: httpx.AsyncClient) -> "AuthenticatedClient": + """Manually the underlying httpx.AsyncClient + + **NOTE**: This will override any other settings on the client, including cookies, headers, and timeout. + """ + self._async_client = async_client + return self + + def get_async_httpx_client(self) -> httpx.AsyncClient: + """Get the underlying httpx.AsyncClient, constructing a new one if not previously set""" + if self._async_client is None: + self._headers[self.auth_header_name] = f"{self.prefix} {self.token}" if self.prefix else self.token + self._async_client = httpx.AsyncClient( + base_url=self._base_url, + cookies=self._cookies, + headers=self._headers, + timeout=self._timeout, + verify=self._verify_ssl, + follow_redirects=self._follow_redirects, + **self._httpx_args, + ) + return self._async_client + + async def __aenter__(self) -> "AuthenticatedClient": + """Enter a context manager for underlying httpx.AsyncClient—you cannot enter twice (see httpx docs)""" + await self.get_async_httpx_client().__aenter__() + return self + + async def __aexit__(self, *args: Any, **kwargs: Any) -> None: + """Exit a context manager for underlying httpx.AsyncClient (see httpx docs)""" + await self.get_async_httpx_client().__aexit__(*args, **kwargs) diff --git a/letsrolld-api-client/letsrolld_api_client/errors.py b/letsrolld-api-client/letsrolld_api_client/errors.py new file mode 100644 index 0000000..5f92e76 --- /dev/null +++ b/letsrolld-api-client/letsrolld_api_client/errors.py @@ -0,0 +1,16 @@ +"""Contains shared errors types that can be raised from API functions""" + + +class UnexpectedStatus(Exception): + """Raised by api functions when the response status an undocumented status and Client.raise_on_unexpected_status is True""" + + def __init__(self, status_code: int, content: bytes): + self.status_code = status_code + self.content = content + + super().__init__( + f"Unexpected status code: {status_code}\n\nResponse content:\n{content.decode(errors='ignore')}" + ) + + +__all__ = ["UnexpectedStatus"] diff --git a/letsrolld-api-client/letsrolld_api_client/models/__init__.py b/letsrolld-api-client/letsrolld_api_client/models/__init__.py new file mode 100644 index 0000000..c8a6bdd --- /dev/null +++ b/letsrolld-api-client/letsrolld_api_client/models/__init__.py @@ -0,0 +1,45 @@ +"""Contains all the data models used in inputs/outputs""" + +from .array_of_directors_item import ArrayOfDirectorsItem +from .array_of_directors_item_films_item import ArrayOfDirectorsItemFilmsItem +from .array_of_directors_item_films_item_countries_item import ArrayOfDirectorsItemFilmsItemCountriesItem +from .array_of_directors_item_films_item_directors_item import ArrayOfDirectorsItemFilmsItemDirectorsItem +from .array_of_directors_item_films_item_offers_item import ArrayOfDirectorsItemFilmsItemOffersItem +from .array_of_directors_item_info import ArrayOfDirectorsItemInfo +from .array_of_films_item import ArrayOfFilmsItem +from .array_of_films_item_countries_item import ArrayOfFilmsItemCountriesItem +from .array_of_films_item_directors_item import ArrayOfFilmsItemDirectorsItem +from .array_of_films_item_offers_item import ArrayOfFilmsItemOffersItem +from .director import Director +from .director_films_item import DirectorFilmsItem +from .director_films_item_countries_item import DirectorFilmsItemCountriesItem +from .director_films_item_directors_item import DirectorFilmsItemDirectorsItem +from .director_films_item_offers_item import DirectorFilmsItemOffersItem +from .director_info import DirectorInfo +from .film import Film +from .film_countries_item import FilmCountriesItem +from .film_directors_item import FilmDirectorsItem +from .film_offers_item import FilmOffersItem + +__all__ = ( + "ArrayOfDirectorsItem", + "ArrayOfDirectorsItemFilmsItem", + "ArrayOfDirectorsItemFilmsItemCountriesItem", + "ArrayOfDirectorsItemFilmsItemDirectorsItem", + "ArrayOfDirectorsItemFilmsItemOffersItem", + "ArrayOfDirectorsItemInfo", + "ArrayOfFilmsItem", + "ArrayOfFilmsItemCountriesItem", + "ArrayOfFilmsItemDirectorsItem", + "ArrayOfFilmsItemOffersItem", + "Director", + "DirectorFilmsItem", + "DirectorFilmsItemCountriesItem", + "DirectorFilmsItemDirectorsItem", + "DirectorFilmsItemOffersItem", + "DirectorInfo", + "Film", + "FilmCountriesItem", + "FilmDirectorsItem", + "FilmOffersItem", +) diff --git a/letsrolld-api-client/letsrolld_api_client/models/array_of_directors_item.py b/letsrolld-api-client/letsrolld_api_client/models/array_of_directors_item.py new file mode 100644 index 0000000..5ad978f --- /dev/null +++ b/letsrolld-api-client/letsrolld_api_client/models/array_of_directors_item.py @@ -0,0 +1,87 @@ +from typing import TYPE_CHECKING, Any, Dict, List, Type, TypeVar, Union + +from attrs import define as _attrs_define +from attrs import field as _attrs_field + +from ..types import UNSET, Unset + +if TYPE_CHECKING: + from ..models.array_of_directors_item_films_item import ArrayOfDirectorsItemFilmsItem + from ..models.array_of_directors_item_info import ArrayOfDirectorsItemInfo + + +T = TypeVar("T", bound="ArrayOfDirectorsItem") + + +@_attrs_define +class ArrayOfDirectorsItem: + """ + Attributes: + info (ArrayOfDirectorsItemInfo): + films (Union[Unset, List['ArrayOfDirectorsItemFilmsItem']]): + """ + + info: "ArrayOfDirectorsItemInfo" + films: Union[Unset, List["ArrayOfDirectorsItemFilmsItem"]] = UNSET + additional_properties: Dict[str, Any] = _attrs_field(init=False, factory=dict) + + def to_dict(self) -> Dict[str, Any]: + info = self.info.to_dict() + + films: Union[Unset, List[Dict[str, Any]]] = UNSET + if not isinstance(self.films, Unset): + films = [] + for films_item_data in self.films: + films_item = films_item_data.to_dict() + films.append(films_item) + + field_dict: Dict[str, Any] = {} + field_dict.update(self.additional_properties) + field_dict.update( + { + "info": info, + } + ) + if films is not UNSET: + field_dict["films"] = films + + return field_dict + + @classmethod + def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: + from ..models.array_of_directors_item_films_item import ArrayOfDirectorsItemFilmsItem + from ..models.array_of_directors_item_info import ArrayOfDirectorsItemInfo + + d = src_dict.copy() + info = ArrayOfDirectorsItemInfo.from_dict(d.pop("info")) + + films = [] + _films = d.pop("films", UNSET) + for films_item_data in _films or []: + films_item = ArrayOfDirectorsItemFilmsItem.from_dict(films_item_data) + + films.append(films_item) + + array_of_directors_item = cls( + info=info, + films=films, + ) + + array_of_directors_item.additional_properties = d + return array_of_directors_item + + @property + def additional_keys(self) -> List[str]: + return list(self.additional_properties.keys()) + + def __getitem__(self, key: str) -> Any: + return self.additional_properties[key] + + def __setitem__(self, key: str, value: Any) -> None: + self.additional_properties[key] = value + + def __delitem__(self, key: str) -> None: + del self.additional_properties[key] + + def __contains__(self, key: str) -> bool: + return key in self.additional_properties diff --git a/letsrolld-api-client/letsrolld_api_client/models/array_of_directors_item_films_item.py b/letsrolld-api-client/letsrolld_api_client/models/array_of_directors_item_films_item.py new file mode 100644 index 0000000..6abb5a5 --- /dev/null +++ b/letsrolld-api-client/letsrolld_api_client/models/array_of_directors_item_films_item.py @@ -0,0 +1,258 @@ +from typing import TYPE_CHECKING, Any, Dict, List, Type, TypeVar, Union, cast + +from attrs import define as _attrs_define +from attrs import field as _attrs_field + +from ..types import UNSET, Unset + +if TYPE_CHECKING: + from ..models.array_of_directors_item_films_item_countries_item import ArrayOfDirectorsItemFilmsItemCountriesItem + from ..models.array_of_directors_item_films_item_directors_item import ArrayOfDirectorsItemFilmsItemDirectorsItem + from ..models.array_of_directors_item_films_item_offers_item import ArrayOfDirectorsItemFilmsItemOffersItem + + +T = TypeVar("T", bound="ArrayOfDirectorsItemFilmsItem") + + +@_attrs_define +class ArrayOfDirectorsItemFilmsItem: + """ + Attributes: + title (str): + id (Union[Unset, int]): + description (Union[Unset, str]): + year (Union[None, Unset, int]): + rating (Union[Unset, str]): + runtime (Union[None, Unset, int]): + lb_url (Union[Unset, str]): + jw_url (Union[None, Unset, str]): + trailer_url (Union[None, Unset, str]): + genres (Union[Unset, List[str]]): + countries (Union[Unset, List['ArrayOfDirectorsItemFilmsItemCountriesItem']]): + offers (Union[Unset, List['ArrayOfDirectorsItemFilmsItemOffersItem']]): + directors (Union[Unset, List['ArrayOfDirectorsItemFilmsItemDirectorsItem']]): + """ + + title: str + id: Union[Unset, int] = UNSET + description: Union[Unset, str] = UNSET + year: Union[None, Unset, int] = UNSET + rating: Union[Unset, str] = UNSET + runtime: Union[None, Unset, int] = UNSET + lb_url: Union[Unset, str] = UNSET + jw_url: Union[None, Unset, str] = UNSET + trailer_url: Union[None, Unset, str] = UNSET + genres: Union[Unset, List[str]] = UNSET + countries: Union[Unset, List["ArrayOfDirectorsItemFilmsItemCountriesItem"]] = UNSET + offers: Union[Unset, List["ArrayOfDirectorsItemFilmsItemOffersItem"]] = UNSET + directors: Union[Unset, List["ArrayOfDirectorsItemFilmsItemDirectorsItem"]] = UNSET + additional_properties: Dict[str, Any] = _attrs_field(init=False, factory=dict) + + def to_dict(self) -> Dict[str, Any]: + title = self.title + + id = self.id + + description = self.description + + year: Union[None, Unset, int] + if isinstance(self.year, Unset): + year = UNSET + else: + year = self.year + + rating = self.rating + + runtime: Union[None, Unset, int] + if isinstance(self.runtime, Unset): + runtime = UNSET + else: + runtime = self.runtime + + lb_url = self.lb_url + + jw_url: Union[None, Unset, str] + if isinstance(self.jw_url, Unset): + jw_url = UNSET + else: + jw_url = self.jw_url + + trailer_url: Union[None, Unset, str] + if isinstance(self.trailer_url, Unset): + trailer_url = UNSET + else: + trailer_url = self.trailer_url + + genres: Union[Unset, List[str]] = UNSET + if not isinstance(self.genres, Unset): + genres = self.genres + + countries: Union[Unset, List[Dict[str, Any]]] = UNSET + if not isinstance(self.countries, Unset): + countries = [] + for countries_item_data in self.countries: + countries_item = countries_item_data.to_dict() + countries.append(countries_item) + + offers: Union[Unset, List[Dict[str, Any]]] = UNSET + if not isinstance(self.offers, Unset): + offers = [] + for offers_item_data in self.offers: + offers_item = offers_item_data.to_dict() + offers.append(offers_item) + + directors: Union[Unset, List[Dict[str, Any]]] = UNSET + if not isinstance(self.directors, Unset): + directors = [] + for directors_item_data in self.directors: + directors_item = directors_item_data.to_dict() + directors.append(directors_item) + + field_dict: Dict[str, Any] = {} + field_dict.update(self.additional_properties) + field_dict.update( + { + "title": title, + } + ) + if id is not UNSET: + field_dict["id"] = id + if description is not UNSET: + field_dict["description"] = description + if year is not UNSET: + field_dict["year"] = year + if rating is not UNSET: + field_dict["rating"] = rating + if runtime is not UNSET: + field_dict["runtime"] = runtime + if lb_url is not UNSET: + field_dict["lb_url"] = lb_url + if jw_url is not UNSET: + field_dict["jw_url"] = jw_url + if trailer_url is not UNSET: + field_dict["trailer_url"] = trailer_url + if genres is not UNSET: + field_dict["genres"] = genres + if countries is not UNSET: + field_dict["countries"] = countries + if offers is not UNSET: + field_dict["offers"] = offers + if directors is not UNSET: + field_dict["directors"] = directors + + return field_dict + + @classmethod + def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: + from ..models.array_of_directors_item_films_item_countries_item import ( + ArrayOfDirectorsItemFilmsItemCountriesItem, + ) + from ..models.array_of_directors_item_films_item_directors_item import ( + ArrayOfDirectorsItemFilmsItemDirectorsItem, + ) + from ..models.array_of_directors_item_films_item_offers_item import ArrayOfDirectorsItemFilmsItemOffersItem + + d = src_dict.copy() + title = d.pop("title") + + id = d.pop("id", UNSET) + + description = d.pop("description", UNSET) + + def _parse_year(data: object) -> Union[None, Unset, int]: + if data is None: + return data + if isinstance(data, Unset): + return data + return cast(Union[None, Unset, int], data) + + year = _parse_year(d.pop("year", UNSET)) + + rating = d.pop("rating", UNSET) + + def _parse_runtime(data: object) -> Union[None, Unset, int]: + if data is None: + return data + if isinstance(data, Unset): + return data + return cast(Union[None, Unset, int], data) + + runtime = _parse_runtime(d.pop("runtime", UNSET)) + + lb_url = d.pop("lb_url", UNSET) + + def _parse_jw_url(data: object) -> Union[None, Unset, str]: + if data is None: + return data + if isinstance(data, Unset): + return data + return cast(Union[None, Unset, str], data) + + jw_url = _parse_jw_url(d.pop("jw_url", UNSET)) + + def _parse_trailer_url(data: object) -> Union[None, Unset, str]: + if data is None: + return data + if isinstance(data, Unset): + return data + return cast(Union[None, Unset, str], data) + + trailer_url = _parse_trailer_url(d.pop("trailer_url", UNSET)) + + genres = cast(List[str], d.pop("genres", UNSET)) + + countries = [] + _countries = d.pop("countries", UNSET) + for countries_item_data in _countries or []: + countries_item = ArrayOfDirectorsItemFilmsItemCountriesItem.from_dict(countries_item_data) + + countries.append(countries_item) + + offers = [] + _offers = d.pop("offers", UNSET) + for offers_item_data in _offers or []: + offers_item = ArrayOfDirectorsItemFilmsItemOffersItem.from_dict(offers_item_data) + + offers.append(offers_item) + + directors = [] + _directors = d.pop("directors", UNSET) + for directors_item_data in _directors or []: + directors_item = ArrayOfDirectorsItemFilmsItemDirectorsItem.from_dict(directors_item_data) + + directors.append(directors_item) + + array_of_directors_item_films_item = cls( + title=title, + id=id, + description=description, + year=year, + rating=rating, + runtime=runtime, + lb_url=lb_url, + jw_url=jw_url, + trailer_url=trailer_url, + genres=genres, + countries=countries, + offers=offers, + directors=directors, + ) + + array_of_directors_item_films_item.additional_properties = d + return array_of_directors_item_films_item + + @property + def additional_keys(self) -> List[str]: + return list(self.additional_properties.keys()) + + def __getitem__(self, key: str) -> Any: + return self.additional_properties[key] + + def __setitem__(self, key: str, value: Any) -> None: + self.additional_properties[key] = value + + def __delitem__(self, key: str) -> None: + del self.additional_properties[key] + + def __contains__(self, key: str) -> bool: + return key in self.additional_properties diff --git a/letsrolld-api-client/letsrolld_api_client/models/array_of_directors_item_films_item_countries_item.py b/letsrolld-api-client/letsrolld_api_client/models/array_of_directors_item_films_item_countries_item.py new file mode 100644 index 0000000..4c195d0 --- /dev/null +++ b/letsrolld-api-client/letsrolld_api_client/models/array_of_directors_item_films_item_countries_item.py @@ -0,0 +1,80 @@ +from typing import Any, Dict, List, Type, TypeVar, Union, cast + +from attrs import define as _attrs_define +from attrs import field as _attrs_field + +from ..types import UNSET, Unset + +T = TypeVar("T", bound="ArrayOfDirectorsItemFilmsItemCountriesItem") + + +@_attrs_define +class ArrayOfDirectorsItemFilmsItemCountriesItem: + """ + Attributes: + name (str): + flag (Union[None, Unset, str]): + """ + + name: str + flag: Union[None, Unset, str] = UNSET + additional_properties: Dict[str, Any] = _attrs_field(init=False, factory=dict) + + def to_dict(self) -> Dict[str, Any]: + name = self.name + + flag: Union[None, Unset, str] + if isinstance(self.flag, Unset): + flag = UNSET + else: + flag = self.flag + + field_dict: Dict[str, Any] = {} + field_dict.update(self.additional_properties) + field_dict.update( + { + "name": name, + } + ) + if flag is not UNSET: + field_dict["flag"] = flag + + return field_dict + + @classmethod + def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: + d = src_dict.copy() + name = d.pop("name") + + def _parse_flag(data: object) -> Union[None, Unset, str]: + if data is None: + return data + if isinstance(data, Unset): + return data + return cast(Union[None, Unset, str], data) + + flag = _parse_flag(d.pop("flag", UNSET)) + + array_of_directors_item_films_item_countries_item = cls( + name=name, + flag=flag, + ) + + array_of_directors_item_films_item_countries_item.additional_properties = d + return array_of_directors_item_films_item_countries_item + + @property + def additional_keys(self) -> List[str]: + return list(self.additional_properties.keys()) + + def __getitem__(self, key: str) -> Any: + return self.additional_properties[key] + + def __setitem__(self, key: str, value: Any) -> None: + self.additional_properties[key] = value + + def __delitem__(self, key: str) -> None: + del self.additional_properties[key] + + def __contains__(self, key: str) -> bool: + return key in self.additional_properties diff --git a/letsrolld-api-client/letsrolld_api_client/models/array_of_directors_item_films_item_directors_item.py b/letsrolld-api-client/letsrolld_api_client/models/array_of_directors_item_films_item_directors_item.py new file mode 100644 index 0000000..0428b34 --- /dev/null +++ b/letsrolld-api-client/letsrolld_api_client/models/array_of_directors_item_films_item_directors_item.py @@ -0,0 +1,77 @@ +from typing import Any, Dict, List, Type, TypeVar, Union + +from attrs import define as _attrs_define +from attrs import field as _attrs_field + +from ..types import UNSET, Unset + +T = TypeVar("T", bound="ArrayOfDirectorsItemFilmsItemDirectorsItem") + + +@_attrs_define +class ArrayOfDirectorsItemFilmsItemDirectorsItem: + """ + Attributes: + id (int): + name (str): + lb_url (Union[Unset, str]): + """ + + id: int + name: str + lb_url: Union[Unset, str] = UNSET + additional_properties: Dict[str, Any] = _attrs_field(init=False, factory=dict) + + def to_dict(self) -> Dict[str, Any]: + id = self.id + + name = self.name + + lb_url = self.lb_url + + field_dict: Dict[str, Any] = {} + field_dict.update(self.additional_properties) + field_dict.update( + { + "id": id, + "name": name, + } + ) + if lb_url is not UNSET: + field_dict["lb_url"] = lb_url + + return field_dict + + @classmethod + def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: + d = src_dict.copy() + id = d.pop("id") + + name = d.pop("name") + + lb_url = d.pop("lb_url", UNSET) + + array_of_directors_item_films_item_directors_item = cls( + id=id, + name=name, + lb_url=lb_url, + ) + + array_of_directors_item_films_item_directors_item.additional_properties = d + return array_of_directors_item_films_item_directors_item + + @property + def additional_keys(self) -> List[str]: + return list(self.additional_properties.keys()) + + def __getitem__(self, key: str) -> Any: + return self.additional_properties[key] + + def __setitem__(self, key: str, value: Any) -> None: + self.additional_properties[key] = value + + def __delitem__(self, key: str) -> None: + del self.additional_properties[key] + + def __contains__(self, key: str) -> bool: + return key in self.additional_properties diff --git a/letsrolld-api-client/letsrolld_api_client/models/array_of_directors_item_films_item_offers_item.py b/letsrolld-api-client/letsrolld_api_client/models/array_of_directors_item_films_item_offers_item.py new file mode 100644 index 0000000..2ee2f92 --- /dev/null +++ b/letsrolld-api-client/letsrolld_api_client/models/array_of_directors_item_films_item_offers_item.py @@ -0,0 +1,72 @@ +from typing import Any, Dict, List, Type, TypeVar, Union, cast + +from attrs import define as _attrs_define +from attrs import field as _attrs_field + +T = TypeVar("T", bound="ArrayOfDirectorsItemFilmsItemOffersItem") + + +@_attrs_define +class ArrayOfDirectorsItemFilmsItemOffersItem: + """ + Attributes: + name (str): + url (Union[None, str]): + """ + + name: str + url: Union[None, str] + additional_properties: Dict[str, Any] = _attrs_field(init=False, factory=dict) + + def to_dict(self) -> Dict[str, Any]: + name = self.name + + url: Union[None, str] + url = self.url + + field_dict: Dict[str, Any] = {} + field_dict.update(self.additional_properties) + field_dict.update( + { + "name": name, + "url": url, + } + ) + + return field_dict + + @classmethod + def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: + d = src_dict.copy() + name = d.pop("name") + + def _parse_url(data: object) -> Union[None, str]: + if data is None: + return data + return cast(Union[None, str], data) + + url = _parse_url(d.pop("url")) + + array_of_directors_item_films_item_offers_item = cls( + name=name, + url=url, + ) + + array_of_directors_item_films_item_offers_item.additional_properties = d + return array_of_directors_item_films_item_offers_item + + @property + def additional_keys(self) -> List[str]: + return list(self.additional_properties.keys()) + + def __getitem__(self, key: str) -> Any: + return self.additional_properties[key] + + def __setitem__(self, key: str, value: Any) -> None: + self.additional_properties[key] = value + + def __delitem__(self, key: str) -> None: + del self.additional_properties[key] + + def __contains__(self, key: str) -> bool: + return key in self.additional_properties diff --git a/letsrolld-api-client/letsrolld_api_client/models/array_of_directors_item_info.py b/letsrolld-api-client/letsrolld_api_client/models/array_of_directors_item_info.py new file mode 100644 index 0000000..b42257e --- /dev/null +++ b/letsrolld-api-client/letsrolld_api_client/models/array_of_directors_item_info.py @@ -0,0 +1,77 @@ +from typing import Any, Dict, List, Type, TypeVar, Union + +from attrs import define as _attrs_define +from attrs import field as _attrs_field + +from ..types import UNSET, Unset + +T = TypeVar("T", bound="ArrayOfDirectorsItemInfo") + + +@_attrs_define +class ArrayOfDirectorsItemInfo: + """ + Attributes: + id (int): + name (str): + lb_url (Union[Unset, str]): + """ + + id: int + name: str + lb_url: Union[Unset, str] = UNSET + additional_properties: Dict[str, Any] = _attrs_field(init=False, factory=dict) + + def to_dict(self) -> Dict[str, Any]: + id = self.id + + name = self.name + + lb_url = self.lb_url + + field_dict: Dict[str, Any] = {} + field_dict.update(self.additional_properties) + field_dict.update( + { + "id": id, + "name": name, + } + ) + if lb_url is not UNSET: + field_dict["lb_url"] = lb_url + + return field_dict + + @classmethod + def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: + d = src_dict.copy() + id = d.pop("id") + + name = d.pop("name") + + lb_url = d.pop("lb_url", UNSET) + + array_of_directors_item_info = cls( + id=id, + name=name, + lb_url=lb_url, + ) + + array_of_directors_item_info.additional_properties = d + return array_of_directors_item_info + + @property + def additional_keys(self) -> List[str]: + return list(self.additional_properties.keys()) + + def __getitem__(self, key: str) -> Any: + return self.additional_properties[key] + + def __setitem__(self, key: str, value: Any) -> None: + self.additional_properties[key] = value + + def __delitem__(self, key: str) -> None: + del self.additional_properties[key] + + def __contains__(self, key: str) -> bool: + return key in self.additional_properties diff --git a/letsrolld-api-client/letsrolld_api_client/models/array_of_films_item.py b/letsrolld-api-client/letsrolld_api_client/models/array_of_films_item.py new file mode 100644 index 0000000..d74e3c7 --- /dev/null +++ b/letsrolld-api-client/letsrolld_api_client/models/array_of_films_item.py @@ -0,0 +1,254 @@ +from typing import TYPE_CHECKING, Any, Dict, List, Type, TypeVar, Union, cast + +from attrs import define as _attrs_define +from attrs import field as _attrs_field + +from ..types import UNSET, Unset + +if TYPE_CHECKING: + from ..models.array_of_films_item_countries_item import ArrayOfFilmsItemCountriesItem + from ..models.array_of_films_item_directors_item import ArrayOfFilmsItemDirectorsItem + from ..models.array_of_films_item_offers_item import ArrayOfFilmsItemOffersItem + + +T = TypeVar("T", bound="ArrayOfFilmsItem") + + +@_attrs_define +class ArrayOfFilmsItem: + """ + Attributes: + title (str): + id (Union[Unset, int]): + description (Union[Unset, str]): + year (Union[None, Unset, int]): + rating (Union[Unset, str]): + runtime (Union[None, Unset, int]): + lb_url (Union[Unset, str]): + jw_url (Union[None, Unset, str]): + trailer_url (Union[None, Unset, str]): + genres (Union[Unset, List[str]]): + countries (Union[Unset, List['ArrayOfFilmsItemCountriesItem']]): + offers (Union[Unset, List['ArrayOfFilmsItemOffersItem']]): + directors (Union[Unset, List['ArrayOfFilmsItemDirectorsItem']]): + """ + + title: str + id: Union[Unset, int] = UNSET + description: Union[Unset, str] = UNSET + year: Union[None, Unset, int] = UNSET + rating: Union[Unset, str] = UNSET + runtime: Union[None, Unset, int] = UNSET + lb_url: Union[Unset, str] = UNSET + jw_url: Union[None, Unset, str] = UNSET + trailer_url: Union[None, Unset, str] = UNSET + genres: Union[Unset, List[str]] = UNSET + countries: Union[Unset, List["ArrayOfFilmsItemCountriesItem"]] = UNSET + offers: Union[Unset, List["ArrayOfFilmsItemOffersItem"]] = UNSET + directors: Union[Unset, List["ArrayOfFilmsItemDirectorsItem"]] = UNSET + additional_properties: Dict[str, Any] = _attrs_field(init=False, factory=dict) + + def to_dict(self) -> Dict[str, Any]: + title = self.title + + id = self.id + + description = self.description + + year: Union[None, Unset, int] + if isinstance(self.year, Unset): + year = UNSET + else: + year = self.year + + rating = self.rating + + runtime: Union[None, Unset, int] + if isinstance(self.runtime, Unset): + runtime = UNSET + else: + runtime = self.runtime + + lb_url = self.lb_url + + jw_url: Union[None, Unset, str] + if isinstance(self.jw_url, Unset): + jw_url = UNSET + else: + jw_url = self.jw_url + + trailer_url: Union[None, Unset, str] + if isinstance(self.trailer_url, Unset): + trailer_url = UNSET + else: + trailer_url = self.trailer_url + + genres: Union[Unset, List[str]] = UNSET + if not isinstance(self.genres, Unset): + genres = self.genres + + countries: Union[Unset, List[Dict[str, Any]]] = UNSET + if not isinstance(self.countries, Unset): + countries = [] + for countries_item_data in self.countries: + countries_item = countries_item_data.to_dict() + countries.append(countries_item) + + offers: Union[Unset, List[Dict[str, Any]]] = UNSET + if not isinstance(self.offers, Unset): + offers = [] + for offers_item_data in self.offers: + offers_item = offers_item_data.to_dict() + offers.append(offers_item) + + directors: Union[Unset, List[Dict[str, Any]]] = UNSET + if not isinstance(self.directors, Unset): + directors = [] + for directors_item_data in self.directors: + directors_item = directors_item_data.to_dict() + directors.append(directors_item) + + field_dict: Dict[str, Any] = {} + field_dict.update(self.additional_properties) + field_dict.update( + { + "title": title, + } + ) + if id is not UNSET: + field_dict["id"] = id + if description is not UNSET: + field_dict["description"] = description + if year is not UNSET: + field_dict["year"] = year + if rating is not UNSET: + field_dict["rating"] = rating + if runtime is not UNSET: + field_dict["runtime"] = runtime + if lb_url is not UNSET: + field_dict["lb_url"] = lb_url + if jw_url is not UNSET: + field_dict["jw_url"] = jw_url + if trailer_url is not UNSET: + field_dict["trailer_url"] = trailer_url + if genres is not UNSET: + field_dict["genres"] = genres + if countries is not UNSET: + field_dict["countries"] = countries + if offers is not UNSET: + field_dict["offers"] = offers + if directors is not UNSET: + field_dict["directors"] = directors + + return field_dict + + @classmethod + def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: + from ..models.array_of_films_item_countries_item import ArrayOfFilmsItemCountriesItem + from ..models.array_of_films_item_directors_item import ArrayOfFilmsItemDirectorsItem + from ..models.array_of_films_item_offers_item import ArrayOfFilmsItemOffersItem + + d = src_dict.copy() + title = d.pop("title") + + id = d.pop("id", UNSET) + + description = d.pop("description", UNSET) + + def _parse_year(data: object) -> Union[None, Unset, int]: + if data is None: + return data + if isinstance(data, Unset): + return data + return cast(Union[None, Unset, int], data) + + year = _parse_year(d.pop("year", UNSET)) + + rating = d.pop("rating", UNSET) + + def _parse_runtime(data: object) -> Union[None, Unset, int]: + if data is None: + return data + if isinstance(data, Unset): + return data + return cast(Union[None, Unset, int], data) + + runtime = _parse_runtime(d.pop("runtime", UNSET)) + + lb_url = d.pop("lb_url", UNSET) + + def _parse_jw_url(data: object) -> Union[None, Unset, str]: + if data is None: + return data + if isinstance(data, Unset): + return data + return cast(Union[None, Unset, str], data) + + jw_url = _parse_jw_url(d.pop("jw_url", UNSET)) + + def _parse_trailer_url(data: object) -> Union[None, Unset, str]: + if data is None: + return data + if isinstance(data, Unset): + return data + return cast(Union[None, Unset, str], data) + + trailer_url = _parse_trailer_url(d.pop("trailer_url", UNSET)) + + genres = cast(List[str], d.pop("genres", UNSET)) + + countries = [] + _countries = d.pop("countries", UNSET) + for countries_item_data in _countries or []: + countries_item = ArrayOfFilmsItemCountriesItem.from_dict(countries_item_data) + + countries.append(countries_item) + + offers = [] + _offers = d.pop("offers", UNSET) + for offers_item_data in _offers or []: + offers_item = ArrayOfFilmsItemOffersItem.from_dict(offers_item_data) + + offers.append(offers_item) + + directors = [] + _directors = d.pop("directors", UNSET) + for directors_item_data in _directors or []: + directors_item = ArrayOfFilmsItemDirectorsItem.from_dict(directors_item_data) + + directors.append(directors_item) + + array_of_films_item = cls( + title=title, + id=id, + description=description, + year=year, + rating=rating, + runtime=runtime, + lb_url=lb_url, + jw_url=jw_url, + trailer_url=trailer_url, + genres=genres, + countries=countries, + offers=offers, + directors=directors, + ) + + array_of_films_item.additional_properties = d + return array_of_films_item + + @property + def additional_keys(self) -> List[str]: + return list(self.additional_properties.keys()) + + def __getitem__(self, key: str) -> Any: + return self.additional_properties[key] + + def __setitem__(self, key: str, value: Any) -> None: + self.additional_properties[key] = value + + def __delitem__(self, key: str) -> None: + del self.additional_properties[key] + + def __contains__(self, key: str) -> bool: + return key in self.additional_properties diff --git a/letsrolld-api-client/letsrolld_api_client/models/array_of_films_item_countries_item.py b/letsrolld-api-client/letsrolld_api_client/models/array_of_films_item_countries_item.py new file mode 100644 index 0000000..bed20d1 --- /dev/null +++ b/letsrolld-api-client/letsrolld_api_client/models/array_of_films_item_countries_item.py @@ -0,0 +1,80 @@ +from typing import Any, Dict, List, Type, TypeVar, Union, cast + +from attrs import define as _attrs_define +from attrs import field as _attrs_field + +from ..types import UNSET, Unset + +T = TypeVar("T", bound="ArrayOfFilmsItemCountriesItem") + + +@_attrs_define +class ArrayOfFilmsItemCountriesItem: + """ + Attributes: + name (str): + flag (Union[None, Unset, str]): + """ + + name: str + flag: Union[None, Unset, str] = UNSET + additional_properties: Dict[str, Any] = _attrs_field(init=False, factory=dict) + + def to_dict(self) -> Dict[str, Any]: + name = self.name + + flag: Union[None, Unset, str] + if isinstance(self.flag, Unset): + flag = UNSET + else: + flag = self.flag + + field_dict: Dict[str, Any] = {} + field_dict.update(self.additional_properties) + field_dict.update( + { + "name": name, + } + ) + if flag is not UNSET: + field_dict["flag"] = flag + + return field_dict + + @classmethod + def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: + d = src_dict.copy() + name = d.pop("name") + + def _parse_flag(data: object) -> Union[None, Unset, str]: + if data is None: + return data + if isinstance(data, Unset): + return data + return cast(Union[None, Unset, str], data) + + flag = _parse_flag(d.pop("flag", UNSET)) + + array_of_films_item_countries_item = cls( + name=name, + flag=flag, + ) + + array_of_films_item_countries_item.additional_properties = d + return array_of_films_item_countries_item + + @property + def additional_keys(self) -> List[str]: + return list(self.additional_properties.keys()) + + def __getitem__(self, key: str) -> Any: + return self.additional_properties[key] + + def __setitem__(self, key: str, value: Any) -> None: + self.additional_properties[key] = value + + def __delitem__(self, key: str) -> None: + del self.additional_properties[key] + + def __contains__(self, key: str) -> bool: + return key in self.additional_properties diff --git a/letsrolld-api-client/letsrolld_api_client/models/array_of_films_item_directors_item.py b/letsrolld-api-client/letsrolld_api_client/models/array_of_films_item_directors_item.py new file mode 100644 index 0000000..2a5c43d --- /dev/null +++ b/letsrolld-api-client/letsrolld_api_client/models/array_of_films_item_directors_item.py @@ -0,0 +1,77 @@ +from typing import Any, Dict, List, Type, TypeVar, Union + +from attrs import define as _attrs_define +from attrs import field as _attrs_field + +from ..types import UNSET, Unset + +T = TypeVar("T", bound="ArrayOfFilmsItemDirectorsItem") + + +@_attrs_define +class ArrayOfFilmsItemDirectorsItem: + """ + Attributes: + id (int): + name (str): + lb_url (Union[Unset, str]): + """ + + id: int + name: str + lb_url: Union[Unset, str] = UNSET + additional_properties: Dict[str, Any] = _attrs_field(init=False, factory=dict) + + def to_dict(self) -> Dict[str, Any]: + id = self.id + + name = self.name + + lb_url = self.lb_url + + field_dict: Dict[str, Any] = {} + field_dict.update(self.additional_properties) + field_dict.update( + { + "id": id, + "name": name, + } + ) + if lb_url is not UNSET: + field_dict["lb_url"] = lb_url + + return field_dict + + @classmethod + def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: + d = src_dict.copy() + id = d.pop("id") + + name = d.pop("name") + + lb_url = d.pop("lb_url", UNSET) + + array_of_films_item_directors_item = cls( + id=id, + name=name, + lb_url=lb_url, + ) + + array_of_films_item_directors_item.additional_properties = d + return array_of_films_item_directors_item + + @property + def additional_keys(self) -> List[str]: + return list(self.additional_properties.keys()) + + def __getitem__(self, key: str) -> Any: + return self.additional_properties[key] + + def __setitem__(self, key: str, value: Any) -> None: + self.additional_properties[key] = value + + def __delitem__(self, key: str) -> None: + del self.additional_properties[key] + + def __contains__(self, key: str) -> bool: + return key in self.additional_properties diff --git a/letsrolld-api-client/letsrolld_api_client/models/array_of_films_item_offers_item.py b/letsrolld-api-client/letsrolld_api_client/models/array_of_films_item_offers_item.py new file mode 100644 index 0000000..36a1692 --- /dev/null +++ b/letsrolld-api-client/letsrolld_api_client/models/array_of_films_item_offers_item.py @@ -0,0 +1,72 @@ +from typing import Any, Dict, List, Type, TypeVar, Union, cast + +from attrs import define as _attrs_define +from attrs import field as _attrs_field + +T = TypeVar("T", bound="ArrayOfFilmsItemOffersItem") + + +@_attrs_define +class ArrayOfFilmsItemOffersItem: + """ + Attributes: + name (str): + url (Union[None, str]): + """ + + name: str + url: Union[None, str] + additional_properties: Dict[str, Any] = _attrs_field(init=False, factory=dict) + + def to_dict(self) -> Dict[str, Any]: + name = self.name + + url: Union[None, str] + url = self.url + + field_dict: Dict[str, Any] = {} + field_dict.update(self.additional_properties) + field_dict.update( + { + "name": name, + "url": url, + } + ) + + return field_dict + + @classmethod + def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: + d = src_dict.copy() + name = d.pop("name") + + def _parse_url(data: object) -> Union[None, str]: + if data is None: + return data + return cast(Union[None, str], data) + + url = _parse_url(d.pop("url")) + + array_of_films_item_offers_item = cls( + name=name, + url=url, + ) + + array_of_films_item_offers_item.additional_properties = d + return array_of_films_item_offers_item + + @property + def additional_keys(self) -> List[str]: + return list(self.additional_properties.keys()) + + def __getitem__(self, key: str) -> Any: + return self.additional_properties[key] + + def __setitem__(self, key: str, value: Any) -> None: + self.additional_properties[key] = value + + def __delitem__(self, key: str) -> None: + del self.additional_properties[key] + + def __contains__(self, key: str) -> bool: + return key in self.additional_properties diff --git a/letsrolld-api-client/letsrolld_api_client/models/director.py b/letsrolld-api-client/letsrolld_api_client/models/director.py new file mode 100644 index 0000000..78aa2ac --- /dev/null +++ b/letsrolld-api-client/letsrolld_api_client/models/director.py @@ -0,0 +1,87 @@ +from typing import TYPE_CHECKING, Any, Dict, List, Type, TypeVar, Union + +from attrs import define as _attrs_define +from attrs import field as _attrs_field + +from ..types import UNSET, Unset + +if TYPE_CHECKING: + from ..models.director_films_item import DirectorFilmsItem + from ..models.director_info import DirectorInfo + + +T = TypeVar("T", bound="Director") + + +@_attrs_define +class Director: + """ + Attributes: + info (DirectorInfo): + films (Union[Unset, List['DirectorFilmsItem']]): + """ + + info: "DirectorInfo" + films: Union[Unset, List["DirectorFilmsItem"]] = UNSET + additional_properties: Dict[str, Any] = _attrs_field(init=False, factory=dict) + + def to_dict(self) -> Dict[str, Any]: + info = self.info.to_dict() + + films: Union[Unset, List[Dict[str, Any]]] = UNSET + if not isinstance(self.films, Unset): + films = [] + for films_item_data in self.films: + films_item = films_item_data.to_dict() + films.append(films_item) + + field_dict: Dict[str, Any] = {} + field_dict.update(self.additional_properties) + field_dict.update( + { + "info": info, + } + ) + if films is not UNSET: + field_dict["films"] = films + + return field_dict + + @classmethod + def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: + from ..models.director_films_item import DirectorFilmsItem + from ..models.director_info import DirectorInfo + + d = src_dict.copy() + info = DirectorInfo.from_dict(d.pop("info")) + + films = [] + _films = d.pop("films", UNSET) + for films_item_data in _films or []: + films_item = DirectorFilmsItem.from_dict(films_item_data) + + films.append(films_item) + + director = cls( + info=info, + films=films, + ) + + director.additional_properties = d + return director + + @property + def additional_keys(self) -> List[str]: + return list(self.additional_properties.keys()) + + def __getitem__(self, key: str) -> Any: + return self.additional_properties[key] + + def __setitem__(self, key: str, value: Any) -> None: + self.additional_properties[key] = value + + def __delitem__(self, key: str) -> None: + del self.additional_properties[key] + + def __contains__(self, key: str) -> bool: + return key in self.additional_properties diff --git a/letsrolld-api-client/letsrolld_api_client/models/director_films_item.py b/letsrolld-api-client/letsrolld_api_client/models/director_films_item.py new file mode 100644 index 0000000..b1a751a --- /dev/null +++ b/letsrolld-api-client/letsrolld_api_client/models/director_films_item.py @@ -0,0 +1,254 @@ +from typing import TYPE_CHECKING, Any, Dict, List, Type, TypeVar, Union, cast + +from attrs import define as _attrs_define +from attrs import field as _attrs_field + +from ..types import UNSET, Unset + +if TYPE_CHECKING: + from ..models.director_films_item_countries_item import DirectorFilmsItemCountriesItem + from ..models.director_films_item_directors_item import DirectorFilmsItemDirectorsItem + from ..models.director_films_item_offers_item import DirectorFilmsItemOffersItem + + +T = TypeVar("T", bound="DirectorFilmsItem") + + +@_attrs_define +class DirectorFilmsItem: + """ + Attributes: + title (str): + id (Union[Unset, int]): + description (Union[Unset, str]): + year (Union[None, Unset, int]): + rating (Union[Unset, str]): + runtime (Union[None, Unset, int]): + lb_url (Union[Unset, str]): + jw_url (Union[None, Unset, str]): + trailer_url (Union[None, Unset, str]): + genres (Union[Unset, List[str]]): + countries (Union[Unset, List['DirectorFilmsItemCountriesItem']]): + offers (Union[Unset, List['DirectorFilmsItemOffersItem']]): + directors (Union[Unset, List['DirectorFilmsItemDirectorsItem']]): + """ + + title: str + id: Union[Unset, int] = UNSET + description: Union[Unset, str] = UNSET + year: Union[None, Unset, int] = UNSET + rating: Union[Unset, str] = UNSET + runtime: Union[None, Unset, int] = UNSET + lb_url: Union[Unset, str] = UNSET + jw_url: Union[None, Unset, str] = UNSET + trailer_url: Union[None, Unset, str] = UNSET + genres: Union[Unset, List[str]] = UNSET + countries: Union[Unset, List["DirectorFilmsItemCountriesItem"]] = UNSET + offers: Union[Unset, List["DirectorFilmsItemOffersItem"]] = UNSET + directors: Union[Unset, List["DirectorFilmsItemDirectorsItem"]] = UNSET + additional_properties: Dict[str, Any] = _attrs_field(init=False, factory=dict) + + def to_dict(self) -> Dict[str, Any]: + title = self.title + + id = self.id + + description = self.description + + year: Union[None, Unset, int] + if isinstance(self.year, Unset): + year = UNSET + else: + year = self.year + + rating = self.rating + + runtime: Union[None, Unset, int] + if isinstance(self.runtime, Unset): + runtime = UNSET + else: + runtime = self.runtime + + lb_url = self.lb_url + + jw_url: Union[None, Unset, str] + if isinstance(self.jw_url, Unset): + jw_url = UNSET + else: + jw_url = self.jw_url + + trailer_url: Union[None, Unset, str] + if isinstance(self.trailer_url, Unset): + trailer_url = UNSET + else: + trailer_url = self.trailer_url + + genres: Union[Unset, List[str]] = UNSET + if not isinstance(self.genres, Unset): + genres = self.genres + + countries: Union[Unset, List[Dict[str, Any]]] = UNSET + if not isinstance(self.countries, Unset): + countries = [] + for countries_item_data in self.countries: + countries_item = countries_item_data.to_dict() + countries.append(countries_item) + + offers: Union[Unset, List[Dict[str, Any]]] = UNSET + if not isinstance(self.offers, Unset): + offers = [] + for offers_item_data in self.offers: + offers_item = offers_item_data.to_dict() + offers.append(offers_item) + + directors: Union[Unset, List[Dict[str, Any]]] = UNSET + if not isinstance(self.directors, Unset): + directors = [] + for directors_item_data in self.directors: + directors_item = directors_item_data.to_dict() + directors.append(directors_item) + + field_dict: Dict[str, Any] = {} + field_dict.update(self.additional_properties) + field_dict.update( + { + "title": title, + } + ) + if id is not UNSET: + field_dict["id"] = id + if description is not UNSET: + field_dict["description"] = description + if year is not UNSET: + field_dict["year"] = year + if rating is not UNSET: + field_dict["rating"] = rating + if runtime is not UNSET: + field_dict["runtime"] = runtime + if lb_url is not UNSET: + field_dict["lb_url"] = lb_url + if jw_url is not UNSET: + field_dict["jw_url"] = jw_url + if trailer_url is not UNSET: + field_dict["trailer_url"] = trailer_url + if genres is not UNSET: + field_dict["genres"] = genres + if countries is not UNSET: + field_dict["countries"] = countries + if offers is not UNSET: + field_dict["offers"] = offers + if directors is not UNSET: + field_dict["directors"] = directors + + return field_dict + + @classmethod + def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: + from ..models.director_films_item_countries_item import DirectorFilmsItemCountriesItem + from ..models.director_films_item_directors_item import DirectorFilmsItemDirectorsItem + from ..models.director_films_item_offers_item import DirectorFilmsItemOffersItem + + d = src_dict.copy() + title = d.pop("title") + + id = d.pop("id", UNSET) + + description = d.pop("description", UNSET) + + def _parse_year(data: object) -> Union[None, Unset, int]: + if data is None: + return data + if isinstance(data, Unset): + return data + return cast(Union[None, Unset, int], data) + + year = _parse_year(d.pop("year", UNSET)) + + rating = d.pop("rating", UNSET) + + def _parse_runtime(data: object) -> Union[None, Unset, int]: + if data is None: + return data + if isinstance(data, Unset): + return data + return cast(Union[None, Unset, int], data) + + runtime = _parse_runtime(d.pop("runtime", UNSET)) + + lb_url = d.pop("lb_url", UNSET) + + def _parse_jw_url(data: object) -> Union[None, Unset, str]: + if data is None: + return data + if isinstance(data, Unset): + return data + return cast(Union[None, Unset, str], data) + + jw_url = _parse_jw_url(d.pop("jw_url", UNSET)) + + def _parse_trailer_url(data: object) -> Union[None, Unset, str]: + if data is None: + return data + if isinstance(data, Unset): + return data + return cast(Union[None, Unset, str], data) + + trailer_url = _parse_trailer_url(d.pop("trailer_url", UNSET)) + + genres = cast(List[str], d.pop("genres", UNSET)) + + countries = [] + _countries = d.pop("countries", UNSET) + for countries_item_data in _countries or []: + countries_item = DirectorFilmsItemCountriesItem.from_dict(countries_item_data) + + countries.append(countries_item) + + offers = [] + _offers = d.pop("offers", UNSET) + for offers_item_data in _offers or []: + offers_item = DirectorFilmsItemOffersItem.from_dict(offers_item_data) + + offers.append(offers_item) + + directors = [] + _directors = d.pop("directors", UNSET) + for directors_item_data in _directors or []: + directors_item = DirectorFilmsItemDirectorsItem.from_dict(directors_item_data) + + directors.append(directors_item) + + director_films_item = cls( + title=title, + id=id, + description=description, + year=year, + rating=rating, + runtime=runtime, + lb_url=lb_url, + jw_url=jw_url, + trailer_url=trailer_url, + genres=genres, + countries=countries, + offers=offers, + directors=directors, + ) + + director_films_item.additional_properties = d + return director_films_item + + @property + def additional_keys(self) -> List[str]: + return list(self.additional_properties.keys()) + + def __getitem__(self, key: str) -> Any: + return self.additional_properties[key] + + def __setitem__(self, key: str, value: Any) -> None: + self.additional_properties[key] = value + + def __delitem__(self, key: str) -> None: + del self.additional_properties[key] + + def __contains__(self, key: str) -> bool: + return key in self.additional_properties diff --git a/letsrolld-api-client/letsrolld_api_client/models/director_films_item_countries_item.py b/letsrolld-api-client/letsrolld_api_client/models/director_films_item_countries_item.py new file mode 100644 index 0000000..0080107 --- /dev/null +++ b/letsrolld-api-client/letsrolld_api_client/models/director_films_item_countries_item.py @@ -0,0 +1,80 @@ +from typing import Any, Dict, List, Type, TypeVar, Union, cast + +from attrs import define as _attrs_define +from attrs import field as _attrs_field + +from ..types import UNSET, Unset + +T = TypeVar("T", bound="DirectorFilmsItemCountriesItem") + + +@_attrs_define +class DirectorFilmsItemCountriesItem: + """ + Attributes: + name (str): + flag (Union[None, Unset, str]): + """ + + name: str + flag: Union[None, Unset, str] = UNSET + additional_properties: Dict[str, Any] = _attrs_field(init=False, factory=dict) + + def to_dict(self) -> Dict[str, Any]: + name = self.name + + flag: Union[None, Unset, str] + if isinstance(self.flag, Unset): + flag = UNSET + else: + flag = self.flag + + field_dict: Dict[str, Any] = {} + field_dict.update(self.additional_properties) + field_dict.update( + { + "name": name, + } + ) + if flag is not UNSET: + field_dict["flag"] = flag + + return field_dict + + @classmethod + def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: + d = src_dict.copy() + name = d.pop("name") + + def _parse_flag(data: object) -> Union[None, Unset, str]: + if data is None: + return data + if isinstance(data, Unset): + return data + return cast(Union[None, Unset, str], data) + + flag = _parse_flag(d.pop("flag", UNSET)) + + director_films_item_countries_item = cls( + name=name, + flag=flag, + ) + + director_films_item_countries_item.additional_properties = d + return director_films_item_countries_item + + @property + def additional_keys(self) -> List[str]: + return list(self.additional_properties.keys()) + + def __getitem__(self, key: str) -> Any: + return self.additional_properties[key] + + def __setitem__(self, key: str, value: Any) -> None: + self.additional_properties[key] = value + + def __delitem__(self, key: str) -> None: + del self.additional_properties[key] + + def __contains__(self, key: str) -> bool: + return key in self.additional_properties diff --git a/letsrolld-api-client/letsrolld_api_client/models/director_films_item_directors_item.py b/letsrolld-api-client/letsrolld_api_client/models/director_films_item_directors_item.py new file mode 100644 index 0000000..be30296 --- /dev/null +++ b/letsrolld-api-client/letsrolld_api_client/models/director_films_item_directors_item.py @@ -0,0 +1,77 @@ +from typing import Any, Dict, List, Type, TypeVar, Union + +from attrs import define as _attrs_define +from attrs import field as _attrs_field + +from ..types import UNSET, Unset + +T = TypeVar("T", bound="DirectorFilmsItemDirectorsItem") + + +@_attrs_define +class DirectorFilmsItemDirectorsItem: + """ + Attributes: + id (int): + name (str): + lb_url (Union[Unset, str]): + """ + + id: int + name: str + lb_url: Union[Unset, str] = UNSET + additional_properties: Dict[str, Any] = _attrs_field(init=False, factory=dict) + + def to_dict(self) -> Dict[str, Any]: + id = self.id + + name = self.name + + lb_url = self.lb_url + + field_dict: Dict[str, Any] = {} + field_dict.update(self.additional_properties) + field_dict.update( + { + "id": id, + "name": name, + } + ) + if lb_url is not UNSET: + field_dict["lb_url"] = lb_url + + return field_dict + + @classmethod + def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: + d = src_dict.copy() + id = d.pop("id") + + name = d.pop("name") + + lb_url = d.pop("lb_url", UNSET) + + director_films_item_directors_item = cls( + id=id, + name=name, + lb_url=lb_url, + ) + + director_films_item_directors_item.additional_properties = d + return director_films_item_directors_item + + @property + def additional_keys(self) -> List[str]: + return list(self.additional_properties.keys()) + + def __getitem__(self, key: str) -> Any: + return self.additional_properties[key] + + def __setitem__(self, key: str, value: Any) -> None: + self.additional_properties[key] = value + + def __delitem__(self, key: str) -> None: + del self.additional_properties[key] + + def __contains__(self, key: str) -> bool: + return key in self.additional_properties diff --git a/letsrolld-api-client/letsrolld_api_client/models/director_films_item_offers_item.py b/letsrolld-api-client/letsrolld_api_client/models/director_films_item_offers_item.py new file mode 100644 index 0000000..1b0cee7 --- /dev/null +++ b/letsrolld-api-client/letsrolld_api_client/models/director_films_item_offers_item.py @@ -0,0 +1,72 @@ +from typing import Any, Dict, List, Type, TypeVar, Union, cast + +from attrs import define as _attrs_define +from attrs import field as _attrs_field + +T = TypeVar("T", bound="DirectorFilmsItemOffersItem") + + +@_attrs_define +class DirectorFilmsItemOffersItem: + """ + Attributes: + name (str): + url (Union[None, str]): + """ + + name: str + url: Union[None, str] + additional_properties: Dict[str, Any] = _attrs_field(init=False, factory=dict) + + def to_dict(self) -> Dict[str, Any]: + name = self.name + + url: Union[None, str] + url = self.url + + field_dict: Dict[str, Any] = {} + field_dict.update(self.additional_properties) + field_dict.update( + { + "name": name, + "url": url, + } + ) + + return field_dict + + @classmethod + def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: + d = src_dict.copy() + name = d.pop("name") + + def _parse_url(data: object) -> Union[None, str]: + if data is None: + return data + return cast(Union[None, str], data) + + url = _parse_url(d.pop("url")) + + director_films_item_offers_item = cls( + name=name, + url=url, + ) + + director_films_item_offers_item.additional_properties = d + return director_films_item_offers_item + + @property + def additional_keys(self) -> List[str]: + return list(self.additional_properties.keys()) + + def __getitem__(self, key: str) -> Any: + return self.additional_properties[key] + + def __setitem__(self, key: str, value: Any) -> None: + self.additional_properties[key] = value + + def __delitem__(self, key: str) -> None: + del self.additional_properties[key] + + def __contains__(self, key: str) -> bool: + return key in self.additional_properties diff --git a/letsrolld-api-client/letsrolld_api_client/models/director_info.py b/letsrolld-api-client/letsrolld_api_client/models/director_info.py new file mode 100644 index 0000000..7cf3776 --- /dev/null +++ b/letsrolld-api-client/letsrolld_api_client/models/director_info.py @@ -0,0 +1,77 @@ +from typing import Any, Dict, List, Type, TypeVar, Union + +from attrs import define as _attrs_define +from attrs import field as _attrs_field + +from ..types import UNSET, Unset + +T = TypeVar("T", bound="DirectorInfo") + + +@_attrs_define +class DirectorInfo: + """ + Attributes: + id (int): + name (str): + lb_url (Union[Unset, str]): + """ + + id: int + name: str + lb_url: Union[Unset, str] = UNSET + additional_properties: Dict[str, Any] = _attrs_field(init=False, factory=dict) + + def to_dict(self) -> Dict[str, Any]: + id = self.id + + name = self.name + + lb_url = self.lb_url + + field_dict: Dict[str, Any] = {} + field_dict.update(self.additional_properties) + field_dict.update( + { + "id": id, + "name": name, + } + ) + if lb_url is not UNSET: + field_dict["lb_url"] = lb_url + + return field_dict + + @classmethod + def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: + d = src_dict.copy() + id = d.pop("id") + + name = d.pop("name") + + lb_url = d.pop("lb_url", UNSET) + + director_info = cls( + id=id, + name=name, + lb_url=lb_url, + ) + + director_info.additional_properties = d + return director_info + + @property + def additional_keys(self) -> List[str]: + return list(self.additional_properties.keys()) + + def __getitem__(self, key: str) -> Any: + return self.additional_properties[key] + + def __setitem__(self, key: str, value: Any) -> None: + self.additional_properties[key] = value + + def __delitem__(self, key: str) -> None: + del self.additional_properties[key] + + def __contains__(self, key: str) -> bool: + return key in self.additional_properties diff --git a/letsrolld-api-client/letsrolld_api_client/models/film.py b/letsrolld-api-client/letsrolld_api_client/models/film.py new file mode 100644 index 0000000..963e104 --- /dev/null +++ b/letsrolld-api-client/letsrolld_api_client/models/film.py @@ -0,0 +1,254 @@ +from typing import TYPE_CHECKING, Any, Dict, List, Type, TypeVar, Union, cast + +from attrs import define as _attrs_define +from attrs import field as _attrs_field + +from ..types import UNSET, Unset + +if TYPE_CHECKING: + from ..models.film_countries_item import FilmCountriesItem + from ..models.film_directors_item import FilmDirectorsItem + from ..models.film_offers_item import FilmOffersItem + + +T = TypeVar("T", bound="Film") + + +@_attrs_define +class Film: + """ + Attributes: + title (str): + id (Union[Unset, int]): + description (Union[Unset, str]): + year (Union[None, Unset, int]): + rating (Union[Unset, str]): + runtime (Union[None, Unset, int]): + lb_url (Union[Unset, str]): + jw_url (Union[None, Unset, str]): + trailer_url (Union[None, Unset, str]): + genres (Union[Unset, List[str]]): + countries (Union[Unset, List['FilmCountriesItem']]): + offers (Union[Unset, List['FilmOffersItem']]): + directors (Union[Unset, List['FilmDirectorsItem']]): + """ + + title: str + id: Union[Unset, int] = UNSET + description: Union[Unset, str] = UNSET + year: Union[None, Unset, int] = UNSET + rating: Union[Unset, str] = UNSET + runtime: Union[None, Unset, int] = UNSET + lb_url: Union[Unset, str] = UNSET + jw_url: Union[None, Unset, str] = UNSET + trailer_url: Union[None, Unset, str] = UNSET + genres: Union[Unset, List[str]] = UNSET + countries: Union[Unset, List["FilmCountriesItem"]] = UNSET + offers: Union[Unset, List["FilmOffersItem"]] = UNSET + directors: Union[Unset, List["FilmDirectorsItem"]] = UNSET + additional_properties: Dict[str, Any] = _attrs_field(init=False, factory=dict) + + def to_dict(self) -> Dict[str, Any]: + title = self.title + + id = self.id + + description = self.description + + year: Union[None, Unset, int] + if isinstance(self.year, Unset): + year = UNSET + else: + year = self.year + + rating = self.rating + + runtime: Union[None, Unset, int] + if isinstance(self.runtime, Unset): + runtime = UNSET + else: + runtime = self.runtime + + lb_url = self.lb_url + + jw_url: Union[None, Unset, str] + if isinstance(self.jw_url, Unset): + jw_url = UNSET + else: + jw_url = self.jw_url + + trailer_url: Union[None, Unset, str] + if isinstance(self.trailer_url, Unset): + trailer_url = UNSET + else: + trailer_url = self.trailer_url + + genres: Union[Unset, List[str]] = UNSET + if not isinstance(self.genres, Unset): + genres = self.genres + + countries: Union[Unset, List[Dict[str, Any]]] = UNSET + if not isinstance(self.countries, Unset): + countries = [] + for countries_item_data in self.countries: + countries_item = countries_item_data.to_dict() + countries.append(countries_item) + + offers: Union[Unset, List[Dict[str, Any]]] = UNSET + if not isinstance(self.offers, Unset): + offers = [] + for offers_item_data in self.offers: + offers_item = offers_item_data.to_dict() + offers.append(offers_item) + + directors: Union[Unset, List[Dict[str, Any]]] = UNSET + if not isinstance(self.directors, Unset): + directors = [] + for directors_item_data in self.directors: + directors_item = directors_item_data.to_dict() + directors.append(directors_item) + + field_dict: Dict[str, Any] = {} + field_dict.update(self.additional_properties) + field_dict.update( + { + "title": title, + } + ) + if id is not UNSET: + field_dict["id"] = id + if description is not UNSET: + field_dict["description"] = description + if year is not UNSET: + field_dict["year"] = year + if rating is not UNSET: + field_dict["rating"] = rating + if runtime is not UNSET: + field_dict["runtime"] = runtime + if lb_url is not UNSET: + field_dict["lb_url"] = lb_url + if jw_url is not UNSET: + field_dict["jw_url"] = jw_url + if trailer_url is not UNSET: + field_dict["trailer_url"] = trailer_url + if genres is not UNSET: + field_dict["genres"] = genres + if countries is not UNSET: + field_dict["countries"] = countries + if offers is not UNSET: + field_dict["offers"] = offers + if directors is not UNSET: + field_dict["directors"] = directors + + return field_dict + + @classmethod + def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: + from ..models.film_countries_item import FilmCountriesItem + from ..models.film_directors_item import FilmDirectorsItem + from ..models.film_offers_item import FilmOffersItem + + d = src_dict.copy() + title = d.pop("title") + + id = d.pop("id", UNSET) + + description = d.pop("description", UNSET) + + def _parse_year(data: object) -> Union[None, Unset, int]: + if data is None: + return data + if isinstance(data, Unset): + return data + return cast(Union[None, Unset, int], data) + + year = _parse_year(d.pop("year", UNSET)) + + rating = d.pop("rating", UNSET) + + def _parse_runtime(data: object) -> Union[None, Unset, int]: + if data is None: + return data + if isinstance(data, Unset): + return data + return cast(Union[None, Unset, int], data) + + runtime = _parse_runtime(d.pop("runtime", UNSET)) + + lb_url = d.pop("lb_url", UNSET) + + def _parse_jw_url(data: object) -> Union[None, Unset, str]: + if data is None: + return data + if isinstance(data, Unset): + return data + return cast(Union[None, Unset, str], data) + + jw_url = _parse_jw_url(d.pop("jw_url", UNSET)) + + def _parse_trailer_url(data: object) -> Union[None, Unset, str]: + if data is None: + return data + if isinstance(data, Unset): + return data + return cast(Union[None, Unset, str], data) + + trailer_url = _parse_trailer_url(d.pop("trailer_url", UNSET)) + + genres = cast(List[str], d.pop("genres", UNSET)) + + countries = [] + _countries = d.pop("countries", UNSET) + for countries_item_data in _countries or []: + countries_item = FilmCountriesItem.from_dict(countries_item_data) + + countries.append(countries_item) + + offers = [] + _offers = d.pop("offers", UNSET) + for offers_item_data in _offers or []: + offers_item = FilmOffersItem.from_dict(offers_item_data) + + offers.append(offers_item) + + directors = [] + _directors = d.pop("directors", UNSET) + for directors_item_data in _directors or []: + directors_item = FilmDirectorsItem.from_dict(directors_item_data) + + directors.append(directors_item) + + film = cls( + title=title, + id=id, + description=description, + year=year, + rating=rating, + runtime=runtime, + lb_url=lb_url, + jw_url=jw_url, + trailer_url=trailer_url, + genres=genres, + countries=countries, + offers=offers, + directors=directors, + ) + + film.additional_properties = d + return film + + @property + def additional_keys(self) -> List[str]: + return list(self.additional_properties.keys()) + + def __getitem__(self, key: str) -> Any: + return self.additional_properties[key] + + def __setitem__(self, key: str, value: Any) -> None: + self.additional_properties[key] = value + + def __delitem__(self, key: str) -> None: + del self.additional_properties[key] + + def __contains__(self, key: str) -> bool: + return key in self.additional_properties diff --git a/letsrolld-api-client/letsrolld_api_client/models/film_countries_item.py b/letsrolld-api-client/letsrolld_api_client/models/film_countries_item.py new file mode 100644 index 0000000..eef7df1 --- /dev/null +++ b/letsrolld-api-client/letsrolld_api_client/models/film_countries_item.py @@ -0,0 +1,80 @@ +from typing import Any, Dict, List, Type, TypeVar, Union, cast + +from attrs import define as _attrs_define +from attrs import field as _attrs_field + +from ..types import UNSET, Unset + +T = TypeVar("T", bound="FilmCountriesItem") + + +@_attrs_define +class FilmCountriesItem: + """ + Attributes: + name (str): + flag (Union[None, Unset, str]): + """ + + name: str + flag: Union[None, Unset, str] = UNSET + additional_properties: Dict[str, Any] = _attrs_field(init=False, factory=dict) + + def to_dict(self) -> Dict[str, Any]: + name = self.name + + flag: Union[None, Unset, str] + if isinstance(self.flag, Unset): + flag = UNSET + else: + flag = self.flag + + field_dict: Dict[str, Any] = {} + field_dict.update(self.additional_properties) + field_dict.update( + { + "name": name, + } + ) + if flag is not UNSET: + field_dict["flag"] = flag + + return field_dict + + @classmethod + def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: + d = src_dict.copy() + name = d.pop("name") + + def _parse_flag(data: object) -> Union[None, Unset, str]: + if data is None: + return data + if isinstance(data, Unset): + return data + return cast(Union[None, Unset, str], data) + + flag = _parse_flag(d.pop("flag", UNSET)) + + film_countries_item = cls( + name=name, + flag=flag, + ) + + film_countries_item.additional_properties = d + return film_countries_item + + @property + def additional_keys(self) -> List[str]: + return list(self.additional_properties.keys()) + + def __getitem__(self, key: str) -> Any: + return self.additional_properties[key] + + def __setitem__(self, key: str, value: Any) -> None: + self.additional_properties[key] = value + + def __delitem__(self, key: str) -> None: + del self.additional_properties[key] + + def __contains__(self, key: str) -> bool: + return key in self.additional_properties diff --git a/letsrolld-api-client/letsrolld_api_client/models/film_directors_item.py b/letsrolld-api-client/letsrolld_api_client/models/film_directors_item.py new file mode 100644 index 0000000..18d7a12 --- /dev/null +++ b/letsrolld-api-client/letsrolld_api_client/models/film_directors_item.py @@ -0,0 +1,77 @@ +from typing import Any, Dict, List, Type, TypeVar, Union + +from attrs import define as _attrs_define +from attrs import field as _attrs_field + +from ..types import UNSET, Unset + +T = TypeVar("T", bound="FilmDirectorsItem") + + +@_attrs_define +class FilmDirectorsItem: + """ + Attributes: + id (int): + name (str): + lb_url (Union[Unset, str]): + """ + + id: int + name: str + lb_url: Union[Unset, str] = UNSET + additional_properties: Dict[str, Any] = _attrs_field(init=False, factory=dict) + + def to_dict(self) -> Dict[str, Any]: + id = self.id + + name = self.name + + lb_url = self.lb_url + + field_dict: Dict[str, Any] = {} + field_dict.update(self.additional_properties) + field_dict.update( + { + "id": id, + "name": name, + } + ) + if lb_url is not UNSET: + field_dict["lb_url"] = lb_url + + return field_dict + + @classmethod + def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: + d = src_dict.copy() + id = d.pop("id") + + name = d.pop("name") + + lb_url = d.pop("lb_url", UNSET) + + film_directors_item = cls( + id=id, + name=name, + lb_url=lb_url, + ) + + film_directors_item.additional_properties = d + return film_directors_item + + @property + def additional_keys(self) -> List[str]: + return list(self.additional_properties.keys()) + + def __getitem__(self, key: str) -> Any: + return self.additional_properties[key] + + def __setitem__(self, key: str, value: Any) -> None: + self.additional_properties[key] = value + + def __delitem__(self, key: str) -> None: + del self.additional_properties[key] + + def __contains__(self, key: str) -> bool: + return key in self.additional_properties diff --git a/letsrolld-api-client/letsrolld_api_client/models/film_offers_item.py b/letsrolld-api-client/letsrolld_api_client/models/film_offers_item.py new file mode 100644 index 0000000..3f8c04e --- /dev/null +++ b/letsrolld-api-client/letsrolld_api_client/models/film_offers_item.py @@ -0,0 +1,72 @@ +from typing import Any, Dict, List, Type, TypeVar, Union, cast + +from attrs import define as _attrs_define +from attrs import field as _attrs_field + +T = TypeVar("T", bound="FilmOffersItem") + + +@_attrs_define +class FilmOffersItem: + """ + Attributes: + name (str): + url (Union[None, str]): + """ + + name: str + url: Union[None, str] + additional_properties: Dict[str, Any] = _attrs_field(init=False, factory=dict) + + def to_dict(self) -> Dict[str, Any]: + name = self.name + + url: Union[None, str] + url = self.url + + field_dict: Dict[str, Any] = {} + field_dict.update(self.additional_properties) + field_dict.update( + { + "name": name, + "url": url, + } + ) + + return field_dict + + @classmethod + def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: + d = src_dict.copy() + name = d.pop("name") + + def _parse_url(data: object) -> Union[None, str]: + if data is None: + return data + return cast(Union[None, str], data) + + url = _parse_url(d.pop("url")) + + film_offers_item = cls( + name=name, + url=url, + ) + + film_offers_item.additional_properties = d + return film_offers_item + + @property + def additional_keys(self) -> List[str]: + return list(self.additional_properties.keys()) + + def __getitem__(self, key: str) -> Any: + return self.additional_properties[key] + + def __setitem__(self, key: str, value: Any) -> None: + self.additional_properties[key] = value + + def __delitem__(self, key: str) -> None: + del self.additional_properties[key] + + def __contains__(self, key: str) -> bool: + return key in self.additional_properties diff --git a/letsrolld-api-client/letsrolld_api_client/py.typed b/letsrolld-api-client/letsrolld_api_client/py.typed new file mode 100644 index 0000000..1aad327 --- /dev/null +++ b/letsrolld-api-client/letsrolld_api_client/py.typed @@ -0,0 +1 @@ +# Marker file for PEP 561 \ No newline at end of file diff --git a/letsrolld-api-client/letsrolld_api_client/types.py b/letsrolld-api-client/letsrolld_api_client/types.py new file mode 100644 index 0000000..21fac10 --- /dev/null +++ b/letsrolld-api-client/letsrolld_api_client/types.py @@ -0,0 +1,45 @@ +"""Contains some shared types for properties""" + +from http import HTTPStatus +from typing import BinaryIO, Generic, Literal, MutableMapping, Optional, Tuple, TypeVar + +from attrs import define + + +class Unset: + def __bool__(self) -> Literal[False]: + return False + + +UNSET: Unset = Unset() + +FileJsonType = Tuple[Optional[str], BinaryIO, Optional[str]] + + +@define +class File: + """Contains information for file uploads""" + + payload: BinaryIO + file_name: Optional[str] = None + mime_type: Optional[str] = None + + def to_tuple(self) -> FileJsonType: + """Return a tuple representation that httpx will accept for multipart/form-data""" + return self.file_name, self.payload, self.mime_type + + +T = TypeVar("T") + + +@define +class Response(Generic[T]): + """A response from an endpoint""" + + status_code: HTTPStatus + content: bytes + headers: MutableMapping[str, str] + parsed: Optional[T] + + +__all__ = ["File", "Response", "FileJsonType", "Unset", "UNSET"] diff --git a/letsrolld-api-client/pyproject.toml b/letsrolld-api-client/pyproject.toml new file mode 100644 index 0000000..d97ef2d --- /dev/null +++ b/letsrolld-api-client/pyproject.toml @@ -0,0 +1,27 @@ +[tool.poetry] +name = "letsrolld-api-client" +version = "0.1" +description = "A client library for accessing letsrolld API" +authors = [] +readme = "README.md" +packages = [ + {include = "letsrolld_api_client"}, +] +include = ["CHANGELOG.md", "letsrolld_api_client/py.typed"] + + +[tool.poetry.dependencies] +python = "^3.8" +httpx = ">=0.20.0,<0.28.0" +attrs = ">=21.3.0" +python-dateutil = "^2.8.0" + +[build-system] +requires = ["poetry-core>=1.0.0"] +build-backend = "poetry.core.masonry.api" + +[tool.ruff] +line-length = 120 + +[tool.ruff.lint] +select = ["F", "I", "UP"] diff --git a/pdm.lock b/pdm.lock index 8a5256c..def3f64 100644 --- a/pdm.lock +++ b/pdm.lock @@ -5,7 +5,7 @@ groups = ["default", "dev"] strategy = ["cross_platform"] lock_version = "4.4" -content_hash = "sha256:7fa75fd682e1779978bc77d90006e64884065f72c3cff59e12f0357418c1bb9d" +content_hash = "sha256:6c6f7696e235e138c6b6e143446b493ac22bca001a31f5d12925b529d6f5e087" [[package]] name = "alembic" @@ -362,8 +362,7 @@ files = [ name = "letsrolld-api-client" version = "0.1" requires_python = ">=3.8,<4.0" -git = "https://github.com/booxter/letsrolld-client.git" -revision = "1822119c7add754bd5a42166fbb786908eb3b556" +path = "./letsrolld-api-client" summary = "A client library for accessing letsrolld API" dependencies = [ "attrs>=21.3.0", diff --git a/pyproject.toml b/pyproject.toml index a7045e1..c0bd9ec 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -15,7 +15,7 @@ dependencies = [ "SQLAlchemy>=2.0.27", "alembic>=1.13.1", "flask-restful-swagger-3 @ git+https://github.com/booxter/flask-restful-swagger-3@master", - "letsrolld-api-client @ git+https://github.com/booxter/letsrolld-client.git", + "letsrolld-api-client @ file:///${PROJECT_ROOT}/letsrolld-api-client", "click>=8.1.7", "Jinja2>=3.1.3", "Flask-Sqlalchemy>=3.1.1", diff --git a/sanity-check.sh b/sanity-check.sh index 0562148..27d0646 100755 --- a/sanity-check.sh +++ b/sanity-check.sh @@ -1,6 +1,20 @@ #!/bin/sh set -xe +StringContains() { + string="$1" + substring="$2" + + case "$string" in + *"$substring"*) + return 0 + ;; + *) + return 1 + ;; + esac +} + DIRECTORS_FILE=directors.csv # create empty database @@ -26,8 +40,8 @@ test $lines -eq 10 # 10 is default in webapi # (the first two entries in the input file) out=$(lcli directors get) # TODO: we could probably extract these programmatically here -test grep -q "Maryam Touzani" $out -test grep -q "Štefan Uher" $out +StringContains "$out" "Maryam Touzani" +StringContains "$out" "Štefan Uher" # stop webapp kill $WEBAPP_PID diff --git a/src/letsrolld/webcli/templates/director.template b/src/letsrolld/webcli/templates/director.template index e01454f..3e14013 100644 --- a/src/letsrolld/webcli/templates/director.template +++ b/src/letsrolld/webcli/templates/director.template @@ -1,4 +1,4 @@ -{{ director.name }}: +{{ director.info.name }}: {%- for film in director.films|sort(attribute='rating', reverse=True) %} - {{ film.title }} {{ film.year }} ({{ film.rating }}) {%- endfor -%}