C - Any class extending AbstractRestClientR - Any class extending AbstractWebRequestpublic abstract class AbstractWebApiInterface<C extends AbstractRestClient,R extends AbstractWebApiRequest,S extends AbstractWebApiResponse<com.google.gson.JsonElement>> extends Object
An API Interface containing a set/group of methods that are usually defined by the publisher
| Modifier and Type | Field and Description |
|---|---|
static int |
VERSION_1
Used by the underlying concrete classes for api versioning
|
static int |
VERSION_2
Used by the underlying concrete classes for api versioning
|
static int |
VERSION_3
Used by the underlying concrete classes for api versioning
|
| Constructor and Description |
|---|
AbstractWebApiInterface(C client)
Default Constructor
|
| Modifier and Type | Method and Description |
|---|---|
protected <A extends Collection> |
asCollectionOf(Class itemType,
String searchKey,
com.google.gson.JsonObject searchElement,
Class<? extends Collection> collectionClass,
boolean strict)
A Utility function that retrieves the specified json element and converts it to a Parameterized
Collection instance. |
protected <A> List<A> |
asListOf(Class itemType,
String searchKey,
com.google.gson.JsonObject searchElement,
boolean strict)
Similar to
asCollectionOf(Class, String, JsonObject, Class, boolean) minus the Collection class argument. |
protected com.google.gson.Gson |
builder()
Lazy-Inititalization
|
protected void |
configureBuilder(com.google.gson.GsonBuilder builder)
Override this method if you need to perform additional configurations against the builder (e.g.
|
protected <V> V |
fromJson(com.google.gson.JsonElement element,
Class<V> classTypeOf)
fromJson.
|
protected <V> V |
fromJson(com.google.gson.JsonElement element,
Type typeOf)
fromJson.
|
protected void |
handleError(AbstractWebResponse response,
Throwable error)
The default error handler.
|
protected <A> CompletableFuture<A> |
sendRequest(R request)
Sends a requests to the internal client.
|
public static final int VERSION_1
public static final int VERSION_2
public static final int VERSION_3
public AbstractWebApiInterface(C client)
Default Constructor
client - A AbstractRestClient instanceprotected <V> V fromJson(com.google.gson.JsonElement element,
Class<V> classTypeOf)
fromJson.
V - a V classelement - a JsonElement objectclassTypeOf - a Class objectprotected com.google.gson.Gson builder()
Gson instanceprotected void configureBuilder(com.google.gson.GsonBuilder builder)
Override this method if you need to perform additional configurations against the builder (e.g. Register custom deserializers)
builder - A GsonBuilder instance that will be accessed and configured by a concrete AbstractWebApiInterface implementationprotected <A> List<A> asListOf(Class itemType, String searchKey, com.google.gson.JsonObject searchElement, boolean strict)
Similar to asCollectionOf(Class, String, JsonObject, Class, boolean) minus the Collection class argument. This also returns a List collection type instead.
A - The type of the List to be returneditemType - The Class type of the item in the CollectionsearchKey - The name of the JsonArray element that we will convertsearchElement - The JsonObject that will be used to search for the JsonArray elementstrict - If true an exception will be thrown if the listName is not found within the search element specified.
Otherwise no exceptions will be raised and an empty Collection instance will be returned.List containing the parsed json entitiesprotected <A extends Collection> A asCollectionOf(Class itemType, String searchKey, com.google.gson.JsonObject searchElement, Class<? extends Collection> collectionClass, boolean strict)
A Utility function that retrieves the specified json element and converts it to a Parameterized Collection instance.
A - The internal type of the Collection to be returneditemType - The Class type of the item in the CollectionsearchKey - The name of the JsonArray element that we will convertsearchElement - The JsonObject that will be used to search for the JsonArray elementcollectionClass - A Class representing the concrete implementation of the Collectionstrict - If true an exception will be thrown if the listName is not found within the search element specified. Otherwise no exceptions will be raised and an empty Collection instance will be returned.Collection containing the type specified by collectionClass argumentprotected <V> V fromJson(com.google.gson.JsonElement element,
Type typeOf)
fromJson.
V - a V classelement - a JsonElement objecttypeOf - a Type objectprotected <A> CompletableFuture<A> sendRequest(R request)
Sends a requests to the internal client.
A - a A classrequest - An instance of AbstractWebRequestCompletableFuture that will hold the expected value once a response has been received by the serverprotected void handleError(AbstractWebResponse response, Throwable error)
response - An instance of AbstractWebApiResponse or null if an exception was thrown.error - A Throwable instance or null if no error has occured.Copyright © 2016–2024. All rights reserved.