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

public class GHBase extends Object implements JSONHelper, HttpRequestInterface
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
  • Constructor Details

    • GHBase

      public GHBase()
  • Method Details

    • toJSONObject

      public org.json.JSONObject toJSONObject()
      Returns a new JSONObject.
      Returns:
      a new JSONObject
    • getBaseUrl

      public static String 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 from
      mapper - a function that maps a JSONObject to an object of type T
      token - the authentication token to use for the request
      params - 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 from
      mapper - a function that maps a JSONObject to an object of type T
      token - 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 from
      endpoint - the endpoint to fetch data from if the URL is null
      mapper - a function that maps a JSONObject to an object of type T
      token - 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 from
      mapper - a function that maps a JSONObject to an object of type T
      token - the authentication token to use for the request
      entryPoint - 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 from
      endpoint - the endpoint to fetch data from if the URL is null
      mapper - a function that maps a JSONObject to an object of type T
      token - the authentication token to use for the request
      entryPoint - 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