mirror of
https://github.com/RGBCube/GitHubWrapper
synced 2025-05-18 06:55:09 +00:00
Adjustments and an init
This commit is contained in:
parent
05d522eb1e
commit
b4045c70bd
1 changed files with 22 additions and 2 deletions
|
@ -4,12 +4,32 @@ __all__ = (
|
||||||
'Github',
|
'Github',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
from getpass import getpass
|
||||||
import aiohttp
|
import aiohttp
|
||||||
|
|
||||||
from . import http
|
from . import http
|
||||||
|
from .objects import User
|
||||||
|
|
||||||
class Github:
|
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):
|
async def start(self):
|
||||||
"""Main entry point to the wrapper, this creates the ClientSession."""
|
"""Main entry point to the wrapper, this creates the ClientSession."""
|
||||||
headers = {}
|
self._state = await http.make_session(headers=self._headers, authorization=self._auth)
|
||||||
self._session = http.make_session(headers=headers)
|
|
||||||
|
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)
|
Loading…
Add table
Add a link
Reference in a new issue