-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Уточнение ошибки в set_trade_link * Добавлен set_trade_mode
- Loading branch information
Bananchiki
authored
Aug 30, 2024
1 parent
d1171b2
commit df43281
Showing
6 changed files
with
131 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
from dataclasses import dataclass | ||
from collections.abc import Sequence | ||
from typing import TYPE_CHECKING, Optional, Union | ||
|
||
from steam_trader import TraderClientObject | ||
from steam_trader import exceptions | ||
|
||
if TYPE_CHECKING: | ||
from ._client_ext import ExtClient | ||
from ._client_async_ext import ExtClientAsync | ||
|
||
@dataclass | ||
class TradeMode(TraderClientObject): | ||
"""Класс, представляющий режим торговли. | ||
Attributes: | ||
success (:obj:`bool`): Результат запроса. | ||
state (:obj:`bool`): Режим обычной торговли. | ||
p2p (:obj:`bool`): Режим p2p торговли. | ||
client (Union[:class:`steam_trader.ExtClient`, :class:`steam_trader.ExtClientAsync`, :obj:`None`]): | ||
Клиент Steam Trader. | ||
""" | ||
|
||
success: bool | ||
state: bool | ||
p2p: bool | ||
client: Union['ExtClient', 'ExtClientAsync', None] | ||
|
||
@classmethod | ||
def de_json( | ||
cls: dataclass, | ||
data: dict, | ||
client: Union['ExtClient', 'ExtClientAsync', None] = None | ||
) -> Optional['TradeMode']: | ||
"""Десериализация объекта. | ||
Args: | ||
data (:obj:`dict`): Поля и значения десериализуемого объекта. | ||
client (Union[:class:`steam_trader.ExtClient`, :class:`steam_trader.ExtClientAsync`, :obj:`None`]): | ||
Клиент Steam Trader. | ||
Returns: | ||
:class:`steam_trader.TradeMode`, optional: Режим торговли. | ||
""" | ||
|
||
if not cls.is_valid_model_data(data): | ||
return | ||
|
||
if not data['success']: | ||
match data['code']: | ||
case 400: | ||
raise exceptions.BadRequestError('Неправильный запрос.') | ||
case 401: | ||
raise exceptions.Unauthorized('Неправильный api-токен.') | ||
case 429: | ||
raise exceptions.TooManyRequests('Вы отправили слишком много запросов.') | ||
|
||
data = super(TradeMode, cls).de_json(data) | ||
|
||
return cls(client=client, **data) | ||
|