How can this be integrated with Retrofit 2?
jlmalone opened this issue · comments
jlmalone commented
Raphael Seher commented
We have no direct integration with Retrofit. But you can make a Retrofit Call to return the ResponseBody
and then parse the json returned by the call. Get json from Retrofit - Stackoverflow
Code from xamoom android sdk
public void enqueCall(Call<ResponseBody> call, final APICallback<T, List<Error>> callback) {
call.enqueue(new Callback<ResponseBody>() {
@Override
public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
String json = getJsonFromResponse(response); //get the json
try {
//parse json with morpheus
JsonApiObject jsonApiObject = morpheus.parse(json);
if (jsonApiObject.getResource() != null) {
T t = (T) jsonApiObject.getResource();
callback.finished(t);
} else if (jsonApiObject.getErrors() != null && jsonApiObject.getErrors().size() > 0) {
callback.error(jsonApiObject.getErrors());
}
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void onFailure(Call<ResponseBody> call, Throwable t) {
//error handling
}
});
}
jlmalone commented
I posted a gist with my solution to this problem https://gist.github.com/jlmalone/8074fb9eaeb60694874f5506ed539b04