import httpx class API: headers = {"Accept": "application/vnd.github.v3+json"} def __init__(self, user_name: str) -> None: self.user = self.load_user(user_name) self.user_name = self.user["login"] self.repos = self.load_repos() # TODO: Check if pagination def _get(self, url: str) -> dict: """Uses httpx.Client().get to send the appropriate github headers, and return the url""" with httpx.Client(headers=self.headers) as client: return client.get(url).json() def load_user(self, user_name: str) -> dict: """Sets the user object""" return self._get(f"https://api.github.com/users/{user_name}") def load_repo(self, repo_name: str) -> dict: """Set the repo object""" return self._get(f"https://api.github.com/repos/{self.user_name}/{repo_name}") def load_repos(self) -> dict: """Set the users repos""" return self._get(f"https://api.github.com/users/{self.user_name}/repos")