From b4045c70bdd561346bb2b16d6821fffa3acc78bd Mon Sep 17 00:00:00 2001 From: sudosnok Date: Sat, 26 Mar 2022 21:35:52 +0000 Subject: [PATCH] Adjustments and an init --- Github/main.py | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/Github/main.py b/Github/main.py index a80aef2..4fb82eb 100644 --- a/Github/main.py +++ b/Github/main.py @@ -4,12 +4,32 @@ __all__ = ( 'Github', ) +from getpass import getpass import aiohttp from . import http +from .objects import User class Github: + _auth = None + _state = aiohttp.ClientSession + def __init__( + self, + *, + using_auth: bool = False, + custom_headers: dict[str, str | int] = {} + ): + """The main client, used to start most use-cases.""" + self._headers = custom_headers + if using_auth: + username = input('Enter your username: ') #these two lines are blocking, but it's probably not a problem + auth_token = getpass.getpass('Enter your token: ') + self._auth = aiohttp.BasicAuth(username, auth_token) + async def start(self): """Main entry point to the wrapper, this creates the ClientSession.""" - headers = {} - self._session = http.make_session(headers=headers) \ No newline at end of file + self._state = await http.make_session(headers=self._headers, authorization=self._auth) + + async def get_user(self, username: str): + """Fetch a Github user from their username.""" + return User(await http.get_user(self._state, username), self._state) \ No newline at end of file