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

io.blockfrost.sdk.impl.HealthServiceImpl Maven / Gradle / Ivy

package io.blockfrost.sdk.impl;

import io.blockfrost.sdk.api.HealthService;
import io.blockfrost.sdk.api.exception.APIException;
import io.blockfrost.sdk.api.model.Clock;
import io.blockfrost.sdk.api.model.Health;
import io.blockfrost.sdk.impl.retrofit.HealthApi;
import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.Response;

import java.io.IOException;
import java.util.concurrent.TimeUnit;

public class HealthServiceImpl extends BaseService implements HealthService {

    private HealthApi healthApi;

    public HealthServiceImpl(String baseUrl, String projectId) {
        super(baseUrl, projectId);
        healthApi = getRetrofit().create(HealthApi.class);
    }

    @Override
    public Health getHealth() throws APIException {

        Call healthCall = healthApi.healthGet(getProjectId());

        try {
            Response healthResponse = healthCall.execute();
            return processResponse(healthResponse);
        } catch (IOException exp) {
            throw new APIException("Exception while fetching health status", exp);
        }
    }

    @Override
    public Clock getCurrentBackendTime() throws APIException {
        Call clockCall = healthApi.healthClockGet(getProjectId());

        try {
            Response clockResponse = clockCall.execute();
            return processResponse(clockResponse);
        } catch (IOException exp) {
            throw new APIException("Exception while fetching current backend time", exp);
        }
    }

    @Override
    public String getApiRoot() throws APIException {

        Call apiRootCall = healthApi.rootGet(getProjectId());

        try {
            Response apiRootResponse = apiRootCall.execute();
            ResponseBody responseBody = apiRootResponse.raw().body();
            //return processResponse(apiRootResponse);
            TimeUnit.SECONDS.sleep(1);
            return "done";
        } catch (Exception exp) {
            throw new APIException("Exception while fetching Api Root", exp);
        }

    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy