Skip to content

Commit 829acef

Browse files
committed
feat: add helpdesk channels and cases services
1 parent d0c4a94 commit 829acef

File tree

14 files changed

+373
-0
lines changed

14 files changed

+373
-0
lines changed

mpt_api_client/mpt_client.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@
88
AsyncBilling,
99
AsyncCatalog,
1010
AsyncCommerce,
11+
AsyncHelpdesk,
1112
AsyncNotifications,
1213
Audit,
1314
Billing,
1415
Catalog,
1516
Commerce,
17+
Helpdesk,
1618
Notifications,
1719
)
1820

@@ -70,6 +72,11 @@ def notifications(self) -> AsyncNotifications:
7072
"""Notifications MPT API Client."""
7173
return AsyncNotifications(http_client=self.http_client)
7274

75+
@property
76+
def helpdesk(self) -> AsyncHelpdesk:
77+
"""Helpdesk MPT API Client."""
78+
return AsyncHelpdesk(http_client=self.http_client)
79+
7380

7481
class MPTClient:
7582
"""MPT API Client."""
@@ -128,3 +135,8 @@ def accounts(self) -> Accounts:
128135
def notifications(self) -> Notifications:
129136
"""Notifications MPT API Client."""
130137
return Notifications(http_client=self.http_client)
138+
139+
@property
140+
def helpdesk(self) -> Helpdesk:
141+
"""Helpdesk MPT API Client."""
142+
return Helpdesk(http_client=self.http_client)

mpt_api_client/resources/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from mpt_api_client.resources.billing import AsyncBilling, Billing
44
from mpt_api_client.resources.catalog import AsyncCatalog, Catalog
55
from mpt_api_client.resources.commerce import AsyncCommerce, Commerce
6+
from mpt_api_client.resources.helpdesk import AsyncHelpdesk, Helpdesk
67
from mpt_api_client.resources.notifications import AsyncNotifications, Notifications
78

89
__all__ = [ # noqa: WPS410
@@ -12,10 +13,12 @@
1213
"AsyncBilling",
1314
"AsyncCatalog",
1415
"AsyncCommerce",
16+
"AsyncHelpdesk",
1517
"AsyncNotifications",
1618
"Audit",
1719
"Billing",
1820
"Catalog",
1921
"Commerce",
22+
"Helpdesk",
2023
"Notifications",
2124
]
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from mpt_api_client.resources.helpdesk.helpdesk import AsyncHelpdesk, Helpdesk
2+
3+
__all__ = ["AsyncHelpdesk", "Helpdesk"] # noqa: WPS410
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
from mpt_api_client.http import AsyncService, Service
2+
from mpt_api_client.http.mixins import (
3+
AsyncCollectionMixin,
4+
AsyncCreateMixin,
5+
AsyncGetMixin,
6+
AsyncUpdateMixin,
7+
CollectionMixin,
8+
CreateMixin,
9+
GetMixin,
10+
UpdateMixin,
11+
)
12+
from mpt_api_client.models import Model, ResourceData
13+
14+
15+
class Case(Model):
16+
"""Helpdesk case resource."""
17+
18+
19+
class CasesServiceConfig:
20+
"""Cases service configuration."""
21+
22+
_endpoint = "/public/v1/helpdesk/cases"
23+
_model_class = Case
24+
_collection_key = "data"
25+
26+
27+
class CasesService(
28+
CollectionMixin[Case],
29+
CreateMixin[Case],
30+
GetMixin[Case],
31+
UpdateMixin[Case],
32+
Service[Case],
33+
CasesServiceConfig,
34+
):
35+
"""Cases service."""
36+
37+
def complete(self, resource_id: str, resource_data: ResourceData | None = None) -> Case:
38+
"""Switch case to complete state.
39+
40+
Args:
41+
resource_id: Case resource ID
42+
resource_data: Case data will be updated
43+
44+
Returns:
45+
Updated case resource
46+
"""
47+
return self._resource_action(resource_id, "POST", "complete", json=resource_data)
48+
49+
def process(self, resource_id: str, resource_data: ResourceData | None = None) -> Case:
50+
"""Switch case to process state.
51+
52+
Args:
53+
resource_id: Case resource ID
54+
resource_data: Case data will be updated
55+
56+
Returns:
57+
Updated case resource
58+
"""
59+
return self._resource_action(resource_id, "POST", "process", json=resource_data)
60+
61+
def query(self, resource_id: str, resource_data: ResourceData | None = None) -> Case:
62+
"""Switch case to query state.
63+
64+
Args:
65+
resource_id: Case resource ID
66+
resource_data: Case data will be updated
67+
68+
Returns:
69+
Updated case resource
70+
"""
71+
return self._resource_action(resource_id, "POST", "query", json=resource_data)
72+
73+
74+
class AsyncCasesService(
75+
AsyncCollectionMixin[Case],
76+
AsyncCreateMixin[Case],
77+
AsyncGetMixin[Case],
78+
AsyncUpdateMixin[Case],
79+
AsyncService[Case],
80+
CasesServiceConfig,
81+
):
82+
"""Async cases service."""
83+
84+
async def complete(self, resource_id: str, resource_data: ResourceData | None = None) -> Case:
85+
"""Switch case to complete state.
86+
87+
Args:
88+
resource_id: Case resource ID
89+
resource_data: Case data will be updated
90+
91+
Returns:
92+
Updated case resource
93+
"""
94+
return await self._resource_action(resource_id, "POST", "complete", json=resource_data)
95+
96+
async def process(self, resource_id: str, resource_data: ResourceData | None = None) -> Case:
97+
"""Switch case to process state.
98+
99+
Args:
100+
resource_id: Case resource ID
101+
resource_data: Case data will be updated
102+
103+
Returns:
104+
Updated case resource
105+
"""
106+
return await self._resource_action(resource_id, "POST", "process", json=resource_data)
107+
108+
async def query(self, resource_id: str, resource_data: ResourceData | None = None) -> Case:
109+
"""Switch case to query state.
110+
111+
Args:
112+
resource_id: Case resource ID
113+
resource_data: Case data will be updated
114+
115+
Returns:
116+
Updated case resource
117+
"""
118+
return await self._resource_action(resource_id, "POST", "query", json=resource_data)
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
from mpt_api_client.http import AsyncService, Service
2+
from mpt_api_client.http.mixins import (
3+
AsyncCollectionMixin,
4+
AsyncManagedResourceMixin,
5+
CollectionMixin,
6+
ManagedResourceMixin,
7+
)
8+
from mpt_api_client.models import Model
9+
10+
11+
class Channel(Model):
12+
"""Helpdesk channel resource."""
13+
14+
15+
class ChannelsServiceConfig:
16+
"""Channels service configuration."""
17+
18+
_endpoint = "/public/v1/helpdesk/channels"
19+
_model_class = Channel
20+
_collection_key = "data"
21+
22+
23+
class ChannelsService(
24+
CollectionMixin[Channel],
25+
ManagedResourceMixin[Channel],
26+
Service[Channel],
27+
ChannelsServiceConfig,
28+
):
29+
"""Channels service."""
30+
31+
32+
class AsyncChannelsService(
33+
AsyncCollectionMixin[Channel],
34+
AsyncManagedResourceMixin[Channel],
35+
AsyncService[Channel],
36+
ChannelsServiceConfig,
37+
):
38+
"""Async channels service."""
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
from mpt_api_client.http import AsyncHTTPClient, HTTPClient
2+
from mpt_api_client.resources.helpdesk.cases import AsyncCasesService, CasesService
3+
from mpt_api_client.resources.helpdesk.channels import AsyncChannelsService, ChannelsService
4+
5+
6+
class Helpdesk:
7+
"""Helpdesk MPT API Module."""
8+
9+
def __init__(self, http_client: HTTPClient):
10+
self.http_client = http_client
11+
12+
@property
13+
def cases(self) -> CasesService:
14+
"""Cases service."""
15+
return CasesService(http_client=self.http_client)
16+
17+
@property
18+
def channels(self) -> ChannelsService:
19+
"""Channels service."""
20+
return ChannelsService(http_client=self.http_client)
21+
22+
23+
class AsyncHelpdesk:
24+
"""Async Helpdesk MPT API Module."""
25+
26+
def __init__(self, http_client: AsyncHTTPClient):
27+
self.http_client = http_client
28+
29+
@property
30+
def cases(self) -> AsyncCasesService:
31+
"""Cases service."""
32+
return AsyncCasesService(http_client=self.http_client)
33+
34+
@property
35+
def channels(self) -> AsyncChannelsService:
36+
"""Channels service."""
37+
return AsyncChannelsService(http_client=self.http_client)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import pytest
2+
3+
pytestmark = [pytest.mark.flaky]
4+
5+
6+
async def test_list_cases(async_mpt_ops) -> None:
7+
service = async_mpt_ops.helpdesk.cases
8+
9+
result = await service.fetch_page(limit=1)
10+
11+
assert result is not None
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import pytest
2+
3+
pytestmark = [pytest.mark.flaky]
4+
5+
6+
def test_list_cases(mpt_ops) -> None:
7+
service = mpt_ops.helpdesk.cases
8+
9+
result = service.fetch_page(limit=1)
10+
11+
assert result is not None
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import pytest
2+
3+
pytestmark = [pytest.mark.flaky]
4+
5+
6+
async def test_list_channels(async_mpt_ops) -> None:
7+
service = async_mpt_ops.helpdesk.channels
8+
9+
result = await service.fetch_page(limit=1)
10+
11+
assert result is not None
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import pytest
2+
3+
pytestmark = [pytest.mark.flaky]
4+
5+
6+
def test_list_channels(mpt_ops) -> None:
7+
service = mpt_ops.helpdesk.channels
8+
9+
result = service.fetch_page(limit=1)
10+
11+
assert result is not None

0 commit comments

Comments
 (0)