From c9b18e8d3a30976330fe797dcf17470a2f1983e1 Mon Sep 17 00:00:00 2001 From: Haydar Ghasemi Date: Mon, 1 Jun 2026 13:41:36 +0330 Subject: [PATCH] FEATURE(crm-backend): add other service clients add other service clients --- .env.example | 9 + .gitignore | 1 + utils/accounts_client.py | 76 ++++ .../gooyal_accounts_client/__init__.py | 8 + .../gooyal_accounts_client/api/__init__.py | 1 + .../api/oauth2/__init__.py | 1 + ...auth2_apis_applications_avatar_retrieve.py | 142 ++++++ .../oauth2/oauth2_apis_applications_list.py | 154 +++++++ .../oauth2_apis_applications_retrieve.py | 142 ++++++ .../api/users/__init__.py | 1 + .../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_inquiry_create.py | 151 +++++++ .../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 ++++ .../users/users_api_users_details_retrieve.py | 143 ++++++ .../api/users/users_api_users_list.py | 154 +++++++ .../api/users/users_api_users_retrieve.py | 143 ++++++ .../clients/gooyal_accounts_client/client.py | 268 +++++++++++ .../clients/gooyal_accounts_client/errors.py | 16 + .../gooyal_accounts_client/models/__init__.py | 33 ++ .../gooyal_accounts_client/models/account.py | 410 +++++++++++++++++ .../models/application.py | 106 +++++ .../models/blank_enum.py | 8 + .../models/change_password.py | 78 ++++ .../models/education_degree_enum.py | 14 + .../models/gender_enum.py | 9 + .../models/paginated_application_list.py | 123 +++++ .../models/paginated_public_user_list.py | 123 +++++ .../models/patched_account.py | 425 ++++++++++++++++++ .../models/patched_change_password.py | 77 ++++ .../models/public_user.py | 113 +++++ .../models/request_otp.py | 94 ++++ .../models/request_ott.py | 100 +++++ .../models/user_inquiry.py | 68 +++ utils/clients/gooyal_accounts_client/py.typed | 1 + utils/clients/gooyal_accounts_client/types.py | 46 ++ .../clients/gooyal_wallet_client/__init__.py | 8 + .../gooyal_wallet_client/api/__init__.py | 1 + .../api/wallet/__init__.py | 1 + .../wallet_api_application_deposit_create.py | 168 +++++++ ...i_application_deposit_rollback_retrieve.py | 160 +++++++ ...api_application_deposit_verify_retrieve.py | 160 +++++++ ...allet_api_application_transactions_list.py | 227 ++++++++++ ...t_api_application_transactions_retrieve.py | 144 ++++++ ...allet_api_application_user_wallets_list.py | 208 +++++++++ .../wallet_api_application_wallets_list.py | 174 +++++++ .../wallet_api_application_withdraw_create.py | 168 +++++++ ..._application_withdraw_rollback_retrieve.py | 160 +++++++ ...pi_application_withdraw_verify_retrieve.py | 160 +++++++ .../wallet_api_transactions_grouped_list.py | 227 ++++++++++ .../wallet/wallet_api_transactions_list.py | 227 ++++++++++ .../api/wallet/wallet_api_wallets_list.py | 195 ++++++++ utils/clients/gooyal_wallet_client/client.py | 268 +++++++++++ utils/clients/gooyal_wallet_client/errors.py | 16 + .../gooyal_wallet_client/models/__init__.py | 23 + .../gooyal_wallet_client/models/account.py | 90 ++++ .../models/application_deposit.py | 170 +++++++ .../models/application_withdraw.py | 170 +++++++ .../models/paginated_account_list.py | 123 +++++ .../paginated_transaction_grouped_list.py | 123 +++++ .../models/paginated_transaction_list.py | 123 +++++ .../gooyal_wallet_client/models/state_enum.py | 16 + .../models/transaction.py | 178 ++++++++ .../models/transaction_grouped.py | 140 ++++++ utils/clients/gooyal_wallet_client/py.typed | 1 + utils/clients/gooyal_wallet_client/types.py | 54 +++ utils/commons.py | 112 +++++ utils/exceptions.py | 93 ++++ utils/i18n.py | 14 + utils/logs/__init__.py | 4 + utils/logs/formatters.py | 77 ++++ utils/logs/handlers.py | 58 +++ utils/wallet_client.py | 139 ++++++ 78 files changed, 8744 insertions(+) create mode 100644 utils/accounts_client.py create mode 100644 utils/clients/gooyal_accounts_client/__init__.py create mode 100644 utils/clients/gooyal_accounts_client/api/__init__.py create mode 100644 utils/clients/gooyal_accounts_client/api/oauth2/__init__.py create mode 100644 utils/clients/gooyal_accounts_client/api/oauth2/oauth2_apis_applications_avatar_retrieve.py create mode 100644 utils/clients/gooyal_accounts_client/api/oauth2/oauth2_apis_applications_list.py create mode 100644 utils/clients/gooyal_accounts_client/api/oauth2/oauth2_apis_applications_retrieve.py create mode 100644 utils/clients/gooyal_accounts_client/api/users/__init__.py create mode 100644 utils/clients/gooyal_accounts_client/api/users/users_api_account_partial_update.py create mode 100644 utils/clients/gooyal_accounts_client/api/users/users_api_account_retrieve.py create mode 100644 utils/clients/gooyal_accounts_client/api/users/users_api_account_update.py create mode 100644 utils/clients/gooyal_accounts_client/api/users/users_api_change_password_partial_update.py create mode 100644 utils/clients/gooyal_accounts_client/api/users/users_api_change_password_update.py create mode 100644 utils/clients/gooyal_accounts_client/api/users/users_api_inquiry_create.py create mode 100644 utils/clients/gooyal_accounts_client/api/users/users_api_request_otp_create.py create mode 100644 utils/clients/gooyal_accounts_client/api/users/users_api_request_ott_create.py create mode 100644 utils/clients/gooyal_accounts_client/api/users/users_api_users_avatar_retrieve.py create mode 100644 utils/clients/gooyal_accounts_client/api/users/users_api_users_details_retrieve.py create mode 100644 utils/clients/gooyal_accounts_client/api/users/users_api_users_list.py create mode 100644 utils/clients/gooyal_accounts_client/api/users/users_api_users_retrieve.py create mode 100644 utils/clients/gooyal_accounts_client/client.py create mode 100644 utils/clients/gooyal_accounts_client/errors.py create mode 100644 utils/clients/gooyal_accounts_client/models/__init__.py create mode 100644 utils/clients/gooyal_accounts_client/models/account.py create mode 100644 utils/clients/gooyal_accounts_client/models/application.py create mode 100644 utils/clients/gooyal_accounts_client/models/blank_enum.py create mode 100644 utils/clients/gooyal_accounts_client/models/change_password.py create mode 100644 utils/clients/gooyal_accounts_client/models/education_degree_enum.py create mode 100644 utils/clients/gooyal_accounts_client/models/gender_enum.py create mode 100644 utils/clients/gooyal_accounts_client/models/paginated_application_list.py create mode 100644 utils/clients/gooyal_accounts_client/models/paginated_public_user_list.py create mode 100644 utils/clients/gooyal_accounts_client/models/patched_account.py create mode 100644 utils/clients/gooyal_accounts_client/models/patched_change_password.py create mode 100644 utils/clients/gooyal_accounts_client/models/public_user.py create mode 100644 utils/clients/gooyal_accounts_client/models/request_otp.py create mode 100644 utils/clients/gooyal_accounts_client/models/request_ott.py create mode 100644 utils/clients/gooyal_accounts_client/models/user_inquiry.py create mode 100644 utils/clients/gooyal_accounts_client/py.typed create mode 100644 utils/clients/gooyal_accounts_client/types.py create mode 100644 utils/clients/gooyal_wallet_client/__init__.py create mode 100644 utils/clients/gooyal_wallet_client/api/__init__.py create mode 100644 utils/clients/gooyal_wallet_client/api/wallet/__init__.py create mode 100644 utils/clients/gooyal_wallet_client/api/wallet/wallet_api_application_deposit_create.py create mode 100644 utils/clients/gooyal_wallet_client/api/wallet/wallet_api_application_deposit_rollback_retrieve.py create mode 100644 utils/clients/gooyal_wallet_client/api/wallet/wallet_api_application_deposit_verify_retrieve.py create mode 100644 utils/clients/gooyal_wallet_client/api/wallet/wallet_api_application_transactions_list.py create mode 100644 utils/clients/gooyal_wallet_client/api/wallet/wallet_api_application_transactions_retrieve.py create mode 100644 utils/clients/gooyal_wallet_client/api/wallet/wallet_api_application_user_wallets_list.py create mode 100644 utils/clients/gooyal_wallet_client/api/wallet/wallet_api_application_wallets_list.py create mode 100644 utils/clients/gooyal_wallet_client/api/wallet/wallet_api_application_withdraw_create.py create mode 100644 utils/clients/gooyal_wallet_client/api/wallet/wallet_api_application_withdraw_rollback_retrieve.py create mode 100644 utils/clients/gooyal_wallet_client/api/wallet/wallet_api_application_withdraw_verify_retrieve.py create mode 100644 utils/clients/gooyal_wallet_client/api/wallet/wallet_api_transactions_grouped_list.py create mode 100644 utils/clients/gooyal_wallet_client/api/wallet/wallet_api_transactions_list.py create mode 100644 utils/clients/gooyal_wallet_client/api/wallet/wallet_api_wallets_list.py create mode 100644 utils/clients/gooyal_wallet_client/client.py create mode 100644 utils/clients/gooyal_wallet_client/errors.py create mode 100644 utils/clients/gooyal_wallet_client/models/__init__.py create mode 100644 utils/clients/gooyal_wallet_client/models/account.py create mode 100644 utils/clients/gooyal_wallet_client/models/application_deposit.py create mode 100644 utils/clients/gooyal_wallet_client/models/application_withdraw.py create mode 100644 utils/clients/gooyal_wallet_client/models/paginated_account_list.py create mode 100644 utils/clients/gooyal_wallet_client/models/paginated_transaction_grouped_list.py create mode 100644 utils/clients/gooyal_wallet_client/models/paginated_transaction_list.py create mode 100644 utils/clients/gooyal_wallet_client/models/state_enum.py create mode 100644 utils/clients/gooyal_wallet_client/models/transaction.py create mode 100644 utils/clients/gooyal_wallet_client/models/transaction_grouped.py create mode 100644 utils/clients/gooyal_wallet_client/py.typed create mode 100644 utils/clients/gooyal_wallet_client/types.py create mode 100644 utils/commons.py create mode 100644 utils/exceptions.py create mode 100644 utils/i18n.py create mode 100644 utils/logs/__init__.py create mode 100644 utils/logs/formatters.py create mode 100644 utils/logs/handlers.py create mode 100644 utils/wallet_client.py diff --git a/.env.example b/.env.example index ded5713..e0a7cfe 100644 --- a/.env.example +++ b/.env.example @@ -16,3 +16,12 @@ OAUTH2_PROVIDER_PRIVATE_URL= OAUTH2_CLIENT_ID= OAUTH2_CLIENT_SECRET= OAUTH2_SCOPES= +OAUTH2_PROVIDER_BASE_PUBLIC_URL=https://accounts-staging.gooyal.ir/oauth2 +OAUTH2_PROVIDER_BASE_PRIVATE_URL=https://accounts-staging.gooyal.ir/oauth2 +OAUTH2_PROVIDER_CLIENT_ID=sample +OAUTH2_PROVIDER_CLIENT_SECRET=sample +OAUTH2_PROVIDER_SCOPES=wallet.application.withdraw:rollback wallet.application.deposit:rollback wallet.application.withdraw:submit wallet.application.withdraw:verify wallet.application:get_user_balance accounts.profile:detailed_retrieve +ACCOUNTS_BASE_PUBLIC_URL=https://accounts-staging.gooyal.ir +WALLET_BASE_PUBLIC_URL=https://wallet-staging.gooyal.ir +WALLET_RIAL=af7d967f-30c0-409b-9066-2549f2da5e5e +WALLET_REWARD=e7c9d4d1-4d1f-43b2-96f7-4d4a168f480d diff --git a/.gitignore b/.gitignore index 76930a3..6bf278a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.idea .DS_Store .env .venv/ diff --git a/utils/accounts_client.py b/utils/accounts_client.py new file mode 100644 index 0000000..c3dd2d8 --- /dev/null +++ b/utils/accounts_client.py @@ -0,0 +1,76 @@ +import time + +import requests +from django.conf import settings +from django.core.cache import cache +from django.db import models +from httpx import Request + +from utils.clients.gooyal_accounts_client import AuthenticatedClient +from utils.clients.gooyal_accounts_client.models import Account +from utils.clients.gooyal_accounts_client.api.users import (users_api_users_details_retrieve) +from utils.clients.gooyal_wallet_client.types import Response + +from django.conf import Settings + + + +def login_as_client_credentials(): + access_token = cache.get('settlement_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.OAUTH2_PROVIDER_SCOPES, + } + auth = (settings.OAUTH2_PROVIDER_CLIENT_ID, settings.OAUTH2_PROVIDER_CLIENT_SECRET) + + response = requests.post(f'{settings.OAUTH2_PROVIDER_BASE_PUBLIC_URL}/token/', + data=data, + auth=auth) + print(response.content) + + auth_data = response.json() + if 'access_token' in auth_data: + auth_data['created_at'] = time.time() + cache.set('settlement_access_token', auth_data, timeout=auth_data.get('expires_in') - 5) + + return auth_data + + +def log_request(request: Request): + print(request.headers['authorization']) + print( + f"Request event hook: {request.method} {request.url} {request.method} {request.headers} - Waiting for response") + + +def log_response(response): + request = response.request + print(f"Response event hook: {request.method} {request.url} - Status {response.status_code}") + + +def get_client(): + access_token = login_as_client_credentials()['access_token'] + client = AuthenticatedClient(base_url=settings.ACCOUNTS_BASE_PUBLIC_URL, token=access_token, + httpx_args={"event_hooks": {"request": [log_request], "response": [log_response]}}, + ) + return client + + +def get_user_detailed_info(uuid): + client = get_client() + response: Account = users_api_users_details_retrieve.sync(uuid=uuid, client=client) + print(response) + + return response + + diff --git a/utils/clients/gooyal_accounts_client/__init__.py b/utils/clients/gooyal_accounts_client/__init__.py new file mode 100644 index 0000000..94931df --- /dev/null +++ b/utils/clients/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/utils/clients/gooyal_accounts_client/api/__init__.py b/utils/clients/gooyal_accounts_client/api/__init__.py new file mode 100644 index 0000000..81f9fa2 --- /dev/null +++ b/utils/clients/gooyal_accounts_client/api/__init__.py @@ -0,0 +1 @@ +"""Contains methods for accessing the API""" diff --git a/utils/clients/gooyal_accounts_client/api/oauth2/__init__.py b/utils/clients/gooyal_accounts_client/api/oauth2/__init__.py new file mode 100644 index 0000000..2d7c0b2 --- /dev/null +++ b/utils/clients/gooyal_accounts_client/api/oauth2/__init__.py @@ -0,0 +1 @@ +"""Contains endpoint functions for accessing the API""" diff --git a/utils/clients/gooyal_accounts_client/api/oauth2/oauth2_apis_applications_avatar_retrieve.py b/utils/clients/gooyal_accounts_client/api/oauth2/oauth2_apis_applications_avatar_retrieve.py new file mode 100644 index 0000000..8a48f72 --- /dev/null +++ b/utils/clients/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/utils/clients/gooyal_accounts_client/api/oauth2/oauth2_apis_applications_list.py b/utils/clients/gooyal_accounts_client/api/oauth2/oauth2_apis_applications_list.py new file mode 100644 index 0000000..0683709 --- /dev/null +++ b/utils/clients/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/utils/clients/gooyal_accounts_client/api/oauth2/oauth2_apis_applications_retrieve.py b/utils/clients/gooyal_accounts_client/api/oauth2/oauth2_apis_applications_retrieve.py new file mode 100644 index 0000000..464b71b --- /dev/null +++ b/utils/clients/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/utils/clients/gooyal_accounts_client/api/users/__init__.py b/utils/clients/gooyal_accounts_client/api/users/__init__.py new file mode 100644 index 0000000..2d7c0b2 --- /dev/null +++ b/utils/clients/gooyal_accounts_client/api/users/__init__.py @@ -0,0 +1 @@ +"""Contains endpoint functions for accessing the API""" diff --git a/utils/clients/gooyal_accounts_client/api/users/users_api_account_partial_update.py b/utils/clients/gooyal_accounts_client/api/users/users_api_account_partial_update.py new file mode 100644 index 0000000..8bbbab3 --- /dev/null +++ b/utils/clients/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/utils/clients/gooyal_accounts_client/api/users/users_api_account_retrieve.py b/utils/clients/gooyal_accounts_client/api/users/users_api_account_retrieve.py new file mode 100644 index 0000000..e15e774 --- /dev/null +++ b/utils/clients/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/utils/clients/gooyal_accounts_client/api/users/users_api_account_update.py b/utils/clients/gooyal_accounts_client/api/users/users_api_account_update.py new file mode 100644 index 0000000..1a621e6 --- /dev/null +++ b/utils/clients/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/utils/clients/gooyal_accounts_client/api/users/users_api_change_password_partial_update.py b/utils/clients/gooyal_accounts_client/api/users/users_api_change_password_partial_update.py new file mode 100644 index 0000000..87f5f90 --- /dev/null +++ b/utils/clients/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/utils/clients/gooyal_accounts_client/api/users/users_api_change_password_update.py b/utils/clients/gooyal_accounts_client/api/users/users_api_change_password_update.py new file mode 100644 index 0000000..0200030 --- /dev/null +++ b/utils/clients/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/utils/clients/gooyal_accounts_client/api/users/users_api_inquiry_create.py b/utils/clients/gooyal_accounts_client/api/users/users_api_inquiry_create.py new file mode 100644 index 0000000..971684f --- /dev/null +++ b/utils/clients/gooyal_accounts_client/api/users/users_api_inquiry_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.user_inquiry import UserInquiry +from ...types import Response + + +def _get_kwargs( + *, + body: UserInquiry, +) -> dict[str, Any]: + headers: dict[str, Any] = {} + + _kwargs: dict[str, Any] = { + "method": "post", + "url": "/users/api/inquiry/", + } + + _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[UserInquiry]: + if response.status_code == 201: + response_201 = UserInquiry.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[UserInquiry]: + 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: UserInquiry, +) -> Response[UserInquiry]: + """ + Args: + body (UserInquiry): + + 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[UserInquiry] + """ + + kwargs = _get_kwargs( + body=body, + ) + + response = client.get_httpx_client().request( + **kwargs, + ) + + return _build_response(client=client, response=response) + + +def sync( + *, + client: AuthenticatedClient, + body: UserInquiry, +) -> Optional[UserInquiry]: + """ + Args: + body (UserInquiry): + + 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: + UserInquiry + """ + + return sync_detailed( + client=client, + body=body, + ).parsed + + +async def asyncio_detailed( + *, + client: AuthenticatedClient, + body: UserInquiry, +) -> Response[UserInquiry]: + """ + Args: + body (UserInquiry): + + 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[UserInquiry] + """ + + 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: UserInquiry, +) -> Optional[UserInquiry]: + """ + Args: + body (UserInquiry): + + 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: + UserInquiry + """ + + return ( + await asyncio_detailed( + client=client, + body=body, + ) + ).parsed diff --git a/utils/clients/gooyal_accounts_client/api/users/users_api_request_otp_create.py b/utils/clients/gooyal_accounts_client/api/users/users_api_request_otp_create.py new file mode 100644 index 0000000..c987308 --- /dev/null +++ b/utils/clients/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/utils/clients/gooyal_accounts_client/api/users/users_api_request_ott_create.py b/utils/clients/gooyal_accounts_client/api/users/users_api_request_ott_create.py new file mode 100644 index 0000000..13142f9 --- /dev/null +++ b/utils/clients/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/utils/clients/gooyal_accounts_client/api/users/users_api_users_avatar_retrieve.py b/utils/clients/gooyal_accounts_client/api/users/users_api_users_avatar_retrieve.py new file mode 100644 index 0000000..6c317d9 --- /dev/null +++ b/utils/clients/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/utils/clients/gooyal_accounts_client/api/users/users_api_users_details_retrieve.py b/utils/clients/gooyal_accounts_client/api/users/users_api_users_details_retrieve.py new file mode 100644 index 0000000..1da2a43 --- /dev/null +++ b/utils/clients/gooyal_accounts_client/api/users/users_api_users_details_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.account import Account +from ...types import Response + + +def _get_kwargs( + uuid: UUID, +) -> dict[str, Any]: + _kwargs: dict[str, Any] = { + "method": "get", + "url": f"/users/api/users/{uuid}/details", + } + + 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( + uuid: UUID, + *, + client: AuthenticatedClient, +) -> Response[Account]: + """ + 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[Account] + """ + + 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[Account]: + """ + 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: + Account + """ + + return sync_detailed( + uuid=uuid, + client=client, + ).parsed + + +async def asyncio_detailed( + uuid: UUID, + *, + client: AuthenticatedClient, +) -> Response[Account]: + """ + 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[Account] + """ + + 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[Account]: + """ + 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: + Account + """ + + return ( + await asyncio_detailed( + uuid=uuid, + client=client, + ) + ).parsed diff --git a/utils/clients/gooyal_accounts_client/api/users/users_api_users_list.py b/utils/clients/gooyal_accounts_client/api/users/users_api_users_list.py new file mode 100644 index 0000000..f43b9ea --- /dev/null +++ b/utils/clients/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/utils/clients/gooyal_accounts_client/api/users/users_api_users_retrieve.py b/utils/clients/gooyal_accounts_client/api/users/users_api_users_retrieve.py new file mode 100644 index 0000000..17488a5 --- /dev/null +++ b/utils/clients/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/utils/clients/gooyal_accounts_client/client.py b/utils/clients/gooyal_accounts_client/client.py new file mode 100644 index 0000000..e80446f --- /dev/null +++ b/utils/clients/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/utils/clients/gooyal_accounts_client/errors.py b/utils/clients/gooyal_accounts_client/errors.py new file mode 100644 index 0000000..5f92e76 --- /dev/null +++ b/utils/clients/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/utils/clients/gooyal_accounts_client/models/__init__.py b/utils/clients/gooyal_accounts_client/models/__init__.py new file mode 100644 index 0000000..91f431d --- /dev/null +++ b/utils/clients/gooyal_accounts_client/models/__init__.py @@ -0,0 +1,33 @@ +"""Contains all the data models used in inputs/outputs""" + +from .account import Account +from .application import Application +from .blank_enum import BlankEnum +from .change_password import ChangePassword +from .education_degree_enum import EducationDegreeEnum +from .gender_enum import GenderEnum +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 +from .user_inquiry import UserInquiry + +__all__ = ( + "Account", + "Application", + "BlankEnum", + "ChangePassword", + "EducationDegreeEnum", + "GenderEnum", + "PaginatedApplicationList", + "PaginatedPublicUserList", + "PatchedAccount", + "PatchedChangePassword", + "PublicUser", + "RequestOTP", + "RequestOTT", + "UserInquiry", +) diff --git a/utils/clients/gooyal_accounts_client/models/account.py b/utils/clients/gooyal_accounts_client/models/account.py new file mode 100644 index 0000000..b53855c --- /dev/null +++ b/utils/clients/gooyal_accounts_client/models/account.py @@ -0,0 +1,410 @@ +import datetime +from collections.abc import Mapping +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 dateutil.parser import isoparse + +from ..models.blank_enum import BlankEnum +from ..models.education_degree_enum import EducationDegreeEnum +from ..models.gender_enum import GenderEnum +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]): + gender (Union[BlankEnum, GenderEnum, None, Unset]): + education_degree (Union[BlankEnum, EducationDegreeEnum, None, Unset]): + education_field (Union[None, Unset, str]): + birthdate (Union[None, Unset, datetime.date]): + 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 + gender: Union[BlankEnum, GenderEnum, None, Unset] = UNSET + education_degree: Union[BlankEnum, EducationDegreeEnum, None, Unset] = UNSET + education_field: Union[None, Unset, str] = UNSET + birthdate: Union[None, Unset, datetime.date] = 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 + + gender: Union[None, Unset, str] + if isinstance(self.gender, Unset): + gender = UNSET + elif isinstance(self.gender, GenderEnum): + gender = self.gender.value + elif isinstance(self.gender, BlankEnum): + gender = self.gender.value + else: + gender = self.gender + + education_degree: Union[None, Unset, str] + if isinstance(self.education_degree, Unset): + education_degree = UNSET + elif isinstance(self.education_degree, EducationDegreeEnum): + education_degree = self.education_degree.value + elif isinstance(self.education_degree, BlankEnum): + education_degree = self.education_degree.value + else: + education_degree = self.education_degree + + education_field: Union[None, Unset, str] + if isinstance(self.education_field, Unset): + education_field = UNSET + else: + education_field = self.education_field + + birthdate: Union[None, Unset, str] + if isinstance(self.birthdate, Unset): + birthdate = UNSET + elif isinstance(self.birthdate, datetime.date): + birthdate = self.birthdate.isoformat() + else: + birthdate = self.birthdate + + 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 gender is not UNSET: + field_dict["gender"] = gender + if education_degree is not UNSET: + field_dict["education_degree"] = education_degree + if education_field is not UNSET: + field_dict["education_field"] = education_field + if birthdate is not UNSET: + field_dict["birthdate"] = birthdate + 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: Mapping[str, Any]) -> T: + d = dict(src_dict) + 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_gender(data: object) -> Union[BlankEnum, GenderEnum, None, Unset]: + if data is None: + return data + if isinstance(data, Unset): + return data + try: + if not isinstance(data, str): + raise TypeError() + gender_type_0 = GenderEnum(data) + + return gender_type_0 + except: # noqa: E722 + pass + try: + if not isinstance(data, str): + raise TypeError() + gender_type_1 = BlankEnum(data) + + return gender_type_1 + except: # noqa: E722 + pass + return cast(Union[BlankEnum, GenderEnum, None, Unset], data) + + gender = _parse_gender(d.pop("gender", UNSET)) + + def _parse_education_degree(data: object) -> Union[BlankEnum, EducationDegreeEnum, None, Unset]: + if data is None: + return data + if isinstance(data, Unset): + return data + try: + if not isinstance(data, str): + raise TypeError() + education_degree_type_0 = EducationDegreeEnum(data) + + return education_degree_type_0 + except: # noqa: E722 + pass + try: + if not isinstance(data, str): + raise TypeError() + education_degree_type_1 = BlankEnum(data) + + return education_degree_type_1 + except: # noqa: E722 + pass + return cast(Union[BlankEnum, EducationDegreeEnum, None, Unset], data) + + education_degree = _parse_education_degree(d.pop("education_degree", UNSET)) + + def _parse_education_field(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) + + education_field = _parse_education_field(d.pop("education_field", UNSET)) + + def _parse_birthdate(data: object) -> Union[None, Unset, datetime.date]: + if data is None: + return data + if isinstance(data, Unset): + return data + try: + if not isinstance(data, str): + raise TypeError() + birthdate_type_0 = isoparse(data).date() + + return birthdate_type_0 + except: # noqa: E722 + pass + return cast(Union[None, Unset, datetime.date], data) + + birthdate = _parse_birthdate(d.pop("birthdate", 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, + gender=gender, + education_degree=education_degree, + education_field=education_field, + birthdate=birthdate, + 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/utils/clients/gooyal_accounts_client/models/application.py b/utils/clients/gooyal_accounts_client/models/application.py new file mode 100644 index 0000000..c3538c5 --- /dev/null +++ b/utils/clients/gooyal_accounts_client/models/application.py @@ -0,0 +1,106 @@ +from collections.abc import Mapping +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="Application") + + +@_attrs_define +class Application: + """ + Attributes: + uuid (UUID): + name (str): + avatar (Union[None, str]): + client_id (str): + user (UUID): + allowed_scope (str): + """ + + uuid: UUID + name: str + avatar: Union[None, 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 + + avatar: Union[None, str] + avatar = self.avatar + + 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, + "avatar": avatar, + "client_id": client_id, + "user": user, + "allowed_scope": allowed_scope, + } + ) + + return field_dict + + @classmethod + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + d = dict(src_dict) + uuid = UUID(d.pop("uuid")) + + name = d.pop("name") + + 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")) + + client_id = d.pop("client_id") + + user = UUID(d.pop("user")) + + allowed_scope = d.pop("allowed_scope") + + application = cls( + uuid=uuid, + name=name, + avatar=avatar, + 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/utils/clients/gooyal_accounts_client/models/blank_enum.py b/utils/clients/gooyal_accounts_client/models/blank_enum.py new file mode 100644 index 0000000..8a87569 --- /dev/null +++ b/utils/clients/gooyal_accounts_client/models/blank_enum.py @@ -0,0 +1,8 @@ +from enum import Enum + + +class BlankEnum(str, Enum): + VALUE_0 = "" + + def __str__(self) -> str: + return str(self.value) diff --git a/utils/clients/gooyal_accounts_client/models/change_password.py b/utils/clients/gooyal_accounts_client/models/change_password.py new file mode 100644 index 0000000..a49b227 --- /dev/null +++ b/utils/clients/gooyal_accounts_client/models/change_password.py @@ -0,0 +1,78 @@ +from collections.abc import Mapping +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: Mapping[str, Any]) -> T: + d = dict(src_dict) + 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/utils/clients/gooyal_accounts_client/models/education_degree_enum.py b/utils/clients/gooyal_accounts_client/models/education_degree_enum.py new file mode 100644 index 0000000..d8d5573 --- /dev/null +++ b/utils/clients/gooyal_accounts_client/models/education_degree_enum.py @@ -0,0 +1,14 @@ +from enum import Enum + + +class EducationDegreeEnum(str, Enum): + ASSOCIATE = "associate" + BACHELORS = "bachelors" + DOCTORATE = "doctorate" + HIGH = "high" + MASTERS = "masters" + MIDDLE = "middle" + PRIMARY = "primary" + + def __str__(self) -> str: + return str(self.value) diff --git a/utils/clients/gooyal_accounts_client/models/gender_enum.py b/utils/clients/gooyal_accounts_client/models/gender_enum.py new file mode 100644 index 0000000..2da7760 --- /dev/null +++ b/utils/clients/gooyal_accounts_client/models/gender_enum.py @@ -0,0 +1,9 @@ +from enum import Enum + + +class GenderEnum(str, Enum): + F = "f" + M = "m" + + def __str__(self) -> str: + return str(self.value) diff --git a/utils/clients/gooyal_accounts_client/models/paginated_application_list.py b/utils/clients/gooyal_accounts_client/models/paginated_application_list.py new file mode 100644 index 0000000..3d76808 --- /dev/null +++ b/utils/clients/gooyal_accounts_client/models/paginated_application_list.py @@ -0,0 +1,123 @@ +from collections.abc import Mapping +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: Mapping[str, Any]) -> T: + from ..models.application import Application + + d = dict(src_dict) + 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/utils/clients/gooyal_accounts_client/models/paginated_public_user_list.py b/utils/clients/gooyal_accounts_client/models/paginated_public_user_list.py new file mode 100644 index 0000000..dbea027 --- /dev/null +++ b/utils/clients/gooyal_accounts_client/models/paginated_public_user_list.py @@ -0,0 +1,123 @@ +from collections.abc import Mapping +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: Mapping[str, Any]) -> T: + from ..models.public_user import PublicUser + + d = dict(src_dict) + 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/utils/clients/gooyal_accounts_client/models/patched_account.py b/utils/clients/gooyal_accounts_client/models/patched_account.py new file mode 100644 index 0000000..837b3be --- /dev/null +++ b/utils/clients/gooyal_accounts_client/models/patched_account.py @@ -0,0 +1,425 @@ +import datetime +from collections.abc import Mapping +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 dateutil.parser import isoparse + +from ..models.blank_enum import BlankEnum +from ..models.education_degree_enum import EducationDegreeEnum +from ..models.gender_enum import GenderEnum +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]): + gender (Union[BlankEnum, GenderEnum, None, Unset]): + education_degree (Union[BlankEnum, EducationDegreeEnum, None, Unset]): + education_field (Union[None, Unset, str]): + birthdate (Union[None, Unset, datetime.date]): + 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 + gender: Union[BlankEnum, GenderEnum, None, Unset] = UNSET + education_degree: Union[BlankEnum, EducationDegreeEnum, None, Unset] = UNSET + education_field: Union[None, Unset, str] = UNSET + birthdate: Union[None, Unset, datetime.date] = 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 + + gender: Union[None, Unset, str] + if isinstance(self.gender, Unset): + gender = UNSET + elif isinstance(self.gender, GenderEnum): + gender = self.gender.value + elif isinstance(self.gender, BlankEnum): + gender = self.gender.value + else: + gender = self.gender + + education_degree: Union[None, Unset, str] + if isinstance(self.education_degree, Unset): + education_degree = UNSET + elif isinstance(self.education_degree, EducationDegreeEnum): + education_degree = self.education_degree.value + elif isinstance(self.education_degree, BlankEnum): + education_degree = self.education_degree.value + else: + education_degree = self.education_degree + + education_field: Union[None, Unset, str] + if isinstance(self.education_field, Unset): + education_field = UNSET + else: + education_field = self.education_field + + birthdate: Union[None, Unset, str] + if isinstance(self.birthdate, Unset): + birthdate = UNSET + elif isinstance(self.birthdate, datetime.date): + birthdate = self.birthdate.isoformat() + else: + birthdate = self.birthdate + + 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 gender is not UNSET: + field_dict["gender"] = gender + if education_degree is not UNSET: + field_dict["education_degree"] = education_degree + if education_field is not UNSET: + field_dict["education_field"] = education_field + if birthdate is not UNSET: + field_dict["birthdate"] = birthdate + 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: Mapping[str, Any]) -> T: + d = dict(src_dict) + _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_gender(data: object) -> Union[BlankEnum, GenderEnum, None, Unset]: + if data is None: + return data + if isinstance(data, Unset): + return data + try: + if not isinstance(data, str): + raise TypeError() + gender_type_0 = GenderEnum(data) + + return gender_type_0 + except: # noqa: E722 + pass + try: + if not isinstance(data, str): + raise TypeError() + gender_type_1 = BlankEnum(data) + + return gender_type_1 + except: # noqa: E722 + pass + return cast(Union[BlankEnum, GenderEnum, None, Unset], data) + + gender = _parse_gender(d.pop("gender", UNSET)) + + def _parse_education_degree(data: object) -> Union[BlankEnum, EducationDegreeEnum, None, Unset]: + if data is None: + return data + if isinstance(data, Unset): + return data + try: + if not isinstance(data, str): + raise TypeError() + education_degree_type_0 = EducationDegreeEnum(data) + + return education_degree_type_0 + except: # noqa: E722 + pass + try: + if not isinstance(data, str): + raise TypeError() + education_degree_type_1 = BlankEnum(data) + + return education_degree_type_1 + except: # noqa: E722 + pass + return cast(Union[BlankEnum, EducationDegreeEnum, None, Unset], data) + + education_degree = _parse_education_degree(d.pop("education_degree", UNSET)) + + def _parse_education_field(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) + + education_field = _parse_education_field(d.pop("education_field", UNSET)) + + def _parse_birthdate(data: object) -> Union[None, Unset, datetime.date]: + if data is None: + return data + if isinstance(data, Unset): + return data + try: + if not isinstance(data, str): + raise TypeError() + birthdate_type_0 = isoparse(data).date() + + return birthdate_type_0 + except: # noqa: E722 + pass + return cast(Union[None, Unset, datetime.date], data) + + birthdate = _parse_birthdate(d.pop("birthdate", 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, + gender=gender, + education_degree=education_degree, + education_field=education_field, + birthdate=birthdate, + 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/utils/clients/gooyal_accounts_client/models/patched_change_password.py b/utils/clients/gooyal_accounts_client/models/patched_change_password.py new file mode 100644 index 0000000..60bb80a --- /dev/null +++ b/utils/clients/gooyal_accounts_client/models/patched_change_password.py @@ -0,0 +1,77 @@ +from collections.abc import Mapping +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: Mapping[str, Any]) -> T: + d = dict(src_dict) + 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/utils/clients/gooyal_accounts_client/models/public_user.py b/utils/clients/gooyal_accounts_client/models/public_user.py new file mode 100644 index 0000000..7d834e8 --- /dev/null +++ b/utils/clients/gooyal_accounts_client/models/public_user.py @@ -0,0 +1,113 @@ +from collections.abc import Mapping +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: Mapping[str, Any]) -> T: + d = dict(src_dict) + + 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/utils/clients/gooyal_accounts_client/models/request_otp.py b/utils/clients/gooyal_accounts_client/models/request_otp.py new file mode 100644 index 0000000..a72c886 --- /dev/null +++ b/utils/clients/gooyal_accounts_client/models/request_otp.py @@ -0,0 +1,94 @@ +import datetime +from collections.abc import Mapping +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: Mapping[str, Any]) -> T: + d = dict(src_dict) + 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/utils/clients/gooyal_accounts_client/models/request_ott.py b/utils/clients/gooyal_accounts_client/models/request_ott.py new file mode 100644 index 0000000..a48091b --- /dev/null +++ b/utils/clients/gooyal_accounts_client/models/request_ott.py @@ -0,0 +1,100 @@ +import datetime +from collections.abc import Mapping +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: Mapping[str, Any]) -> T: + d = dict(src_dict) + 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/utils/clients/gooyal_accounts_client/models/user_inquiry.py b/utils/clients/gooyal_accounts_client/models/user_inquiry.py new file mode 100644 index 0000000..d507185 --- /dev/null +++ b/utils/clients/gooyal_accounts_client/models/user_inquiry.py @@ -0,0 +1,68 @@ +from collections.abc import Mapping +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="UserInquiry") + + +@_attrs_define +class UserInquiry: + """ + Attributes: + uuid (UUID): + phone_number (str): + """ + + uuid: UUID + phone_number: str + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) + + def to_dict(self) -> dict[str, Any]: + uuid = str(self.uuid) + + phone_number = self.phone_number + + field_dict: dict[str, Any] = {} + field_dict.update(self.additional_properties) + field_dict.update( + { + "uuid": uuid, + "phone_number": phone_number, + } + ) + + return field_dict + + @classmethod + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + d = dict(src_dict) + uuid = UUID(d.pop("uuid")) + + phone_number = d.pop("phone_number") + + user_inquiry = cls( + uuid=uuid, + phone_number=phone_number, + ) + + user_inquiry.additional_properties = d + return user_inquiry + + @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/utils/clients/gooyal_accounts_client/py.typed b/utils/clients/gooyal_accounts_client/py.typed new file mode 100644 index 0000000..1aad327 --- /dev/null +++ b/utils/clients/gooyal_accounts_client/py.typed @@ -0,0 +1 @@ +# Marker file for PEP 561 \ No newline at end of file diff --git a/utils/clients/gooyal_accounts_client/types.py b/utils/clients/gooyal_accounts_client/types.py new file mode 100644 index 0000000..b9ed58b --- /dev/null +++ b/utils/clients/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/utils/clients/gooyal_wallet_client/__init__.py b/utils/clients/gooyal_wallet_client/__init__.py new file mode 100644 index 0000000..fe01c71 --- /dev/null +++ b/utils/clients/gooyal_wallet_client/__init__.py @@ -0,0 +1,8 @@ +"""A client library for accessing Gooyal Wallet""" + +from .client import AuthenticatedClient, Client + +__all__ = ( + "AuthenticatedClient", + "Client", +) diff --git a/utils/clients/gooyal_wallet_client/api/__init__.py b/utils/clients/gooyal_wallet_client/api/__init__.py new file mode 100644 index 0000000..81f9fa2 --- /dev/null +++ b/utils/clients/gooyal_wallet_client/api/__init__.py @@ -0,0 +1 @@ +"""Contains methods for accessing the API""" diff --git a/utils/clients/gooyal_wallet_client/api/wallet/__init__.py b/utils/clients/gooyal_wallet_client/api/wallet/__init__.py new file mode 100644 index 0000000..2d7c0b2 --- /dev/null +++ b/utils/clients/gooyal_wallet_client/api/wallet/__init__.py @@ -0,0 +1 @@ +"""Contains endpoint functions for accessing the API""" diff --git a/utils/clients/gooyal_wallet_client/api/wallet/wallet_api_application_deposit_create.py b/utils/clients/gooyal_wallet_client/api/wallet/wallet_api_application_deposit_create.py new file mode 100644 index 0000000..c4f8fa1 --- /dev/null +++ b/utils/clients/gooyal_wallet_client/api/wallet/wallet_api_application_deposit_create.py @@ -0,0 +1,168 @@ +from http import HTTPStatus +from typing import Any, Optional, Union + +import httpx + +from ... import errors +from ...client import AuthenticatedClient, Client +from ...models.application_deposit import ApplicationDeposit +from ...types import Response + + +def _get_kwargs( + payer_wallet: str, + *, + body: ApplicationDeposit, +) -> dict[str, Any]: + headers: dict[str, Any] = {} + + _kwargs: dict[str, Any] = { + "method": "post", + "url": f"/wallet/api/application/{payer_wallet}/deposit/", + } + + _kwargs["json"] = body.to_dict() + + headers["Content-Type"] = "application/json" + + _kwargs["headers"] = headers + return _kwargs + + +def _parse_response( + *, client: Union[AuthenticatedClient, Client], response: httpx.Response +) -> Optional[ApplicationDeposit]: + if response.status_code == 201: + response_201 = ApplicationDeposit.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[ApplicationDeposit]: + return Response( + status_code=HTTPStatus(response.status_code), + content=response.content, + headers=response.headers, + parsed=_parse_response(client=client, response=response), + ) + + +def sync_detailed( + payer_wallet: str, + *, + client: AuthenticatedClient, + body: ApplicationDeposit, +) -> Response[ApplicationDeposit]: + """ + Args: + payer_wallet (str): + body (ApplicationDeposit): + + 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[ApplicationDeposit] + """ + + kwargs = _get_kwargs( + payer_wallet=payer_wallet, + body=body, + ) + + response = client.get_httpx_client().request( + **kwargs, + ) + + return _build_response(client=client, response=response) + + +def sync( + payer_wallet: str, + *, + client: AuthenticatedClient, + body: ApplicationDeposit, +) -> Optional[ApplicationDeposit]: + """ + Args: + payer_wallet (str): + body (ApplicationDeposit): + + 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: + ApplicationDeposit + """ + + return sync_detailed( + payer_wallet=payer_wallet, + client=client, + body=body, + ).parsed + + +async def asyncio_detailed( + payer_wallet: str, + *, + client: AuthenticatedClient, + body: ApplicationDeposit, +) -> Response[ApplicationDeposit]: + """ + Args: + payer_wallet (str): + body (ApplicationDeposit): + + 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[ApplicationDeposit] + """ + + kwargs = _get_kwargs( + payer_wallet=payer_wallet, + body=body, + ) + + response = await client.get_async_httpx_client().request(**kwargs) + + return _build_response(client=client, response=response) + + +async def asyncio( + payer_wallet: str, + *, + client: AuthenticatedClient, + body: ApplicationDeposit, +) -> Optional[ApplicationDeposit]: + """ + Args: + payer_wallet (str): + body (ApplicationDeposit): + + 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: + ApplicationDeposit + """ + + return ( + await asyncio_detailed( + payer_wallet=payer_wallet, + client=client, + body=body, + ) + ).parsed diff --git a/utils/clients/gooyal_wallet_client/api/wallet/wallet_api_application_deposit_rollback_retrieve.py b/utils/clients/gooyal_wallet_client/api/wallet/wallet_api_application_deposit_rollback_retrieve.py new file mode 100644 index 0000000..21afdac --- /dev/null +++ b/utils/clients/gooyal_wallet_client/api/wallet/wallet_api_application_deposit_rollback_retrieve.py @@ -0,0 +1,160 @@ +from http import HTTPStatus +from typing import Any, Optional, Union + +import httpx + +from ... import errors +from ...client import AuthenticatedClient, Client +from ...models.application_deposit import ApplicationDeposit +from ...types import Response + + +def _get_kwargs( + payer_wallet: str, + uuid: str, +) -> dict[str, Any]: + _kwargs: dict[str, Any] = { + "method": "get", + "url": f"/wallet/api/application/{payer_wallet}/deposit/{uuid}/rollback", + } + + return _kwargs + + +def _parse_response( + *, client: Union[AuthenticatedClient, Client], response: httpx.Response +) -> Optional[ApplicationDeposit]: + if response.status_code == 200: + response_200 = ApplicationDeposit.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[ApplicationDeposit]: + return Response( + status_code=HTTPStatus(response.status_code), + content=response.content, + headers=response.headers, + parsed=_parse_response(client=client, response=response), + ) + + +def sync_detailed( + payer_wallet: str, + uuid: str, + *, + client: AuthenticatedClient, +) -> Response[ApplicationDeposit]: + """ + Args: + payer_wallet (str): + uuid (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[ApplicationDeposit] + """ + + kwargs = _get_kwargs( + payer_wallet=payer_wallet, + uuid=uuid, + ) + + response = client.get_httpx_client().request( + **kwargs, + ) + + return _build_response(client=client, response=response) + + +def sync( + payer_wallet: str, + uuid: str, + *, + client: AuthenticatedClient, +) -> Optional[ApplicationDeposit]: + """ + Args: + payer_wallet (str): + uuid (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: + ApplicationDeposit + """ + + return sync_detailed( + payer_wallet=payer_wallet, + uuid=uuid, + client=client, + ).parsed + + +async def asyncio_detailed( + payer_wallet: str, + uuid: str, + *, + client: AuthenticatedClient, +) -> Response[ApplicationDeposit]: + """ + Args: + payer_wallet (str): + uuid (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[ApplicationDeposit] + """ + + kwargs = _get_kwargs( + payer_wallet=payer_wallet, + uuid=uuid, + ) + + response = await client.get_async_httpx_client().request(**kwargs) + + return _build_response(client=client, response=response) + + +async def asyncio( + payer_wallet: str, + uuid: str, + *, + client: AuthenticatedClient, +) -> Optional[ApplicationDeposit]: + """ + Args: + payer_wallet (str): + uuid (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: + ApplicationDeposit + """ + + return ( + await asyncio_detailed( + payer_wallet=payer_wallet, + uuid=uuid, + client=client, + ) + ).parsed diff --git a/utils/clients/gooyal_wallet_client/api/wallet/wallet_api_application_deposit_verify_retrieve.py b/utils/clients/gooyal_wallet_client/api/wallet/wallet_api_application_deposit_verify_retrieve.py new file mode 100644 index 0000000..29042f3 --- /dev/null +++ b/utils/clients/gooyal_wallet_client/api/wallet/wallet_api_application_deposit_verify_retrieve.py @@ -0,0 +1,160 @@ +from http import HTTPStatus +from typing import Any, Optional, Union + +import httpx + +from ... import errors +from ...client import AuthenticatedClient, Client +from ...models.application_deposit import ApplicationDeposit +from ...types import Response + + +def _get_kwargs( + payer_wallet: str, + uuid: str, +) -> dict[str, Any]: + _kwargs: dict[str, Any] = { + "method": "get", + "url": f"/wallet/api/application/{payer_wallet}/deposit/{uuid}/verify", + } + + return _kwargs + + +def _parse_response( + *, client: Union[AuthenticatedClient, Client], response: httpx.Response +) -> Optional[ApplicationDeposit]: + if response.status_code == 200: + response_200 = ApplicationDeposit.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[ApplicationDeposit]: + return Response( + status_code=HTTPStatus(response.status_code), + content=response.content, + headers=response.headers, + parsed=_parse_response(client=client, response=response), + ) + + +def sync_detailed( + payer_wallet: str, + uuid: str, + *, + client: AuthenticatedClient, +) -> Response[ApplicationDeposit]: + """ + Args: + payer_wallet (str): + uuid (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[ApplicationDeposit] + """ + + kwargs = _get_kwargs( + payer_wallet=payer_wallet, + uuid=uuid, + ) + + response = client.get_httpx_client().request( + **kwargs, + ) + + return _build_response(client=client, response=response) + + +def sync( + payer_wallet: str, + uuid: str, + *, + client: AuthenticatedClient, +) -> Optional[ApplicationDeposit]: + """ + Args: + payer_wallet (str): + uuid (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: + ApplicationDeposit + """ + + return sync_detailed( + payer_wallet=payer_wallet, + uuid=uuid, + client=client, + ).parsed + + +async def asyncio_detailed( + payer_wallet: str, + uuid: str, + *, + client: AuthenticatedClient, +) -> Response[ApplicationDeposit]: + """ + Args: + payer_wallet (str): + uuid (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[ApplicationDeposit] + """ + + kwargs = _get_kwargs( + payer_wallet=payer_wallet, + uuid=uuid, + ) + + response = await client.get_async_httpx_client().request(**kwargs) + + return _build_response(client=client, response=response) + + +async def asyncio( + payer_wallet: str, + uuid: str, + *, + client: AuthenticatedClient, +) -> Optional[ApplicationDeposit]: + """ + Args: + payer_wallet (str): + uuid (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: + ApplicationDeposit + """ + + return ( + await asyncio_detailed( + payer_wallet=payer_wallet, + uuid=uuid, + client=client, + ) + ).parsed diff --git a/utils/clients/gooyal_wallet_client/api/wallet/wallet_api_application_transactions_list.py b/utils/clients/gooyal_wallet_client/api/wallet/wallet_api_application_transactions_list.py new file mode 100644 index 0000000..e808f0e --- /dev/null +++ b/utils/clients/gooyal_wallet_client/api/wallet/wallet_api_application_transactions_list.py @@ -0,0 +1,227 @@ +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.paginated_transaction_list import PaginatedTransactionList +from ...types import UNSET, Response, Unset + + +def _get_kwargs( + *, + limit: Union[Unset, int] = UNSET, + offset: Union[Unset, int] = UNSET, + payee: Union[Unset, UUID] = UNSET, + payer: Union[Unset, UUID] = UNSET, + wallets: list[UUID], +) -> dict[str, Any]: + params: dict[str, Any] = {} + + params["limit"] = limit + + params["offset"] = offset + + json_payee: Union[Unset, str] = UNSET + if not isinstance(payee, Unset): + json_payee = str(payee) + params["payee"] = json_payee + + json_payer: Union[Unset, str] = UNSET + if not isinstance(payer, Unset): + json_payer = str(payer) + params["payer"] = json_payer + + json_wallets = [] + for wallets_item_data in wallets: + wallets_item = str(wallets_item_data) + json_wallets.append(wallets_item) + + params["wallets"] = json_wallets + + 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": "/wallet/api/application/transactions/", + "params": params, + } + + return _kwargs + + +def _parse_response( + *, client: Union[AuthenticatedClient, Client], response: httpx.Response +) -> Optional[PaginatedTransactionList]: + if response.status_code == 200: + response_200 = PaginatedTransactionList.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[PaginatedTransactionList]: + 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, + limit: Union[Unset, int] = UNSET, + offset: Union[Unset, int] = UNSET, + payee: Union[Unset, UUID] = UNSET, + payer: Union[Unset, UUID] = UNSET, + wallets: list[UUID], +) -> Response[PaginatedTransactionList]: + """ + Args: + limit (Union[Unset, int]): + offset (Union[Unset, int]): + payee (Union[Unset, UUID]): + payer (Union[Unset, UUID]): + wallets (list[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[PaginatedTransactionList] + """ + + kwargs = _get_kwargs( + limit=limit, + offset=offset, + payee=payee, + payer=payer, + wallets=wallets, + ) + + response = client.get_httpx_client().request( + **kwargs, + ) + + return _build_response(client=client, response=response) + + +def sync( + *, + client: AuthenticatedClient, + limit: Union[Unset, int] = UNSET, + offset: Union[Unset, int] = UNSET, + payee: Union[Unset, UUID] = UNSET, + payer: Union[Unset, UUID] = UNSET, + wallets: list[UUID], +) -> Optional[PaginatedTransactionList]: + """ + Args: + limit (Union[Unset, int]): + offset (Union[Unset, int]): + payee (Union[Unset, UUID]): + payer (Union[Unset, UUID]): + wallets (list[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: + PaginatedTransactionList + """ + + return sync_detailed( + client=client, + limit=limit, + offset=offset, + payee=payee, + payer=payer, + wallets=wallets, + ).parsed + + +async def asyncio_detailed( + *, + client: AuthenticatedClient, + limit: Union[Unset, int] = UNSET, + offset: Union[Unset, int] = UNSET, + payee: Union[Unset, UUID] = UNSET, + payer: Union[Unset, UUID] = UNSET, + wallets: list[UUID], +) -> Response[PaginatedTransactionList]: + """ + Args: + limit (Union[Unset, int]): + offset (Union[Unset, int]): + payee (Union[Unset, UUID]): + payer (Union[Unset, UUID]): + wallets (list[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[PaginatedTransactionList] + """ + + kwargs = _get_kwargs( + limit=limit, + offset=offset, + payee=payee, + payer=payer, + wallets=wallets, + ) + + response = await client.get_async_httpx_client().request(**kwargs) + + return _build_response(client=client, response=response) + + +async def asyncio( + *, + client: AuthenticatedClient, + limit: Union[Unset, int] = UNSET, + offset: Union[Unset, int] = UNSET, + payee: Union[Unset, UUID] = UNSET, + payer: Union[Unset, UUID] = UNSET, + wallets: list[UUID], +) -> Optional[PaginatedTransactionList]: + """ + Args: + limit (Union[Unset, int]): + offset (Union[Unset, int]): + payee (Union[Unset, UUID]): + payer (Union[Unset, UUID]): + wallets (list[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: + PaginatedTransactionList + """ + + return ( + await asyncio_detailed( + client=client, + limit=limit, + offset=offset, + payee=payee, + payer=payer, + wallets=wallets, + ) + ).parsed diff --git a/utils/clients/gooyal_wallet_client/api/wallet/wallet_api_application_transactions_retrieve.py b/utils/clients/gooyal_wallet_client/api/wallet/wallet_api_application_transactions_retrieve.py new file mode 100644 index 0000000..1939f25 --- /dev/null +++ b/utils/clients/gooyal_wallet_client/api/wallet/wallet_api_application_transactions_retrieve.py @@ -0,0 +1,144 @@ +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.transaction import Transaction +from ...types import Response + + +def _get_kwargs( + uuid: UUID, +) -> dict[str, Any]: + _kwargs: dict[str, Any] = { + "method": "get", + "url": f"/wallet/api/application/transactions/{uuid}/", + } + + return _kwargs + + +def _parse_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Optional[Transaction]: + if response.status_code == 200: + response_200 = Transaction.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[Transaction]: + 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[Transaction]: + """ + 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[Transaction] + """ + + 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[Transaction]: + """ + 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: + Transaction + """ + + return sync_detailed( + uuid=uuid, + client=client, + ).parsed + + +async def asyncio_detailed( + uuid: UUID, + *, + client: AuthenticatedClient, +) -> Response[Transaction]: + """ + 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[Transaction] + """ + + 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[Transaction]: + """ + 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: + Transaction + """ + + return ( + await asyncio_detailed( + uuid=uuid, + client=client, + ) + ).parsed diff --git a/utils/clients/gooyal_wallet_client/api/wallet/wallet_api_application_user_wallets_list.py b/utils/clients/gooyal_wallet_client/api/wallet/wallet_api_application_user_wallets_list.py new file mode 100644 index 0000000..3317b1e --- /dev/null +++ b/utils/clients/gooyal_wallet_client/api/wallet/wallet_api_application_user_wallets_list.py @@ -0,0 +1,208 @@ +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.paginated_account_list import PaginatedAccountList +from ...types import UNSET, Response, Unset + + +def _get_kwargs( + owner: str, + *, + limit: Union[Unset, int] = UNSET, + offset: Union[Unset, int] = UNSET, + wallet: list[UUID], +) -> dict[str, Any]: + params: dict[str, Any] = {} + + params["limit"] = limit + + params["offset"] = offset + + json_wallet = [] + for wallet_item_data in wallet: + wallet_item = str(wallet_item_data) + json_wallet.append(wallet_item) + + params["wallet"] = json_wallet + + 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": f"/wallet/api/application/user/wallets/{owner}/", + "params": params, + } + + return _kwargs + + +def _parse_response( + *, client: Union[AuthenticatedClient, Client], response: httpx.Response +) -> Optional[PaginatedAccountList]: + if response.status_code == 200: + response_200 = PaginatedAccountList.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[PaginatedAccountList]: + return Response( + status_code=HTTPStatus(response.status_code), + content=response.content, + headers=response.headers, + parsed=_parse_response(client=client, response=response), + ) + + +def sync_detailed( + owner: str, + *, + client: AuthenticatedClient, + limit: Union[Unset, int] = UNSET, + offset: Union[Unset, int] = UNSET, + wallet: list[UUID], +) -> Response[PaginatedAccountList]: + """API for getting specified user wallet. + + Args: + owner (str): + limit (Union[Unset, int]): + offset (Union[Unset, int]): + wallet (list[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[PaginatedAccountList] + """ + + kwargs = _get_kwargs( + owner=owner, + limit=limit, + offset=offset, + wallet=wallet, + ) + + response = client.get_httpx_client().request( + **kwargs, + ) + + return _build_response(client=client, response=response) + + +def sync( + owner: str, + *, + client: AuthenticatedClient, + limit: Union[Unset, int] = UNSET, + offset: Union[Unset, int] = UNSET, + wallet: list[UUID], +) -> Optional[PaginatedAccountList]: + """API for getting specified user wallet. + + Args: + owner (str): + limit (Union[Unset, int]): + offset (Union[Unset, int]): + wallet (list[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: + PaginatedAccountList + """ + + return sync_detailed( + owner=owner, + client=client, + limit=limit, + offset=offset, + wallet=wallet, + ).parsed + + +async def asyncio_detailed( + owner: str, + *, + client: AuthenticatedClient, + limit: Union[Unset, int] = UNSET, + offset: Union[Unset, int] = UNSET, + wallet: list[UUID], +) -> Response[PaginatedAccountList]: + """API for getting specified user wallet. + + Args: + owner (str): + limit (Union[Unset, int]): + offset (Union[Unset, int]): + wallet (list[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[PaginatedAccountList] + """ + + kwargs = _get_kwargs( + owner=owner, + limit=limit, + offset=offset, + wallet=wallet, + ) + + response = await client.get_async_httpx_client().request(**kwargs) + + return _build_response(client=client, response=response) + + +async def asyncio( + owner: str, + *, + client: AuthenticatedClient, + limit: Union[Unset, int] = UNSET, + offset: Union[Unset, int] = UNSET, + wallet: list[UUID], +) -> Optional[PaginatedAccountList]: + """API for getting specified user wallet. + + Args: + owner (str): + limit (Union[Unset, int]): + offset (Union[Unset, int]): + wallet (list[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: + PaginatedAccountList + """ + + return ( + await asyncio_detailed( + owner=owner, + client=client, + limit=limit, + offset=offset, + wallet=wallet, + ) + ).parsed diff --git a/utils/clients/gooyal_wallet_client/api/wallet/wallet_api_application_wallets_list.py b/utils/clients/gooyal_wallet_client/api/wallet/wallet_api_application_wallets_list.py new file mode 100644 index 0000000..9d5a57b --- /dev/null +++ b/utils/clients/gooyal_wallet_client/api/wallet/wallet_api_application_wallets_list.py @@ -0,0 +1,174 @@ +from http import HTTPStatus +from typing import Any, Optional, Union + +import httpx + +from ... import errors +from ...client import AuthenticatedClient, Client +from ...models.paginated_account_list import PaginatedAccountList +from ...types import UNSET, Response, Unset + + +def _get_kwargs( + *, + limit: Union[Unset, int] = UNSET, + offset: Union[Unset, int] = UNSET, +) -> dict[str, Any]: + params: dict[str, Any] = {} + + params["limit"] = limit + + params["offset"] = offset + + 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": "/wallet/api/application/wallets/", + "params": params, + } + + return _kwargs + + +def _parse_response( + *, client: Union[AuthenticatedClient, Client], response: httpx.Response +) -> Optional[PaginatedAccountList]: + if response.status_code == 200: + response_200 = PaginatedAccountList.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[PaginatedAccountList]: + 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, + limit: Union[Unset, int] = UNSET, + offset: Union[Unset, int] = UNSET, +) -> Response[PaginatedAccountList]: + """API for getting specified user or application balance. + + Args: + limit (Union[Unset, int]): + offset (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[PaginatedAccountList] + """ + + kwargs = _get_kwargs( + limit=limit, + offset=offset, + ) + + response = client.get_httpx_client().request( + **kwargs, + ) + + return _build_response(client=client, response=response) + + +def sync( + *, + client: AuthenticatedClient, + limit: Union[Unset, int] = UNSET, + offset: Union[Unset, int] = UNSET, +) -> Optional[PaginatedAccountList]: + """API for getting specified user or application balance. + + Args: + limit (Union[Unset, int]): + offset (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: + PaginatedAccountList + """ + + return sync_detailed( + client=client, + limit=limit, + offset=offset, + ).parsed + + +async def asyncio_detailed( + *, + client: AuthenticatedClient, + limit: Union[Unset, int] = UNSET, + offset: Union[Unset, int] = UNSET, +) -> Response[PaginatedAccountList]: + """API for getting specified user or application balance. + + Args: + limit (Union[Unset, int]): + offset (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[PaginatedAccountList] + """ + + kwargs = _get_kwargs( + limit=limit, + offset=offset, + ) + + response = await client.get_async_httpx_client().request(**kwargs) + + return _build_response(client=client, response=response) + + +async def asyncio( + *, + client: AuthenticatedClient, + limit: Union[Unset, int] = UNSET, + offset: Union[Unset, int] = UNSET, +) -> Optional[PaginatedAccountList]: + """API for getting specified user or application balance. + + Args: + limit (Union[Unset, int]): + offset (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: + PaginatedAccountList + """ + + return ( + await asyncio_detailed( + client=client, + limit=limit, + offset=offset, + ) + ).parsed diff --git a/utils/clients/gooyal_wallet_client/api/wallet/wallet_api_application_withdraw_create.py b/utils/clients/gooyal_wallet_client/api/wallet/wallet_api_application_withdraw_create.py new file mode 100644 index 0000000..74d6944 --- /dev/null +++ b/utils/clients/gooyal_wallet_client/api/wallet/wallet_api_application_withdraw_create.py @@ -0,0 +1,168 @@ +from http import HTTPStatus +from typing import Any, Optional, Union + +import httpx + +from ... import errors +from ...client import AuthenticatedClient, Client +from ...models.application_withdraw import ApplicationWithdraw +from ...types import Response + + +def _get_kwargs( + payee_wallet: str, + *, + body: ApplicationWithdraw, +) -> dict[str, Any]: + headers: dict[str, Any] = {} + + _kwargs: dict[str, Any] = { + "method": "post", + "url": f"/wallet/api/application/{payee_wallet}/withdraw/", + } + + _kwargs["json"] = body.to_dict() + + headers["Content-Type"] = "application/json" + + _kwargs["headers"] = headers + return _kwargs + + +def _parse_response( + *, client: Union[AuthenticatedClient, Client], response: httpx.Response +) -> Optional[ApplicationWithdraw]: + if response.status_code == 201: + response_201 = ApplicationWithdraw.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[ApplicationWithdraw]: + return Response( + status_code=HTTPStatus(response.status_code), + content=response.content, + headers=response.headers, + parsed=_parse_response(client=client, response=response), + ) + + +def sync_detailed( + payee_wallet: str, + *, + client: AuthenticatedClient, + body: ApplicationWithdraw, +) -> Response[ApplicationWithdraw]: + """ + Args: + payee_wallet (str): + body (ApplicationWithdraw): + + 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[ApplicationWithdraw] + """ + + kwargs = _get_kwargs( + payee_wallet=payee_wallet, + body=body, + ) + + response = client.get_httpx_client().request( + **kwargs, + ) + + return _build_response(client=client, response=response) + + +def sync( + payee_wallet: str, + *, + client: AuthenticatedClient, + body: ApplicationWithdraw, +) -> Optional[ApplicationWithdraw]: + """ + Args: + payee_wallet (str): + body (ApplicationWithdraw): + + 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: + ApplicationWithdraw + """ + + return sync_detailed( + payee_wallet=payee_wallet, + client=client, + body=body, + ).parsed + + +async def asyncio_detailed( + payee_wallet: str, + *, + client: AuthenticatedClient, + body: ApplicationWithdraw, +) -> Response[ApplicationWithdraw]: + """ + Args: + payee_wallet (str): + body (ApplicationWithdraw): + + 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[ApplicationWithdraw] + """ + + kwargs = _get_kwargs( + payee_wallet=payee_wallet, + body=body, + ) + + response = await client.get_async_httpx_client().request(**kwargs) + + return _build_response(client=client, response=response) + + +async def asyncio( + payee_wallet: str, + *, + client: AuthenticatedClient, + body: ApplicationWithdraw, +) -> Optional[ApplicationWithdraw]: + """ + Args: + payee_wallet (str): + body (ApplicationWithdraw): + + 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: + ApplicationWithdraw + """ + + return ( + await asyncio_detailed( + payee_wallet=payee_wallet, + client=client, + body=body, + ) + ).parsed diff --git a/utils/clients/gooyal_wallet_client/api/wallet/wallet_api_application_withdraw_rollback_retrieve.py b/utils/clients/gooyal_wallet_client/api/wallet/wallet_api_application_withdraw_rollback_retrieve.py new file mode 100644 index 0000000..32421fb --- /dev/null +++ b/utils/clients/gooyal_wallet_client/api/wallet/wallet_api_application_withdraw_rollback_retrieve.py @@ -0,0 +1,160 @@ +from http import HTTPStatus +from typing import Any, Optional, Union + +import httpx + +from ... import errors +from ...client import AuthenticatedClient, Client +from ...models.application_withdraw import ApplicationWithdraw +from ...types import Response + + +def _get_kwargs( + payee_wallet: str, + uuid: str, +) -> dict[str, Any]: + _kwargs: dict[str, Any] = { + "method": "get", + "url": f"/wallet/api/application/{payee_wallet}/withdraw/{uuid}/rollback", + } + + return _kwargs + + +def _parse_response( + *, client: Union[AuthenticatedClient, Client], response: httpx.Response +) -> Optional[ApplicationWithdraw]: + if response.status_code == 200: + response_200 = ApplicationWithdraw.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[ApplicationWithdraw]: + return Response( + status_code=HTTPStatus(response.status_code), + content=response.content, + headers=response.headers, + parsed=_parse_response(client=client, response=response), + ) + + +def sync_detailed( + payee_wallet: str, + uuid: str, + *, + client: AuthenticatedClient, +) -> Response[ApplicationWithdraw]: + """ + Args: + payee_wallet (str): + uuid (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[ApplicationWithdraw] + """ + + kwargs = _get_kwargs( + payee_wallet=payee_wallet, + uuid=uuid, + ) + + response = client.get_httpx_client().request( + **kwargs, + ) + + return _build_response(client=client, response=response) + + +def sync( + payee_wallet: str, + uuid: str, + *, + client: AuthenticatedClient, +) -> Optional[ApplicationWithdraw]: + """ + Args: + payee_wallet (str): + uuid (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: + ApplicationWithdraw + """ + + return sync_detailed( + payee_wallet=payee_wallet, + uuid=uuid, + client=client, + ).parsed + + +async def asyncio_detailed( + payee_wallet: str, + uuid: str, + *, + client: AuthenticatedClient, +) -> Response[ApplicationWithdraw]: + """ + Args: + payee_wallet (str): + uuid (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[ApplicationWithdraw] + """ + + kwargs = _get_kwargs( + payee_wallet=payee_wallet, + uuid=uuid, + ) + + response = await client.get_async_httpx_client().request(**kwargs) + + return _build_response(client=client, response=response) + + +async def asyncio( + payee_wallet: str, + uuid: str, + *, + client: AuthenticatedClient, +) -> Optional[ApplicationWithdraw]: + """ + Args: + payee_wallet (str): + uuid (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: + ApplicationWithdraw + """ + + return ( + await asyncio_detailed( + payee_wallet=payee_wallet, + uuid=uuid, + client=client, + ) + ).parsed diff --git a/utils/clients/gooyal_wallet_client/api/wallet/wallet_api_application_withdraw_verify_retrieve.py b/utils/clients/gooyal_wallet_client/api/wallet/wallet_api_application_withdraw_verify_retrieve.py new file mode 100644 index 0000000..757b597 --- /dev/null +++ b/utils/clients/gooyal_wallet_client/api/wallet/wallet_api_application_withdraw_verify_retrieve.py @@ -0,0 +1,160 @@ +from http import HTTPStatus +from typing import Any, Optional, Union + +import httpx + +from ... import errors +from ...client import AuthenticatedClient, Client +from ...models.application_withdraw import ApplicationWithdraw +from ...types import Response + + +def _get_kwargs( + payee_wallet: str, + uuid: str, +) -> dict[str, Any]: + _kwargs: dict[str, Any] = { + "method": "get", + "url": f"/wallet/api/application/{payee_wallet}/withdraw/{uuid}/verify", + } + + return _kwargs + + +def _parse_response( + *, client: Union[AuthenticatedClient, Client], response: httpx.Response +) -> Optional[ApplicationWithdraw]: + if response.status_code == 200: + response_200 = ApplicationWithdraw.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[ApplicationWithdraw]: + return Response( + status_code=HTTPStatus(response.status_code), + content=response.content, + headers=response.headers, + parsed=_parse_response(client=client, response=response), + ) + + +def sync_detailed( + payee_wallet: str, + uuid: str, + *, + client: AuthenticatedClient, +) -> Response[ApplicationWithdraw]: + """ + Args: + payee_wallet (str): + uuid (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[ApplicationWithdraw] + """ + + kwargs = _get_kwargs( + payee_wallet=payee_wallet, + uuid=uuid, + ) + + response = client.get_httpx_client().request( + **kwargs, + ) + + return _build_response(client=client, response=response) + + +def sync( + payee_wallet: str, + uuid: str, + *, + client: AuthenticatedClient, +) -> Optional[ApplicationWithdraw]: + """ + Args: + payee_wallet (str): + uuid (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: + ApplicationWithdraw + """ + + return sync_detailed( + payee_wallet=payee_wallet, + uuid=uuid, + client=client, + ).parsed + + +async def asyncio_detailed( + payee_wallet: str, + uuid: str, + *, + client: AuthenticatedClient, +) -> Response[ApplicationWithdraw]: + """ + Args: + payee_wallet (str): + uuid (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[ApplicationWithdraw] + """ + + kwargs = _get_kwargs( + payee_wallet=payee_wallet, + uuid=uuid, + ) + + response = await client.get_async_httpx_client().request(**kwargs) + + return _build_response(client=client, response=response) + + +async def asyncio( + payee_wallet: str, + uuid: str, + *, + client: AuthenticatedClient, +) -> Optional[ApplicationWithdraw]: + """ + Args: + payee_wallet (str): + uuid (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: + ApplicationWithdraw + """ + + return ( + await asyncio_detailed( + payee_wallet=payee_wallet, + uuid=uuid, + client=client, + ) + ).parsed diff --git a/utils/clients/gooyal_wallet_client/api/wallet/wallet_api_transactions_grouped_list.py b/utils/clients/gooyal_wallet_client/api/wallet/wallet_api_transactions_grouped_list.py new file mode 100644 index 0000000..1d1cb15 --- /dev/null +++ b/utils/clients/gooyal_wallet_client/api/wallet/wallet_api_transactions_grouped_list.py @@ -0,0 +1,227 @@ +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.paginated_transaction_grouped_list import PaginatedTransactionGroupedList +from ...types import UNSET, Response, Unset + + +def _get_kwargs( + *, + limit: Union[Unset, int] = UNSET, + offset: Union[Unset, int] = UNSET, + payee: Union[Unset, UUID] = UNSET, + payer: Union[Unset, UUID] = UNSET, + wallets: list[UUID], +) -> dict[str, Any]: + params: dict[str, Any] = {} + + params["limit"] = limit + + params["offset"] = offset + + json_payee: Union[Unset, str] = UNSET + if not isinstance(payee, Unset): + json_payee = str(payee) + params["payee"] = json_payee + + json_payer: Union[Unset, str] = UNSET + if not isinstance(payer, Unset): + json_payer = str(payer) + params["payer"] = json_payer + + json_wallets = [] + for wallets_item_data in wallets: + wallets_item = str(wallets_item_data) + json_wallets.append(wallets_item) + + params["wallets"] = json_wallets + + 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": "/wallet/api/transactions/grouped/", + "params": params, + } + + return _kwargs + + +def _parse_response( + *, client: Union[AuthenticatedClient, Client], response: httpx.Response +) -> Optional[PaginatedTransactionGroupedList]: + if response.status_code == 200: + response_200 = PaginatedTransactionGroupedList.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[PaginatedTransactionGroupedList]: + 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, + limit: Union[Unset, int] = UNSET, + offset: Union[Unset, int] = UNSET, + payee: Union[Unset, UUID] = UNSET, + payer: Union[Unset, UUID] = UNSET, + wallets: list[UUID], +) -> Response[PaginatedTransactionGroupedList]: + """ + Args: + limit (Union[Unset, int]): + offset (Union[Unset, int]): + payee (Union[Unset, UUID]): + payer (Union[Unset, UUID]): + wallets (list[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[PaginatedTransactionGroupedList] + """ + + kwargs = _get_kwargs( + limit=limit, + offset=offset, + payee=payee, + payer=payer, + wallets=wallets, + ) + + response = client.get_httpx_client().request( + **kwargs, + ) + + return _build_response(client=client, response=response) + + +def sync( + *, + client: AuthenticatedClient, + limit: Union[Unset, int] = UNSET, + offset: Union[Unset, int] = UNSET, + payee: Union[Unset, UUID] = UNSET, + payer: Union[Unset, UUID] = UNSET, + wallets: list[UUID], +) -> Optional[PaginatedTransactionGroupedList]: + """ + Args: + limit (Union[Unset, int]): + offset (Union[Unset, int]): + payee (Union[Unset, UUID]): + payer (Union[Unset, UUID]): + wallets (list[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: + PaginatedTransactionGroupedList + """ + + return sync_detailed( + client=client, + limit=limit, + offset=offset, + payee=payee, + payer=payer, + wallets=wallets, + ).parsed + + +async def asyncio_detailed( + *, + client: AuthenticatedClient, + limit: Union[Unset, int] = UNSET, + offset: Union[Unset, int] = UNSET, + payee: Union[Unset, UUID] = UNSET, + payer: Union[Unset, UUID] = UNSET, + wallets: list[UUID], +) -> Response[PaginatedTransactionGroupedList]: + """ + Args: + limit (Union[Unset, int]): + offset (Union[Unset, int]): + payee (Union[Unset, UUID]): + payer (Union[Unset, UUID]): + wallets (list[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[PaginatedTransactionGroupedList] + """ + + kwargs = _get_kwargs( + limit=limit, + offset=offset, + payee=payee, + payer=payer, + wallets=wallets, + ) + + response = await client.get_async_httpx_client().request(**kwargs) + + return _build_response(client=client, response=response) + + +async def asyncio( + *, + client: AuthenticatedClient, + limit: Union[Unset, int] = UNSET, + offset: Union[Unset, int] = UNSET, + payee: Union[Unset, UUID] = UNSET, + payer: Union[Unset, UUID] = UNSET, + wallets: list[UUID], +) -> Optional[PaginatedTransactionGroupedList]: + """ + Args: + limit (Union[Unset, int]): + offset (Union[Unset, int]): + payee (Union[Unset, UUID]): + payer (Union[Unset, UUID]): + wallets (list[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: + PaginatedTransactionGroupedList + """ + + return ( + await asyncio_detailed( + client=client, + limit=limit, + offset=offset, + payee=payee, + payer=payer, + wallets=wallets, + ) + ).parsed diff --git a/utils/clients/gooyal_wallet_client/api/wallet/wallet_api_transactions_list.py b/utils/clients/gooyal_wallet_client/api/wallet/wallet_api_transactions_list.py new file mode 100644 index 0000000..35b6626 --- /dev/null +++ b/utils/clients/gooyal_wallet_client/api/wallet/wallet_api_transactions_list.py @@ -0,0 +1,227 @@ +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.paginated_transaction_list import PaginatedTransactionList +from ...types import UNSET, Response, Unset + + +def _get_kwargs( + *, + limit: Union[Unset, int] = UNSET, + offset: Union[Unset, int] = UNSET, + payee: Union[Unset, UUID] = UNSET, + payer: Union[Unset, UUID] = UNSET, + wallets: list[UUID], +) -> dict[str, Any]: + params: dict[str, Any] = {} + + params["limit"] = limit + + params["offset"] = offset + + json_payee: Union[Unset, str] = UNSET + if not isinstance(payee, Unset): + json_payee = str(payee) + params["payee"] = json_payee + + json_payer: Union[Unset, str] = UNSET + if not isinstance(payer, Unset): + json_payer = str(payer) + params["payer"] = json_payer + + json_wallets = [] + for wallets_item_data in wallets: + wallets_item = str(wallets_item_data) + json_wallets.append(wallets_item) + + params["wallets"] = json_wallets + + 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": "/wallet/api/transactions/", + "params": params, + } + + return _kwargs + + +def _parse_response( + *, client: Union[AuthenticatedClient, Client], response: httpx.Response +) -> Optional[PaginatedTransactionList]: + if response.status_code == 200: + response_200 = PaginatedTransactionList.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[PaginatedTransactionList]: + 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, + limit: Union[Unset, int] = UNSET, + offset: Union[Unset, int] = UNSET, + payee: Union[Unset, UUID] = UNSET, + payer: Union[Unset, UUID] = UNSET, + wallets: list[UUID], +) -> Response[PaginatedTransactionList]: + """ + Args: + limit (Union[Unset, int]): + offset (Union[Unset, int]): + payee (Union[Unset, UUID]): + payer (Union[Unset, UUID]): + wallets (list[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[PaginatedTransactionList] + """ + + kwargs = _get_kwargs( + limit=limit, + offset=offset, + payee=payee, + payer=payer, + wallets=wallets, + ) + + response = client.get_httpx_client().request( + **kwargs, + ) + + return _build_response(client=client, response=response) + + +def sync( + *, + client: AuthenticatedClient, + limit: Union[Unset, int] = UNSET, + offset: Union[Unset, int] = UNSET, + payee: Union[Unset, UUID] = UNSET, + payer: Union[Unset, UUID] = UNSET, + wallets: list[UUID], +) -> Optional[PaginatedTransactionList]: + """ + Args: + limit (Union[Unset, int]): + offset (Union[Unset, int]): + payee (Union[Unset, UUID]): + payer (Union[Unset, UUID]): + wallets (list[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: + PaginatedTransactionList + """ + + return sync_detailed( + client=client, + limit=limit, + offset=offset, + payee=payee, + payer=payer, + wallets=wallets, + ).parsed + + +async def asyncio_detailed( + *, + client: AuthenticatedClient, + limit: Union[Unset, int] = UNSET, + offset: Union[Unset, int] = UNSET, + payee: Union[Unset, UUID] = UNSET, + payer: Union[Unset, UUID] = UNSET, + wallets: list[UUID], +) -> Response[PaginatedTransactionList]: + """ + Args: + limit (Union[Unset, int]): + offset (Union[Unset, int]): + payee (Union[Unset, UUID]): + payer (Union[Unset, UUID]): + wallets (list[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[PaginatedTransactionList] + """ + + kwargs = _get_kwargs( + limit=limit, + offset=offset, + payee=payee, + payer=payer, + wallets=wallets, + ) + + response = await client.get_async_httpx_client().request(**kwargs) + + return _build_response(client=client, response=response) + + +async def asyncio( + *, + client: AuthenticatedClient, + limit: Union[Unset, int] = UNSET, + offset: Union[Unset, int] = UNSET, + payee: Union[Unset, UUID] = UNSET, + payer: Union[Unset, UUID] = UNSET, + wallets: list[UUID], +) -> Optional[PaginatedTransactionList]: + """ + Args: + limit (Union[Unset, int]): + offset (Union[Unset, int]): + payee (Union[Unset, UUID]): + payer (Union[Unset, UUID]): + wallets (list[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: + PaginatedTransactionList + """ + + return ( + await asyncio_detailed( + client=client, + limit=limit, + offset=offset, + payee=payee, + payer=payer, + wallets=wallets, + ) + ).parsed diff --git a/utils/clients/gooyal_wallet_client/api/wallet/wallet_api_wallets_list.py b/utils/clients/gooyal_wallet_client/api/wallet/wallet_api_wallets_list.py new file mode 100644 index 0000000..f406ae8 --- /dev/null +++ b/utils/clients/gooyal_wallet_client/api/wallet/wallet_api_wallets_list.py @@ -0,0 +1,195 @@ +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.paginated_account_list import PaginatedAccountList +from ...types import UNSET, Response, Unset + + +def _get_kwargs( + *, + limit: Union[Unset, int] = UNSET, + offset: Union[Unset, int] = UNSET, + wallet: list[UUID], +) -> dict[str, Any]: + params: dict[str, Any] = {} + + params["limit"] = limit + + params["offset"] = offset + + json_wallet = [] + for wallet_item_data in wallet: + wallet_item = str(wallet_item_data) + json_wallet.append(wallet_item) + + params["wallet"] = json_wallet + + 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": "/wallet/api/wallets/", + "params": params, + } + + return _kwargs + + +def _parse_response( + *, client: Union[AuthenticatedClient, Client], response: httpx.Response +) -> Optional[PaginatedAccountList]: + if response.status_code == 200: + response_200 = PaginatedAccountList.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[PaginatedAccountList]: + 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, + limit: Union[Unset, int] = UNSET, + offset: Union[Unset, int] = UNSET, + wallet: list[UUID], +) -> Response[PaginatedAccountList]: + """API for getting authenticated user balance. + + Args: + limit (Union[Unset, int]): + offset (Union[Unset, int]): + wallet (list[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[PaginatedAccountList] + """ + + kwargs = _get_kwargs( + limit=limit, + offset=offset, + wallet=wallet, + ) + + response = client.get_httpx_client().request( + **kwargs, + ) + + return _build_response(client=client, response=response) + + +def sync( + *, + client: AuthenticatedClient, + limit: Union[Unset, int] = UNSET, + offset: Union[Unset, int] = UNSET, + wallet: list[UUID], +) -> Optional[PaginatedAccountList]: + """API for getting authenticated user balance. + + Args: + limit (Union[Unset, int]): + offset (Union[Unset, int]): + wallet (list[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: + PaginatedAccountList + """ + + return sync_detailed( + client=client, + limit=limit, + offset=offset, + wallet=wallet, + ).parsed + + +async def asyncio_detailed( + *, + client: AuthenticatedClient, + limit: Union[Unset, int] = UNSET, + offset: Union[Unset, int] = UNSET, + wallet: list[UUID], +) -> Response[PaginatedAccountList]: + """API for getting authenticated user balance. + + Args: + limit (Union[Unset, int]): + offset (Union[Unset, int]): + wallet (list[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[PaginatedAccountList] + """ + + kwargs = _get_kwargs( + limit=limit, + offset=offset, + wallet=wallet, + ) + + response = await client.get_async_httpx_client().request(**kwargs) + + return _build_response(client=client, response=response) + + +async def asyncio( + *, + client: AuthenticatedClient, + limit: Union[Unset, int] = UNSET, + offset: Union[Unset, int] = UNSET, + wallet: list[UUID], +) -> Optional[PaginatedAccountList]: + """API for getting authenticated user balance. + + Args: + limit (Union[Unset, int]): + offset (Union[Unset, int]): + wallet (list[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: + PaginatedAccountList + """ + + return ( + await asyncio_detailed( + client=client, + limit=limit, + offset=offset, + wallet=wallet, + ) + ).parsed diff --git a/utils/clients/gooyal_wallet_client/client.py b/utils/clients/gooyal_wallet_client/client.py new file mode 100644 index 0000000..e80446f --- /dev/null +++ b/utils/clients/gooyal_wallet_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/utils/clients/gooyal_wallet_client/errors.py b/utils/clients/gooyal_wallet_client/errors.py new file mode 100644 index 0000000..5f92e76 --- /dev/null +++ b/utils/clients/gooyal_wallet_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/utils/clients/gooyal_wallet_client/models/__init__.py b/utils/clients/gooyal_wallet_client/models/__init__.py new file mode 100644 index 0000000..7df448d --- /dev/null +++ b/utils/clients/gooyal_wallet_client/models/__init__.py @@ -0,0 +1,23 @@ +"""Contains all the data models used in inputs/outputs""" + +from .account import Account +from .application_deposit import ApplicationDeposit +from .application_withdraw import ApplicationWithdraw +from .paginated_account_list import PaginatedAccountList +from .paginated_transaction_grouped_list import PaginatedTransactionGroupedList +from .paginated_transaction_list import PaginatedTransactionList +from .state_enum import StateEnum +from .transaction import Transaction +from .transaction_grouped import TransactionGrouped + +__all__ = ( + "Account", + "ApplicationDeposit", + "ApplicationWithdraw", + "PaginatedAccountList", + "PaginatedTransactionGroupedList", + "PaginatedTransactionList", + "StateEnum", + "Transaction", + "TransactionGrouped", +) diff --git a/utils/clients/gooyal_wallet_client/models/account.py b/utils/clients/gooyal_wallet_client/models/account.py new file mode 100644 index 0000000..25b08bb --- /dev/null +++ b/utils/clients/gooyal_wallet_client/models/account.py @@ -0,0 +1,90 @@ +from collections.abc import Mapping +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: + balance (Union[Unset, int]): + wallet (Union[None, UUID, Unset]): + """ + + balance: Union[Unset, int] = UNSET + wallet: Union[None, UUID, Unset] = UNSET + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) + + def to_dict(self) -> dict[str, Any]: + balance = self.balance + + wallet: Union[None, Unset, str] + if isinstance(self.wallet, Unset): + wallet = UNSET + elif isinstance(self.wallet, UUID): + wallet = str(self.wallet) + else: + wallet = self.wallet + + field_dict: dict[str, Any] = {} + field_dict.update(self.additional_properties) + field_dict.update({}) + if balance is not UNSET: + field_dict["balance"] = balance + if wallet is not UNSET: + field_dict["wallet"] = wallet + + return field_dict + + @classmethod + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + d = dict(src_dict) + balance = d.pop("balance", UNSET) + + def _parse_wallet(data: object) -> Union[None, UUID, Unset]: + if data is None: + return data + if isinstance(data, Unset): + return data + try: + if not isinstance(data, str): + raise TypeError() + wallet_type_0 = UUID(data) + + return wallet_type_0 + except: # noqa: E722 + pass + return cast(Union[None, UUID, Unset], data) + + wallet = _parse_wallet(d.pop("wallet", UNSET)) + + account = cls( + balance=balance, + wallet=wallet, + ) + + 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/utils/clients/gooyal_wallet_client/models/application_deposit.py b/utils/clients/gooyal_wallet_client/models/application_deposit.py new file mode 100644 index 0000000..7f6d00f --- /dev/null +++ b/utils/clients/gooyal_wallet_client/models/application_deposit.py @@ -0,0 +1,170 @@ +import datetime +from collections.abc import Mapping +from typing import Any, TypeVar, Union +from uuid import UUID + +from attrs import define as _attrs_define +from attrs import field as _attrs_field +from dateutil.parser import isoparse + +from ..models.state_enum import StateEnum +from ..types import UNSET, Unset + +T = TypeVar("T", bound="ApplicationDeposit") + + +@_attrs_define +class ApplicationDeposit: + """ + Attributes: + payer (str): + payer_type (str): + payer_wallet (UUID): + payee (UUID): + payee_type (int): + payee_wallet (UUID): + created_at (datetime.datetime): + state (StateEnum): * `1` - created + * `2` - delayed + * `3` - pending + * `4` - incomplete + * `5` - success + * `6` - failed + * `7` - expected_failure + * `8` - ROLLED_BACK + * `9` - CANCELED + amount (int): + updated_at (datetime.datetime): + uuid (Union[Unset, UUID]): + details (Union[Unset, Any]): + """ + + payer: str + payer_type: str + payer_wallet: UUID + payee: UUID + payee_type: int + payee_wallet: UUID + created_at: datetime.datetime + state: StateEnum + amount: int + updated_at: datetime.datetime + uuid: Union[Unset, UUID] = UNSET + details: Union[Unset, Any] = UNSET + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) + + def to_dict(self) -> dict[str, Any]: + payer = self.payer + + payer_type = self.payer_type + + payer_wallet = str(self.payer_wallet) + + payee = str(self.payee) + + payee_type = self.payee_type + + payee_wallet = str(self.payee_wallet) + + created_at = self.created_at.isoformat() + + state = self.state.value + + amount = self.amount + + updated_at = self.updated_at.isoformat() + + uuid: Union[Unset, str] = UNSET + if not isinstance(self.uuid, Unset): + uuid = str(self.uuid) + + details = self.details + + field_dict: dict[str, Any] = {} + field_dict.update(self.additional_properties) + field_dict.update( + { + "payer": payer, + "payer_type": payer_type, + "payer_wallet": payer_wallet, + "payee": payee, + "payee_type": payee_type, + "payee_wallet": payee_wallet, + "created_at": created_at, + "state": state, + "amount": amount, + "updated_at": updated_at, + } + ) + if uuid is not UNSET: + field_dict["uuid"] = uuid + if details is not UNSET: + field_dict["details"] = details + + return field_dict + + @classmethod + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + d = dict(src_dict) + payer = d.pop("payer") + + payer_type = d.pop("payer_type") + + payer_wallet = UUID(d.pop("payer_wallet")) + + payee = UUID(d.pop("payee")) + + payee_type = d.pop("payee_type") + + payee_wallet = UUID(d.pop("payee_wallet")) + + created_at = isoparse(d.pop("created_at")) + + state = StateEnum(d.pop("state")) + + amount = d.pop("amount") + + updated_at = isoparse(d.pop("updated_at")) + + _uuid = d.pop("uuid", UNSET) + uuid: Union[Unset, UUID] + if isinstance(_uuid, Unset): + uuid = UNSET + else: + uuid = UUID(_uuid) + + details = d.pop("details", UNSET) + + application_deposit = cls( + payer=payer, + payer_type=payer_type, + payer_wallet=payer_wallet, + payee=payee, + payee_type=payee_type, + payee_wallet=payee_wallet, + created_at=created_at, + state=state, + amount=amount, + updated_at=updated_at, + uuid=uuid, + details=details, + ) + + application_deposit.additional_properties = d + return application_deposit + + @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/utils/clients/gooyal_wallet_client/models/application_withdraw.py b/utils/clients/gooyal_wallet_client/models/application_withdraw.py new file mode 100644 index 0000000..ac64a92 --- /dev/null +++ b/utils/clients/gooyal_wallet_client/models/application_withdraw.py @@ -0,0 +1,170 @@ +import datetime +from collections.abc import Mapping +from typing import Any, TypeVar, Union +from uuid import UUID + +from attrs import define as _attrs_define +from attrs import field as _attrs_field +from dateutil.parser import isoparse + +from ..models.state_enum import StateEnum +from ..types import UNSET, Unset + +T = TypeVar("T", bound="ApplicationWithdraw") + + +@_attrs_define +class ApplicationWithdraw: + """ + Attributes: + payer (UUID): + payer_type (int): + payer_wallet (UUID): + payee (str): + payee_type (str): + payee_wallet (UUID): + created_at (datetime.datetime): + state (StateEnum): * `1` - created + * `2` - delayed + * `3` - pending + * `4` - incomplete + * `5` - success + * `6` - failed + * `7` - expected_failure + * `8` - ROLLED_BACK + * `9` - CANCELED + amount (int): + updated_at (datetime.datetime): + uuid (Union[Unset, UUID]): + details (Union[Unset, Any]): + """ + + payer: UUID + payer_type: int + payer_wallet: UUID + payee: str + payee_type: str + payee_wallet: UUID + created_at: datetime.datetime + state: StateEnum + amount: int + updated_at: datetime.datetime + uuid: Union[Unset, UUID] = UNSET + details: Union[Unset, Any] = UNSET + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) + + def to_dict(self) -> dict[str, Any]: + payer = str(self.payer) + + payer_type = self.payer_type + + payer_wallet = str(self.payer_wallet) + + payee = self.payee + + payee_type = self.payee_type + + payee_wallet = str(self.payee_wallet) + + created_at = self.created_at.isoformat() + + state = self.state.value + + amount = self.amount + + updated_at = self.updated_at.isoformat() + + uuid: Union[Unset, str] = UNSET + if not isinstance(self.uuid, Unset): + uuid = str(self.uuid) + + details = self.details + + field_dict: dict[str, Any] = {} + field_dict.update(self.additional_properties) + field_dict.update( + { + "payer": payer, + "payer_type": payer_type, + "payer_wallet": payer_wallet, + "payee": payee, + "payee_type": payee_type, + "payee_wallet": payee_wallet, + "created_at": created_at, + "state": state, + "amount": amount, + "updated_at": updated_at, + } + ) + if uuid is not UNSET: + field_dict["uuid"] = uuid + if details is not UNSET: + field_dict["details"] = details + + return field_dict + + @classmethod + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + d = dict(src_dict) + payer = UUID(d.pop("payer")) + + payer_type = d.pop("payer_type") + + payer_wallet = UUID(d.pop("payer_wallet")) + + payee = d.pop("payee") + + payee_type = d.pop("payee_type") + + payee_wallet = UUID(d.pop("payee_wallet")) + + created_at = isoparse(d.pop("created_at")) + + state = StateEnum(d.pop("state")) + + amount = d.pop("amount") + + updated_at = isoparse(d.pop("updated_at")) + + _uuid = d.pop("uuid", UNSET) + uuid: Union[Unset, UUID] + if isinstance(_uuid, Unset): + uuid = UNSET + else: + uuid = UUID(_uuid) + + details = d.pop("details", UNSET) + + application_withdraw = cls( + payer=payer, + payer_type=payer_type, + payer_wallet=payer_wallet, + payee=payee, + payee_type=payee_type, + payee_wallet=payee_wallet, + created_at=created_at, + state=state, + amount=amount, + updated_at=updated_at, + uuid=uuid, + details=details, + ) + + application_withdraw.additional_properties = d + return application_withdraw + + @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/utils/clients/gooyal_wallet_client/models/paginated_account_list.py b/utils/clients/gooyal_wallet_client/models/paginated_account_list.py new file mode 100644 index 0000000..18aee85 --- /dev/null +++ b/utils/clients/gooyal_wallet_client/models/paginated_account_list.py @@ -0,0 +1,123 @@ +from collections.abc import Mapping +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.account import Account + + +T = TypeVar("T", bound="PaginatedAccountList") + + +@_attrs_define +class PaginatedAccountList: + """ + Attributes: + count (int): Example: 123. + results (list['Account']): + next_ (Union[None, Unset, str]): Example: http://api.example.org/accounts/?offset=400&limit=100. + previous (Union[None, Unset, str]): Example: http://api.example.org/accounts/?offset=200&limit=100. + """ + + count: int + results: list["Account"] + 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: Mapping[str, Any]) -> T: + from ..models.account import Account + + d = dict(src_dict) + count = d.pop("count") + + results = [] + _results = d.pop("results") + for results_item_data in _results: + results_item = Account.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_account_list = cls( + count=count, + results=results, + next_=next_, + previous=previous, + ) + + paginated_account_list.additional_properties = d + return paginated_account_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/utils/clients/gooyal_wallet_client/models/paginated_transaction_grouped_list.py b/utils/clients/gooyal_wallet_client/models/paginated_transaction_grouped_list.py new file mode 100644 index 0000000..ebde34e --- /dev/null +++ b/utils/clients/gooyal_wallet_client/models/paginated_transaction_grouped_list.py @@ -0,0 +1,123 @@ +from collections.abc import Mapping +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.transaction_grouped import TransactionGrouped + + +T = TypeVar("T", bound="PaginatedTransactionGroupedList") + + +@_attrs_define +class PaginatedTransactionGroupedList: + """ + Attributes: + count (int): Example: 123. + results (list['TransactionGrouped']): + next_ (Union[None, Unset, str]): Example: http://api.example.org/accounts/?offset=400&limit=100. + previous (Union[None, Unset, str]): Example: http://api.example.org/accounts/?offset=200&limit=100. + """ + + count: int + results: list["TransactionGrouped"] + 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: Mapping[str, Any]) -> T: + from ..models.transaction_grouped import TransactionGrouped + + d = dict(src_dict) + count = d.pop("count") + + results = [] + _results = d.pop("results") + for results_item_data in _results: + results_item = TransactionGrouped.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_transaction_grouped_list = cls( + count=count, + results=results, + next_=next_, + previous=previous, + ) + + paginated_transaction_grouped_list.additional_properties = d + return paginated_transaction_grouped_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/utils/clients/gooyal_wallet_client/models/paginated_transaction_list.py b/utils/clients/gooyal_wallet_client/models/paginated_transaction_list.py new file mode 100644 index 0000000..71f2a07 --- /dev/null +++ b/utils/clients/gooyal_wallet_client/models/paginated_transaction_list.py @@ -0,0 +1,123 @@ +from collections.abc import Mapping +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.transaction import Transaction + + +T = TypeVar("T", bound="PaginatedTransactionList") + + +@_attrs_define +class PaginatedTransactionList: + """ + Attributes: + count (int): Example: 123. + results (list['Transaction']): + next_ (Union[None, Unset, str]): Example: http://api.example.org/accounts/?offset=400&limit=100. + previous (Union[None, Unset, str]): Example: http://api.example.org/accounts/?offset=200&limit=100. + """ + + count: int + results: list["Transaction"] + 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: Mapping[str, Any]) -> T: + from ..models.transaction import Transaction + + d = dict(src_dict) + count = d.pop("count") + + results = [] + _results = d.pop("results") + for results_item_data in _results: + results_item = Transaction.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_transaction_list = cls( + count=count, + results=results, + next_=next_, + previous=previous, + ) + + paginated_transaction_list.additional_properties = d + return paginated_transaction_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/utils/clients/gooyal_wallet_client/models/state_enum.py b/utils/clients/gooyal_wallet_client/models/state_enum.py new file mode 100644 index 0000000..dac91c3 --- /dev/null +++ b/utils/clients/gooyal_wallet_client/models/state_enum.py @@ -0,0 +1,16 @@ +from enum import IntEnum + + +class StateEnum(IntEnum): + VALUE_1 = 1 + VALUE_2 = 2 + VALUE_3 = 3 + VALUE_4 = 4 + VALUE_5 = 5 + VALUE_6 = 6 + VALUE_7 = 7 + VALUE_8 = 8 + VALUE_9 = 9 + + def __str__(self) -> str: + return str(self.value) diff --git a/utils/clients/gooyal_wallet_client/models/transaction.py b/utils/clients/gooyal_wallet_client/models/transaction.py new file mode 100644 index 0000000..41a7a83 --- /dev/null +++ b/utils/clients/gooyal_wallet_client/models/transaction.py @@ -0,0 +1,178 @@ +import datetime +from collections.abc import Mapping +from typing import Any, TypeVar, Union +from uuid import UUID + +from attrs import define as _attrs_define +from attrs import field as _attrs_field +from dateutil.parser import isoparse + +from ..models.state_enum import StateEnum +from ..types import UNSET, Unset + +T = TypeVar("T", bound="Transaction") + + +@_attrs_define +class Transaction: + """ + Attributes: + uuid (UUID): + payer (str): + payer_type (str): + payer_wallet (str): + payee (UUID): + payee_type (int): + payee_wallet (str): + created_at (datetime.datetime): + state (StateEnum): * `1` - created + * `2` - delayed + * `3` - pending + * `4` - incomplete + * `5` - success + * `6` - failed + * `7` - expected_failure + * `8` - ROLLED_BACK + * `9` - CANCELED + amount (int): + updated_at (datetime.datetime): + details (Any): + role (int): + delay (Union[Unset, int]): + """ + + uuid: UUID + payer: str + payer_type: str + payer_wallet: str + payee: UUID + payee_type: int + payee_wallet: str + created_at: datetime.datetime + state: StateEnum + amount: int + updated_at: datetime.datetime + details: Any + role: int + delay: Union[Unset, int] = UNSET + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) + + def to_dict(self) -> dict[str, Any]: + uuid = str(self.uuid) + + payer = self.payer + + payer_type = self.payer_type + + payer_wallet = self.payer_wallet + + payee = str(self.payee) + + payee_type = self.payee_type + + payee_wallet = self.payee_wallet + + created_at = self.created_at.isoformat() + + state = self.state.value + + amount = self.amount + + updated_at = self.updated_at.isoformat() + + details = self.details + + role = self.role + + delay = self.delay + + field_dict: dict[str, Any] = {} + field_dict.update(self.additional_properties) + field_dict.update( + { + "uuid": uuid, + "payer": payer, + "payer_type": payer_type, + "payer_wallet": payer_wallet, + "payee": payee, + "payee_type": payee_type, + "payee_wallet": payee_wallet, + "created_at": created_at, + "state": state, + "amount": amount, + "updated_at": updated_at, + "details": details, + "role": role, + } + ) + if delay is not UNSET: + field_dict["delay"] = delay + + return field_dict + + @classmethod + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + d = dict(src_dict) + uuid = UUID(d.pop("uuid")) + + payer = d.pop("payer") + + payer_type = d.pop("payer_type") + + payer_wallet = d.pop("payer_wallet") + + payee = UUID(d.pop("payee")) + + payee_type = d.pop("payee_type") + + payee_wallet = d.pop("payee_wallet") + + created_at = isoparse(d.pop("created_at")) + + state = StateEnum(d.pop("state")) + + amount = d.pop("amount") + + updated_at = isoparse(d.pop("updated_at")) + + details = d.pop("details") + + role = d.pop("role") + + delay = d.pop("delay", UNSET) + + transaction = cls( + uuid=uuid, + payer=payer, + payer_type=payer_type, + payer_wallet=payer_wallet, + payee=payee, + payee_type=payee_type, + payee_wallet=payee_wallet, + created_at=created_at, + state=state, + amount=amount, + updated_at=updated_at, + details=details, + role=role, + delay=delay, + ) + + transaction.additional_properties = d + return transaction + + @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/utils/clients/gooyal_wallet_client/models/transaction_grouped.py b/utils/clients/gooyal_wallet_client/models/transaction_grouped.py new file mode 100644 index 0000000..bf72d4c --- /dev/null +++ b/utils/clients/gooyal_wallet_client/models/transaction_grouped.py @@ -0,0 +1,140 @@ +import datetime +from collections.abc import Mapping +from typing import TYPE_CHECKING, Any, TypeVar +from uuid import UUID + +from attrs import define as _attrs_define +from attrs import field as _attrs_field +from dateutil.parser import isoparse + +if TYPE_CHECKING: + from ..models.transaction import Transaction + + +T = TypeVar("T", bound="TransactionGrouped") + + +@_attrs_define +class TransactionGrouped: + """ + Attributes: + reference (UUID): + application (UUID): + total_amount (float): + total_count (int): + state (int): + description (str): + created_at (datetime.datetime): + role (int): + transactions (list['Transaction']): + """ + + reference: UUID + application: UUID + total_amount: float + total_count: int + state: int + description: str + created_at: datetime.datetime + role: int + transactions: list["Transaction"] + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) + + def to_dict(self) -> dict[str, Any]: + reference = str(self.reference) + + application = str(self.application) + + total_amount = self.total_amount + + total_count = self.total_count + + state = self.state + + description = self.description + + created_at = self.created_at.isoformat() + + role = self.role + + transactions = [] + for transactions_item_data in self.transactions: + transactions_item = transactions_item_data.to_dict() + transactions.append(transactions_item) + + field_dict: dict[str, Any] = {} + field_dict.update(self.additional_properties) + field_dict.update( + { + "reference": reference, + "application": application, + "total_amount": total_amount, + "total_count": total_count, + "state": state, + "description": description, + "created_at": created_at, + "role": role, + "transactions": transactions, + } + ) + + return field_dict + + @classmethod + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + from ..models.transaction import Transaction + + d = dict(src_dict) + reference = UUID(d.pop("reference")) + + application = UUID(d.pop("application")) + + total_amount = d.pop("total_amount") + + total_count = d.pop("total_count") + + state = d.pop("state") + + description = d.pop("description") + + created_at = isoparse(d.pop("created_at")) + + role = d.pop("role") + + transactions = [] + _transactions = d.pop("transactions") + for transactions_item_data in _transactions: + transactions_item = Transaction.from_dict(transactions_item_data) + + transactions.append(transactions_item) + + transaction_grouped = cls( + reference=reference, + application=application, + total_amount=total_amount, + total_count=total_count, + state=state, + description=description, + created_at=created_at, + role=role, + transactions=transactions, + ) + + transaction_grouped.additional_properties = d + return transaction_grouped + + @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/utils/clients/gooyal_wallet_client/py.typed b/utils/clients/gooyal_wallet_client/py.typed new file mode 100644 index 0000000..1aad327 --- /dev/null +++ b/utils/clients/gooyal_wallet_client/py.typed @@ -0,0 +1 @@ +# Marker file for PEP 561 \ No newline at end of file diff --git a/utils/clients/gooyal_wallet_client/types.py b/utils/clients/gooyal_wallet_client/types.py new file mode 100644 index 0000000..1b96ca4 --- /dev/null +++ b/utils/clients/gooyal_wallet_client/types.py @@ -0,0 +1,54 @@ +"""Contains some shared types for properties""" + +from collections.abc import Mapping, MutableMapping +from http import HTTPStatus +from typing import IO, BinaryIO, Generic, Literal, Optional, TypeVar, Union + +from attrs import define + + +class Unset: + def __bool__(self) -> Literal[False]: + return False + + +UNSET: Unset = Unset() + +# The types that `httpx.Client(files=)` can accept, copied from that library. +FileContent = Union[IO[bytes], bytes, str] +FileTypes = Union[ + # (filename, file (or bytes), content_type) + tuple[Optional[str], FileContent, Optional[str]], + # (filename, file (or bytes), content_type, headers) + tuple[Optional[str], FileContent, Optional[str], Mapping[str, str]], +] +RequestFiles = list[tuple[str, FileTypes]] + + +@define +class File: + """Contains information for file uploads""" + + payload: BinaryIO + file_name: Optional[str] = None + mime_type: Optional[str] = None + + def to_tuple(self) -> FileTypes: + """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", "FileTypes", "RequestFiles", "Response", "Unset"] diff --git a/utils/commons.py b/utils/commons.py new file mode 100644 index 0000000..43838c5 --- /dev/null +++ b/utils/commons.py @@ -0,0 +1,112 @@ +from main import settings +from utils.exceptions import UnprocessableEntity +from apps.payout.constans import TransferTypeChoices +import uuid +from utils.wallet_client import get_user_wallets +from django.utils.translation import gettext_lazy as _ +from main import settings + + +def calculate_reward_wallet_commission(amount: int) -> int: + platform_commission = 0.01 * amount + platform_commission += platform_commission * 0.10 + return int(platform_commission) + +def calculate_platform_commission(amount: int) -> int: + platform_commission = 0.01 * amount + # platform_commission += platform_commission * 0.10 # disable Value Added Tax + return int(platform_commission) + +def calculate_transfer_commission(amount: int, transfer_type: TransferTypeChoices) -> int: + commission = 0 + if transfer_type == TransferTypeChoices.ACH: + if amount < 20000: # minimum settlement amount 20000 + raise UnprocessableEntity(_('Minimum PAYA settlement amount is 2000 toman.')) + commission = settings.COMMISSION_ACH_RATE * amount + if commission < settings.COMMISSION_ACH_LOWER_BOUND: + commission = settings.COMMISSION_ACH_LOWER_BOUND + elif commission > settings.COMMISSION_ACH_UPPER_BOUND: + commission = settings.COMMISSION_ACH_UPPER_BOUND + elif transfer_type == TransferTypeChoices.RTGS: + if amount < 100000: # minimum settlement amount 100000 + raise UnprocessableEntity(_('Minimum Real Time settlement amount is 10000 toman.')) + commission = settings.TOMAN_COMMISSION_RTGS_RATE * amount + if commission < settings.TOMAN_COMMISSION_RTGS_LOWER_BOUND: + commission = settings.TOMAN_COMMISSION_RTGS_LOWER_BOUND + elif commission > settings.TOMAN_COMMISSION_RTGS_UPPER_BOUND: + commission = settings.TOMAN_COMMISSION_RTGS_UPPER_BOUND + else: + raise UnprocessableEntity(_('Not a valid transfer type')) + return commission + +def calculate_settlement_amounts(user_id: uuid, amount: int, transfer_type: TransferTypeChoices.choices) -> (int, int, int, int): + user_wallets = get_user_wallets(str(user_id), [settings.WALLET_RIAL, settings.WALLET_REWARD]) + rial_wallet_balance = user_wallets[settings.WALLET_RIAL] if settings.WALLET_RIAL in user_wallets else 0 + reward_wallet_balance = user_wallets[settings.WALLET_REWARD] if settings.WALLET_REWARD in user_wallets else 0 + + user_balance = rial_wallet_balance + reward_wallet_balance + if not user_balance: + raise UnprocessableEntity(_('settlement not possible for balance zero')) + commission = calculate_transfer_commission(amount, transfer_type) + if user_balance < amount: # required balance + raise UnprocessableEntity(_('settlement not possible for balance less than amount')) + amount -= commission + rial_commission = 0 if not rial_wallet_balance else commission if commission <= rial_wallet_balance else rial_wallet_balance + reward_commission = commission - rial_commission if rial_commission != commission else 0 + rial_wallet_balance -= rial_commission + reward_wallet_balance -= reward_commission + + + rial_amount = 0 if not rial_wallet_balance else amount if amount <= rial_wallet_balance else rial_wallet_balance + reward_amount = amount - rial_amount if rial_amount != amount else 0 + + if reward_amount: + additional_reward_commission = calculate_reward_wallet_commission(reward_amount) + reward_commission += additional_reward_commission + reward_amount -= additional_reward_commission + return rial_amount, rial_commission, reward_amount, reward_commission + +def calculate_settlement_amounts_by_transfer_commission_free(user_id: uuid, amount: int) -> (int, int, int, int): + user_wallets = get_user_wallets(str(user_id), [settings.WALLET_RIAL, settings.WALLET_REWARD]) + rial_wallet_balance = user_wallets[settings.WALLET_RIAL] if settings.WALLET_RIAL in user_wallets else 0 + reward_wallet_balance = user_wallets[settings.WALLET_REWARD] if settings.WALLET_REWARD in user_wallets else 0 + + user_balance = rial_wallet_balance + reward_wallet_balance + if not user_balance: + raise UnprocessableEntity(_('settlement not possible for balance zero')) + if user_balance < amount: # required balance + raise UnprocessableEntity(_('settlement not possible for balance less than amount')) + commission = calculate_platform_commission(amount) # transfer commission paid by platform + amount -= commission + rial_commission = 0 if not rial_wallet_balance else commission if commission <= rial_wallet_balance else rial_wallet_balance + reward_commission = commission - rial_commission if rial_commission != commission else 0 + rial_wallet_balance -= rial_commission + reward_wallet_balance -= reward_commission + + rial_amount = 0 if not rial_wallet_balance else amount if amount <= rial_wallet_balance else rial_wallet_balance + reward_amount = amount - rial_amount if rial_amount != amount else 0 + + return rial_amount, rial_commission, reward_amount, reward_commission + +def calculate_settlement_amounts_by_transfer_commission_free_and_single_commission_transaction(user_id: uuid, amount: int) -> (int, int, int, int): + user_wallets = get_user_wallets(str(user_id), [settings.WALLET_RIAL, settings.WALLET_REWARD]) + rial_wallet_balance = user_wallets[settings.WALLET_RIAL] if settings.WALLET_RIAL in user_wallets else 0 + reward_wallet_balance = user_wallets[settings.WALLET_REWARD] if settings.WALLET_REWARD in user_wallets else 0 + + user_balance = rial_wallet_balance + reward_wallet_balance + if not user_balance: + raise UnprocessableEntity(_('settlement not possible for balance zero')) + if user_balance < amount: # required balance + raise UnprocessableEntity(_('settlement not possible for balance less than amount')) + commission = calculate_platform_commission(amount) # transfer commission paid by platform + amount -= commission + # requirement: commission transaction in single form instead of two transaction(if one has value!=0 other should be 0) + rial_commission = 0 if not rial_wallet_balance else commission if commission <= rial_wallet_balance else 0 + reward_commission = 0 if not reward_wallet_balance else commission if not rial_commission and commission <= reward_wallet_balance else 0 + rial_wallet_balance -= rial_commission + reward_wallet_balance -= reward_commission + + rial_amount = 0 if not rial_wallet_balance else amount if amount <= rial_wallet_balance else rial_wallet_balance + reward_amount = amount - rial_amount if rial_amount != amount else 0 + + return rial_amount, rial_commission, reward_amount, reward_commission \ No newline at end of file diff --git a/utils/exceptions.py b/utils/exceptions.py new file mode 100644 index 0000000..d85b168 --- /dev/null +++ b/utils/exceptions.py @@ -0,0 +1,93 @@ +import logging + +from django.conf import settings +from django.utils import timezone +from rest_framework.exceptions import APIException +from rest_framework.views import exception_handler as drf_exception_handler + +logger = logging.getLogger(__name__) +def exception_handler(exc, context): + logger.exception(exc) + # پاسخ پیش‌فرض DRF را دریافت می‌کنیم + response = drf_exception_handler(exc, context) + + if response is not None: + response_data = { + 'success': False, + 'status_code': response.status_code, + 'status_message': str(exc.default_detail), + 'details': exc.detail, + } + + if isinstance(exc, APIException): + try: + if isinstance(exc.detail, dict): + if 'code' in exc.detail: + error = exc.detail['code'] + else: + attr = next(iter(exc.detail)) + error = exc.detail[attr].code + else: + error = exc.detail.code or exc.code + except: + error = '' + + # if isinstance(exc.detail, str): + # message = exc.detail + # elif isinstance(exc.detail, dict): + # if 'message' in exc.detail or 'string' in exc.detail: + # message = exc.detail.get('message') or exc.detail.get('string') + # else: + # message = error + # + # else: + # message = error + # + # response_data['message'] = message + response_data['details'] = exc.detail if isinstance(exc.detail, dict) else {} + response_data['details']['error'] = error + response_data['details']['timestamp'] = timezone.now().isoformat() + + response.data = response_data + + return response + + +# در فایل middleware.py +from django.http import JsonResponse + +class ErrorMiddleware: + def __init__(self, get_response): + self.get_response = get_response + + def __call__(self, request): + response = self.get_response(request) + return response + + def process_exception(self, request, exception): + logger.exception(exception) + return JsonResponse( + { + "success": False, + "status_code": 500, + "status_message": "Internal server error", + "details": str(exception) if settings.DEBUG else None, + }, + status=500 + ) + +from rest_framework.exceptions import APIException +from rest_framework import status +from django.utils.translation import gettext_lazy as _ + + +class UnprocessableEntity(APIException): + status_code = 422 + default_detail = 'The request was well-formed but cannot be processed due to semantic errors.' + default_code = 'unprocessable_entity' + +class ServiceUnavailable(APIException): + status_code = status.HTTP_503_SERVICE_UNAVAILABLE + default_ = _('SERVICE_UNAVAILABLE') + default_code = 'service_unavailable' + default_detail = 'Service Unavailable' diff --git a/utils/i18n.py b/utils/i18n.py new file mode 100644 index 0000000..fe38f0d --- /dev/null +++ b/utils/i18n.py @@ -0,0 +1,14 @@ +from django.utils import translation + +class ForceAdminLanguageMiddleware: + def __init__(self, get_response): + self.get_response = get_response + + def __call__(self, request): + if request.path.startswith('/admin/'): + translation.activate('fa') + request.LANGUAGE_CODE = 'fa' + else: + translation.activate('fa') + request.LANGUAGE_CODE = 'fa' + return self.get_response(request) \ No newline at end of file diff --git a/utils/logs/__init__.py b/utils/logs/__init__.py new file mode 100644 index 0000000..5afab06 --- /dev/null +++ b/utils/logs/__init__.py @@ -0,0 +1,4 @@ +from .formatters import LokiFormatter +from .handlers import LokiHandler + +__all__ = ['LokiHandler', 'LokiFormatter'] \ No newline at end of file diff --git a/utils/logs/formatters.py b/utils/logs/formatters.py new file mode 100644 index 0000000..def86d5 --- /dev/null +++ b/utils/logs/formatters.py @@ -0,0 +1,77 @@ +import logging +import socket +from datetime import datetime +from logging import BASIC_FORMAT + + +class LokiFormatter(logging.Formatter): + asctime_search = "%(asctime)" + tz = "UTC" + source = "Loki" + src_host = "localhost" + tags = {} + + def __init__(self, fmt, dfmt, style, fqdn=False): + super(LokiFormatter, self).__init__() + + self.fmt = fmt or BASIC_FORMAT + self.dfmt = dfmt or "%Y-%m-%d %H:%M:%S" + self.style = style + + if fqdn: + self.host = socket.getfqdn() + else: + self.host = socket.gethostname() + + def format_timestamp(self, time): + return str(int(time * 10**9)) + + def usesTime(self): + return self.fmt.find(self.asctime_search) >= 0 + + def formatMessage(self, record): + try: + return self.fmt % record.__dict__ + except KeyError as e: + raise ValueError("Formatting field not found in record: %s" % e) + + def format(self, record): + record.message = record.getMessage() + + if self.usesTime(): + record.asctime = self.formatTime(record, self.dfmt) + + message = self.formatMessage(record) + + if record.exc_info: + if not record.exc_text: + record.exc_text = self.formatException(record.exc_info) + + if record.exc_text: + if message[-1:] != "\n": + message = message + "\n" + message = message + record.exc_text + + if record.stack_info: + if message[-1:] != "\n": + message = message + "\n" + + message = message + self.formatStack(record.stack_info) + + message = { + "streams": [ + { + "stream": { + **self.tags, + }, + "values": [ + [ + self.format_timestamp(record.created), + message, + ] + ], + } + ] + } + + return message diff --git a/utils/logs/handlers.py b/utils/logs/handlers.py new file mode 100644 index 0000000..07df949 --- /dev/null +++ b/utils/logs/handlers.py @@ -0,0 +1,58 @@ +import logging +import sys +from threading import Thread +from django.conf import settings +import requests + + +class LokiHandler(logging.Handler): + def __init__( + self, + timeout=0.5, + # url="http://localhost:3100/loki/api/v1/push", + url=f'{settings.LOKI_BASE_PUBLIC_URL}/api/v1/push', + auth=None, + tags={}, + mode="sync", + ): + super(LokiHandler, self).__init__() + + self._url = url + self._timeout = timeout + self._auth = auth + self._tags = tags + + self._mode = mode + + def emit(self, record): + try: + payload = self.formatter.format(record) + + self._push_message( + self._url, json=payload, timeout=self._timeout, auth=self._auth + ) + except requests.exceptions.ReadTimeout: + sys.stderr.write("Loki connection timed out\n") + except Exception as e: + sys.stderr.write(f"Loki connection failed with: {e}\n") + + def setFormatter(self, fmt): + fmt.tags = self._tags + + self.formatter = fmt + + def _push_message(self, *args, **kwargs): + if self._mode == "sync": + return _push_message(*args, **kwargs) + + if self._mode == "thread": + return Thread(target=_push_message, args=args, kwargs=kwargs).start() + + +def _push_message(*args, **kwargs): + response = requests.post(*args, **kwargs) + + if response.status_code != 204: + sys.stderr.write( + f"Got status {response.status_code} from loki with message: {response.text}\n" + ) diff --git a/utils/wallet_client.py b/utils/wallet_client.py new file mode 100644 index 0000000..87e5b8b --- /dev/null +++ b/utils/wallet_client.py @@ -0,0 +1,139 @@ +import time + +import requests +from django.conf import settings +from django.core.cache import cache +from httpx import Request + +from utils.clients.gooyal_wallet_client import AuthenticatedClient +from utils.clients.gooyal_wallet_client.models import Transaction, Account, ApplicationDeposit, ApplicationWithdraw, PaginatedAccountList +from utils.clients.gooyal_wallet_client.api.wallet import (wallet_api_application_deposit_create, + wallet_api_application_deposit_rollback_retrieve, + wallet_api_application_deposit_verify_retrieve, + wallet_api_application_withdraw_create, + wallet_api_application_withdraw_rollback_retrieve, + wallet_api_application_withdraw_verify_retrieve, + wallet_api_application_user_wallets_list) + + + + +def login_as_client_credentials(): + access_token = cache.get('settlement_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.OAUTH2_PROVIDER_SCOPES, + } + auth = (settings.OAUTH2_PROVIDER_CLIENT_ID, settings.OAUTH2_PROVIDER_CLIENT_SECRET) + + response = requests.post(f'{settings.OAUTH2_PROVIDER_BASE_PUBLIC_URL}/token/', + data=data, + auth=auth) + print(response.content) + + auth_data = response.json() + if 'access_token' in auth_data: + auth_data['created_at'] = time.time() + cache.set('settlement_access_token', auth_data, timeout=auth_data.get('expires_in') - 5) + + return auth_data + + +def log_request(request: Request): + print(request.headers['authorization']) + print( + f"Request event hook: {request.method} {request.url} {request.method} {request.headers} - Waiting for response") + + +def log_response(response): + request = response.request + print(f"Response event hook: {request.method} {request.url} - Status {response.status_code}") + + +def get_client(): + access_token = login_as_client_credentials()['access_token'] + client = AuthenticatedClient(base_url=settings.WALLET_BASE_PUBLIC_URL, token=access_token, + httpx_args={"event_hooks": {"request": [log_request], "response": [log_response]}}, + ) + return client + + +def deposit_to_user_wallet_submit(payer_wallet, data): + class Tmp(): + def to_dict(self): + return data + + deposit_data = Tmp() + client = get_client() + response: ApplicationDeposit = wallet_api_application_deposit_create.sync(payer_wallet=payer_wallet, + client=client, + body=deposit_data) + print(response) + return response + + +def deposit_to_user_wallet_verify(payer_wallet, uuid): + client = get_client() + response: ApplicationDeposit = wallet_api_application_deposit_verify_retrieve.sync(payer_wallet=payer_wallet, uuid=uuid, client=client) + print(response) + return response + +def rollback_deposit_to_user_wallet(payer_wallet, uuid): + client = get_client() + response: ApplicationDeposit = wallet_api_application_deposit_rollback_retrieve.sync(payer_wallet=payer_wallet, uuid=uuid, client=client) + print(response) + return response + + +def withdraw_from_user_wallet_submit(payee_wallet, data): + class Tmp(): + def to_dict(self): + return data + + withdraw_data = Tmp() + client = get_client() + response: ApplicationWithdraw = wallet_api_application_withdraw_create.sync(payee_wallet=payee_wallet, client=client, body=withdraw_data) + print(response) + return response + +def rollback_withdraw_from_user_wallet(payee_wallet, uuid): + client = get_client() + response: ApplicationWithdraw = wallet_api_application_withdraw_rollback_retrieve.sync(payee_wallet=payee_wallet, uuid=uuid, client=client) + print(response) + return response + + +def withdraw_from_user_wallet_verify(payee_wallet, uuid): + client = get_client() + response: ApplicationWithdraw = wallet_api_application_withdraw_verify_retrieve.sync(payee_wallet=payee_wallet, uuid=uuid, client=client) + print(response) + return response + + +def get_user_wallets(owner, wallets): + client = get_client() + # by pass several wallet query params: [','.join([str(i) for i in wallets])] + response: PaginatedAccountList = wallet_api_application_user_wallets_list.sync(owner=owner, wallet=[','.join([str(i) for i in wallets])], client=client) + print(response) + balances = dict(map(lambda result: (str(result.wallet), result.balance), response.results)) + return balances + + +sample_data = { + "uuid": "3fa85f64-5717-4562-b3fc-2c963f66afb1", + "payee_id": "5d66d02e-6087-4b0a-bb0c-291d5c11755a", + "payee_type": 1, + "amount": 2000, + "details": "string", +}