From bf34654a4668d788acc94e6462e6f0ef53af99ea Mon Sep 17 00:00:00 2001 From: agatha Date: Sat, 11 Nov 2023 14:03:33 -0500 Subject: [PATCH] Update docstrings --- gitmon/api.py | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/gitmon/api.py b/gitmon/api.py index 1c78d80..79b5e10 100644 --- a/gitmon/api.py +++ b/gitmon/api.py @@ -12,6 +12,14 @@ setup_logger() class GitHubApi: def __init__(self, token=None, headers=None, proxy=None): + """Initialize the GitHubApi instance. + + Args: + token (str, optional): GitHub API token. + headers (dict, optional): Additional headers to include in API requests. + proxy (dict, optional): Proxy information. + + """ self.base_url = 'https://api.github.com' self.session = requests.Session() @@ -30,7 +38,16 @@ class GitHubApi: self.rate_remaining = None def __get(self, endpoint, params=None): - """GET an HTTP resource and return JSON.""" + """Send a GET request to the GitHub API and return the JSON response. + + Args: + endpoint (str): The API endpoint. + params (dict, optional): Query parameters for the request. + + Returns: + dict: The JSON response from the API. + + """ url = self.base_url + endpoint # Check rate limits and sleep if exceeded @@ -49,13 +66,26 @@ class GitHubApi: return response.json() def __parse_headers(self, headers): - """Parse headers to update rate limits.""" + """Parse the response headers to update the rate limit information. + + Args: + headers (dict): The response headers from the GitHub API. + + """ self.rate_reset = datetime.fromtimestamp(int(headers['x-ratelimit-reset'])) self.rate_remaining = int(headers['x-ratelimit-remaining']) logger.info(f'{self.rate_remaining} calls remaining until {self.rate_reset} ({self.rate_reset - datetime.now()})') def get_events(self, page=None): - """Fetch GitHub events.""" + """Fetch GitHub events. + + Args: + page (int, optional): The page number of events to retrieve. + + Returns: + dict: The JSON response containing the events. + + """ endpoint = '/events' params = None