Skip to content

Commit eb11da4

Browse files
committed
MPT-12330 Moved modules to resources
1 parent eb3633b commit eb11da4

File tree

15 files changed

+45
-36
lines changed

15 files changed

+45
-36
lines changed

mpt_api_client/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from mpt_api_client.mptclient import MPTClient
2+
from mpt_api_client.rql import RQLQuery
3+
4+
__all__ = ["MPTClient", "RQLQuery"] # noqa: WPS410

mpt_api_client/http/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import httpx
44

55

6-
class MPTClient(httpx.Client):
6+
class HTTPClient(httpx.Client):
77
"""A client for interacting with SoftwareOne Marketplace Platform API."""
88

99
def __init__(

mpt_api_client/http/collection.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import httpx
77

8-
from mpt_api_client.http.client import MPTClient
8+
from mpt_api_client.http.client import HTTPClient
99
from mpt_api_client.http.resource import ResourceBaseClient
1010
from mpt_api_client.models import Collection, Resource
1111
from mpt_api_client.rql.query_builder import RQLQuery
@@ -33,9 +33,9 @@ class CollectionBaseClient[ResourceModel: Resource, ResourceClient: ResourceBase
3333
def __init__(
3434
self,
3535
query_rql: RQLQuery | None = None,
36-
client: MPTClient | None = None,
36+
client: HTTPClient | None = None,
3737
) -> None:
38-
self.mpt_client = client or MPTClient()
38+
self.mpt_client = client or HTTPClient()
3939
self.query_rql: RQLQuery | None = query_rql
4040
self.query_order_by: list[str] | None = None
4141
self.query_select: list[str] | None = None
@@ -158,18 +158,23 @@ def fetch_one(self) -> ResourceModel:
158158

159159
return resource_list[0]
160160

161-
def iterate(self) -> Iterator[ResourceModel]:
161+
def iterate(self, batch_size: int = 100) -> Iterator[ResourceModel]:
162162
"""Iterate over all resources, yielding GenericResource objects.
163163
164+
Args:
165+
batch_size: Number of resources to fetch per request
166+
164167
Returns:
165168
Iterator of resources.
166169
"""
167170
offset = 0
168-
limit = 100 # Default page size
171+
limit = batch_size # Default page size
169172

170173
while True:
171174
response = self._fetch_page_as_response(limit=limit, offset=offset)
172-
items_collection: Collection[ResourceModel] = Collection.from_response(response)
175+
items_collection: Collection[ResourceModel] = self._collection_class.from_response(
176+
response
177+
)
173178
yield from items_collection
174179

175180
if not items_collection.meta:

mpt_api_client/http/resource.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from httpx import Response
55

6-
from mpt_api_client.http.client import MPTClient
6+
from mpt_api_client.http.client import HTTPClient
77
from mpt_api_client.models import Resource
88

99

@@ -14,7 +14,7 @@ class ResourceBaseClient[ResourceType: Resource](ABC): # noqa: WPS214
1414
_resource_class: type[ResourceType]
1515
_safe_attributes: ClassVar[set[str]] = {"mpt_client_", "resource_id_", "resource_"}
1616

17-
def __init__(self, client: MPTClient, resource_id: str) -> None:
17+
def __init__(self, client: HTTPClient, resource_id: str) -> None:
1818
self.mpt_client_ = client # noqa: WPS120
1919
self.resource_id_ = resource_id # noqa: WPS120
2020
self.resource_: Resource | None = None # noqa: WPS120

mpt_api_client/modules/__init__.py

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
from mpt_api_client.http.client import MPTClient
2-
from mpt_api_client.modules import OrderCollectionClient
1+
from mpt_api_client.http.client import HTTPClient
32
from mpt_api_client.registry import Registry, commerce
3+
from mpt_api_client.resources import OrderCollectionClient
44

55

6-
class MPT:
6+
class MPTClient:
77
"""MPT API Client."""
88

99
def __init__(
1010
self,
1111
base_url: str | None = None,
1212
api_key: str | None = None,
1313
registry: Registry | None = None,
14-
mpt_client: MPTClient | None = None,
14+
mpt_client: HTTPClient | None = None,
1515
):
16-
self.mpt_client = mpt_client or MPTClient(base_url=base_url, api_token=api_key)
16+
self.mpt_client = mpt_client or HTTPClient(base_url=base_url, api_token=api_key)
1717
self.registry: Registry = registry or Registry()
1818

1919
def __getattr__(self, name): # type: ignore[no-untyped-def]
@@ -30,7 +30,7 @@ def commerce(self) -> "CommerceMpt":
3030
return CommerceMpt(mpt_client=self.mpt_client, registry=commerce)
3131

3232

33-
class CommerceMpt(MPT):
33+
class CommerceMpt(MPTClient):
3434
"""Commerce MPT API Client."""
3535

3636
@property
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from mpt_api_client.resources.order import Order, OrderCollectionClient, OrderResourceClient
2+
3+
__all__ = ["Order", "OrderCollectionClient", "OrderResourceClient"] # noqa: WPS410

tests/conftest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import pytest
22

3-
from mpt_api_client.http.client import MPTClient
3+
from mpt_api_client.http.client import HTTPClient
44
from mpt_api_client.models import Resource
55

66
API_TOKEN = "test-token"
@@ -15,4 +15,4 @@ class DummyResource(Resource):
1515

1616
@pytest.fixture
1717
def mpt_client():
18-
return MPTClient(base_url=API_URL, api_token=API_TOKEN)
18+
return HTTPClient(base_url=API_URL, api_token=API_TOKEN)

tests/http/collection/test_collection_client_init.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import pytest
22

3-
from mpt_api_client.http.client import MPTClient
3+
from mpt_api_client.http.client import HTTPClient
44
from mpt_api_client.rql.query_builder import RQLQuery
55
from tests.http.conftest import DummyCollectionClient
66

77

88
@pytest.fixture
99
def mock_mpt_client(api_url, api_token):
10-
return MPTClient(base_url=api_url, api_token=api_token)
10+
return HTTPClient(base_url=api_url, api_token=api_token)
1111

1212

1313
@pytest.fixture

0 commit comments

Comments
 (0)