public class Internal
extends java.lang.Object
Note that you should call init() after any modification of the token, otherwise the behavior of this
class is not defined.
| Constructor and Description |
|---|
Internal() |
| Modifier and Type | Method and Description |
|---|---|
static void |
clean()
Cleans the cache -- that is, removes every object that is not valid anymore from it (see
Descriptor.isValid()). |
static void |
clear()
Fully clears the cache, but keeps the token.
|
static java.util.Optional<User> |
getCachedUser(int id)
Gets the cached version of a user.
|
static LoggedUser |
getMe()
Gets the current user, that is, the user that corresponds to the saved token.
|
static int |
getMyId()
The ID of the logged-in user.
|
static java.lang.String |
getToken()
Returns the token used for authentication.
|
static void |
init()
Connects to the server & tries to access the logged-user's ID.
|
static boolean |
isMyId(int id)
Checks whether a user ID is the ID of the current user.
|
static void |
requestToken(java.lang.String username,
java.lang.String password)
Requests a token using a username and a password.
|
static void |
reset()
Resets the API.
|
static void |
setToken(java.lang.String token)
Sets the token used by the API.
|
static void |
submit(java.lang.Runnable task)
Submits a new task to be executed concurrently.
|
public static void clear()
Only remove the data that has expiredpublic static void clean()
Descriptor.isValid()).public static void reset()
This means that the user's token is removed, and the cache is fully cleared.
public static java.util.Optional<User> getCachedUser(int id)
User.query(int) instead.id - the user's IDpublic static LoggedUser getMe()
public static boolean isMyId(int id)
true if the provided ID is the ID of the logged-in user.public static int getMyId()
public static java.lang.String getToken()
public static void submit(java.lang.Runnable task)
task - the task to be executed concurrently.public static void requestToken(java.lang.String username,
java.lang.String password)
throws Request.CantConnectException
username - the user's usernamepassword - the user's passwordRequest.CantConnectException - if the API cannot connect to the serverpublic static void setToken(java.lang.String token)
token - the new tokenpublic static void init()
throws Request.CantConnectException
Request.CantConnectException - if the API cannot connect to the server