This commit is contained in:
2025-06-15 21:10:31 +03:00
parent 32c6f4aaac
commit a8f60bd767
59 changed files with 1413 additions and 0 deletions

36
maxapi/connection/base.py Normal file
View File

@@ -0,0 +1,36 @@
import aiohttp
from pydantic import BaseModel
from ..types.errors import Error
from ..enums.http_method import HTTPMethod
from ..enums.api_path import ApiPath
class BaseConnection:
API_URL = 'https://botapi.max.ru'
async def request(
self,
method: HTTPMethod,
path: ApiPath,
model: BaseModel,
is_return_raw: bool = False,
**kwargs
):
async with aiohttp.ClientSession(self.API_URL) as s:
r = await s.request(
method=method.value,
url=path.value,
**kwargs
)
if not r.ok:
raw = await r.text()
return Error(code=r.status, text=raw)
raw = await r.json()
if is_return_raw: return raw
return model(**raw)