From 50f57875e08fea9a12cb5f759d29afc6fba658df Mon Sep 17 00:00:00 2001 From: Sayyid Hamid Mahdavi Date: Tue, 11 Mar 2025 18:45:29 +0330 Subject: [PATCH] accounts client --- apps/users/models.py | 3 +- gooyal_accounts_client/__init__.py | 8 + gooyal_accounts_client/api/__init__.py | 1 + gooyal_accounts_client/api/oauth2/__init__.py | 0 ...auth2_apis_applications_avatar_retrieve.py | 142 +++++++++ .../oauth2/oauth2_apis_applications_list.py | 154 ++++++++++ .../oauth2_apis_applications_retrieve.py | 142 +++++++++ gooyal_accounts_client/api/users/__init__.py | 0 .../users/users_api_account_partial_update.py | 152 +++++++++ .../api/users/users_api_account_retrieve.py | 118 +++++++ .../api/users/users_api_account_update.py | 151 +++++++++ ...sers_api_change_password_partial_update.py | 156 ++++++++++ .../users/users_api_change_password_update.py | 155 ++++++++++ .../api/users/users_api_request_otp_create.py | 151 +++++++++ .../api/users/users_api_request_ott_create.py | 151 +++++++++ .../users/users_api_users_avatar_retrieve.py | 92 ++++++ .../api/users/users_api_users_list.py | 154 ++++++++++ .../api/users/users_api_users_retrieve.py | 143 +++++++++ gooyal_accounts_client/client.py | 268 ++++++++++++++++ gooyal_accounts_client/errors.py | 16 + gooyal_accounts_client/models/__init__.py | 25 ++ gooyal_accounts_client/models/account.py | 274 +++++++++++++++++ gooyal_accounts_client/models/application.py | 91 ++++++ .../models/change_password.py | 77 +++++ .../models/paginated_application_list.py | 122 ++++++++ .../models/paginated_public_user_list.py | 122 ++++++++ .../models/patched_account.py | 289 ++++++++++++++++++ .../models/patched_change_password.py | 76 +++++ gooyal_accounts_client/models/public_user.py | 112 +++++++ gooyal_accounts_client/models/request_otp.py | 93 ++++++ gooyal_accounts_client/models/request_ott.py | 99 ++++++ gooyal_accounts_client/py.typed | 1 + gooyal_accounts_client/types.py | 46 +++ requirements.in | 2 + requirements.txt | 28 +- utils/accounts_client.py | 59 ++++ wallet/settings.py | 12 +- 37 files changed, 3680 insertions(+), 5 deletions(-) create mode 100644 gooyal_accounts_client/__init__.py create mode 100644 gooyal_accounts_client/api/__init__.py create mode 100644 gooyal_accounts_client/api/oauth2/__init__.py create mode 100644 gooyal_accounts_client/api/oauth2/oauth2_apis_applications_avatar_retrieve.py create mode 100644 gooyal_accounts_client/api/oauth2/oauth2_apis_applications_list.py create mode 100644 gooyal_accounts_client/api/oauth2/oauth2_apis_applications_retrieve.py create mode 100644 gooyal_accounts_client/api/users/__init__.py create mode 100644 gooyal_accounts_client/api/users/users_api_account_partial_update.py create mode 100644 gooyal_accounts_client/api/users/users_api_account_retrieve.py create mode 100644 gooyal_accounts_client/api/users/users_api_account_update.py create mode 100644 gooyal_accounts_client/api/users/users_api_change_password_partial_update.py create mode 100644 gooyal_accounts_client/api/users/users_api_change_password_update.py create mode 100644 gooyal_accounts_client/api/users/users_api_request_otp_create.py create mode 100644 gooyal_accounts_client/api/users/users_api_request_ott_create.py create mode 100644 gooyal_accounts_client/api/users/users_api_users_avatar_retrieve.py create mode 100644 gooyal_accounts_client/api/users/users_api_users_list.py create mode 100644 gooyal_accounts_client/api/users/users_api_users_retrieve.py create mode 100644 gooyal_accounts_client/client.py create mode 100644 gooyal_accounts_client/errors.py create mode 100644 gooyal_accounts_client/models/__init__.py create mode 100644 gooyal_accounts_client/models/account.py create mode 100644 gooyal_accounts_client/models/application.py create mode 100644 gooyal_accounts_client/models/change_password.py create mode 100644 gooyal_accounts_client/models/paginated_application_list.py create mode 100644 gooyal_accounts_client/models/paginated_public_user_list.py create mode 100644 gooyal_accounts_client/models/patched_account.py create mode 100644 gooyal_accounts_client/models/patched_change_password.py create mode 100644 gooyal_accounts_client/models/public_user.py create mode 100644 gooyal_accounts_client/models/request_otp.py create mode 100644 gooyal_accounts_client/models/request_ott.py create mode 100644 gooyal_accounts_client/py.typed create mode 100644 gooyal_accounts_client/types.py create mode 100644 utils/accounts_client.py diff --git a/apps/users/models.py b/apps/users/models.py index 97e408b..58b078c 100644 --- a/apps/users/models.py +++ b/apps/users/models.py @@ -106,7 +106,8 @@ class OAuthCode(models.Model): def generate_login_url(self): redirect_uri = 'http://127.0.0.1:8000/users/login/callback/' - url = f'{settings.BASE_OAUTH2_PROVIDER_PUBLIC_URL}/authorize/?response_type=code&code_challenge={self.generate_code_challenge()}&code_challenge_method=S256&client_id={settings.CLIENT_ID}&scope={settings.SCOPES}&state={self.uuid}&redirect_uri={self.redirect_uri}' + scope = '+'.join(settings.SCOPES.split(' ')) + url = f'{settings.BASE_OAUTH2_PROVIDER_PUBLIC_URL}/authorize/?response_type=code&code_challenge={self.generate_code_challenge()}&code_challenge_method=S256&client_id={settings.CLIENT_ID}&scope={scope}&state={self.uuid}&redirect_uri={self.redirect_uri}' return url def validate_code(self, redirect_uri): diff --git a/gooyal_accounts_client/__init__.py b/gooyal_accounts_client/__init__.py new file mode 100644 index 0000000..94931df --- /dev/null +++ b/gooyal_accounts_client/__init__.py @@ -0,0 +1,8 @@ +"""A client library for accessing Gooyal Accounts""" + +from .client import AuthenticatedClient, Client + +__all__ = ( + "AuthenticatedClient", + "Client", +) diff --git a/gooyal_accounts_client/api/__init__.py b/gooyal_accounts_client/api/__init__.py new file mode 100644 index 0000000..81f9fa2 --- /dev/null +++ b/gooyal_accounts_client/api/__init__.py @@ -0,0 +1 @@ +"""Contains methods for accessing the API""" diff --git a/gooyal_accounts_client/api/oauth2/__init__.py b/gooyal_accounts_client/api/oauth2/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/gooyal_accounts_client/api/oauth2/oauth2_apis_applications_avatar_retrieve.py b/gooyal_accounts_client/api/oauth2/oauth2_apis_applications_avatar_retrieve.py new file mode 100644 index 0000000..8a48f72 --- /dev/null +++ b/gooyal_accounts_client/api/oauth2/oauth2_apis_applications_avatar_retrieve.py @@ -0,0 +1,142 @@ +from http import HTTPStatus +from typing import Any, Optional, Union + +import httpx + +from ... import errors +from ...client import AuthenticatedClient, Client +from ...models.application import Application +from ...types import Response + + +def _get_kwargs( + id: str, +) -> dict[str, Any]: + _kwargs: dict[str, Any] = { + "method": "get", + "url": f"/oauth2/apis/applications/{id}/avatar/", + } + + return _kwargs + + +def _parse_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Optional[Application]: + if response.status_code == 200: + response_200 = Application.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[Application]: + 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: str, + *, + client: AuthenticatedClient, +) -> Response[Application]: + """ + Args: + id (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[Application] + """ + + kwargs = _get_kwargs( + id=id, + ) + + response = client.get_httpx_client().request( + **kwargs, + ) + + return _build_response(client=client, response=response) + + +def sync( + id: str, + *, + client: AuthenticatedClient, +) -> Optional[Application]: + """ + Args: + id (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: + Application + """ + + return sync_detailed( + id=id, + client=client, + ).parsed + + +async def asyncio_detailed( + id: str, + *, + client: AuthenticatedClient, +) -> Response[Application]: + """ + Args: + id (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[Application] + """ + + 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: str, + *, + client: AuthenticatedClient, +) -> Optional[Application]: + """ + Args: + id (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: + Application + """ + + return ( + await asyncio_detailed( + id=id, + client=client, + ) + ).parsed diff --git a/gooyal_accounts_client/api/oauth2/oauth2_apis_applications_list.py b/gooyal_accounts_client/api/oauth2/oauth2_apis_applications_list.py new file mode 100644 index 0000000..0683709 --- /dev/null +++ b/gooyal_accounts_client/api/oauth2/oauth2_apis_applications_list.py @@ -0,0 +1,154 @@ +from http import HTTPStatus +from typing import Any, Optional, Union + +import httpx + +from ... import errors +from ...client import AuthenticatedClient, Client +from ...models.paginated_application_list import PaginatedApplicationList +from ...types import UNSET, Response, Unset + + +def _get_kwargs( + *, + page: Union[Unset, int] = UNSET, +) -> dict[str, Any]: + params: dict[str, Any] = {} + + params["page"] = page + + 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": "/oauth2/apis/applications/", + "params": params, + } + + return _kwargs + + +def _parse_response( + *, client: Union[AuthenticatedClient, Client], response: httpx.Response +) -> Optional[PaginatedApplicationList]: + if response.status_code == 200: + response_200 = PaginatedApplicationList.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[PaginatedApplicationList]: + 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: AuthenticatedClient, + page: Union[Unset, int] = UNSET, +) -> Response[PaginatedApplicationList]: + """ + Args: + page (Union[Unset, 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[PaginatedApplicationList] + """ + + kwargs = _get_kwargs( + page=page, + ) + + response = client.get_httpx_client().request( + **kwargs, + ) + + return _build_response(client=client, response=response) + + +def sync( + *, + client: AuthenticatedClient, + page: Union[Unset, int] = UNSET, +) -> Optional[PaginatedApplicationList]: + """ + Args: + page (Union[Unset, 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: + PaginatedApplicationList + """ + + return sync_detailed( + client=client, + page=page, + ).parsed + + +async def asyncio_detailed( + *, + client: AuthenticatedClient, + page: Union[Unset, int] = UNSET, +) -> Response[PaginatedApplicationList]: + """ + Args: + page (Union[Unset, 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[PaginatedApplicationList] + """ + + kwargs = _get_kwargs( + page=page, + ) + + response = await client.get_async_httpx_client().request(**kwargs) + + return _build_response(client=client, response=response) + + +async def asyncio( + *, + client: AuthenticatedClient, + page: Union[Unset, int] = UNSET, +) -> Optional[PaginatedApplicationList]: + """ + Args: + page (Union[Unset, 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: + PaginatedApplicationList + """ + + return ( + await asyncio_detailed( + client=client, + page=page, + ) + ).parsed diff --git a/gooyal_accounts_client/api/oauth2/oauth2_apis_applications_retrieve.py b/gooyal_accounts_client/api/oauth2/oauth2_apis_applications_retrieve.py new file mode 100644 index 0000000..464b71b --- /dev/null +++ b/gooyal_accounts_client/api/oauth2/oauth2_apis_applications_retrieve.py @@ -0,0 +1,142 @@ +from http import HTTPStatus +from typing import Any, Optional, Union + +import httpx + +from ... import errors +from ...client import AuthenticatedClient, Client +from ...models.application import Application +from ...types import Response + + +def _get_kwargs( + id: str, +) -> dict[str, Any]: + _kwargs: dict[str, Any] = { + "method": "get", + "url": f"/oauth2/apis/applications/{id}/", + } + + return _kwargs + + +def _parse_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Optional[Application]: + if response.status_code == 200: + response_200 = Application.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[Application]: + 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: str, + *, + client: AuthenticatedClient, +) -> Response[Application]: + """ + Args: + id (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[Application] + """ + + kwargs = _get_kwargs( + id=id, + ) + + response = client.get_httpx_client().request( + **kwargs, + ) + + return _build_response(client=client, response=response) + + +def sync( + id: str, + *, + client: AuthenticatedClient, +) -> Optional[Application]: + """ + Args: + id (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: + Application + """ + + return sync_detailed( + id=id, + client=client, + ).parsed + + +async def asyncio_detailed( + id: str, + *, + client: AuthenticatedClient, +) -> Response[Application]: + """ + Args: + id (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[Application] + """ + + 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: str, + *, + client: AuthenticatedClient, +) -> Optional[Application]: + """ + Args: + id (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: + Application + """ + + return ( + await asyncio_detailed( + id=id, + client=client, + ) + ).parsed diff --git a/gooyal_accounts_client/api/users/__init__.py b/gooyal_accounts_client/api/users/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/gooyal_accounts_client/api/users/users_api_account_partial_update.py b/gooyal_accounts_client/api/users/users_api_account_partial_update.py new file mode 100644 index 0000000..8bbbab3 --- /dev/null +++ b/gooyal_accounts_client/api/users/users_api_account_partial_update.py @@ -0,0 +1,152 @@ +from http import HTTPStatus +from typing import Any, Optional, Union + +import httpx + +from ... import errors +from ...client import AuthenticatedClient, Client +from ...models.account import Account +from ...models.patched_account import PatchedAccount +from ...types import Response + + +def _get_kwargs( + *, + body: PatchedAccount, +) -> dict[str, Any]: + headers: dict[str, Any] = {} + + _kwargs: dict[str, Any] = { + "method": "patch", + "url": "/users/api/account/", + } + + _body = body.to_dict() + + _kwargs["json"] = _body + headers["Content-Type"] = "application/json" + + _kwargs["headers"] = headers + return _kwargs + + +def _parse_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Optional[Account]: + if response.status_code == 200: + response_200 = Account.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[Account]: + 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: AuthenticatedClient, + body: PatchedAccount, +) -> Response[Account]: + """ + Args: + body (PatchedAccount): + + 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[Account] + """ + + kwargs = _get_kwargs( + body=body, + ) + + response = client.get_httpx_client().request( + **kwargs, + ) + + return _build_response(client=client, response=response) + + +def sync( + *, + client: AuthenticatedClient, + body: PatchedAccount, +) -> Optional[Account]: + """ + Args: + body (PatchedAccount): + + 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: + Account + """ + + return sync_detailed( + client=client, + body=body, + ).parsed + + +async def asyncio_detailed( + *, + client: AuthenticatedClient, + body: PatchedAccount, +) -> Response[Account]: + """ + Args: + body (PatchedAccount): + + 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[Account] + """ + + kwargs = _get_kwargs( + body=body, + ) + + response = await client.get_async_httpx_client().request(**kwargs) + + return _build_response(client=client, response=response) + + +async def asyncio( + *, + client: AuthenticatedClient, + body: PatchedAccount, +) -> Optional[Account]: + """ + Args: + body (PatchedAccount): + + 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: + Account + """ + + return ( + await asyncio_detailed( + client=client, + body=body, + ) + ).parsed diff --git a/gooyal_accounts_client/api/users/users_api_account_retrieve.py b/gooyal_accounts_client/api/users/users_api_account_retrieve.py new file mode 100644 index 0000000..e15e774 --- /dev/null +++ b/gooyal_accounts_client/api/users/users_api_account_retrieve.py @@ -0,0 +1,118 @@ +from http import HTTPStatus +from typing import Any, Optional, Union + +import httpx + +from ... import errors +from ...client import AuthenticatedClient, Client +from ...models.account import Account +from ...types import Response + + +def _get_kwargs() -> dict[str, Any]: + _kwargs: dict[str, Any] = { + "method": "get", + "url": "/users/api/account/", + } + + return _kwargs + + +def _parse_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Optional[Account]: + if response.status_code == 200: + response_200 = Account.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[Account]: + 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: AuthenticatedClient, +) -> Response[Account]: + """ + 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[Account] + """ + + kwargs = _get_kwargs() + + response = client.get_httpx_client().request( + **kwargs, + ) + + return _build_response(client=client, response=response) + + +def sync( + *, + client: AuthenticatedClient, +) -> Optional[Account]: + """ + 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: + Account + """ + + return sync_detailed( + client=client, + ).parsed + + +async def asyncio_detailed( + *, + client: AuthenticatedClient, +) -> Response[Account]: + """ + 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[Account] + """ + + kwargs = _get_kwargs() + + response = await client.get_async_httpx_client().request(**kwargs) + + return _build_response(client=client, response=response) + + +async def asyncio( + *, + client: AuthenticatedClient, +) -> Optional[Account]: + """ + 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: + Account + """ + + return ( + await asyncio_detailed( + client=client, + ) + ).parsed diff --git a/gooyal_accounts_client/api/users/users_api_account_update.py b/gooyal_accounts_client/api/users/users_api_account_update.py new file mode 100644 index 0000000..1a621e6 --- /dev/null +++ b/gooyal_accounts_client/api/users/users_api_account_update.py @@ -0,0 +1,151 @@ +from http import HTTPStatus +from typing import Any, Optional, Union + +import httpx + +from ... import errors +from ...client import AuthenticatedClient, Client +from ...models.account import Account +from ...types import Response + + +def _get_kwargs( + *, + body: Account, +) -> dict[str, Any]: + headers: dict[str, Any] = {} + + _kwargs: dict[str, Any] = { + "method": "put", + "url": "/users/api/account/", + } + + _body = body.to_dict() + + _kwargs["json"] = _body + headers["Content-Type"] = "application/json" + + _kwargs["headers"] = headers + return _kwargs + + +def _parse_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Optional[Account]: + if response.status_code == 200: + response_200 = Account.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[Account]: + 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: AuthenticatedClient, + body: Account, +) -> Response[Account]: + """ + Args: + body (Account): + + 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[Account] + """ + + kwargs = _get_kwargs( + body=body, + ) + + response = client.get_httpx_client().request( + **kwargs, + ) + + return _build_response(client=client, response=response) + + +def sync( + *, + client: AuthenticatedClient, + body: Account, +) -> Optional[Account]: + """ + Args: + body (Account): + + 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: + Account + """ + + return sync_detailed( + client=client, + body=body, + ).parsed + + +async def asyncio_detailed( + *, + client: AuthenticatedClient, + body: Account, +) -> Response[Account]: + """ + Args: + body (Account): + + 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[Account] + """ + + kwargs = _get_kwargs( + body=body, + ) + + response = await client.get_async_httpx_client().request(**kwargs) + + return _build_response(client=client, response=response) + + +async def asyncio( + *, + client: AuthenticatedClient, + body: Account, +) -> Optional[Account]: + """ + Args: + body (Account): + + 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: + Account + """ + + return ( + await asyncio_detailed( + client=client, + body=body, + ) + ).parsed diff --git a/gooyal_accounts_client/api/users/users_api_change_password_partial_update.py b/gooyal_accounts_client/api/users/users_api_change_password_partial_update.py new file mode 100644 index 0000000..87f5f90 --- /dev/null +++ b/gooyal_accounts_client/api/users/users_api_change_password_partial_update.py @@ -0,0 +1,156 @@ +from http import HTTPStatus +from typing import Any, Optional, Union + +import httpx + +from ... import errors +from ...client import AuthenticatedClient, Client +from ...models.change_password import ChangePassword +from ...models.patched_change_password import PatchedChangePassword +from ...types import Response + + +def _get_kwargs( + *, + body: PatchedChangePassword, +) -> dict[str, Any]: + headers: dict[str, Any] = {} + + _kwargs: dict[str, Any] = { + "method": "patch", + "url": "/users/api/change_password/", + } + + _body = body.to_dict() + + _kwargs["json"] = _body + headers["Content-Type"] = "application/json" + + _kwargs["headers"] = headers + return _kwargs + + +def _parse_response( + *, client: Union[AuthenticatedClient, Client], response: httpx.Response +) -> Optional[ChangePassword]: + if response.status_code == 200: + response_200 = ChangePassword.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[ChangePassword]: + 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: AuthenticatedClient, + body: PatchedChangePassword, +) -> Response[ChangePassword]: + """ + Args: + body (PatchedChangePassword): + + 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[ChangePassword] + """ + + kwargs = _get_kwargs( + body=body, + ) + + response = client.get_httpx_client().request( + **kwargs, + ) + + return _build_response(client=client, response=response) + + +def sync( + *, + client: AuthenticatedClient, + body: PatchedChangePassword, +) -> Optional[ChangePassword]: + """ + Args: + body (PatchedChangePassword): + + 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: + ChangePassword + """ + + return sync_detailed( + client=client, + body=body, + ).parsed + + +async def asyncio_detailed( + *, + client: AuthenticatedClient, + body: PatchedChangePassword, +) -> Response[ChangePassword]: + """ + Args: + body (PatchedChangePassword): + + 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[ChangePassword] + """ + + kwargs = _get_kwargs( + body=body, + ) + + response = await client.get_async_httpx_client().request(**kwargs) + + return _build_response(client=client, response=response) + + +async def asyncio( + *, + client: AuthenticatedClient, + body: PatchedChangePassword, +) -> Optional[ChangePassword]: + """ + Args: + body (PatchedChangePassword): + + 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: + ChangePassword + """ + + return ( + await asyncio_detailed( + client=client, + body=body, + ) + ).parsed diff --git a/gooyal_accounts_client/api/users/users_api_change_password_update.py b/gooyal_accounts_client/api/users/users_api_change_password_update.py new file mode 100644 index 0000000..0200030 --- /dev/null +++ b/gooyal_accounts_client/api/users/users_api_change_password_update.py @@ -0,0 +1,155 @@ +from http import HTTPStatus +from typing import Any, Optional, Union + +import httpx + +from ... import errors +from ...client import AuthenticatedClient, Client +from ...models.change_password import ChangePassword +from ...types import Response + + +def _get_kwargs( + *, + body: ChangePassword, +) -> dict[str, Any]: + headers: dict[str, Any] = {} + + _kwargs: dict[str, Any] = { + "method": "put", + "url": "/users/api/change_password/", + } + + _body = body.to_dict() + + _kwargs["json"] = _body + headers["Content-Type"] = "application/json" + + _kwargs["headers"] = headers + return _kwargs + + +def _parse_response( + *, client: Union[AuthenticatedClient, Client], response: httpx.Response +) -> Optional[ChangePassword]: + if response.status_code == 200: + response_200 = ChangePassword.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[ChangePassword]: + 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: AuthenticatedClient, + body: ChangePassword, +) -> Response[ChangePassword]: + """ + Args: + body (ChangePassword): + + 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[ChangePassword] + """ + + kwargs = _get_kwargs( + body=body, + ) + + response = client.get_httpx_client().request( + **kwargs, + ) + + return _build_response(client=client, response=response) + + +def sync( + *, + client: AuthenticatedClient, + body: ChangePassword, +) -> Optional[ChangePassword]: + """ + Args: + body (ChangePassword): + + 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: + ChangePassword + """ + + return sync_detailed( + client=client, + body=body, + ).parsed + + +async def asyncio_detailed( + *, + client: AuthenticatedClient, + body: ChangePassword, +) -> Response[ChangePassword]: + """ + Args: + body (ChangePassword): + + 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[ChangePassword] + """ + + kwargs = _get_kwargs( + body=body, + ) + + response = await client.get_async_httpx_client().request(**kwargs) + + return _build_response(client=client, response=response) + + +async def asyncio( + *, + client: AuthenticatedClient, + body: ChangePassword, +) -> Optional[ChangePassword]: + """ + Args: + body (ChangePassword): + + 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: + ChangePassword + """ + + return ( + await asyncio_detailed( + client=client, + body=body, + ) + ).parsed diff --git a/gooyal_accounts_client/api/users/users_api_request_otp_create.py b/gooyal_accounts_client/api/users/users_api_request_otp_create.py new file mode 100644 index 0000000..c987308 --- /dev/null +++ b/gooyal_accounts_client/api/users/users_api_request_otp_create.py @@ -0,0 +1,151 @@ +from http import HTTPStatus +from typing import Any, Optional, Union + +import httpx + +from ... import errors +from ...client import AuthenticatedClient, Client +from ...models.request_otp import RequestOTP +from ...types import Response + + +def _get_kwargs( + *, + body: RequestOTP, +) -> dict[str, Any]: + headers: dict[str, Any] = {} + + _kwargs: dict[str, Any] = { + "method": "post", + "url": "/users/api/request_otp/", + } + + _body = body.to_dict() + + _kwargs["json"] = _body + headers["Content-Type"] = "application/json" + + _kwargs["headers"] = headers + return _kwargs + + +def _parse_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Optional[RequestOTP]: + if response.status_code == 201: + response_201 = RequestOTP.from_dict(response.json()) + + return response_201 + 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[RequestOTP]: + 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: AuthenticatedClient, + body: RequestOTP, +) -> Response[RequestOTP]: + """ + Args: + body (RequestOTP): + + 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[RequestOTP] + """ + + kwargs = _get_kwargs( + body=body, + ) + + response = client.get_httpx_client().request( + **kwargs, + ) + + return _build_response(client=client, response=response) + + +def sync( + *, + client: AuthenticatedClient, + body: RequestOTP, +) -> Optional[RequestOTP]: + """ + Args: + body (RequestOTP): + + 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: + RequestOTP + """ + + return sync_detailed( + client=client, + body=body, + ).parsed + + +async def asyncio_detailed( + *, + client: AuthenticatedClient, + body: RequestOTP, +) -> Response[RequestOTP]: + """ + Args: + body (RequestOTP): + + 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[RequestOTP] + """ + + kwargs = _get_kwargs( + body=body, + ) + + response = await client.get_async_httpx_client().request(**kwargs) + + return _build_response(client=client, response=response) + + +async def asyncio( + *, + client: AuthenticatedClient, + body: RequestOTP, +) -> Optional[RequestOTP]: + """ + Args: + body (RequestOTP): + + 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: + RequestOTP + """ + + return ( + await asyncio_detailed( + client=client, + body=body, + ) + ).parsed diff --git a/gooyal_accounts_client/api/users/users_api_request_ott_create.py b/gooyal_accounts_client/api/users/users_api_request_ott_create.py new file mode 100644 index 0000000..13142f9 --- /dev/null +++ b/gooyal_accounts_client/api/users/users_api_request_ott_create.py @@ -0,0 +1,151 @@ +from http import HTTPStatus +from typing import Any, Optional, Union + +import httpx + +from ... import errors +from ...client import AuthenticatedClient, Client +from ...models.request_ott import RequestOTT +from ...types import Response + + +def _get_kwargs( + *, + body: RequestOTT, +) -> dict[str, Any]: + headers: dict[str, Any] = {} + + _kwargs: dict[str, Any] = { + "method": "post", + "url": "/users/api/request_ott/", + } + + _body = body.to_dict() + + _kwargs["json"] = _body + headers["Content-Type"] = "application/json" + + _kwargs["headers"] = headers + return _kwargs + + +def _parse_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Optional[RequestOTT]: + if response.status_code == 201: + response_201 = RequestOTT.from_dict(response.json()) + + return response_201 + 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[RequestOTT]: + 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: AuthenticatedClient, + body: RequestOTT, +) -> Response[RequestOTT]: + """ + Args: + body (RequestOTT): + + 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[RequestOTT] + """ + + kwargs = _get_kwargs( + body=body, + ) + + response = client.get_httpx_client().request( + **kwargs, + ) + + return _build_response(client=client, response=response) + + +def sync( + *, + client: AuthenticatedClient, + body: RequestOTT, +) -> Optional[RequestOTT]: + """ + Args: + body (RequestOTT): + + 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: + RequestOTT + """ + + return sync_detailed( + client=client, + body=body, + ).parsed + + +async def asyncio_detailed( + *, + client: AuthenticatedClient, + body: RequestOTT, +) -> Response[RequestOTT]: + """ + Args: + body (RequestOTT): + + 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[RequestOTT] + """ + + kwargs = _get_kwargs( + body=body, + ) + + response = await client.get_async_httpx_client().request(**kwargs) + + return _build_response(client=client, response=response) + + +async def asyncio( + *, + client: AuthenticatedClient, + body: RequestOTT, +) -> Optional[RequestOTT]: + """ + Args: + body (RequestOTT): + + 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: + RequestOTT + """ + + return ( + await asyncio_detailed( + client=client, + body=body, + ) + ).parsed diff --git a/gooyal_accounts_client/api/users/users_api_users_avatar_retrieve.py b/gooyal_accounts_client/api/users/users_api_users_avatar_retrieve.py new file mode 100644 index 0000000..6c317d9 --- /dev/null +++ b/gooyal_accounts_client/api/users/users_api_users_avatar_retrieve.py @@ -0,0 +1,92 @@ +from http import HTTPStatus +from typing import Any, Optional, Union +from uuid import UUID + +import httpx + +from ... import errors +from ...client import AuthenticatedClient, Client +from ...types import Response + + +def _get_kwargs( + uuid: UUID, +) -> dict[str, Any]: + _kwargs: dict[str, Any] = { + "method": "get", + "url": f"/users/api/users/{uuid}/avatar", + } + + return _kwargs + + +def _parse_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Optional[Any]: + if response.status_code == 200: + return None + 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[Any]: + return Response( + status_code=HTTPStatus(response.status_code), + content=response.content, + headers=response.headers, + parsed=_parse_response(client=client, response=response), + ) + + +def sync_detailed( + uuid: UUID, + *, + client: AuthenticatedClient, +) -> Response[Any]: + """ + Args: + uuid (UUID): + + 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[Any] + """ + + kwargs = _get_kwargs( + uuid=uuid, + ) + + response = client.get_httpx_client().request( + **kwargs, + ) + + return _build_response(client=client, response=response) + + +async def asyncio_detailed( + uuid: UUID, + *, + client: AuthenticatedClient, +) -> Response[Any]: + """ + Args: + uuid (UUID): + + 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[Any] + """ + + kwargs = _get_kwargs( + uuid=uuid, + ) + + response = await client.get_async_httpx_client().request(**kwargs) + + return _build_response(client=client, response=response) diff --git a/gooyal_accounts_client/api/users/users_api_users_list.py b/gooyal_accounts_client/api/users/users_api_users_list.py new file mode 100644 index 0000000..f43b9ea --- /dev/null +++ b/gooyal_accounts_client/api/users/users_api_users_list.py @@ -0,0 +1,154 @@ +from http import HTTPStatus +from typing import Any, Optional, Union + +import httpx + +from ... import errors +from ...client import AuthenticatedClient, Client +from ...models.paginated_public_user_list import PaginatedPublicUserList +from ...types import UNSET, Response, Unset + + +def _get_kwargs( + *, + page: Union[Unset, int] = UNSET, +) -> dict[str, Any]: + params: dict[str, Any] = {} + + params["page"] = page + + 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": "/users/api/users/", + "params": params, + } + + return _kwargs + + +def _parse_response( + *, client: Union[AuthenticatedClient, Client], response: httpx.Response +) -> Optional[PaginatedPublicUserList]: + if response.status_code == 200: + response_200 = PaginatedPublicUserList.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[PaginatedPublicUserList]: + 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: AuthenticatedClient, + page: Union[Unset, int] = UNSET, +) -> Response[PaginatedPublicUserList]: + """ + Args: + page (Union[Unset, 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[PaginatedPublicUserList] + """ + + kwargs = _get_kwargs( + page=page, + ) + + response = client.get_httpx_client().request( + **kwargs, + ) + + return _build_response(client=client, response=response) + + +def sync( + *, + client: AuthenticatedClient, + page: Union[Unset, int] = UNSET, +) -> Optional[PaginatedPublicUserList]: + """ + Args: + page (Union[Unset, 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: + PaginatedPublicUserList + """ + + return sync_detailed( + client=client, + page=page, + ).parsed + + +async def asyncio_detailed( + *, + client: AuthenticatedClient, + page: Union[Unset, int] = UNSET, +) -> Response[PaginatedPublicUserList]: + """ + Args: + page (Union[Unset, 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[PaginatedPublicUserList] + """ + + kwargs = _get_kwargs( + page=page, + ) + + response = await client.get_async_httpx_client().request(**kwargs) + + return _build_response(client=client, response=response) + + +async def asyncio( + *, + client: AuthenticatedClient, + page: Union[Unset, int] = UNSET, +) -> Optional[PaginatedPublicUserList]: + """ + Args: + page (Union[Unset, 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: + PaginatedPublicUserList + """ + + return ( + await asyncio_detailed( + client=client, + page=page, + ) + ).parsed diff --git a/gooyal_accounts_client/api/users/users_api_users_retrieve.py b/gooyal_accounts_client/api/users/users_api_users_retrieve.py new file mode 100644 index 0000000..17488a5 --- /dev/null +++ b/gooyal_accounts_client/api/users/users_api_users_retrieve.py @@ -0,0 +1,143 @@ +from http import HTTPStatus +from typing import Any, Optional, Union +from uuid import UUID + +import httpx + +from ... import errors +from ...client import AuthenticatedClient, Client +from ...models.public_user import PublicUser +from ...types import Response + + +def _get_kwargs( + uuid: UUID, +) -> dict[str, Any]: + _kwargs: dict[str, Any] = { + "method": "get", + "url": f"/users/api/users/{uuid}/", + } + + return _kwargs + + +def _parse_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Optional[PublicUser]: + if response.status_code == 200: + response_200 = PublicUser.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[PublicUser]: + return Response( + status_code=HTTPStatus(response.status_code), + content=response.content, + headers=response.headers, + parsed=_parse_response(client=client, response=response), + ) + + +def sync_detailed( + uuid: UUID, + *, + client: AuthenticatedClient, +) -> Response[PublicUser]: + """ + Args: + uuid (UUID): + + 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[PublicUser] + """ + + kwargs = _get_kwargs( + uuid=uuid, + ) + + response = client.get_httpx_client().request( + **kwargs, + ) + + return _build_response(client=client, response=response) + + +def sync( + uuid: UUID, + *, + client: AuthenticatedClient, +) -> Optional[PublicUser]: + """ + Args: + uuid (UUID): + + 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: + PublicUser + """ + + return sync_detailed( + uuid=uuid, + client=client, + ).parsed + + +async def asyncio_detailed( + uuid: UUID, + *, + client: AuthenticatedClient, +) -> Response[PublicUser]: + """ + Args: + uuid (UUID): + + 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[PublicUser] + """ + + kwargs = _get_kwargs( + uuid=uuid, + ) + + response = await client.get_async_httpx_client().request(**kwargs) + + return _build_response(client=client, response=response) + + +async def asyncio( + uuid: UUID, + *, + client: AuthenticatedClient, +) -> Optional[PublicUser]: + """ + Args: + uuid (UUID): + + 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: + PublicUser + """ + + return ( + await asyncio_detailed( + uuid=uuid, + client=client, + ) + ).parsed diff --git a/gooyal_accounts_client/client.py b/gooyal_accounts_client/client.py new file mode 100644 index 0000000..e80446f --- /dev/null +++ b/gooyal_accounts_client/client.py @@ -0,0 +1,268 @@ +import ssl +from typing import Any, 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 set 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 set 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/gooyal_accounts_client/errors.py b/gooyal_accounts_client/errors.py new file mode 100644 index 0000000..5f92e76 --- /dev/null +++ b/gooyal_accounts_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/gooyal_accounts_client/models/__init__.py b/gooyal_accounts_client/models/__init__.py new file mode 100644 index 0000000..185bd96 --- /dev/null +++ b/gooyal_accounts_client/models/__init__.py @@ -0,0 +1,25 @@ +"""Contains all the data models used in inputs/outputs""" + +from .account import Account +from .application import Application +from .change_password import ChangePassword +from .paginated_application_list import PaginatedApplicationList +from .paginated_public_user_list import PaginatedPublicUserList +from .patched_account import PatchedAccount +from .patched_change_password import PatchedChangePassword +from .public_user import PublicUser +from .request_otp import RequestOTP +from .request_ott import RequestOTT + +__all__ = ( + "Account", + "Application", + "ChangePassword", + "PaginatedApplicationList", + "PaginatedPublicUserList", + "PatchedAccount", + "PatchedChangePassword", + "PublicUser", + "RequestOTP", + "RequestOTT", +) diff --git a/gooyal_accounts_client/models/account.py b/gooyal_accounts_client/models/account.py new file mode 100644 index 0000000..589a7a8 --- /dev/null +++ b/gooyal_accounts_client/models/account.py @@ -0,0 +1,274 @@ +from typing import Any, TypeVar, Union, cast +from uuid import UUID + +from attrs import define as _attrs_define +from attrs import field as _attrs_field + +from ..types import UNSET, Unset + +T = TypeVar("T", bound="Account") + + +@_attrs_define +class Account: + """ + Attributes: + uuid (UUID): + email (str): + phone_number (str): + iban_verified (Union[None, bool]): + province_name (str): + city_name (str): + username (Union[None, Unset, str]): Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only. + first_name (Union[Unset, str]): + last_name (Union[Unset, str]): + name (Union[Unset, str]): + avatar (Union[None, Unset, str]): + iban (Union[None, Unset, str]): + province (Union[None, Unset, int]): + city (Union[None, Unset, int]): + postal_code (Union[None, Unset, str]): + address (Union[None, Unset, str]): + """ + + uuid: UUID + email: str + phone_number: str + iban_verified: Union[None, bool] + province_name: str + city_name: str + username: Union[None, Unset, str] = UNSET + first_name: Union[Unset, str] = UNSET + last_name: Union[Unset, str] = UNSET + name: Union[Unset, str] = UNSET + avatar: Union[None, Unset, str] = UNSET + iban: Union[None, Unset, str] = UNSET + province: Union[None, Unset, int] = UNSET + city: Union[None, Unset, int] = UNSET + postal_code: Union[None, Unset, str] = UNSET + address: Union[None, Unset, str] = UNSET + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) + + def to_dict(self) -> dict[str, Any]: + uuid = str(self.uuid) + + email = self.email + + phone_number = self.phone_number + + iban_verified: Union[None, bool] + iban_verified = self.iban_verified + + province_name = self.province_name + + city_name = self.city_name + + username: Union[None, Unset, str] + if isinstance(self.username, Unset): + username = UNSET + else: + username = self.username + + first_name = self.first_name + + last_name = self.last_name + + name = self.name + + avatar: Union[None, Unset, str] + if isinstance(self.avatar, Unset): + avatar = UNSET + else: + avatar = self.avatar + + iban: Union[None, Unset, str] + if isinstance(self.iban, Unset): + iban = UNSET + else: + iban = self.iban + + province: Union[None, Unset, int] + if isinstance(self.province, Unset): + province = UNSET + else: + province = self.province + + city: Union[None, Unset, int] + if isinstance(self.city, Unset): + city = UNSET + else: + city = self.city + + postal_code: Union[None, Unset, str] + if isinstance(self.postal_code, Unset): + postal_code = UNSET + else: + postal_code = self.postal_code + + address: Union[None, Unset, str] + if isinstance(self.address, Unset): + address = UNSET + else: + address = self.address + + field_dict: dict[str, Any] = {} + field_dict.update(self.additional_properties) + field_dict.update( + { + "uuid": uuid, + "email": email, + "phone_number": phone_number, + "iban_verified": iban_verified, + "province_name": province_name, + "city_name": city_name, + } + ) + if username is not UNSET: + field_dict["username"] = username + if first_name is not UNSET: + field_dict["first_name"] = first_name + if last_name is not UNSET: + field_dict["last_name"] = last_name + if name is not UNSET: + field_dict["name"] = name + if avatar is not UNSET: + field_dict["avatar"] = avatar + if iban is not UNSET: + field_dict["iban"] = iban + if province is not UNSET: + field_dict["province"] = province + if city is not UNSET: + field_dict["city"] = city + if postal_code is not UNSET: + field_dict["postal_code"] = postal_code + if address is not UNSET: + field_dict["address"] = address + + return field_dict + + @classmethod + def from_dict(cls: type[T], src_dict: dict[str, Any]) -> T: + d = src_dict.copy() + uuid = UUID(d.pop("uuid")) + + email = d.pop("email") + + phone_number = d.pop("phone_number") + + def _parse_iban_verified(data: object) -> Union[None, bool]: + if data is None: + return data + return cast(Union[None, bool], data) + + iban_verified = _parse_iban_verified(d.pop("iban_verified")) + + province_name = d.pop("province_name") + + city_name = d.pop("city_name") + + def _parse_username(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) + + username = _parse_username(d.pop("username", UNSET)) + + first_name = d.pop("first_name", UNSET) + + last_name = d.pop("last_name", UNSET) + + name = d.pop("name", UNSET) + + def _parse_avatar(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) + + avatar = _parse_avatar(d.pop("avatar", UNSET)) + + def _parse_iban(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) + + iban = _parse_iban(d.pop("iban", UNSET)) + + def _parse_province(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) + + province = _parse_province(d.pop("province", UNSET)) + + def _parse_city(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) + + city = _parse_city(d.pop("city", UNSET)) + + def _parse_postal_code(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) + + postal_code = _parse_postal_code(d.pop("postal_code", UNSET)) + + def _parse_address(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) + + address = _parse_address(d.pop("address", UNSET)) + + account = cls( + uuid=uuid, + email=email, + phone_number=phone_number, + iban_verified=iban_verified, + province_name=province_name, + city_name=city_name, + username=username, + first_name=first_name, + last_name=last_name, + name=name, + avatar=avatar, + iban=iban, + province=province, + city=city, + postal_code=postal_code, + address=address, + ) + + account.additional_properties = d + return account + + @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/gooyal_accounts_client/models/application.py b/gooyal_accounts_client/models/application.py new file mode 100644 index 0000000..bae2ccc --- /dev/null +++ b/gooyal_accounts_client/models/application.py @@ -0,0 +1,91 @@ +from typing import Any, TypeVar +from uuid import UUID + +from attrs import define as _attrs_define +from attrs import field as _attrs_field + +T = TypeVar("T", bound="Application") + + +@_attrs_define +class Application: + """ + Attributes: + uuid (UUID): + name (str): + client_id (str): + user (UUID): + allowed_scope (str): + """ + + uuid: UUID + name: str + client_id: str + user: UUID + allowed_scope: str + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) + + def to_dict(self) -> dict[str, Any]: + uuid = str(self.uuid) + + name = self.name + + client_id = self.client_id + + user = str(self.user) + + allowed_scope = self.allowed_scope + + field_dict: dict[str, Any] = {} + field_dict.update(self.additional_properties) + field_dict.update( + { + "uuid": uuid, + "name": name, + "client_id": client_id, + "user": user, + "allowed_scope": allowed_scope, + } + ) + + return field_dict + + @classmethod + def from_dict(cls: type[T], src_dict: dict[str, Any]) -> T: + d = src_dict.copy() + uuid = UUID(d.pop("uuid")) + + name = d.pop("name") + + client_id = d.pop("client_id") + + user = UUID(d.pop("user")) + + allowed_scope = d.pop("allowed_scope") + + application = cls( + uuid=uuid, + name=name, + client_id=client_id, + user=user, + allowed_scope=allowed_scope, + ) + + application.additional_properties = d + return application + + @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/gooyal_accounts_client/models/change_password.py b/gooyal_accounts_client/models/change_password.py new file mode 100644 index 0000000..7065c9d --- /dev/null +++ b/gooyal_accounts_client/models/change_password.py @@ -0,0 +1,77 @@ +from typing import Any, 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="ChangePassword") + + +@_attrs_define +class ChangePassword: + """ + Attributes: + old_password (str): + new_password (str): + old_password_field (Union[Unset, str]): Default: 'password'. + """ + + old_password: str + new_password: str + old_password_field: Union[Unset, str] = "password" + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) + + def to_dict(self) -> dict[str, Any]: + old_password = self.old_password + + new_password = self.new_password + + old_password_field = self.old_password_field + + field_dict: dict[str, Any] = {} + field_dict.update(self.additional_properties) + field_dict.update( + { + "old_password": old_password, + "new_password": new_password, + } + ) + if old_password_field is not UNSET: + field_dict["old_password_field"] = old_password_field + + return field_dict + + @classmethod + def from_dict(cls: type[T], src_dict: dict[str, Any]) -> T: + d = src_dict.copy() + old_password = d.pop("old_password") + + new_password = d.pop("new_password") + + old_password_field = d.pop("old_password_field", UNSET) + + change_password = cls( + old_password=old_password, + new_password=new_password, + old_password_field=old_password_field, + ) + + change_password.additional_properties = d + return change_password + + @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/gooyal_accounts_client/models/paginated_application_list.py b/gooyal_accounts_client/models/paginated_application_list.py new file mode 100644 index 0000000..c0b4d8b --- /dev/null +++ b/gooyal_accounts_client/models/paginated_application_list.py @@ -0,0 +1,122 @@ +from typing import TYPE_CHECKING, Any, 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.application import Application + + +T = TypeVar("T", bound="PaginatedApplicationList") + + +@_attrs_define +class PaginatedApplicationList: + """ + Attributes: + count (int): Example: 123. + results (list['Application']): + next_ (Union[None, Unset, str]): Example: http://api.example.org/accounts/?page=4. + previous (Union[None, Unset, str]): Example: http://api.example.org/accounts/?page=2. + """ + + count: int + results: list["Application"] + next_: Union[None, Unset, str] = UNSET + previous: Union[None, Unset, str] = UNSET + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) + + def to_dict(self) -> dict[str, Any]: + count = self.count + + results = [] + for results_item_data in self.results: + results_item = results_item_data.to_dict() + results.append(results_item) + + next_: Union[None, Unset, str] + if isinstance(self.next_, Unset): + next_ = UNSET + else: + next_ = self.next_ + + previous: Union[None, Unset, str] + if isinstance(self.previous, Unset): + previous = UNSET + else: + previous = self.previous + + field_dict: dict[str, Any] = {} + field_dict.update(self.additional_properties) + field_dict.update( + { + "count": count, + "results": results, + } + ) + if next_ is not UNSET: + field_dict["next"] = next_ + if previous is not UNSET: + field_dict["previous"] = previous + + return field_dict + + @classmethod + def from_dict(cls: type[T], src_dict: dict[str, Any]) -> T: + from ..models.application import Application + + d = src_dict.copy() + count = d.pop("count") + + results = [] + _results = d.pop("results") + for results_item_data in _results: + results_item = Application.from_dict(results_item_data) + + results.append(results_item) + + def _parse_next_(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) + + next_ = _parse_next_(d.pop("next", UNSET)) + + def _parse_previous(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) + + previous = _parse_previous(d.pop("previous", UNSET)) + + paginated_application_list = cls( + count=count, + results=results, + next_=next_, + previous=previous, + ) + + paginated_application_list.additional_properties = d + return paginated_application_list + + @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/gooyal_accounts_client/models/paginated_public_user_list.py b/gooyal_accounts_client/models/paginated_public_user_list.py new file mode 100644 index 0000000..e7096e5 --- /dev/null +++ b/gooyal_accounts_client/models/paginated_public_user_list.py @@ -0,0 +1,122 @@ +from typing import TYPE_CHECKING, Any, 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.public_user import PublicUser + + +T = TypeVar("T", bound="PaginatedPublicUserList") + + +@_attrs_define +class PaginatedPublicUserList: + """ + Attributes: + count (int): Example: 123. + results (list['PublicUser']): + next_ (Union[None, Unset, str]): Example: http://api.example.org/accounts/?page=4. + previous (Union[None, Unset, str]): Example: http://api.example.org/accounts/?page=2. + """ + + count: int + results: list["PublicUser"] + next_: Union[None, Unset, str] = UNSET + previous: Union[None, Unset, str] = UNSET + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) + + def to_dict(self) -> dict[str, Any]: + count = self.count + + results = [] + for results_item_data in self.results: + results_item = results_item_data.to_dict() + results.append(results_item) + + next_: Union[None, Unset, str] + if isinstance(self.next_, Unset): + next_ = UNSET + else: + next_ = self.next_ + + previous: Union[None, Unset, str] + if isinstance(self.previous, Unset): + previous = UNSET + else: + previous = self.previous + + field_dict: dict[str, Any] = {} + field_dict.update(self.additional_properties) + field_dict.update( + { + "count": count, + "results": results, + } + ) + if next_ is not UNSET: + field_dict["next"] = next_ + if previous is not UNSET: + field_dict["previous"] = previous + + return field_dict + + @classmethod + def from_dict(cls: type[T], src_dict: dict[str, Any]) -> T: + from ..models.public_user import PublicUser + + d = src_dict.copy() + count = d.pop("count") + + results = [] + _results = d.pop("results") + for results_item_data in _results: + results_item = PublicUser.from_dict(results_item_data) + + results.append(results_item) + + def _parse_next_(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) + + next_ = _parse_next_(d.pop("next", UNSET)) + + def _parse_previous(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) + + previous = _parse_previous(d.pop("previous", UNSET)) + + paginated_public_user_list = cls( + count=count, + results=results, + next_=next_, + previous=previous, + ) + + paginated_public_user_list.additional_properties = d + return paginated_public_user_list + + @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/gooyal_accounts_client/models/patched_account.py b/gooyal_accounts_client/models/patched_account.py new file mode 100644 index 0000000..b01553d --- /dev/null +++ b/gooyal_accounts_client/models/patched_account.py @@ -0,0 +1,289 @@ +from typing import Any, TypeVar, Union, cast +from uuid import UUID + +from attrs import define as _attrs_define +from attrs import field as _attrs_field + +from ..types import UNSET, Unset + +T = TypeVar("T", bound="PatchedAccount") + + +@_attrs_define +class PatchedAccount: + """ + Attributes: + uuid (Union[Unset, UUID]): + username (Union[None, Unset, str]): Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only. + email (Union[Unset, str]): + phone_number (Union[Unset, str]): + first_name (Union[Unset, str]): + last_name (Union[Unset, str]): + name (Union[Unset, str]): + avatar (Union[None, Unset, str]): + iban (Union[None, Unset, str]): + iban_verified (Union[None, Unset, bool]): + province (Union[None, Unset, int]): + province_name (Union[Unset, str]): + city (Union[None, Unset, int]): + city_name (Union[Unset, str]): + postal_code (Union[None, Unset, str]): + address (Union[None, Unset, str]): + """ + + uuid: Union[Unset, UUID] = UNSET + username: Union[None, Unset, str] = UNSET + email: Union[Unset, str] = UNSET + phone_number: Union[Unset, str] = UNSET + first_name: Union[Unset, str] = UNSET + last_name: Union[Unset, str] = UNSET + name: Union[Unset, str] = UNSET + avatar: Union[None, Unset, str] = UNSET + iban: Union[None, Unset, str] = UNSET + iban_verified: Union[None, Unset, bool] = UNSET + province: Union[None, Unset, int] = UNSET + province_name: Union[Unset, str] = UNSET + city: Union[None, Unset, int] = UNSET + city_name: Union[Unset, str] = UNSET + postal_code: Union[None, Unset, str] = UNSET + address: Union[None, Unset, str] = UNSET + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) + + def to_dict(self) -> dict[str, Any]: + uuid: Union[Unset, str] = UNSET + if not isinstance(self.uuid, Unset): + uuid = str(self.uuid) + + username: Union[None, Unset, str] + if isinstance(self.username, Unset): + username = UNSET + else: + username = self.username + + email = self.email + + phone_number = self.phone_number + + first_name = self.first_name + + last_name = self.last_name + + name = self.name + + avatar: Union[None, Unset, str] + if isinstance(self.avatar, Unset): + avatar = UNSET + else: + avatar = self.avatar + + iban: Union[None, Unset, str] + if isinstance(self.iban, Unset): + iban = UNSET + else: + iban = self.iban + + iban_verified: Union[None, Unset, bool] + if isinstance(self.iban_verified, Unset): + iban_verified = UNSET + else: + iban_verified = self.iban_verified + + province: Union[None, Unset, int] + if isinstance(self.province, Unset): + province = UNSET + else: + province = self.province + + province_name = self.province_name + + city: Union[None, Unset, int] + if isinstance(self.city, Unset): + city = UNSET + else: + city = self.city + + city_name = self.city_name + + postal_code: Union[None, Unset, str] + if isinstance(self.postal_code, Unset): + postal_code = UNSET + else: + postal_code = self.postal_code + + address: Union[None, Unset, str] + if isinstance(self.address, Unset): + address = UNSET + else: + address = self.address + + field_dict: dict[str, Any] = {} + field_dict.update(self.additional_properties) + field_dict.update({}) + if uuid is not UNSET: + field_dict["uuid"] = uuid + if username is not UNSET: + field_dict["username"] = username + if email is not UNSET: + field_dict["email"] = email + if phone_number is not UNSET: + field_dict["phone_number"] = phone_number + if first_name is not UNSET: + field_dict["first_name"] = first_name + if last_name is not UNSET: + field_dict["last_name"] = last_name + if name is not UNSET: + field_dict["name"] = name + if avatar is not UNSET: + field_dict["avatar"] = avatar + if iban is not UNSET: + field_dict["iban"] = iban + if iban_verified is not UNSET: + field_dict["iban_verified"] = iban_verified + if province is not UNSET: + field_dict["province"] = province + if province_name is not UNSET: + field_dict["province_name"] = province_name + if city is not UNSET: + field_dict["city"] = city + if city_name is not UNSET: + field_dict["city_name"] = city_name + if postal_code is not UNSET: + field_dict["postal_code"] = postal_code + if address is not UNSET: + field_dict["address"] = address + + return field_dict + + @classmethod + def from_dict(cls: type[T], src_dict: dict[str, Any]) -> T: + d = src_dict.copy() + _uuid = d.pop("uuid", UNSET) + uuid: Union[Unset, UUID] + if isinstance(_uuid, Unset): + uuid = UNSET + else: + uuid = UUID(_uuid) + + def _parse_username(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) + + username = _parse_username(d.pop("username", UNSET)) + + email = d.pop("email", UNSET) + + phone_number = d.pop("phone_number", UNSET) + + first_name = d.pop("first_name", UNSET) + + last_name = d.pop("last_name", UNSET) + + name = d.pop("name", UNSET) + + def _parse_avatar(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) + + avatar = _parse_avatar(d.pop("avatar", UNSET)) + + def _parse_iban(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) + + iban = _parse_iban(d.pop("iban", UNSET)) + + def _parse_iban_verified(data: object) -> Union[None, Unset, bool]: + if data is None: + return data + if isinstance(data, Unset): + return data + return cast(Union[None, Unset, bool], data) + + iban_verified = _parse_iban_verified(d.pop("iban_verified", UNSET)) + + def _parse_province(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) + + province = _parse_province(d.pop("province", UNSET)) + + province_name = d.pop("province_name", UNSET) + + def _parse_city(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) + + city = _parse_city(d.pop("city", UNSET)) + + city_name = d.pop("city_name", UNSET) + + def _parse_postal_code(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) + + postal_code = _parse_postal_code(d.pop("postal_code", UNSET)) + + def _parse_address(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) + + address = _parse_address(d.pop("address", UNSET)) + + patched_account = cls( + uuid=uuid, + username=username, + email=email, + phone_number=phone_number, + first_name=first_name, + last_name=last_name, + name=name, + avatar=avatar, + iban=iban, + iban_verified=iban_verified, + province=province, + province_name=province_name, + city=city, + city_name=city_name, + postal_code=postal_code, + address=address, + ) + + patched_account.additional_properties = d + return patched_account + + @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/gooyal_accounts_client/models/patched_change_password.py b/gooyal_accounts_client/models/patched_change_password.py new file mode 100644 index 0000000..5651f7e --- /dev/null +++ b/gooyal_accounts_client/models/patched_change_password.py @@ -0,0 +1,76 @@ +from typing import Any, 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="PatchedChangePassword") + + +@_attrs_define +class PatchedChangePassword: + """ + Attributes: + old_password (Union[Unset, str]): + old_password_field (Union[Unset, str]): Default: 'password'. + new_password (Union[Unset, str]): + """ + + old_password: Union[Unset, str] = UNSET + old_password_field: Union[Unset, str] = "password" + new_password: Union[Unset, str] = UNSET + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) + + def to_dict(self) -> dict[str, Any]: + old_password = self.old_password + + old_password_field = self.old_password_field + + new_password = self.new_password + + field_dict: dict[str, Any] = {} + field_dict.update(self.additional_properties) + field_dict.update({}) + if old_password is not UNSET: + field_dict["old_password"] = old_password + if old_password_field is not UNSET: + field_dict["old_password_field"] = old_password_field + if new_password is not UNSET: + field_dict["new_password"] = new_password + + return field_dict + + @classmethod + def from_dict(cls: type[T], src_dict: dict[str, Any]) -> T: + d = src_dict.copy() + old_password = d.pop("old_password", UNSET) + + old_password_field = d.pop("old_password_field", UNSET) + + new_password = d.pop("new_password", UNSET) + + patched_change_password = cls( + old_password=old_password, + old_password_field=old_password_field, + new_password=new_password, + ) + + patched_change_password.additional_properties = d + return patched_change_password + + @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/gooyal_accounts_client/models/public_user.py b/gooyal_accounts_client/models/public_user.py new file mode 100644 index 0000000..7968433 --- /dev/null +++ b/gooyal_accounts_client/models/public_user.py @@ -0,0 +1,112 @@ +from typing import Any, TypeVar, Union, cast +from uuid import UUID + +from attrs import define as _attrs_define +from attrs import field as _attrs_field + +T = TypeVar("T", bound="PublicUser") + + +@_attrs_define +class PublicUser: + """ + Attributes: + avatar (Union[None, str]): + name (str): + username (Union[None, str]): Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only. + first_name (str): + last_name (str): + uuid (UUID): + """ + + avatar: Union[None, str] + name: str + username: Union[None, str] + first_name: str + last_name: str + uuid: UUID + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) + + def to_dict(self) -> dict[str, Any]: + avatar: Union[None, str] + avatar = self.avatar + + name = self.name + + username: Union[None, str] + username = self.username + + first_name = self.first_name + + last_name = self.last_name + + uuid = str(self.uuid) + + field_dict: dict[str, Any] = {} + field_dict.update(self.additional_properties) + field_dict.update( + { + "avatar": avatar, + "name": name, + "username": username, + "first_name": first_name, + "last_name": last_name, + "uuid": uuid, + } + ) + + return field_dict + + @classmethod + def from_dict(cls: type[T], src_dict: dict[str, Any]) -> T: + d = src_dict.copy() + + def _parse_avatar(data: object) -> Union[None, str]: + if data is None: + return data + return cast(Union[None, str], data) + + avatar = _parse_avatar(d.pop("avatar")) + + name = d.pop("name") + + def _parse_username(data: object) -> Union[None, str]: + if data is None: + return data + return cast(Union[None, str], data) + + username = _parse_username(d.pop("username")) + + first_name = d.pop("first_name") + + last_name = d.pop("last_name") + + uuid = UUID(d.pop("uuid")) + + public_user = cls( + avatar=avatar, + name=name, + username=username, + first_name=first_name, + last_name=last_name, + uuid=uuid, + ) + + public_user.additional_properties = d + return public_user + + @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/gooyal_accounts_client/models/request_otp.py b/gooyal_accounts_client/models/request_otp.py new file mode 100644 index 0000000..e67b1e5 --- /dev/null +++ b/gooyal_accounts_client/models/request_otp.py @@ -0,0 +1,93 @@ +import datetime +from typing import Any, TypeVar, Union, cast + +from attrs import define as _attrs_define +from attrs import field as _attrs_field +from dateutil.parser import isoparse + +T = TypeVar("T", bound="RequestOTP") + + +@_attrs_define +class RequestOTP: + """ + Attributes: + phone_number (str): + otp_expire (Union[None, datetime.datetime]): + ttl (str): + """ + + phone_number: str + otp_expire: Union[None, datetime.datetime] + ttl: str + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) + + def to_dict(self) -> dict[str, Any]: + phone_number = self.phone_number + + otp_expire: Union[None, str] + if isinstance(self.otp_expire, datetime.datetime): + otp_expire = self.otp_expire.isoformat() + else: + otp_expire = self.otp_expire + + ttl = self.ttl + + field_dict: dict[str, Any] = {} + field_dict.update(self.additional_properties) + field_dict.update( + { + "phone_number": phone_number, + "otp_expire": otp_expire, + "ttl": ttl, + } + ) + + return field_dict + + @classmethod + def from_dict(cls: type[T], src_dict: dict[str, Any]) -> T: + d = src_dict.copy() + phone_number = d.pop("phone_number") + + def _parse_otp_expire(data: object) -> Union[None, datetime.datetime]: + if data is None: + return data + try: + if not isinstance(data, str): + raise TypeError() + otp_expire_type_0 = isoparse(data) + + return otp_expire_type_0 + except: # noqa: E722 + pass + return cast(Union[None, datetime.datetime], data) + + otp_expire = _parse_otp_expire(d.pop("otp_expire")) + + ttl = d.pop("ttl") + + request_otp = cls( + phone_number=phone_number, + otp_expire=otp_expire, + ttl=ttl, + ) + + request_otp.additional_properties = d + return request_otp + + @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/gooyal_accounts_client/models/request_ott.py b/gooyal_accounts_client/models/request_ott.py new file mode 100644 index 0000000..75c5b6f --- /dev/null +++ b/gooyal_accounts_client/models/request_ott.py @@ -0,0 +1,99 @@ +import datetime +from typing import Any, TypeVar, Union, cast + +from attrs import define as _attrs_define +from attrs import field as _attrs_field +from dateutil.parser import isoparse + +T = TypeVar("T", bound="RequestOTT") + + +@_attrs_define +class RequestOTT: + """ + Attributes: + application (str): + ott (Union[None, str]): + ott_expire (Union[None, datetime.datetime]): + """ + + application: str + ott: Union[None, str] + ott_expire: Union[None, datetime.datetime] + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) + + def to_dict(self) -> dict[str, Any]: + application = self.application + + ott: Union[None, str] + ott = self.ott + + ott_expire: Union[None, str] + if isinstance(self.ott_expire, datetime.datetime): + ott_expire = self.ott_expire.isoformat() + else: + ott_expire = self.ott_expire + + field_dict: dict[str, Any] = {} + field_dict.update(self.additional_properties) + field_dict.update( + { + "application": application, + "ott": ott, + "ott_expire": ott_expire, + } + ) + + return field_dict + + @classmethod + def from_dict(cls: type[T], src_dict: dict[str, Any]) -> T: + d = src_dict.copy() + application = d.pop("application") + + def _parse_ott(data: object) -> Union[None, str]: + if data is None: + return data + return cast(Union[None, str], data) + + ott = _parse_ott(d.pop("ott")) + + def _parse_ott_expire(data: object) -> Union[None, datetime.datetime]: + if data is None: + return data + try: + if not isinstance(data, str): + raise TypeError() + ott_expire_type_0 = isoparse(data) + + return ott_expire_type_0 + except: # noqa: E722 + pass + return cast(Union[None, datetime.datetime], data) + + ott_expire = _parse_ott_expire(d.pop("ott_expire")) + + request_ott = cls( + application=application, + ott=ott, + ott_expire=ott_expire, + ) + + request_ott.additional_properties = d + return request_ott + + @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/gooyal_accounts_client/py.typed b/gooyal_accounts_client/py.typed new file mode 100644 index 0000000..1aad327 --- /dev/null +++ b/gooyal_accounts_client/py.typed @@ -0,0 +1 @@ +# Marker file for PEP 561 \ No newline at end of file diff --git a/gooyal_accounts_client/types.py b/gooyal_accounts_client/types.py new file mode 100644 index 0000000..b9ed58b --- /dev/null +++ b/gooyal_accounts_client/types.py @@ -0,0 +1,46 @@ +"""Contains some shared types for properties""" + +from collections.abc import MutableMapping +from http import HTTPStatus +from typing import BinaryIO, Generic, Literal, Optional, 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__ = ["UNSET", "File", "FileJsonType", "Response", "Unset"] diff --git a/requirements.in b/requirements.in index d735fe8..223256f 100644 --- a/requirements.in +++ b/requirements.in @@ -19,3 +19,5 @@ django-betterforms django-crispy-forms crispy_bootstrap5 psycopg[binary] +django-redis +httpx diff --git a/requirements.txt b/requirements.txt index 9239d4f..57b7c18 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,6 +6,8 @@ # amqp==5.2.0 # via kombu +anyio==4.8.0 + # via httpx asgiref==3.8.1 # via # django @@ -21,7 +23,10 @@ billiard==4.2.0 celery==5.4.0 # via -r requirements.in certifi==2024.6.2 - # via requests + # via + # httpcore + # httpx + # requests cffi==1.16.0 # via cryptography charset-normalizer==3.3.2 @@ -52,6 +57,7 @@ django==5.0.6 # django-filter # django-jalali-date # django-oauth-toolkit + # django-redis # djangorestframework # drf-spectacular django-betterforms==2.0.0 @@ -68,6 +74,8 @@ django-jalali-date==1.1.3 # via -r requirements.in django-oauth-toolkit==2.4.0 # via -r requirements.in +django-redis==5.4.0 + # via -r requirements.in djangorestframework==3.15.2 # via # -r requirements.in @@ -80,8 +88,17 @@ greenlet==3.0.3 # via gevent gunicorn==22.0.0 # via -r requirements.in +h11==0.14.0 + # via httpcore +httpcore==1.0.7 + # via httpx +httpx==0.28.1 + # via -r requirements.in idna==3.7 - # via requests + # via + # anyio + # httpx + # requests inflection==0.5.1 # via drf-spectacular jalali-core==1.0.0 @@ -121,7 +138,9 @@ pytz==2024.1 pyyaml==6.0.1 # via drf-spectacular redis==5.0.6 - # via -r requirements.in + # via + # -r requirements.in + # django-redis referencing==0.35.1 # via # jsonschema @@ -134,10 +153,13 @@ rpds-py==0.18.1 # referencing six==1.16.0 # via python-dateutil +sniffio==1.3.1 + # via anyio sqlparse==0.5.0 # via django typing-extensions==4.12.2 # via + # anyio # jwcrypto # psycopg tzdata==2024.1 diff --git a/utils/accounts_client.py b/utils/accounts_client.py new file mode 100644 index 0000000..1143d0b --- /dev/null +++ b/utils/accounts_client.py @@ -0,0 +1,59 @@ +import time + +import requests +from django.conf import settings +from django.core.cache import cache + +from gooyal_accounts_client import AuthenticatedClient +from gooyal_accounts_client.models import PublicUser, Application +from gooyal_accounts_client.api.users import users_api_users_retrieve +from gooyal_accounts_client.api.oauth2 import oauth2_apis_applications_retrieve +from gooyal_accounts_client.types import Response + +from authlib.integrations.django_client import OAuth + + + +def login_as_client_credentials(): + access_token = cache.get('wallet_access_token') + # expires_in = self.auth_data.get('expires_in') + # created_at = self.auth_data.get('created_at') + # + # if access_token and expires_in > time.time() - created_at: + # return self.auth_data + if access_token: + print('already in cache') + return access_token + + print('not in cache') + + data = { + "grant_type": 'client_credentials', + "scope": settings.SCOPES, + } + auth = (settings.CLIENT_ID, settings.CLIENT_SECRET) + + response = requests.post(f'{settings.BASE_OAUTH2_PROVIDER_PUBLIC_URL}/token/', + data=data, + auth=auth) + + auth_data = response.json() + if 'access_token' in auth_data: + auth_data['created_at'] = time.time() + cache.set('wallet_access_token', auth_data) + + return auth_data + + +access_token = login_as_client_credentials()['access_token'] + +client = AuthenticatedClient(base_url="https://accounts.gooyal.com", token=access_token) + + +def get_user_details(uuid): + data: PublicUser = users_api_users_retrieve.sync(client=client, uuid=uuid) + print(data) + # or if you need more info (e.g. status_code) + # response: Response[MyDataModel] = get_my_data_model.sync_detailed(client=client) + + return data \ No newline at end of file diff --git a/wallet/settings.py b/wallet/settings.py index 4212c83..06b0ae9 100644 --- a/wallet/settings.py +++ b/wallet/settings.py @@ -81,7 +81,7 @@ BASE_OAUTH2_PROVIDER_PRIVATE_URL = config("BASE_OAUTH2_PROVIDER_PRIVATE_URL") CLIENT_ID = config('CLIENT_ID') CLIENT_SECRET = config('CLIENT_SECRET') -SCOPES = config('SCOPES', default='') +SCOPES = config('SCOPES', default='accounts.profile:retrieve accounts.applications:list_or_retrieve') OAUTH2_PROVIDER = { # this is the list of available scopes # 'SCOPES_BACKEND_CLASS': 'apps.gooyal_oauth2.scopes.Scopes', @@ -249,3 +249,13 @@ JALALI_DATE_DEFAULTS = { 'datetime': '%H:%M:%S _ %Y/%m/%d', } } + +CACHES = { + "default": { + "BACKEND": "django_redis.cache.RedisCache", + "LOCATION": config('BASE_REDIS_URL'), + "OPTIONS": { + "CLIENT_CLASS": "django_redis.client.DefaultClient", + } + } +} \ No newline at end of file