All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.sphere.internal.request.FetchRequestImpl Maven / Gradle / Ivy

There is a newer version: 0.72.1
Show newest version
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 - 2024 Weber Informatics LLC | Privacy Policy