
net.stepniak.android.picheese.api.rest.auth.RestAuthHandler Maven / Gradle / Ivy
The newest version!
package net.stepniak.android.picheese.api.rest.auth;
import net.stepniak.android.picheese.Log;
import net.stepniak.picheese.error.server.ServerErrorType;
import net.stepniak.picheese.error.server.exception.InternalServerException;
import net.stepniak.picheese.pojos.v1.Session;
public class RestAuthHandler {
private static final String TAG = RestAuthHandler.class.getName();
// private static final String apiKey = "bd4faddd2b64dcd1ec134393"; //local //TODO config
private static final String apiKey = "4f5421dc4483320927772733"; //dev //TODO config
private static Session session;
private static RestAuthUser user;
public static String getSessionId() {
if (session == null) {
Log.d(TAG, "getSessionId: null");
return null;
}
Log.d(TAG, "getSessionId: %s", session.getId());
return session.getId();
}
public static RestAuthUser getUser() {
if (user == null) {
Log.d(TAG, "getUser: null");
return null;
}
Log.d(TAG, "getUser: %s, %s", user.getId(), user.getName());
return user;
}
public static void renewSession(Session sess) {
Log.d(TAG, "renewSession(%s)", sess.getId());
session = sess;
if (user == null && session.getUser() != null) {
user = new RestAuthUser(session.getUser());
}
}
public static void setUserEmail(String email) {
Log.d(TAG, "setUserEmail(%s)", email);
if (user == null) {
//TODO
throw new InternalServerException(ServerErrorType.INTERNAL_EXCEPTION);
}
user.setEmail(email);
}
public static String getApiKey() {
Log.d(TAG, "getApiKey: %s", apiKey);
return apiKey;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy