Commit f5be9d34 authored by Ivan Del Pino's avatar Ivan Del Pino Committed by Rafael Jesus Hernández Vasquez
Browse files

feat: improve interface callback response


Signed-off-by: default avatarIvan Del Pino <idelpino@teclib.com>
parent 8efdffcf
......@@ -44,6 +44,7 @@ import com.orhanobut.logger.PrettyFormatStrategy;
import org.glpi.api.GLPI;
import org.glpi.api.itemType;
import org.glpi.api.response.FullSessionModel;
import org.glpi.api.response.InitSession;
import java.util.ArrayList;
......@@ -123,7 +124,7 @@ public class MainActivity extends AppCompatActivity {
private void btnKill() {
progressBar.setVisibility(View.VISIBLE);
resultList.clear();
glpi.killSession(new GLPI.VoidCallback() {
glpi.killSession(new GLPI.ResponseHandle<String, String>() {
@Override
public void onResponse(String response) {
FlyveLog.i("killSession: %s", response.toString());
......@@ -145,7 +146,7 @@ public class MainActivity extends AppCompatActivity {
private void btnInit() {
progressBar.setVisibility(View.VISIBLE);
resultList.clear();
glpi.initSessionByUserToken(data.getUserToken(), new GLPI.InitSessionCallback() {
glpi.initSessionByUserToken(data.getUserToken(), new GLPI.ResponseHandle<InitSession, String>() {
@Override
public void onResponse(InitSession response) {
updateAdapter("Success: Init Session User Token");
......@@ -153,32 +154,48 @@ public class MainActivity extends AppCompatActivity {
@Override
public void onFailure(String errorMessage) {
updateAdapter("Error: Init Session User Token");
updateAdapter("Error: Init Session User Token" + errorMessage);
}
});
glpi.initSessionByCredentials(BuildConfig.GLPI_USER, BuildConfig.GLPI_PASSWORD, new GLPI.InitSessionCallback() {
String token = glpi.initSessionByCredentialsSync(BuildConfig.GLPI_USER, BuildConfig.GLPI_PASSWORD);
FlyveLog.i("initSession: %s", token);
updateAdapter("Success: Init Session Credentials");
glpi.fullSession(new GLPI.ResponseHandle<FullSessionModel, String>() {
@Override
public void onResponse(FullSessionModel response) {
FlyveLog.i("Full Session: %s", response.toString());
updateAdapter("Success: Full Session");
}
@Override
public void onFailure(String errorMessage) {
FlyveLog.i("Full Session: %s", errorMessage);
updateAdapter("Error: Full Session");
}
});
GLPI.ResponseHandle<InitSession, String> handle = new GLPI.ResponseHandle<InitSession, String>() {
@Override
public void onResponse(InitSession response) {
FlyveLog.i("initSession: %s", response.getSessionToken());
updateAdapter("Success: Init Session Credentials");
progressBar.setVisibility(View.GONE);
recyclerView.setVisibility(View.VISIBLE);
}
@Override
public void onFailure(String errorMessage) {
updateAdapter("Error: Init Session Credentials");
updateAdapter("Error: Init Session Credentials" + errorMessage);
progressBar.setVisibility(View.GONE);
recyclerView.setVisibility(View.VISIBLE);
}
});
};
glpi.initSessionByCredentials(BuildConfig.GLPI_USER, BuildConfig.GLPI_PASSWORD, handle);
}
private void btnCall() {
progressBar.setVisibility(View.VISIBLE);
resultList.clear();
glpi.getMyProfiles(new GLPI.JsonObjectCallback() {
glpi.getMyProfiles(new GLPI.ResponseHandle<JsonObject, String>() {
@Override
public void onResponse(JsonObject response) {
FlyveLog.i("getMyProfiles: %s", response.toString());
......@@ -192,7 +209,7 @@ public class MainActivity extends AppCompatActivity {
}
});
glpi.getActiveProfile(new GLPI.JsonObjectCallback() {
glpi.getActiveProfile(new GLPI.ResponseHandle<JsonObject, String>() {
@Override
public void onResponse(JsonObject response) {
FlyveLog.i("getActiveProfile: %s", response.toString());
......@@ -206,7 +223,7 @@ public class MainActivity extends AppCompatActivity {
}
});
glpi.getMyEntities(new GLPI.JsonObjectCallback() {
glpi.getMyEntities(new GLPI.ResponseHandle<JsonObject, String>() {
@Override
public void onResponse(JsonObject response) {
FlyveLog.i("getMyEntities: %s", response.toString());
......@@ -220,7 +237,7 @@ public class MainActivity extends AppCompatActivity {
}
});
glpi.getActiveEntities(new GLPI.JsonObjectCallback() {
glpi.getActiveEntities(new GLPI.ResponseHandle<JsonObject, String>() {
@Override
public void onResponse(JsonObject response) {
FlyveLog.i("getActiveEntities: %s", response.toString());
......@@ -234,7 +251,7 @@ public class MainActivity extends AppCompatActivity {
}
});
glpi.getFullSession(new GLPI.JsonObjectCallback() {
glpi.getFullSession(new GLPI.ResponseHandle<JsonObject, String>() {
@Override
public void onResponse(JsonObject response) {
FlyveLog.i("getFullSession: %s", response.toString());
......@@ -248,7 +265,7 @@ public class MainActivity extends AppCompatActivity {
}
});
glpi.getGlpiConfig(new GLPI.JsonObjectCallback() {
glpi.getGlpiConfig(new GLPI.ResponseHandle<JsonObject, String>() {
@Override
public void onResponse(JsonObject response) {
FlyveLog.i("getGlpiConfig: %s", response.toString());
......@@ -262,7 +279,7 @@ public class MainActivity extends AppCompatActivity {
}
});
glpi.getAllItems(itemType.Computer, new GLPI.JsonArrayCallback() {
glpi.getAllItems(itemType.Computer, new GLPI.ResponseHandle<JsonArray, String>() {
@Override
public void onResponse(JsonArray response) {
FlyveLog.i("getAllItems: %s", response.toString());
......@@ -276,7 +293,7 @@ public class MainActivity extends AppCompatActivity {
}
});
glpi.getItem(itemType.Computer, "110", new GLPI.JsonObjectCallback() {
glpi.getItem(itemType.Computer, "110", new GLPI.ResponseHandle<JsonObject, String>() {
@Override
public void onResponse(JsonObject response) {
FlyveLog.i("getAnItem: %s", response.toString());
......@@ -290,7 +307,7 @@ public class MainActivity extends AppCompatActivity {
}
});
glpi.getSubItems(itemType.Computer, "2", itemType.ComputerType, new GLPI.JsonObjectCallback() {
GLPI.ResponseHandle<JsonObject, String> responseHandle = new GLPI.ResponseHandle<JsonObject, String>() {
@Override
public void onResponse(JsonObject response) {
FlyveLog.i("getSubItems", response.toString());
......@@ -302,9 +319,10 @@ public class MainActivity extends AppCompatActivity {
FlyveLog.e("getSubItems: %s", errorMessage);
updateAdapter("Error: sub items");
}
});
};
glpi.getSubItems(itemType.Computer, "2", itemType.ComputerType, responseHandle);
glpi.changeActiveProfile("9", new GLPI.VoidCallback() {
glpi.changeActiveProfile("9", new GLPI.ResponseHandle<String, String>() {
@Override
public void onResponse(String response) {
FlyveLog.i("changeActiveProfile: %s", response);
......@@ -318,7 +336,7 @@ public class MainActivity extends AppCompatActivity {
}
});
glpi.changeActiveEntities("1", false, new GLPI.VoidCallback() {
glpi.changeActiveEntities("1", false, new GLPI.ResponseHandle<String, String>() {
@Override
public void onResponse(String response) {
FlyveLog.i("changeActiveEntities: %s", response);
......@@ -343,21 +361,18 @@ public class MainActivity extends AppCompatActivity {
addItemExamplePayload obj = new addItemExamplePayload(list);
glpi.addItems(itemType.Computer, obj, new GLPI.JsonArrayCallback() {
glpi.addItems(itemType.Computer, obj, new GLPI.ResponseHandle<JsonArray, String>() {
@Override
public void onResponse(JsonArray response) {
FlyveLog.i("addItems: %s", response.toString());
updateAdapter("Success: add items");
}
@Override
public void onFailure(String errorMessage) {
FlyveLog.e("addItems: %s", errorMessage);
updateAdapter("Error: add items");
}
});
glpi.updateItems(itemType.Computer, "10", obj, new GLPI.JsonArrayCallback() {
glpi.updateItems(itemType.Computer, "10", obj, new GLPI.ResponseHandle<JsonArray, String>() {
@Override
public void onResponse(JsonArray response) {
FlyveLog.i("updateItems: %s", response.toString());
......@@ -371,7 +386,7 @@ public class MainActivity extends AppCompatActivity {
}
});
glpi.deleteItems(itemType.Computer, "10", new GLPI.JsonArrayCallback() {
glpi.deleteItems(itemType.Computer, "10", new GLPI.ResponseHandle<JsonArray, String>() {
@Override
public void onResponse(JsonArray response) {
FlyveLog.i("deleteItems: %s", response.toString());
......@@ -396,7 +411,7 @@ public class MainActivity extends AppCompatActivity {
deleteItemExamplePayload deleteObj = new deleteItemExamplePayload(deleteList);
glpi.deleteItems(itemType.Computer, deleteObj, new GLPI.JsonArrayCallback() {
glpi.deleteItems(itemType.Computer, deleteObj, new GLPI.ResponseHandle<JsonArray, String>() {
@Override
public void onResponse(JsonArray response) {
FlyveLog.i("deleteItems: %s", response.toString());
......@@ -410,7 +425,7 @@ public class MainActivity extends AppCompatActivity {
}
});
glpi.recoveryPassword("youremail@yourdomain.com", new GLPI.VoidCallback() {
glpi.recoveryPassword("youremail@yourdomain.com", new GLPI.ResponseHandle<String, String>() {
@Override
public void onResponse(String response) {
FlyveLog.i("lostPassword: %s", response);
......@@ -424,7 +439,7 @@ public class MainActivity extends AppCompatActivity {
}
});
glpi.resetPassword("youremail@yourdomain.com", "asdfasdfafsASDFd333A", "1234", new GLPI.VoidCallback() {
GLPI.ResponseHandle<String, String> callback = new GLPI.ResponseHandle<String, String>() {
@Override
public void onResponse(String response) {
FlyveLog.i("recoveryPassword: %s", response);
......@@ -440,7 +455,8 @@ public class MainActivity extends AppCompatActivity {
progressBar.setVisibility(View.GONE);
recyclerView.setVisibility(View.VISIBLE);
}
});
};
glpi.resetPassword("youremail@yourdomain.com", "asdfasdfafsASDFd333A", "1234", callback);
}
private void updateAdapter(String message) {
......
......@@ -27,7 +27,7 @@ public class GLPITest {
public void initSessionTest() throws Exception {
if (!BuildConfig.GLPI_URL.equals("")) {
GLPI glpi = new GLPI(appContext, BuildConfig.GLPI_URL);
glpi.initSessionByCredentials(BuildConfig.GLPI_USER, BuildConfig.GLPI_PASSWORD, new GLPI.InitSessionCallback() {
glpi.initSessionByCredentials(BuildConfig.GLPI_USER, BuildConfig.GLPI_PASSWORD, new GLPI.ResponseHandle<InitSession, String>() {
@Override
public void onResponse(InitSession response) {
String sessionToken = response.getSessionToken();
......
......@@ -39,6 +39,7 @@ import org.glpi.api.request.ChangeActiveEntitiesRequest;
import org.glpi.api.request.ChangeActiveProfileRequest;
import org.glpi.api.request.RecoveryPasswordRequest;
import org.glpi.api.request.ResetPasswordRequest;
import org.glpi.api.response.FullSessionModel;
import org.glpi.api.response.InitSession;
import org.glpi.api.utils.Helpers;
......@@ -74,7 +75,7 @@ public class GLPI extends ServiceGenerator {
* @param userToken defined in User Preference (See 'Remote access key' on GLPI)
* @param callback here you are going to get the asynchronous response
*/
public void initSessionByUserToken(String userToken, final InitSessionCallback callback) {
public void initSessionByUserToken(String userToken, final ResponseHandle<InitSession, String> callback) {
Call<InitSession> call = interfaces.initSessionByUserToken(userToken, userToken);
responseInitSession(callback, call);
}
......@@ -106,24 +107,55 @@ public class GLPI extends ServiceGenerator {
* @param password valid password on GLPI
* @param callback here you are going to get the asynchronous response
*/
public void initSessionByCredentials(String user, String password, final InitSessionCallback callback) {
public void initSessionByCredentials(String user, String password, final ResponseHandle<InitSession, String> callback) {
this.appToken = null;
String authorization = Helpers.base64encode(user + ":" + password);
responseInitSession(callback, interfaces.initSessionByCredentials("Basic " + authorization.trim()));
}
public void fullSession(final ResponseHandle<FullSessionModel, String> callback) {
HashMap<String, String> header = new HashMap<>();
header.put("Session-Token", sessionToken);
header.put("Accept", "application/json");
header.put("Content-Type", "application/json" + ";" + "charset=UTF-8");
header.put("User-Agent", "Flyve MDM");
header.put("Referer", "/getFullSession");
interfaces.fullSession(header).enqueue(new Callback<FullSessionModel>() {
@Override
public void onResponse(@NonNull Call<FullSessionModel> call, @NonNull Response<FullSessionModel> response) {
if (response.isSuccessful()) {
callback.onResponse(response.body());
} else {
String errorMessage;
try {
assert response.errorBody() != null;
errorMessage = response.errorBody().string();
} catch (Exception ex) {
errorMessage = context.getResources().getString(R.string.error_generic);
}
callback.onFailure(errorMessage);
}
}
@Override
public void onFailure(@NonNull Call<FullSessionModel> call, @NonNull Throwable t) {
callback.onFailure(t.getMessage());
}
});
}
/**
* This endpoint allows to request password reset
*
* @param email email address of the user to recover
* @param callback here you are going to get the asynchronous response
*/
public void recoveryPassword(String email, final VoidCallback callback) {
public void recoveryPassword(String email, final ResponseHandle<String, String> callback) {
RecoveryPasswordRequest requestPost = new RecoveryPasswordRequest(email);
responseInitSession(callback, interfaces.lostPassword(requestPost), R.string.lost_password_success);
}
private void responseInitSession(final InitSessionCallback callback, Call<InitSession> responseCall) {
private void responseInitSession(final ResponseHandle<InitSession, String> callback, Call<InitSession> responseCall) {
responseCall.enqueue(new Callback<InitSession>() {
@Override
public void onResponse(@NonNull Call<InitSession> call, @NonNull Response<InitSession> response) {
......@@ -157,7 +189,7 @@ public class GLPI extends ServiceGenerator {
*
* @param callback here you are going to get the asynchronous response
*/
public void getMyProfiles(final JsonObjectCallback callback) {
public void getMyProfiles(final ResponseHandle<JsonObject, String> callback) {
responseJsonObject(callback, interfaces.getMyProfiles(getHeader()));
}
......@@ -166,7 +198,7 @@ public class GLPI extends ServiceGenerator {
*
* @param callback here you are going to get the asynchronous response
*/
public void getActiveProfile(final JsonObjectCallback callback) {
public void getActiveProfile(final ResponseHandle<JsonObject, String> callback) {
responseJsonObject(callback, interfaces.getActiveProfile(getHeader()));
}
......@@ -175,7 +207,7 @@ public class GLPI extends ServiceGenerator {
*
* @param callback here you are going to get the asynchronous response
*/
public void getMyEntities(final JsonObjectCallback callback) {
public void getMyEntities(final ResponseHandle<JsonObject, String> callback) {
responseJsonObject(callback, interfaces.getMyEntities(getHeader()));
}
......@@ -184,7 +216,7 @@ public class GLPI extends ServiceGenerator {
*
* @param callback here you are going to get the asynchronous response
*/
public void getActiveEntities(final JsonObjectCallback callback) {
public void getActiveEntities(final ResponseHandle<JsonObject, String> callback) {
responseJsonObject(callback, interfaces.getActiveEntities(getHeader()));
}
......@@ -193,7 +225,7 @@ public class GLPI extends ServiceGenerator {
*
* @param callback here you are going to get the asynchronous response
*/
public void getFullSession(final JsonObjectCallback callback) {
public void getFullSession(final ResponseHandle<JsonObject, String> callback) {
responseJsonObject(callback, interfaces.getFullSession(getHeader()));
}
......@@ -202,7 +234,7 @@ public class GLPI extends ServiceGenerator {
*
* @param callback here you are going to get the asynchronous response
*/
public void getGlpiConfig(final JsonObjectCallback callback) {
public void getGlpiConfig(final ResponseHandle<JsonObject, String> callback) {
responseJsonObject(callback, interfaces.getGlpiConfig(getHeader()));
}
......@@ -213,7 +245,7 @@ public class GLPI extends ServiceGenerator {
* @param id unique identifier of the itemtype
* @param callback here you are going to get the asynchronous response
*/
public void getItem(itemType itemType, String id, final JsonObjectCallback callback) {
public void getItem(itemType itemType, String id, final ResponseHandle<JsonObject, String> callback) {
Map<String, String> options = new GetAnItemQuery().getQuery();
responseJsonObject(callback, interfaces.getAnItem(getHeader(), itemType.name(), id, options));
}
......@@ -226,7 +258,7 @@ public class GLPI extends ServiceGenerator {
* @param subItemType These are the item type available on GLPI
* @param callback here you are going to get the asynchronous response
*/
public void getSubItems(String itemType, String id, String subItemType, final JsonObjectCallback callback) {
public void getSubItems(String itemType, String id, String subItemType, final ResponseHandle<JsonObject, String> callback) {
Map<String, String> options = new GetSubItemQuery(this.context).getQuery();
responseJsonObject(callback, interfaces.getSubItem(getHeader(), itemType, id, subItemType, options));
}
......@@ -239,12 +271,12 @@ public class GLPI extends ServiceGenerator {
* @param subItemType These are the item type available on GLPI
* @param callback here you are going to get the asynchronous response
*/
public void getSubItems(itemType itemType, String id, itemType subItemType, final JsonObjectCallback callback) {
public void getSubItems(itemType itemType, String id, itemType subItemType, final ResponseHandle<JsonObject, String> callback) {
Map<String, String> options = new GetSubItemQuery(this.context).getQuery();
responseJsonObject(callback, interfaces.getSubItem(getHeader(), itemType.name(), id, subItemType.name(), options));
}
private void responseJsonObject(final JsonObjectCallback callback, Call<JsonObject> responseCall) {
private void responseJsonObject(final ResponseHandle<JsonObject, String> callback, Call<JsonObject> responseCall) {
responseCall.enqueue(new Callback<JsonObject>() {
@Override
public void onResponse(@NonNull Call<JsonObject> call, @NonNull Response<JsonObject> response) {
......@@ -273,7 +305,7 @@ public class GLPI extends ServiceGenerator {
* @param itemType These are the item type available on GLPI
* @param callback here you are going to get the asynchronous response
*/
public void getAllItems(itemType itemType, final JsonArrayCallback callback) {
public void getAllItems(itemType itemType, final ResponseHandle<JsonArray, String> callback) {
Map<String, String> options = new GetAllItemQuery(this.context).getQuery();
responseJsonArray(callback, interfaces.getAllItem(getHeader(), itemType.name(), options));
}
......@@ -286,7 +318,7 @@ public class GLPI extends ServiceGenerator {
* items in one action by passing an array of objects.
* @param callback here you are going to get the asynchronous response
*/
public void addItems(itemType itemType, Object payload, final JsonArrayCallback callback) {
public void addItems(itemType itemType, Object payload, final ResponseHandle<JsonArray, String> callback) {
responseJsonArray(callback, interfaces.addItem(getHeader(), itemType.name(), payload));
}
......@@ -298,7 +330,7 @@ public class GLPI extends ServiceGenerator {
* @param payload Array of objects with fields of itemtype to be updated.
* @param callback here you are going to get the asynchronous response
*/
public void updateItems(itemType itemType, String id, Object payload, final JsonArrayCallback callback) {
public void updateItems(itemType itemType, String id, Object payload, final ResponseHandle<JsonArray, String> callback) {
responseJsonArray(callback, interfaces.updateItem(getHeader(), itemType.name(), id, payload));
}
......@@ -309,7 +341,7 @@ public class GLPI extends ServiceGenerator {
* @param id unique identifier of the itemtype
* @param callback here you are going to get the asynchronous response
*/
public void deleteItems(itemType itemType, String id, final JsonArrayCallback callback) {
public void deleteItems(itemType itemType, String id, final ResponseHandle<JsonArray, String> callback) {
responseJsonArray(callback, interfaces.deleteItem(getHeader(), itemType.name(), id));
}
......@@ -320,11 +352,11 @@ public class GLPI extends ServiceGenerator {
* @param payload Array of id who need to be deleted
* @param callback here you are going to get the asynchronous response
*/
public void deleteItems(itemType itemType, Object payload, final JsonArrayCallback callback) {
public void deleteItems(itemType itemType, Object payload, final ResponseHandle<JsonArray, String> callback) {
responseJsonArray(callback, interfaces.deleteMultiplesItem(getHeader(), itemType.name(), payload));
}
private void responseJsonArray(final JsonArrayCallback callback, Call<JsonArray> responseCall) {
private void responseJsonArray(final ResponseHandle<JsonArray, String> callback, Call<JsonArray> responseCall) {
responseCall.enqueue(new Callback<JsonArray>() {
@Override
public void onResponse(Call<JsonArray> call, Response<JsonArray> response) {
......@@ -348,7 +380,7 @@ public class GLPI extends ServiceGenerator {
});
}
private void responseInitSession(VoidCallback callback, Call<Void> responseCall, int lost_password_success) {
private void responseInitSession(ResponseHandle<String, String> callback, Call<Void> responseCall, int lost_password_success) {
responseVoid(callback, responseCall, lost_password_success);
}
......@@ -360,7 +392,7 @@ public class GLPI extends ServiceGenerator {
* @param newPassword the new password for the user
* @param callback here you are going to get the asynchronous response
*/
public void resetPassword(String email, String token, String newPassword, final VoidCallback callback) {
public void resetPassword(String email, String token, String newPassword, final ResponseHandle<String, String> callback) {
ResetPasswordRequest requestPost = new ResetPasswordRequest(email, token, newPassword);
responseVoid(callback, interfaces.recoveryPassword(requestPost), R.string.recovery_password_success);
}
......@@ -371,7 +403,7 @@ public class GLPI extends ServiceGenerator {
* @param profilesId (default 'all') ID of the new active profile.
* @param callback here you are going to get the asynchronous response
*/
public void changeActiveProfile(String profilesId, final VoidCallback callback) {
public void changeActiveProfile(String profilesId, final ResponseHandle<String, String> callback) {
ChangeActiveProfileRequest requestPost = new ChangeActiveProfileRequest(profilesId);
int message = R.string.change_active_profile_success;
responseVoid(callback, interfaces.changeActiveProfile(getHeader(), requestPost), message);
......@@ -384,13 +416,13 @@ public class GLPI extends ServiceGenerator {
* @param is_recursive (default false) Also display sub entities of the active entity.
* @param callback here you are going to get the asynchronous response
*/
public void changeActiveEntities(String entitiesId, Boolean is_recursive, final VoidCallback callback) {
public void changeActiveEntities(String entitiesId, Boolean is_recursive, final ResponseHandle<String, String> callback) {
ChangeActiveEntitiesRequest requestPost = new ChangeActiveEntitiesRequest(entitiesId, is_recursive.toString());
int message = R.string.change_active_entities_success;
responseVoid(callback, interfaces.changeActiveEntities(getHeader(), requestPost), message);
}
private void responseVoid(final VoidCallback callback, Call<Void> responseCall, final int message) {
private void responseVoid(final ResponseHandle<String, String> callback, Call<Void> responseCall, final int message) {
responseCall.enqueue(new Callback<Void>() {
@Override
public void onResponse(@NonNull Call<Void> call, @NonNull Response<Void> response) {
......@@ -419,11 +451,11 @@ public class GLPI extends ServiceGenerator {
*
* @param callback here you are going to get the asynchronous response
*/
public void killSession(final VoidCallback callback) {
public void killSession(final ResponseHandle<String, String> callback) {
responseKillSession(callback, interfaces.killSession(getHeader()));
}
private void responseKillSession(final VoidCallback callback, Call<Void> responseCall) {
private void responseKillSession(final ResponseHandle<String, String> callback, Call<Void> responseCall) {
responseCall.enqueue(new Callback<Void>() {
@Override
public void onResponse(@NonNull Call<Void> call, @NonNull Response<Void> response) {
......@@ -471,38 +503,17 @@ public class GLPI extends ServiceGenerator {
public void searchItems() {
}
/**
* Interface definition for a callback to be invoked when a user init session.
*/
public interface InitSessionCallback {
void onResponse(InitSession response);
public interface ResponseHandle<T, U> {
void onResponse(T response);
void onFailure(String errorMessage);
}
/**
* Interface definition for a callback to be invoked when an endpoint return a Json Object.
*/
public interface JsonObjectCallback {
void onResponse(JsonObject response);
void onFailure(String errorMessage);
}
/**
* Interface definition for a callback to be invoked when an endpoint return a Json Array.
*/
public interface JsonArrayCallback {
void onResponse(JsonArray response);
void onFailure(String errorMessage);
void onFailure(U errorMessage);
}
/**
* Interface definition for a callback to be invoked when an endpoint return void.
*/
public interface VoidCallback {
void onResponse(String response);
public interface FullSessionCallback {
void onResponse(FullSessionModel response);
void onFailure(String errorMessage);
}
......
......@@ -32,6 +32,7 @@ import org.glpi.api.request.ChangeActiveEntitiesRequest;
import org.glpi.api.request.ChangeActiveProfileRequest;
import org.glpi.api.request.RecoveryPasswordRequest;
import org.glpi.api.request.ResetPasswordRequest;
import org.glpi.api.response.FullSessionModel;
import org.glpi.api.response.InitSession;
import java.util.Map;
......@@ -59,6 +60,10 @@ public interface Routes {
@GET("initSession")
Call<InitSession> initSessionByCredentials(@Header("Authorization") String authorization);
@Headers("Content-Type: application/json")
@GET("getFullSession")
Call<FullSessionModel> fullSession(@HeaderMap Map<String, String> headers);
@Headers("Content-Type: application/json")
@GET("killSession")
Call<Void> killSession(@HeaderMap Map<String, String> headers);
......
package org.glpi.api.response;
import com.google.gson.annotations.SerializedName;
public class FullSessionModel {
@SerializedName("session")
private Session session;
public void setSession(Session session) {
this.session = session;
}
public Session getSession() {
return session;