feat: PoC using aiohttp

main
Jef Roosens 2022-06-04 10:08:59 +02:00
parent 9023d9ccbb
commit 242d685a6c
Signed by: Jef Roosens
GPG Key ID: B75D4F293C7052DB
4 changed files with 32 additions and 2 deletions

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
.venv/
__pycache__/
main.py

View File

@ -0,0 +1,2 @@
aiohttp
aiodns

11
vieter/repos.py 100644
View File

@ -0,0 +1,11 @@
class VieterRepos:
def __init__(self, vieter):
self._vieter = vieter
async def list(self, offset: int = 0, limit: int = 25):
params = {
'offset': offset,
'limit': limit
}
return await self._vieter._get('/api/repos', params=params)

View File

@ -1,7 +1,23 @@
import aiohttp
from .repos import VieterRepos
class Vieter:
def __init__(self, address: str, api_key: str) -> None:
self._address = address
self._api_key = api_key
self._client = aiohttp.ClientSession(
base_url=address, headers={'X-Api-Key': api_key}
)
def _do_req(self, path: str, method: str, params: dict):
pass
self.repos = VieterRepos(self)
async def close(self):
await self._client.close()
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()
async def _get(self, *args, **kwargs):
return await self._do_req('GET', *args, **kwargs)