Package com.mrivanplays.jdoa2
Interface JDOA2
- All Known Implementing Classes:
JDOA2Impl
public interface JDOA2
Represents the driver of the all components.
JDOA2 stands for Java Discord OAuth2, representing a discord api wrapper of OAuth2 applications for interacting with user data.
-
Method Summary
Modifier and TypeMethodDescriptionstatic JDOA2Builder
builder()
Creates a newJDOA2Builder
static JDOA2Builder
builder
(ApplicationInfo applicationInfo) Creates a newJDOA2Builder
Starts a OAuth2 token exchange process.Refreshes an existing OAuth2 token, or if none found, callsdoTokenExchange()
.Returns theApplicationInfo
Returns the token this JDOA2 instance has last cached.com.github.natanbc.reliqua.request.PendingRequest<CurrentUser>
RetrievesCurrentUser
information, returningPendingRequest
.default String
getGuildIconUrl
(Guild guild) Deprecated.okhttp3.OkHttpClient
Returns theOkHttpClient
, used to handle requests.com.fasterxml.jackson.databind.ObjectMapper
Returns theObjectMapper
, used to read json from discord api responses.default String
getUserAvatarUrl
(CurrentUser user) Returns the icon url of theCurrentUser
specified.boolean
Returns whenever the token we have is valid or not.
-
Method Details
-
builder
Creates a newJDOA2Builder
- Returns:
- builder
-
builder
Creates a newJDOA2Builder
- Parameters:
applicationInfo
- application info- Returns:
- builder
- See Also:
-
doTokenExchange
Starts a OAuth2 token exchange process. You may want to call this right after you receive a instance of this class in order for the application to interact with discord api to provide you information.WARNING: This is a thread blocking method, it may block the thread if the application is rate limited by discord api. CONSIDER RUNNING ASYNCHRONOUSLY!!!!
- Returns:
- token object
- Throws:
RateLimitedException
- if the method wasn't able to block the thread and wait after "retry after".AuthenticationException
- if something went wrong while contacting discord api, or we got an internal error.- See Also:
-
doTokenExchangeUsingRefreshToken
Refreshes an existing OAuth2 token, or if none found, callsdoTokenExchange()
. You may want to call this hand in hand withisCurrentTokenValid()
in order for the wrapper to have a working access token.WARNING: This is a thread blocking method, it may block the thread if the application is rate limited by discord api. CONSIDER RUNNING ASYNCHRONOUSLY!!!!
- Returns:
- token object
- Throws:
RateLimitedException
- if the method wasn't able to block the thread and wait after "retry after".AuthenticationException
- if something went wrong while contacting discord api, or we got an internal error.- See Also:
-
getCurrentToken
Optional<DiscordToken> getCurrentToken()Returns the token this JDOA2 instance has last cached.- Returns:
- last token
-
isCurrentTokenValid
boolean isCurrentTokenValid()Returns whenever the token we have is valid or not. You may want to check this every time before using any of the information receiver methods, and if the token isn't valid you may want to calldoTokenExchangeUsingRefreshToken()
.- Returns:
true
if valid,false
otherwise
-
getCurrentUser
RetrievesCurrentUser
information, returningPendingRequest
.Caching is recommended in order to not hit discord's rate limits. Due to the nature of the api, we currently cannot apply caching.
- Returns:
- pending request, containing current user information
- Throws:
MissingScopeException
- if scope "identify" isn't presentNullPointerException
- if no token exchange occurred.IllegalArgumentException
- if the current token is invalid.RateLimitedException
- if rate limit was hitAuthenticationException
- if something went wrong while contacting discord api, or we got an internal error- See Also:
-
PendingRequest
CurrentUser
-
getUserAvatarUrl
Returns the icon url of theCurrentUser
specified. Note that every avatar method inCurrentUser
returns an icon hash, and not an url.- Parameters:
user
- current user- Returns:
- icon url
-
getGuildIconUrl
Deprecated.replaced byGuild.getIconUrl()
Returns the icon url of the guild specified. Note thatGuild.getIcon()
returns an icon hash, not an url.- Parameters:
guild
- guild- Returns:
- icon url
-
getCurrentUserGuilds
@CheckReturnValue com.github.natanbc.reliqua.request.PendingRequest<List<Guild>> getCurrentUserGuilds()Retrieves aList
ofGuilds
, which theCurrentUser
has joined in, returningPendingRequest
. Requires "guilds" scope.Caching is recommended in order to not hit discord's rate limits. Due to the nature of the api, we currently cannot apply caching.
- Returns:
- pending request, containing guilds information
- Throws:
MissingScopeException
- if "guilds" scope wasn't specifiedNullPointerException
- if no token exchange occurred.IllegalArgumentException
- if the current token is invalid.RateLimitedException
- if rate limit was hitAuthenticationException
- if something went wrong while contacting discord api, or we got an internal error- See Also:
-
PendingRequest
Guild
-
getHttpClient
Returns theOkHttpClient
, used to handle requests.- Returns:
- http client
-
getJsonMapper
Returns theObjectMapper
, used to read json from discord api responses.- Returns:
- json mapper
-
getApplicationInfo
Returns theApplicationInfo
- Returns:
- application info
- See Also:
-
Guild.getIconUrl()