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

io.deepsense.neptune.clientlibrary.services.apiservice.ApiServiceBuilder Maven / Gradle / Ivy

There is a newer version: 1.6.1
Show newest version
/**
 * Copyright (c) 2016, CodiLime Inc.
 */

package io.deepsense.neptune.clientlibrary.services.apiservice;

import io.deepsense.neptune.clientlibrary.api.Credentials;
import io.deepsense.neptune.clientlibrary.services.apimodelconverter.ApiModelConverter;
import io.deepsense.neptune.clientlibrary.services.apiservice.retries.ApiServiceWithRetries;
import io.deepsense.neptune.clientlibrary.services.apiservice.retries.RequestRetryStrategyFactory;

import java.net.URI;

public class ApiServiceBuilder {

    private URI baseUrl;

    private ApiModelConverter apiModelConverter;

    private Credentials credentials;

    private RequestRetryStrategyFactory retryStrategyFactory;

    public ApiServiceBuilder() {

    }

    public ApiServiceBuilder withBaseUrl(URI baseUrl) {
        this.baseUrl = baseUrl;
        return this;
    }

    public ApiServiceBuilder withCredentials(Credentials credentials) {
        this.credentials = credentials;
        return this;
    }

    public ApiServiceBuilder withApiModelConverter(ApiModelConverter apiModelConverter) {
        this.apiModelConverter = apiModelConverter;
        return this;
    }

    public ApiServiceBuilder withRequestRetryStrategyFactory(RequestRetryStrategyFactory retryStrategyFactory) {
        this.retryStrategyFactory = retryStrategyFactory;
        return this;
    }

    public ApiService build() {
        ApiService baseApiService = new SimpleApiService(apiModelConverter, credentials, baseUrl.toString());

        if (retryStrategyFactory == null) {
            return baseApiService;
        } else {
            return new ApiServiceWithRetries(baseApiService, retryStrategyFactory.create());
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy