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
12 changes: 12 additions & 0 deletions mpt_api_client/mpt_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
AsyncBilling,
AsyncCatalog,
AsyncCommerce,
AsyncExchange,
AsyncHelpdesk,
AsyncNotifications,
Audit,
Billing,
Catalog,
Commerce,
Exchange,
Helpdesk,
Notifications,
)
Expand Down Expand Up @@ -83,6 +85,11 @@ def helpdesk(self) -> AsyncHelpdesk:
"""Helpdesk MPT API Client."""
return AsyncHelpdesk(http_client=self.http_client)

@property
def exchange(self) -> AsyncExchange:
"""Exchange MPT API Client."""
return AsyncExchange(http_client=self.http_client)


class MPTClient:
"""MPT API Client."""
Expand Down Expand Up @@ -152,3 +159,8 @@ def notifications(self) -> Notifications:
def helpdesk(self) -> Helpdesk:
"""Helpdesk MPT API Client."""
return Helpdesk(http_client=self.http_client)

@property
def exchange(self) -> Exchange:
"""Exchange MPT API Client."""
return Exchange(http_client=self.http_client)
3 changes: 3 additions & 0 deletions mpt_api_client/resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from mpt_api_client.resources.billing import AsyncBilling, Billing
from mpt_api_client.resources.catalog import AsyncCatalog, Catalog
from mpt_api_client.resources.commerce import AsyncCommerce, Commerce
from mpt_api_client.resources.exchange import AsyncExchange, Exchange
from mpt_api_client.resources.helpdesk import AsyncHelpdesk, Helpdesk
from mpt_api_client.resources.notifications import AsyncNotifications, Notifications

Expand All @@ -13,12 +14,14 @@
"AsyncBilling",
"AsyncCatalog",
"AsyncCommerce",
"AsyncExchange",
"AsyncHelpdesk",
"AsyncNotifications",
"Audit",
"Billing",
"Catalog",
"Commerce",
"Exchange",
"Helpdesk",
"Notifications",
]
6 changes: 6 additions & 0 deletions mpt_api_client/resources/exchange/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from mpt_api_client.resources.exchange.exchange import AsyncExchange, Exchange

__all__ = [ # noqa: WPS410
"AsyncExchange",
"Exchange",
]
97 changes: 97 additions & 0 deletions mpt_api_client/resources/exchange/currencies.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
from mpt_api_client.http import AsyncService, Service
from mpt_api_client.http.mixins import (
AsyncCollectionMixin,
AsyncCreateFileMixin,
AsyncDeleteMixin,
AsyncGetMixin,
AsyncUpdateFileMixin,
CollectionMixin,
CreateFileMixin,
DeleteMixin,
GetMixin,
UpdateFileMixin,
)
from mpt_api_client.models import FileModel, Model
from mpt_api_client.models.model import BaseModel


class Currency(Model):
"""Currency resource.

Attributes:
name: Currency name.
code: ISO code of the currency.
precision: Number of decimal places.
statistics: Currency statistics (seller count, pair count).
status: Current status of the currency.
icon: URL or identifier for the currency icon.
revision: Revision number.
audit: Audit information (created, updated events).
"""

name: str | None
code: str | None
precision: int | None
statistics: BaseModel | None
status: str | None
icon: str | None
revision: int | None
audit: BaseModel | None


class CurrenciesServiceConfig:
"""Currencies service configuration."""

_endpoint = "/public/v1/exchange/currencies"
_model_class = Currency
_collection_key = "data"
_upload_file_key = "icon"
_upload_data_key = "currency"


class CurrenciesService(
CreateFileMixin[Currency],
GetMixin[Currency],
UpdateFileMixin[Currency],
DeleteMixin,
CollectionMixin[Currency],
Service[Currency],
CurrenciesServiceConfig,
):
"""Currencies service."""

def download_icon(self, resource_id: str) -> FileModel:
"""Download the icon for the given currency.

Args:
resource_id: Currency ID.

Returns:
File model containing the downloaded icon.
"""
response = self._resource(resource_id).do_request("GET", "icon")
return FileModel(response)


class AsyncCurrenciesService(
AsyncCreateFileMixin[Currency],
AsyncGetMixin[Currency],
AsyncUpdateFileMixin[Currency],
AsyncDeleteMixin,
AsyncCollectionMixin[Currency],
AsyncService[Currency],
CurrenciesServiceConfig,
):
"""Async currencies service."""

async def download_icon(self, resource_id: str) -> FileModel:
"""Download the icon for the given currency.

Args:
resource_id: Currency ID.

Returns:
File model containing the downloaded icon.
"""
response = await self._resource(resource_id).do_request("GET", "icon")
return FileModel(response)
29 changes: 29 additions & 0 deletions mpt_api_client/resources/exchange/exchange.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from mpt_api_client.http import AsyncHTTPClient, HTTPClient
from mpt_api_client.resources.exchange.currencies import (
AsyncCurrenciesService,
CurrenciesService,
)


class Exchange:
"""Exchange MPT API Module."""

def __init__(self, *, http_client: HTTPClient):
self.http_client = http_client

@property
def currencies(self) -> CurrenciesService:
"""Currencies service."""
return CurrenciesService(http_client=self.http_client)


class AsyncExchange:
"""Exchange MPT API Module."""

def __init__(self, *, http_client: AsyncHTTPClient):
self.http_client = http_client

@property
def currencies(self) -> AsyncCurrenciesService:
"""Currencies service."""
return AsyncCurrenciesService(http_client=self.http_client)
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ per-file-ignores = [
"mpt_api_client/resources/catalog/*.py: WPS110 WPS214 WPS215 WPS235",
"mpt_api_client/resources/catalog/products.py: WPS204 WPS214 WPS215 WPS235",
"mpt_api_client/resources/commerce/*.py: WPS235 WPS215",
"mpt_api_client/resources/exchange/*.py: WPS235 WPS215",
"mpt_api_client/resources/helpdesk/*.py: WPS204 WPS215 WPS214",
"mpt_api_client/rql/query_builder.py: WPS110 WPS115 WPS210 WPS214",
"tests/e2e/accounts/*.py: WPS430 WPS202",
Expand All @@ -144,6 +145,7 @@ per-file-ignores = [
"tests/unit/resources/commerce/*.py: WPS202 WPS204",
"tests/unit/test_mpt_client.py: WPS235",
"tests/*: WPS432 WPS202",
"tests/unit/resources/exchange/*.py: WPS202 WPS204 WPS210",
]

[tool.ruff]
Expand Down
Empty file.
Loading