
com.elypia.elypiai.restutils.RestAction Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of common Show documentation
Show all versions of common Show documentation
Wrappers for many APIs available online from various services.
The newest version!
package com.elypia.elypiai.restutils;
import com.elypia.elypiai.restutils.impl.AbstractRestAction;
import retrofit2.*;
import java.io.IOException;
import java.util.function.Consumer;
public class RestAction extends AbstractRestAction {
private Call call;
private String errorBody;
public RestAction(Call call) {
this.call = call;
}
@Override
public void queue(Consumer success, Consumer ex) {
call.enqueue(new Callback() {
@Override
public void onResponse(Call call, Response response) {
if (success != null)
success.accept(response.body());
}
@Override
public void onFailure(Call call, Throwable t) {
if (ex != null)
ex.accept(t);
}
});
}
@Override
public T complete() throws IOException {
Response response = call.execute();
if (response.body() == null && response.errorBody() != null)
errorBody = response.errorBody().string();
return response.body();
}
@Override
public void cancel() {
call.cancel();
}
public String getErrorBody() {
return errorBody;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy