Changeset View
Changeset View
Standalone View
Standalone View
src/main/java/net/wildfyre/api/WildFyre.java
/* | |||||
* Copyright 2019 Wildfyre.net | |||||
* | |||||
* Licensed under the Apache License, Version 2.0 (the "License"); | |||||
* you may not use this file except in compliance with the License. | |||||
* You may obtain a copy of the License at | |||||
* | |||||
* http://www.apache.org/licenses/LICENSE-2.0 | |||||
* | |||||
* Unless required by applicable law or agreed to in writing, software | |||||
* distributed under the License is distributed on an "AS IS" BASIS, | |||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||||
* See the License for the specific language governing permissions and | |||||
* limitations under the License. | |||||
*/ | |||||
package net.wildfyre.api; | package net.wildfyre.api; | ||||
import net.wildfyre.http.Request; | import net.wildfyre.http.Request; | ||||
import net.wildfyre.users.LoggedUser; | import net.wildfyre.users.LoggedUser; | ||||
import net.wildfyre.users.Users; | import net.wildfyre.users.Users; | ||||
import net.wildfyre.utils.InvalidCredentialsException; | import net.wildfyre.utils.InvalidCredentialsException; | ||||
/** | /** | ||||
Show All 9 Lines | public class WildFyre { | ||||
* @param password the user's password | * @param password the user's password | ||||
* @return Your own user. See also {@link Users#me()}. | * @return Your own user. See also {@link Users#me()}. | ||||
*/ | */ | ||||
public static LoggedUser connect(String username, String password) | public static LoggedUser connect(String username, String password) | ||||
throws Request.CantConnectException, InvalidCredentialsException { | throws Request.CantConnectException, InvalidCredentialsException { | ||||
Internal.requestToken(username, password); | Internal.requestToken(username, password); | ||||
Internal.init(); | Internal.init(); | ||||
return Users.me(); | return Users.INSTANCE.me(); | ||||
} | } | ||||
/** | /** | ||||
* Connects to the server with the specified token. | * Connects to the server with the specified token. | ||||
* This method is NOT executed concurrently, because no action can be taken by the client while the cache is empty | * This method is NOT executed concurrently, because no action can be taken by the client while the cache is empty | ||||
* anyway. | * anyway. | ||||
* @param token the token | * @param token the token | ||||
* @return Your own user. See also {@link Users#me()}. | * @return Your own user. See also {@link Users#me()}. | ||||
*/ | */ | ||||
public static LoggedUser connect(String token) throws Request.CantConnectException { | public static LoggedUser connect(String token) throws Request.CantConnectException { | ||||
if(token == null) | if(token == null) | ||||
throw new NullPointerException("Cannot connect to the token 'null'"); | throw new NullPointerException("Cannot connect to the token 'null'"); | ||||
Internal.setToken(token); | Internal.setToken(token); | ||||
Internal.init(); | Internal.init(); | ||||
return Users.me(); | return Users.INSTANCE.me(); | ||||
} | } | ||||
/** | /** | ||||
* Disconnects the API from the currently-logged-in user. | * Disconnects the API from the currently-logged-in user. | ||||
*/ | */ | ||||
public static void disconnect(){ | public static void disconnect(){ | ||||
Internal.reset(); | Internal.reset(); | ||||
} | } | ||||
Show All 13 Lines |