feat: PoC using aiohttp
parent
9023d9ccbb
commit
2c8d4618d1
|
@ -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())
|
|
@ -0,0 +1,2 @@
|
|||
aiohttp
|
||||
aiodns
|
|
@ -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)
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue