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

com.contentstack.sdk.Client Maven / Gradle / Ivy

There is a newer version: 1.0.2
Show newest version
package com.contentstack.sdk;

import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;


/**
 * The type Client.
 */
public class Client {
    private static Retrofit retrofit;

    private Client() {
        // Private constructor to prevent instantiation
    }

    /**
     * Get or create the Retrofit instance for the specified host.
     *
     * @param host The host of the API.
     * @return Retrofit instance.
     */
    public static Retrofit getInstance(String host) {
        if (retrofit == null) {
            synchronized (Client.class) {
                if (retrofit == null) {
                    retrofit = createRetrofitInstance(host);
                }
            }
        }
        return retrofit;
    }

    private static Retrofit createRetrofitInstance(String host) {
        String BASE_URL = "https://" + host + "/";
        return new Retrofit.Builder()
                .baseUrl(BASE_URL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }
}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy