github_interface()
A class used to interact with the Github API.
The class can perform authenticated get, patch and post requests to the GitHub API using the requests library.
Source code in src/github_api_toolkit/rest.py
__init__(token)
Creates the header attribute containing the Personal Access token to make auth'd API requests.
get(url, params=None, add_prefix=True)
Performs a get request using the passed url.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
The url endpoint of the request. |
required |
params
|
dict | None = None
|
A Dictionary containing any Query Parameters. |
None
|
add_prefix
|
bool
|
A Boolean determining whether to add the "https://api.github.com" prefix to the beginning of the passed url. |
True
|
Returns:
| Type | Description |
|---|---|
Response | Exception
|
The response from the API endpoint. |
Response | Exception
|
If an error occurs, an Exception object is returned to be handled by the importing program. |
Source code in src/github_api_toolkit/rest.py
handle_response(response)
Checks the passed response for errors and returns the response or an Exception object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
response
|
Response
|
The response to be checked for errors. |
required |
Returns:
| Type | Description |
|---|---|
Response | Exception
|
The response from the API endpoint. |
Response | Exception
|
If an error occurs, an Exception object is returned to be handled by the importing program. |
Source code in src/github_api_toolkit/rest.py
patch(url, params=None, add_prefix=True)
Performs a patch request using the passed url.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
The url endpoint of the request. |
required |
params
|
dict | None = None
|
A Dictionary containing any Query Parameters. |
None
|
add_prefix
|
bool
|
A Boolean determining whether to add the "https://api.github.com" prefix to the beginning of the passed url. |
True
|
Returns:
| Type | Description |
|---|---|
Response | Exception
|
The response from the API endpoint. |
Response | Exception
|
If an error occurs, an Exception object is returned to be handled by the importing program. |
Source code in src/github_api_toolkit/rest.py
post(url, params=None, add_prefix=True)
Performs a post request using the passed url.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
The url endpoint of the request. |
required |
params
|
dict | None = None
|
A Dictionary containing any Query Parameters. |
None
|
add_prefix
|
bool
|
A Boolean determining whether to add the "https://api.github.com" prefix to the beginning of the passed url. |
True
|
Returns:
| Type | Description |
|---|---|
Response | Exception
|
The response from the API endpoint. |
Response | Exception
|
If an error occurs, an Exception object is returned to be handled by the importing program. |