Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions mpt_api_client/http/__init__.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
from mpt_api_client.http.async_client import AsyncHTTPClient
from mpt_api_client.http.async_service import AsyncService
from mpt_api_client.http.client import HTTPClient
from mpt_api_client.http.mixins import AsyncCreateMixin, AsyncDeleteMixin, CreateMixin, DeleteMixin
from mpt_api_client.http.service import Service

__all__ = [ # noqa: WPS410
"AsyncCreateMixin",
"AsyncDeleteMixin",
"AsyncHTTPClient",
"AsyncService",
"CreateMixin",
"DeleteMixin",
"HTTPClient",
"Service",
]
14 changes: 0 additions & 14 deletions mpt_api_client/http/async_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,20 +77,6 @@ async def iterate(self, batch_size: int = 100) -> AsyncIterator[Model]:
break
offset = items_collection.meta.pagination.next_offset()

async def get(self, resource_id: str, select: list[str] | str | None = None) -> Model:
"""Fetch a specific resource using `GET /endpoint/{resource_id}`.

Args:
resource_id: Resource ID.
select: List of fields to select.

Returns:
Resource object.
"""
if isinstance(select, list):
select = ",".join(select) if select else None
return await self._resource_action(resource_id=resource_id, query_params={"select": select})

async def _fetch_page_as_response(self, limit: int = 100, offset: int = 0) -> httpx.Response:
"""Fetch one page of resources.

Expand Down
37 changes: 37 additions & 0 deletions mpt_api_client/http/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,3 +192,40 @@ async def download(self, resource_id: str) -> FileModel:
resource_id, method="GET", headers={"Accept": "*"}
)
return FileModel(response)


class GetMixin[Model]:
"""Get resource mixin."""

def get(self, resource_id: str, select: list[str] | str | None = None) -> Model:
"""Fetch a specific resource using `GET /endpoint/{resource_id}`.

Args:
resource_id: Resource ID.
select: List of fields to select.

Returns:
Resource object.
"""
if isinstance(select, list):
select = ",".join(select) if select else None

return self._resource_action(resource_id=resource_id, query_params={"select": select}) # type: ignore[attr-defined, no-any-return]


class AsyncGetMixin[Model]:
"""Async get resource mixin."""

async def get(self, resource_id: str, select: list[str] | str | None = None) -> Model:
"""Fetch a specific resource using `GET /endpoint/{resource_id}`.

Args:
resource_id: Resource ID.
select: List of fields to select.

Returns:
Resource object.
"""
if isinstance(select, list):
select = ",".join(select) if select else None
return await self._resource_action(resource_id=resource_id, query_params={"select": select}) # type: ignore[attr-defined, no-any-return]
15 changes: 0 additions & 15 deletions mpt_api_client/http/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,21 +76,6 @@ def iterate(self, batch_size: int = 100) -> Iterator[Model]:
break
offset = items_collection.meta.pagination.next_offset()

def get(self, resource_id: str, select: list[str] | str | None = None) -> Model:
"""Fetch a specific resource using `GET /endpoint/{resource_id}`.

Args:
resource_id: Resource ID.
select: List of fields to select.

Returns:
Resource object.
"""
if isinstance(select, list):
select = ",".join(select) if select else None

return self._resource_action(resource_id=resource_id, query_params={"select": select})

def _fetch_page_as_response(self, limit: int = 100, offset: int = 0) -> httpx.Response:
"""Fetch one page of resources.

Expand Down
4 changes: 4 additions & 0 deletions mpt_api_client/resources/accounts/account.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from mpt_api_client.http import AsyncService, Service
from mpt_api_client.http.mixins import (
AsyncCreateMixin,
AsyncGetMixin,
AsyncUpdateMixin,
CreateMixin,
GetMixin,
UpdateMixin,
)
from mpt_api_client.models import Model
Expand Down Expand Up @@ -38,6 +40,7 @@ class AccountsService(
ActivatableMixin[Account],
EnablableMixin[Account],
ValidateMixin[Account],
GetMixin[Account],
Service[Account],
AccountsServiceConfig,
):
Expand All @@ -56,6 +59,7 @@ class AsyncAccountsService(
AsyncActivatableMixin[Account],
AsyncEnablableMixin[Account],
AsyncValidateMixin[Account],
AsyncGetMixin[Account],
AsyncService[Account],
AccountsServiceConfig,
):
Expand Down
4 changes: 4 additions & 0 deletions mpt_api_client/resources/accounts/account_user_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
from mpt_api_client.http.mixins import (
AsyncCreateMixin,
AsyncDeleteMixin,
AsyncGetMixin,
AsyncUpdateMixin,
CreateMixin,
DeleteMixin,
GetMixin,
UpdateMixin,
)
from mpt_api_client.models import Model
Expand All @@ -26,6 +28,7 @@ class AccountUserGroupsService(
CreateMixin[AccountUserGroup],
DeleteMixin,
UpdateMixin[AccountUserGroup],
GetMixin[AccountUserGroup],
Service[AccountUserGroup],
AccountUserGroupsServiceConfig,
):
Expand All @@ -36,6 +39,7 @@ class AsyncAccountUserGroupsService(
AsyncCreateMixin[AccountUserGroup],
AsyncDeleteMixin,
AsyncUpdateMixin[AccountUserGroup],
AsyncGetMixin[AccountUserGroup],
AsyncService[AccountUserGroup],
AccountUserGroupsServiceConfig,
):
Expand Down
6 changes: 5 additions & 1 deletion mpt_api_client/resources/accounts/account_users.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from mpt_api_client.http import AsyncService, Service
from mpt_api_client.http.mixins import (
AsyncCreateMixin,
AsyncGetMixin,
CreateMixin,
GetMixin,
)
from mpt_api_client.models import Model
from mpt_api_client.resources.accounts.account_user_groups import (
Expand Down Expand Up @@ -29,6 +31,7 @@ class AccountUsersServiceConfig:
class AccountUsersService(
CreateMixin[AccountUser],
InvitableMixin[AccountUser],
GetMixin[AccountUser],
Service[AccountUser],
AccountUsersServiceConfig,
):
Expand All @@ -44,8 +47,9 @@ def groups(self, account_user_id: str) -> AccountUserGroupsService:

class AsyncAccountUsersService(
AsyncCreateMixin[AccountUser],
AsyncService[AccountUser],
AsyncInvitableMixin[AccountUser],
AsyncGetMixin[AccountUser],
AsyncService[AccountUser],
AccountUsersServiceConfig,
):
"""Asynchronous Account Users Service."""
Expand Down
4 changes: 4 additions & 0 deletions mpt_api_client/resources/accounts/accounts_user_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
from mpt_api_client.http.mixins import (
AsyncCreateMixin,
AsyncDeleteMixin,
AsyncGetMixin,
AsyncUpdateMixin,
CreateMixin,
DeleteMixin,
GetMixin,
UpdateMixin,
)
from mpt_api_client.models import Model
Expand All @@ -25,6 +27,7 @@ class AccountsUserGroupsServiceConfig:
class AccountsUserGroupsService(
UpdateMixin[AccountsUserGroup],
DeleteMixin,
GetMixin[AccountsUserGroup],
CreateMixin[AccountsUserGroup],
Service[AccountsUserGroup],
AccountsUserGroupsServiceConfig,
Expand All @@ -35,6 +38,7 @@ class AccountsUserGroupsService(
class AsyncAccountsUserGroupsService(
AsyncUpdateMixin[AccountsUserGroup],
AsyncDeleteMixin,
AsyncGetMixin[AccountsUserGroup],
AsyncCreateMixin[AccountsUserGroup],
AsyncService[AccountsUserGroup],
AccountsUserGroupsServiceConfig,
Expand Down
6 changes: 5 additions & 1 deletion mpt_api_client/resources/accounts/accounts_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
from mpt_api_client.http.mixins import (
AsyncCreateMixin,
AsyncDeleteMixin,
AsyncGetMixin,
AsyncUpdateMixin,
CreateMixin,
DeleteMixin,
GetMixin,
UpdateMixin,
)
from mpt_api_client.models import Model
Expand Down Expand Up @@ -35,6 +37,7 @@ class AccountsUsersService(
DeleteMixin,
CreateMixin[AccountsUser],
InvitableMixin[AccountsUser],
GetMixin[AccountsUser],
Service[AccountsUser],
AccountsUsersServiceConfig,
):
Expand All @@ -55,8 +58,9 @@ class AsyncAccountsUsersService(
AsyncUpdateMixin[AccountsUser],
AsyncDeleteMixin,
AsyncCreateMixin[AccountsUser],
AsyncService[AccountsUser],
AsyncInvitableMixin[AccountsUser],
AsyncGetMixin[AccountsUser],
AsyncService[AccountsUser],
AccountsUsersServiceConfig,
):
"""Asynchronous Account Users Service."""
Expand Down
4 changes: 4 additions & 0 deletions mpt_api_client/resources/accounts/api_tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
from mpt_api_client.http.mixins import (
AsyncCreateMixin,
AsyncDeleteMixin,
AsyncGetMixin,
AsyncUpdateMixin,
CreateMixin,
DeleteMixin,
GetMixin,
UpdateMixin,
)
from mpt_api_client.models import Model
Expand All @@ -28,6 +30,7 @@ class ApiTokensService(
DeleteMixin,
UpdateMixin[ApiToken],
EnablableMixin[ApiToken],
GetMixin[ApiToken],
Service[ApiToken],
ApiTokensServiceConfig,
):
Expand All @@ -39,6 +42,7 @@ class AsyncApiTokensService(
AsyncDeleteMixin,
AsyncUpdateMixin[ApiToken],
AsyncEnablableMixin[ApiToken],
AsyncGetMixin[ApiToken],
AsyncService[ApiToken],
ApiTokensServiceConfig,
):
Expand Down
4 changes: 4 additions & 0 deletions mpt_api_client/resources/accounts/buyers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
from mpt_api_client.http.mixins import (
AsyncCreateMixin,
AsyncDeleteMixin,
AsyncGetMixin,
AsyncUpdateMixin,
CreateMixin,
DeleteMixin,
GetMixin,
UpdateMixin,
)
from mpt_api_client.models import Model
Expand Down Expand Up @@ -38,6 +40,7 @@ class BuyersService(
ActivatableMixin[Buyer],
EnablableMixin[Buyer],
ValidateMixin[Buyer],
GetMixin[Buyer],
Service[Buyer],
BuyersServiceConfig,
):
Expand Down Expand Up @@ -69,6 +72,7 @@ class AsyncBuyersService(
AsyncActivatableMixin[Buyer],
AsyncEnablableMixin[Buyer],
AsyncValidateMixin[Buyer],
AsyncGetMixin[Buyer],
AsyncService[Buyer],
BuyersServiceConfig,
):
Expand Down
4 changes: 4 additions & 0 deletions mpt_api_client/resources/accounts/cloud_tenants.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
from mpt_api_client.http.mixins import (
AsyncCreateMixin,
AsyncDeleteMixin,
AsyncGetMixin,
AsyncUpdateMixin,
CreateMixin,
DeleteMixin,
GetMixin,
UpdateMixin,
)
from mpt_api_client.models import Model
Expand All @@ -26,6 +28,7 @@ class CloudTenantsService(
CreateMixin[CloudTenant],
DeleteMixin,
UpdateMixin[CloudTenant],
GetMixin[CloudTenant],
Service[CloudTenant],
CloudTenantsServiceConfig,
):
Expand All @@ -36,6 +39,7 @@ class AsyncCloudTenantsService(
AsyncCreateMixin[CloudTenant],
AsyncDeleteMixin,
AsyncUpdateMixin[CloudTenant],
AsyncGetMixin[CloudTenant],
AsyncService[CloudTenant],
CloudTenantsServiceConfig,
):
Expand Down
4 changes: 4 additions & 0 deletions mpt_api_client/resources/accounts/erp_links.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from mpt_api_client.http import AsyncService, Service
from mpt_api_client.http.mixins import (
AsyncCreateMixin,
AsyncGetMixin,
AsyncUpdateMixin,
CreateMixin,
GetMixin,
UpdateMixin,
)
from mpt_api_client.models import Model
Expand All @@ -25,6 +27,7 @@ class ErpLinksService(
CreateMixin[ErpLink],
UpdateMixin[ErpLink],
BlockableMixin[ErpLink],
GetMixin[ErpLink],
Service[ErpLink],
ErpLinksServiceConfig,
):
Expand All @@ -35,6 +38,7 @@ class AsyncErpLinksService(
AsyncCreateMixin[ErpLink],
AsyncUpdateMixin[ErpLink],
AsyncBlockableMixin[ErpLink],
AsyncGetMixin[ErpLink],
AsyncService[ErpLink],
ErpLinksServiceConfig,
):
Expand Down
4 changes: 4 additions & 0 deletions mpt_api_client/resources/accounts/licensees.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
from mpt_api_client.http.mixins import (
AsyncCreateMixin,
AsyncDeleteMixin,
AsyncGetMixin,
AsyncUpdateMixin,
CreateMixin,
DeleteMixin,
GetMixin,
UpdateMixin,
)
from mpt_api_client.models import Model
Expand All @@ -28,6 +30,7 @@ class LicenseesService(
DeleteMixin,
UpdateMixin[Licensee],
EnablableMixin[Licensee],
GetMixin[Licensee],
Service[Licensee],
LicenseesServiceConfig,
):
Expand All @@ -39,6 +42,7 @@ class AsyncLicenseesService(
AsyncDeleteMixin,
AsyncUpdateMixin[Licensee],
AsyncEnablableMixin[Licensee],
AsyncGetMixin[Licensee],
AsyncService[Licensee],
LicenseesServiceConfig,
):
Expand Down
Loading