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 Details

    • builder

      static JDOA2Builder builder()
      Creates a new JDOA2Builder
      Returns:
      builder
    • builder

      static JDOA2Builder builder(ApplicationInfo applicationInfo)
      Creates a new JDOA2Builder
      Parameters:
      applicationInfo - application info
      Returns:
      builder
      See Also:
    • doTokenExchange

      @Nonnull DiscordToken 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

      @Nonnull DiscordToken doTokenExchangeUsingRefreshToken()
      Refreshes an existing OAuth2 token, or if none found, calls doTokenExchange(). You may want to call this hand in hand with isCurrentTokenValid() 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 call doTokenExchangeUsingRefreshToken().
      Returns:
      true if valid, false otherwise
    • getCurrentUser

      @CheckReturnValue com.github.natanbc.reliqua.request.PendingRequest<CurrentUser> getCurrentUser()
      Retrieves CurrentUser information, returning PendingRequest.

      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 present
      NullPointerException - if no token exchange occurred.
      IllegalArgumentException - if the current token is invalid.
      RateLimitedException - if rate limit was hit
      AuthenticationException - if something went wrong while contacting discord api, or we got an internal error
      See Also:
    • getUserAvatarUrl

      @Nonnull default String getUserAvatarUrl(@Nonnull CurrentUser user)
      Returns the icon url of the CurrentUser specified. Note that every avatar method in CurrentUser returns an icon hash, and not an url.
      Parameters:
      user - current user
      Returns:
      icon url
    • getGuildIconUrl

      @Nullable @Deprecated default String getGuildIconUrl(@Nonnull Guild guild)
      Deprecated.
      replaced by Guild.getIconUrl()
      Returns the icon url of the guild specified. Note that Guild.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 a List of Guilds, which the CurrentUser has joined in, returning PendingRequest. 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 specified
      NullPointerException - if no token exchange occurred.
      IllegalArgumentException - if the current token is invalid.
      RateLimitedException - if rate limit was hit
      AuthenticationException - if something went wrong while contacting discord api, or we got an internal error
      See Also:
    • getHttpClient

      @Nonnull okhttp3.OkHttpClient getHttpClient()
      Returns the OkHttpClient, used to handle requests.
      Returns:
      http client
    • getJsonMapper

      @Nonnull com.fasterxml.jackson.databind.ObjectMapper getJsonMapper()
      Returns the ObjectMapper, used to read json from discord api responses.
      Returns:
      json mapper
    • getApplicationInfo

      @Nonnull ApplicationInfo getApplicationInfo()
      Returns the ApplicationInfo
      Returns:
      application info
      See Also: