python/aiovieter/vieter.py

27 lines
773 B
Python
Raw Normal View History

2022-06-04 10:08:59 +02:00
import aiohttp
from .repos import VieterRepos
from .logs import VieterBuildLogs
2022-06-04 10:08:59 +02:00
2022-05-31 08:47:25 +02:00
class Vieter:
def __init__(self, address: str, api_key: str) -> None:
self._address = address
self._api_key = api_key
2022-06-04 10:08:59 +02:00
self._client = aiohttp.ClientSession(
base_url=address, headers={"X-Api-Key": api_key}
2022-06-04 10:08:59 +02:00
)
self.repos = VieterRepos(self)
self.logs = VieterBuildLogs(self)
2022-06-04 10:08:59 +02:00
async def close(self):
await self._client.close()
2022-05-31 08:47:25 +02:00
2022-06-04 10:08:59 +02:00
async def _do_req(self, method: str, path: str, params: dict = None):
async with self._client.request(method, path, params=params) as res:
return await res.json()
2022-06-04 10:08:59 +02:00
async def _get(self, *args, **kwargs):
return await self._do_req("GET", *args, **kwargs)