
io.sphere.internal.request.FetchRequestImpl Maven / Gradle / Ivy
package io.sphere.internal.request;
import com.google.common.base.Optional;
import io.sphere.internal.util.Util;
import io.sphere.client.FetchRequest;
import com.google.common.util.concurrent.ListenableFuture;
import org.codehaus.jackson.type.TypeReference;
public class FetchRequestImpl implements FetchRequest, TestableRequest {
RequestHolder requestHolder;
TypeReference jsonParserTypeRef;
public FetchRequestImpl(RequestHolder requestHolder, TypeReference jsonParserTypeRef) {
this.requestHolder = requestHolder;
this.jsonParserTypeRef = jsonParserTypeRef;
}
@Override public Optional fetch() {
return Util.sync(fetchAsync());
}
@Override public ListenableFuture> fetchAsync() {
return RequestExecutor.executeAndHandleError(requestHolder, 404, jsonParserTypeRef);
}
@Override public FetchRequest expand(String... paths) {
for (String path: paths) {
requestHolder.addQueryParameter("expand", path);
}
return this;
}
// testing purposes
@Override public TestableRequestHolder getRequestHolder() {
return requestHolder;
}
// logging and debugging purposes
@Override public String toString() {
return getRequestHolder().toString();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy