Class Action<T>


  • public class Action<T>
    extends java.lang.Object
    • Constructor Summary

      Constructors 
      Constructor Description
      Action​(SimpleAPI api, @NonNull java.lang.Class<T> responseClass, @NonNull APIRequest apiRequest)
      Creates Action object
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.util.concurrent.CompletableFuture<T> execute()
      Requests the API with specified APIRequest
      Action<T> onDeserialization​(java.util.function.Function<java.net.http.HttpResponse<?>,​T> deserializationCallback)
      Function with HttpResponse argument and your response class return
      This Function will be called for deserializing.
      Action<T> onHttpError​(@NonNull java.util.function.Consumer<HttpError> httpErrorCallback)
      HttpError Consumer which will be called if there would be any HttpException
      Action<T> onSuccess​(java.util.function.BiConsumer<java.net.http.HttpResponse<?>,​T> successCallback)
      HttpResponse and your response class BiConsumer which will be called if the request was successful
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Action

        public Action​(SimpleAPI api,
                      @NonNull
                      @NonNull java.lang.Class<T> responseClass,
                      @NonNull
                      @NonNull APIRequest apiRequest)
        Creates Action object
        Parameters:
        api - Your SimpleAPI object
        responseClass - Non-null Class which you expect to be responded
        apiRequest - Non-null APIRequest
    • Method Detail

      • onHttpError

        public Action<T> onHttpError​(@NonNull
                                     @NonNull java.util.function.Consumer<HttpError> httpErrorCallback)
        HttpError Consumer which will be called if there would be any HttpException
        Parameters:
        httpErrorCallback - Non-null HttpError Consumer
        Returns:
        Action, great for chaining
      • onSuccess

        public Action<T> onSuccess​(java.util.function.BiConsumer<java.net.http.HttpResponse<?>,​T> successCallback)
        HttpResponse and your response class BiConsumer which will be called if the request was successful
        Parameters:
        successCallback - Non-null HttpResponse and your response class BiConsumer
        Returns:
        Action, great for chaining
      • onDeserialization

        public Action<T> onDeserialization​(java.util.function.Function<java.net.http.HttpResponse<?>,​T> deserializationCallback)
        Function with HttpResponse argument and your response class return
        This Function will be called for deserializing. You should return your deserialized object here. If your API returns JSON, your can use GsonDeserializer to automate this step.
        Parameters:
        deserializationCallback - Nullable Function with HttpResponse argument and your response class return
        Returns:
        Action, great for chaining
      • execute

        public java.util.concurrent.CompletableFuture<T> execute()
        Requests the API with specified APIRequest
        Returns:
        CompletableFuture