Package io.github.coho04.githubapi.bases
Class GHBase
java.lang.Object
io.github.coho04.githubapi.bases.GHBase
- All Implemented Interfaces:
HttpRequestInterface,JSONHelper
- Direct Known Subclasses:
ClassBase,GHActionsCache,GHAdvisory,GHAlert,GHBranch,GHEvent,GHFile,GHFileBuilder,GHGitignoreTemplate,GHHook,GHHookBuilder,GHIssueBuilder,GHLabel,GHLicense,GHPages,GHPermission,GHPlan,GHProjectBuilder,GHPublicKey,GHPublicKeyBuilder,GHRepositoryCache,GHSecret,GHStep,GHTeamBuilder,GHVariable,GHVulnerability,GHWorkflowRun,Github,HttpsCertificate
GHBase is a class that implements JSONHelper and HttpRequestInterface. It represents a base class for GitHub objects.
It contains several methods such as toJSONObject, getBaseUrl, and fetchPaginatedData.
This class serves as a foundation for other GitHub-related classes, providing common functionality for HTTP requests and JSON handling.
- Since:
- 2024-1.2
- Version:
- 1.0
- Author:
- Coho04
-
Nested Class Summary
Nested classes/interfaces inherited from interface io.github.coho04.githubapi.interfaces.JSONHelper
JSONHelper.JSONToObject<T> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected <T> List<T> fetchArrayData(String url, String endpoint, Function<org.json.JSONObject, T> mapper, String token, String entryPoint) Fetches array data from a given URL and maps the data to a list of objects of type T.protected <T> List<T> fetchArrayData(String endpoint, Function<org.json.JSONObject, T> mapper, String token, String entryPoint) Fetches array data from a given endpoint and maps the data to a list of objects of type T.protected <T> List<T> fetchPaginatedData(String url, String endpoint, Function<org.json.JSONObject, T> mapper, String token) Fetches paginated data from a given URL and maps the data to a list of objects of type T.protected <T> List<T> fetchPaginatedData(String endpoint, Function<org.json.JSONObject, T> mapper, String token) Fetches paginated data from a given endpoint and maps the data to a list of objects of type T.protected <T> List<T> fetchPaginatedData(String endpoint, Function<org.json.JSONObject, T> mapper, String token, String params) Fetches paginated data from a given endpoint and maps the data to a list of objects of type T.static StringReturns the base URL for the GitHub API.org.json.JSONObjectReturns a new JSONObject.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.github.coho04.githubapi.interfaces.HttpRequestInterface
extractNextPageUrl, sendDeleteRequest, sendDeleteRequestWithResponseCode, sendGetRequest, sendGetRequestWithLinkHeader, sendGetRequestWithResponseCode, sendPatchRequest, sendPostRequest, sendPutRequestMethods inherited from interface io.github.coho04.githubapi.interfaces.JSONHelper
getArrayOrNull, getBooleanOrNull, getIntOrNull, getJSONArrayToStringList, getJSONObjectOrNull, getLocalDateOrNull, getLongOrNull, getStringOrNull
-
Constructor Details
-
GHBase
public GHBase()
-
-
Method Details
-
toJSONObject
public org.json.JSONObject toJSONObject()Returns a new JSONObject.- Returns:
- a new JSONObject
-
getBaseUrl
Returns the base URL for the GitHub API.- Returns:
- the base URL for the GitHub API
-
fetchPaginatedData
protected <T> List<T> fetchPaginatedData(String endpoint, Function<org.json.JSONObject, T> mapper, String token, String params) Fetches paginated data from a given endpoint and maps the data to a list of objects of type T.- Type Parameters:
T- the type of objects in the returned list- Parameters:
endpoint- the endpoint to fetch data frommapper- a function that maps a JSONObject to an object of type Ttoken- the authentication token to use for the requestparams- additional parameters to include in the request URL- Returns:
- a list of objects of type T representing the fetched data
-
fetchPaginatedData
protected <T> List<T> fetchPaginatedData(String endpoint, Function<org.json.JSONObject, T> mapper, String token) Fetches paginated data from a given endpoint and maps the data to a list of objects of type T.- Type Parameters:
T- the type of objects in the returned list- Parameters:
endpoint- the endpoint to fetch data frommapper- a function that maps a JSONObject to an object of type Ttoken- the authentication token to use for the request- Returns:
- a list of objects of type T representing the fetched data
-
fetchPaginatedData
protected <T> List<T> fetchPaginatedData(String url, String endpoint, Function<org.json.JSONObject, T> mapper, String token) Fetches paginated data from a given URL and maps the data to a list of objects of type T.- Type Parameters:
T- the type of objects in the returned list- Parameters:
url- the URL to fetch data fromendpoint- the endpoint to fetch data from if the URL is nullmapper- a function that maps a JSONObject to an object of type Ttoken- the authentication token to use for the request- Returns:
- a list of objects of type T representing the fetched data
-
fetchArrayData
protected <T> List<T> fetchArrayData(String endpoint, Function<org.json.JSONObject, T> mapper, String token, String entryPoint) Fetches array data from a given endpoint and maps the data to a list of objects of type T.- Type Parameters:
T- the type of objects in the returned list- Parameters:
endpoint- the endpoint to fetch data frommapper- a function that maps a JSONObject to an object of type Ttoken- the authentication token to use for the requestentryPoint- the entry point in the JSON response to extract the array data from- Returns:
- a list of objects of type T representing the fetched data
-
fetchArrayData
protected <T> List<T> fetchArrayData(String url, String endpoint, Function<org.json.JSONObject, T> mapper, String token, String entryPoint) Fetches array data from a given URL and maps the data to a list of objects of type T.- Type Parameters:
T- the type of objects in the returned list- Parameters:
url- the URL to fetch data fromendpoint- the endpoint to fetch data from if the URL is nullmapper- a function that maps a JSONObject to an object of type Ttoken- the authentication token to use for the requestentryPoint- the entry point in the JSON response to extract the array data from- Returns:
- a list of objects of type T representing the fetched data
-