feat: PoC using aiohttp

Jef Roosens 2022-06-04 10:01:55 +02:00
parent 9023d9ccbb
commit 2c8d4618d1
Signed by: Jef Roosens
GPG Key ID: B75D4F293C7052DB
4 changed files with 45 additions and 2 deletions

14
main.py 100644
View File

@ -0,0 +1,14 @@
import vieter
import asyncio
async def main():
v = vieter.Vieter('https://arch.r8r.be', 'afzACJG54zhigEytPSNfiS5RHsSLKkx8TXa7p748')
r = await v.repos.list(offset=25)
await v.close()
print(r)
if __name__ == "__main__":
asyncio.run(main())

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)