Class HttpRequestHelper

java.lang.Object
io.github.coho04.githubapi.utilities.HttpRequestHelper

public class HttpRequestHelper extends Object
This class provides helper methods for sending HTTP requests.
  • Constructor Details

    • HttpRequestHelper

      public HttpRequestHelper()
  • Method Details

    • sendPostRequest

      public static String sendPostRequest(String url, String githubToken, org.json.JSONObject jsonObject)
      Sends a POST request to the specified URL with the provided GitHub token and JSON object.
      Parameters:
      url - the URL to send the request to
      githubToken - the GitHub token
      jsonObject - the JSON object to send
    • sendGetRequest

      public static String sendGetRequest(String url, String githubToken)
      Sends a GET request to the specified URL with the provided GitHub token.
      Parameters:
      url - the URL to send the request to
      githubToken - the GitHub token
      Returns:
      the response body as a string
    • sendGetRequestWithLinkHeader

      public static String[] sendGetRequestWithLinkHeader(String url, String githubToken)
      Sends a GET request to the specified URL with the provided GitHub token and returns the response body and the Link header.
      Parameters:
      url - the URL to send the request to
      githubToken - the GitHub token
      Returns:
      an array containing the response body and the Link header
    • extractNextPageUrl

      public static String extractNextPageUrl(String linkHeader)
      Extracts the URL of the next page from the Link header.
      Parameters:
      linkHeader - the Link header
      Returns:
      the URL of the next page
    • sendDeleteRequest

      public static void sendDeleteRequest(String url, String githubToken)
      Sends a DELETE request to the specified URL with the provided GitHub token.
      Parameters:
      url - the URL to send the request to
      githubToken - the GitHub token
    • sendDeleteRequestWithResponseCode

      public static boolean sendDeleteRequestWithResponseCode(String url, String githubToken, int responseCode)
      Sends a DELETE request to the specified URL with the provided GitHub token and checks if the response code matches the expected response code.
      Parameters:
      url - the URL to send the request to
      githubToken - the GitHub token
      responseCode - the expected response code
      Returns:
      true if the response code matches the expected response code, false otherwise
    • sendGetRequestWithResponseCode

      public static boolean sendGetRequestWithResponseCode(String url, String githubToken, int responseCode)
      Sends a GET request to the specified URL with the provided GitHub token and checks if the response code matches the expected response code.
      Parameters:
      url - the URL to send the request to
      githubToken - the GitHub token
      responseCode - the expected response code
      Returns:
      true if the response code matches the expected response code, false otherwise
    • sendPutRequest

      public static void sendPutRequest(String url, String githubToken, org.json.JSONObject jsonObject)
      Sends a PUT request to the specified URL with the provided GitHub token and JSON object.
      Parameters:
      url - the URL to send the request to
      githubToken - the GitHub token
      jsonObject - the JSON object to send
    • sendPatchRequest

      public static void sendPatchRequest(String url, String githubToken, org.json.JSONObject jsonObject)
      Sends a PATCH request to the specified URL with the provided GitHub token and JSON object.
      Parameters:
      url - the URL to send the request to
      githubToken - the GitHub token
      jsonObject - the JSON object to send