This commit is contained in:
2024-07-02 08:55:24 +03:00
parent 386ee7e460
commit 7ba3426989
18 changed files with 228 additions and 155 deletions

View File

@@ -7,7 +7,7 @@ from aiohttp import ClientResponse
from database import Marketplace
class BaseJsonMarketplace(ABC):
class BaseMarketplaceApi(ABC):
@abstractmethod
def __init__(self, marketplace: Marketplace):
pass
@@ -20,18 +20,17 @@ class BaseJsonMarketplace(ABC):
def get_headers(self):
pass
@abstractmethod
@property
@abstractmethod
def api_url(self):
pass
async def _method(self, http_method: Literal['POST', 'GET', 'PATCH', 'PUT', 'DELETE'],
method: str,
data: dict) -> ClientResponse:
async with aiohttp.ClientSession as session:
async with session.request(http_method,
f'{self.api_url}{method}',
json=data,
headers=self.get_headers()
) as response:
return response
async with aiohttp.ClientSession() as session:
return await session.request(http_method,
f'{self.api_url}{method}',
json=data,
headers=self.get_headers()
)