Package io.github.cobas91.util
Class RiotApiHttpClient
java.lang.Object
io.github.cobas91.util.RiotApiHttpClient
- Direct Known Subclasses:
ChampionDownloader,ItemDownloader,MatchDownloader,SummonerDownloader,VersionDownloader
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
FieldsModifier and TypeFieldDescriptionstatic final java.net.http.HttpClientorg.apache.logging.log4j.Loggerstatic final com.fasterxml.jackson.databind.ObjectMapper -
Constructor Summary
ConstructorsConstructorDescriptionRiotApiHttpClient(Class<?> implementingClass) RiotApiHttpClient(Class<?> implementingClass, String apiToken) -
Method Summary
Modifier and TypeMethodDescriptionjava.net.http.HttpRequestRetrieves an HTTP request object for the given URI with the necessary header information.<T> TsendRequest(java.net.http.HttpRequest request, Class<T> clazz) Sends an HTTP request and returns the response body deserialized into the specified class.
-
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
-
RiotApiHttpClient
-
-
Method Details
-
getForUri
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
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 sendclazz- 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
-