Class OAuth2Action<T>
java.lang.Object
com.jagrosh.jdautilities.oauth2.requests.OAuth2Action<T>
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 Summary
Modifier and TypeFieldDescriptionprotected final OAuth2ClientImpl
protected static final Consumer
protected final net.dv8tion.jda.internal.requests.Method
protected final String
-
Constructor Summary
ConstructorDescriptionOAuth2Action
(OAuth2ClientImpl client, net.dv8tion.jda.internal.requests.Method method, String url) -
Method Summary
Modifier and TypeMethodDescriptionprotected okhttp3.Request
complete()
Synchronously executes this OAuth2Action, returning the value constructed from the response if it was successful, or throwing theException
if it was not.protected okhttp3.RequestBody
getBody()
Gets theclient
responsible for creating this OAuth2Action.protected okhttp3.Headers
protected net.dv8tion.jda.internal.requests.Method
protected String
getUrl()
protected abstract T
handle
(okhttp3.Response response) void
queue()
Asynchronously executes this OAuth2Action.void
Asynchronously executes this OAuth2Action, providing the value constructed from the response as the parameter given to the successConsumer
.void
Asynchronously executes this OAuth2Action, providing the value constructed from the response as the parameter given to the successConsumer
if the response is successful, or the exception to the failure Consumer if it's not.
-
Field Details
-
DEFAULT_SUCCESS
-
DEFAULT_FAILURE
-
client
-
method
protected final net.dv8tion.jda.internal.requests.Method method -
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
-
queue
public void queue()Asynchronously executes this OAuth2Action. -
queue
Asynchronously executes this OAuth2Action, providing the value constructed from the response as the parameter given to the successConsumer
.- Parameters:
success
- The success consumer, executed when this OAuth2Action gets a successful response.
-
queue
Asynchronously executes this OAuth2Action, providing the value constructed from the response as the parameter given to the successConsumer
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
Synchronously executes this OAuth2Action, returning the value constructed from the response if it was successful, or throwing theException
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
Gets theclient
responsible for creating this OAuth2Action.- Returns:
- The OAuth2Client responsible for creating this.
-
handle
- Throws:
IOException
-