Class OAuth2Action<T>

java.lang.Object
com.jagrosh.jdautilities.oauth2.requests.OAuth2Action<T>

public abstract class OAuth2Action<T> extends Object
An adaptable lookalike of JDA's RestAction.

OAuth2Actions can either be completed asynchronously using queue, or synchronously using complete.

Note that OAuth2Action does not extend JDA's RestAction.

Author:
Kaidan Gustave
  • Field Details

    • DEFAULT_SUCCESS

      protected static final Consumer DEFAULT_SUCCESS
    • DEFAULT_FAILURE

      protected static final Consumer<Throwable> DEFAULT_FAILURE
    • client

      protected final OAuth2ClientImpl client
    • method

      protected final net.dv8tion.jda.internal.requests.Method method
    • url

      protected final String url
  • Constructor Details

    • OAuth2Action

      public OAuth2Action(OAuth2ClientImpl client, net.dv8tion.jda.internal.requests.Method method, String url)
  • Method Details

    • getBody

      protected okhttp3.RequestBody getBody()
    • getHeaders

      protected okhttp3.Headers getHeaders()
    • buildRequest

      protected okhttp3.Request buildRequest()
    • getMethod

      protected net.dv8tion.jda.internal.requests.Method getMethod()
    • getUrl

      protected String getUrl()
    • queue

      public void queue()
      Asynchronously executes this OAuth2Action.
    • queue

      public void queue(Consumer<T> success)
      Asynchronously executes this OAuth2Action, providing the value constructed from the response as the parameter given to the success Consumer.
      Parameters:
      success - The success consumer, executed when this OAuth2Action gets a successful response.
    • queue

      public void queue(Consumer<T> success, Consumer<Throwable> failure)
      Asynchronously executes this OAuth2Action, providing the value constructed from the response as the parameter given to the success Consumer if the response is successful, or the exception to the failure Consumer if it's not.
      Parameters:
      success - The success consumer, executed when this OAuth2Action gets a successful response.
      failure - The failure consumer, executed when this OAuth2Action gets a failed response.
    • complete

      public T complete() throws IOException
      Synchronously executes this OAuth2Action, returning the value constructed from the response if it was successful, or throwing the Exception if it was not.

      Bear in mind when using this, that this method blocks the thread it is called in.

      Returns:
      the value constructed from the response
      Throws:
      IOException - on unsuccessful execution
    • getClient

      public OAuth2ClientImpl getClient()
      Gets the client responsible for creating this OAuth2Action.
      Returns:
      The OAuth2Client responsible for creating this.
    • handle

      protected abstract T handle(@WillClose okhttp3.Response response) throws IOException
      Throws:
      IOException