Class RiotApiHttpClient

java.lang.Object
io.github.cobas91.util.RiotApiHttpClient
Direct Known Subclasses:
ChampionDownloader, ItemDownloader, MatchDownloader, SummonerDownloader, VersionDownloader

public abstract class RiotApiHttpClient extends Object
Class: HttpClientImpl Author: Description: This abstract class provides a basic implementation for making HTTP requests using the Java HttpClient library. It contains methods for sending GET requests, handling responses, and configuring the HTTP client.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final java.net.http.HttpClient
     
    org.apache.logging.log4j.Logger
     
    static final com.fasterxml.jackson.databind.ObjectMapper
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    RiotApiHttpClient(Class<?> implementingClass)
     
    RiotApiHttpClient(Class<?> implementingClass, String apiToken)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    java.net.http.HttpRequest
    Retrieves an HTTP request object for the given URI with the necessary header information.
    <T> T
    sendRequest(java.net.http.HttpRequest request, Class<T> clazz)
    Sends an HTTP request and returns the response body deserialized into the specified class.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • log

      public org.apache.logging.log4j.Logger log
    • httpClient

      public static final java.net.http.HttpClient httpClient
    • mapper

      public static final com.fasterxml.jackson.databind.ObjectMapper mapper
  • Constructor Details

    • RiotApiHttpClient

      public RiotApiHttpClient(Class<?> implementingClass)
    • RiotApiHttpClient

      public RiotApiHttpClient(Class<?> implementingClass, String apiToken)
  • Method Details

    • getForUri

      public java.net.http.HttpRequest getForUri(URI uri)
      Retrieves an HTTP request object for the given URI with the necessary header information. The "X-Riot-Token" header is set using the token value provided in the containing class.
      Parameters:
      uri - the URI to send the request to
      Returns:
      an instance of HttpRequest with the URI and header information set
    • sendRequest

      public <T> T sendRequest(java.net.http.HttpRequest request, Class<T> clazz)
      Sends an HTTP request and returns the response body deserialized into the specified class.
      Type Parameters:
      T - the type of the response body
      Parameters:
      request - the HttpRequest to send
      clazz - the Class object representing the desired type to deserialize the response body into
      Returns:
      an instance of the specified class with the response body deserialized into it
      Throws:
      RuntimeException - if an error occurs while sending the request or deserializing the response body