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 JDOA2Builderbuilder()Creates a newJDOA2Builderstatic JDOA2Builderbuilder(ApplicationInfo applicationInfo) Creates a newJDOA2BuilderStarts a OAuth2 token exchange process.Refreshes an existing OAuth2 token, or if none found, callsdoTokenExchange().Returns theApplicationInfoReturns the token this JDOA2 instance has last cached.com.github.natanbc.reliqua.request.PendingRequest<CurrentUser>RetrievesCurrentUserinformation, returningPendingRequest.default StringgetGuildIconUrl(Guild guild) Deprecated.okhttp3.OkHttpClientReturns theOkHttpClient, used to handle requests.com.fasterxml.jackson.databind.ObjectMapperReturns theObjectMapper, used to read json from discord api responses.default StringgetUserAvatarUrl(CurrentUser user) Returns the icon url of theCurrentUserspecified.booleanReturns 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:
trueif valid,falseotherwise
-
getCurrentUser
RetrievesCurrentUserinformation, 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:
-
PendingRequestCurrentUser
-
getUserAvatarUrl
Returns the icon url of theCurrentUserspecified. Note that every avatar method inCurrentUserreturns 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 aListofGuilds, which theCurrentUserhas 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:
-
PendingRequestGuild
-
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()