Skip to content

Commit 2cd7079

Browse files
committed
MPT-14452 Move get from service into a mixin
1 parent e1346f4 commit 2cd7079

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+388
-119
lines changed

mpt_api_client/http/__init__.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
11
from mpt_api_client.http.async_client import AsyncHTTPClient
22
from mpt_api_client.http.async_service import AsyncService
33
from mpt_api_client.http.client import HTTPClient
4-
from mpt_api_client.http.mixins import AsyncCreateMixin, AsyncDeleteMixin, CreateMixin, DeleteMixin
54
from mpt_api_client.http.service import Service
65

76
__all__ = [ # noqa: WPS410
8-
"AsyncCreateMixin",
9-
"AsyncDeleteMixin",
107
"AsyncHTTPClient",
118
"AsyncService",
12-
"CreateMixin",
13-
"DeleteMixin",
149
"HTTPClient",
1510
"Service",
1611
]

mpt_api_client/http/async_service.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -77,20 +77,6 @@ async def iterate(self, batch_size: int = 100) -> AsyncIterator[Model]:
7777
break
7878
offset = items_collection.meta.pagination.next_offset()
7979

80-
async def get(self, resource_id: str, select: list[str] | str | None = None) -> Model:
81-
"""Fetch a specific resource using `GET /endpoint/{resource_id}`.
82-
83-
Args:
84-
resource_id: Resource ID.
85-
select: List of fields to select.
86-
87-
Returns:
88-
Resource object.
89-
"""
90-
if isinstance(select, list):
91-
select = ",".join(select) if select else None
92-
return await self._resource_action(resource_id=resource_id, query_params={"select": select})
93-
9480
async def _fetch_page_as_response(self, limit: int = 100, offset: int = 0) -> httpx.Response:
9581
"""Fetch one page of resources.
9682

mpt_api_client/http/mixins.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,3 +192,40 @@ async def download(self, resource_id: str) -> FileModel:
192192
resource_id, method="GET", headers={"Accept": "*"}
193193
)
194194
return FileModel(response)
195+
196+
197+
class GetMixin[Model]:
198+
"""Get resource mixin."""
199+
200+
def get(self, resource_id: str, select: list[str] | str | None = None) -> Model:
201+
"""Fetch a specific resource using `GET /endpoint/{resource_id}`.
202+
203+
Args:
204+
resource_id: Resource ID.
205+
select: List of fields to select.
206+
207+
Returns:
208+
Resource object.
209+
"""
210+
if isinstance(select, list):
211+
select = ",".join(select) if select else None
212+
213+
return self._resource_action(resource_id=resource_id, query_params={"select": select}) # type: ignore[attr-defined, no-any-return]
214+
215+
216+
class AsyncGetMixin[Model]:
217+
"""Async get resource mixin."""
218+
219+
async def get(self, resource_id: str, select: list[str] | str | None = None) -> Model:
220+
"""Fetch a specific resource using `GET /endpoint/{resource_id}`.
221+
222+
Args:
223+
resource_id: Resource ID.
224+
select: List of fields to select.
225+
226+
Returns:
227+
Resource object.
228+
"""
229+
if isinstance(select, list):
230+
select = ",".join(select) if select else None
231+
return await self._resource_action(resource_id=resource_id, query_params={"select": select}) # type: ignore[attr-defined, no-any-return]

mpt_api_client/http/service.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -76,21 +76,6 @@ def iterate(self, batch_size: int = 100) -> Iterator[Model]:
7676
break
7777
offset = items_collection.meta.pagination.next_offset()
7878

79-
def get(self, resource_id: str, select: list[str] | str | None = None) -> Model:
80-
"""Fetch a specific resource using `GET /endpoint/{resource_id}`.
81-
82-
Args:
83-
resource_id: Resource ID.
84-
select: List of fields to select.
85-
86-
Returns:
87-
Resource object.
88-
"""
89-
if isinstance(select, list):
90-
select = ",".join(select) if select else None
91-
92-
return self._resource_action(resource_id=resource_id, query_params={"select": select})
93-
9479
def _fetch_page_as_response(self, limit: int = 100, offset: int = 0) -> httpx.Response:
9580
"""Fetch one page of resources.
9681

mpt_api_client/resources/accounts/account.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
from mpt_api_client.http import AsyncService, Service
22
from mpt_api_client.http.mixins import (
33
AsyncCreateMixin,
4+
AsyncGetMixin,
45
AsyncUpdateMixin,
56
CreateMixin,
7+
GetMixin,
68
UpdateMixin,
79
)
810
from mpt_api_client.models import Model
@@ -38,6 +40,7 @@ class AccountsService(
3840
ActivatableMixin[Account],
3941
EnablableMixin[Account],
4042
ValidateMixin[Account],
43+
GetMixin[Account],
4144
Service[Account],
4245
AccountsServiceConfig,
4346
):
@@ -56,6 +59,7 @@ class AsyncAccountsService(
5659
AsyncActivatableMixin[Account],
5760
AsyncEnablableMixin[Account],
5861
AsyncValidateMixin[Account],
62+
AsyncGetMixin[Account],
5963
AsyncService[Account],
6064
AccountsServiceConfig,
6165
):

mpt_api_client/resources/accounts/account_user_groups.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
from mpt_api_client.http.mixins import (
33
AsyncCreateMixin,
44
AsyncDeleteMixin,
5+
AsyncGetMixin,
56
AsyncUpdateMixin,
67
CreateMixin,
78
DeleteMixin,
9+
GetMixin,
810
UpdateMixin,
911
)
1012
from mpt_api_client.models import Model
@@ -26,6 +28,7 @@ class AccountUserGroupsService(
2628
CreateMixin[AccountUserGroup],
2729
DeleteMixin,
2830
UpdateMixin[AccountUserGroup],
31+
GetMixin[AccountUserGroup],
2932
Service[AccountUserGroup],
3033
AccountUserGroupsServiceConfig,
3134
):
@@ -36,6 +39,7 @@ class AsyncAccountUserGroupsService(
3639
AsyncCreateMixin[AccountUserGroup],
3740
AsyncDeleteMixin,
3841
AsyncUpdateMixin[AccountUserGroup],
42+
AsyncGetMixin[AccountUserGroup],
3943
AsyncService[AccountUserGroup],
4044
AccountUserGroupsServiceConfig,
4145
):

mpt_api_client/resources/accounts/account_users.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
from mpt_api_client.http import AsyncService, Service
22
from mpt_api_client.http.mixins import (
33
AsyncCreateMixin,
4+
AsyncGetMixin,
45
CreateMixin,
6+
GetMixin,
57
)
68
from mpt_api_client.models import Model
79
from mpt_api_client.resources.accounts.account_user_groups import (
@@ -29,6 +31,7 @@ class AccountUsersServiceConfig:
2931
class AccountUsersService(
3032
CreateMixin[AccountUser],
3133
InvitableMixin[AccountUser],
34+
GetMixin[AccountUser],
3235
Service[AccountUser],
3336
AccountUsersServiceConfig,
3437
):
@@ -44,8 +47,9 @@ def groups(self, account_user_id: str) -> AccountUserGroupsService:
4447

4548
class AsyncAccountUsersService(
4649
AsyncCreateMixin[AccountUser],
47-
AsyncService[AccountUser],
4850
AsyncInvitableMixin[AccountUser],
51+
AsyncGetMixin[AccountUser],
52+
AsyncService[AccountUser],
4953
AccountUsersServiceConfig,
5054
):
5155
"""Asynchronous Account Users Service."""

mpt_api_client/resources/accounts/accounts_user_groups.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
from mpt_api_client.http.mixins import (
33
AsyncCreateMixin,
44
AsyncDeleteMixin,
5+
AsyncGetMixin,
56
AsyncUpdateMixin,
67
CreateMixin,
78
DeleteMixin,
9+
GetMixin,
810
UpdateMixin,
911
)
1012
from mpt_api_client.models import Model
@@ -25,6 +27,7 @@ class AccountsUserGroupsServiceConfig:
2527
class AccountsUserGroupsService(
2628
UpdateMixin[AccountsUserGroup],
2729
DeleteMixin,
30+
GetMixin[AccountsUserGroup],
2831
CreateMixin[AccountsUserGroup],
2932
Service[AccountsUserGroup],
3033
AccountsUserGroupsServiceConfig,
@@ -35,6 +38,7 @@ class AccountsUserGroupsService(
3538
class AsyncAccountsUserGroupsService(
3639
AsyncUpdateMixin[AccountsUserGroup],
3740
AsyncDeleteMixin,
41+
AsyncGetMixin[AccountsUserGroup],
3842
AsyncCreateMixin[AccountsUserGroup],
3943
AsyncService[AccountsUserGroup],
4044
AccountsUserGroupsServiceConfig,

mpt_api_client/resources/accounts/accounts_users.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
from mpt_api_client.http.mixins import (
33
AsyncCreateMixin,
44
AsyncDeleteMixin,
5+
AsyncGetMixin,
56
AsyncUpdateMixin,
67
CreateMixin,
78
DeleteMixin,
9+
GetMixin,
810
UpdateMixin,
911
)
1012
from mpt_api_client.models import Model
@@ -35,6 +37,7 @@ class AccountsUsersService(
3537
DeleteMixin,
3638
CreateMixin[AccountsUser],
3739
InvitableMixin[AccountsUser],
40+
GetMixin[AccountsUser],
3841
Service[AccountsUser],
3942
AccountsUsersServiceConfig,
4043
):
@@ -55,8 +58,9 @@ class AsyncAccountsUsersService(
5558
AsyncUpdateMixin[AccountsUser],
5659
AsyncDeleteMixin,
5760
AsyncCreateMixin[AccountsUser],
58-
AsyncService[AccountsUser],
5961
AsyncInvitableMixin[AccountsUser],
62+
AsyncGetMixin[AccountsUser],
63+
AsyncService[AccountsUser],
6064
AccountsUsersServiceConfig,
6165
):
6266
"""Asynchronous Account Users Service."""

mpt_api_client/resources/accounts/api_tokens.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
from mpt_api_client.http.mixins import (
33
AsyncCreateMixin,
44
AsyncDeleteMixin,
5+
AsyncGetMixin,
56
AsyncUpdateMixin,
67
CreateMixin,
78
DeleteMixin,
9+
GetMixin,
810
UpdateMixin,
911
)
1012
from mpt_api_client.models import Model
@@ -28,6 +30,7 @@ class ApiTokensService(
2830
DeleteMixin,
2931
UpdateMixin[ApiToken],
3032
EnablableMixin[ApiToken],
33+
GetMixin[ApiToken],
3134
Service[ApiToken],
3235
ApiTokensServiceConfig,
3336
):
@@ -39,6 +42,7 @@ class AsyncApiTokensService(
3942
AsyncDeleteMixin,
4043
AsyncUpdateMixin[ApiToken],
4144
AsyncEnablableMixin[ApiToken],
45+
AsyncGetMixin[ApiToken],
4246
AsyncService[ApiToken],
4347
ApiTokensServiceConfig,
4448
):

0 commit comments

Comments
 (0)