-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmptclient.py
More file actions
57 lines (40 loc) · 1.69 KB
/
mptclient.py
File metadata and controls
57 lines (40 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from mpt_api_client.http.client import HTTPClient
from mpt_api_client.registry import Registry, commerce
from mpt_api_client.resources import OrderCollectionClientBase
class MPTClientBase:
"""MPT API Client Base."""
def __init__(
self,
base_url: str | None = None,
api_key: str | None = None,
registry: Registry | None = None,
http_client: HTTPClient | None = None,
):
self.http_client = http_client or HTTPClient(base_url=base_url, api_token=api_key)
self.registry: Registry = registry or Registry()
def __getattr__(self, name): # type: ignore[no-untyped-def]
return self.registry.get(name)(http_client=self.http_client)
class MPTClient(MPTClientBase):
"""MPT API Client."""
@property
def commerce(self) -> "CommerceMpt":
"""Commerce MPT API Client.
The Commerce API provides a comprehensive set of endpoints
for managing agreements, requests, subscriptions, and orders
within a vendor-client-ops ecosystem.
"""
return CommerceMpt(http_client=self.http_client, registry=commerce)
class CommerceMpt(MPTClientBase):
"""Commerce MPT API Client."""
@property
def orders(self) -> OrderCollectionClientBase:
"""Orders MPT API collection.
The Orders API provides a comprehensive set of endpoints
for creating, updating, and retrieving orders.
Returns: Order collection
Examples:
active=RQLQuery("status=active")
for order in mpt.orders.filter(active).iterate():
[...]
"""
return self.registry.get("orders")(http_client=self.http_client) # type: ignore[return-value]