feat: PoC using aiohttp
parent
9023d9ccbb
commit
242d685a6c
|
@ -1,2 +1,3 @@
|
|||
.venv/
|
||||
__pycache__/
|
||||
main.py
|
||||
|
|
|
@ -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