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

jp.gopay.sdk.builders.RetrofitRequestBuilder Maven / Gradle / Ivy

There is a newer version: 0.11.17
Show newest version
package jp.gopay.sdk.builders;

import jp.gopay.sdk.models.errors.GoPayException;
import jp.gopay.sdk.models.response.GoPayResponse;
import jp.gopay.sdk.utils.GoPayCallback;
import jp.gopay.sdk.utils.Sleeper;
import retrofit2.Call;
import retrofit2.Retrofit;

import java.io.IOException;
import java.lang.reflect.ParameterizedType;

public abstract class RetrofitRequestBuilder
        implements RequestBuilder>, Request {

    private Class resourceClass;
    protected Retrofit retrofit;

    public RetrofitRequestBuilder(Retrofit retrofit) {
        this.retrofit = retrofit;

        this.resourceClass = (Class) ((ParameterizedType) getClass()
                .getGenericSuperclass()).getActualTypeArguments()[1];
    }

    protected Call createCall() {
        R resource = retrofit.create(resourceClass);
        return getRequest(resource);
    }

    protected abstract Call getRequest(R resource);

    @Override
    public Request build() {
        return new RetrofitRequestCaller<>(retrofit, createCall());
    }

    @Override
    public void dispatch(final GoPayCallback callback) {
        build().dispatch(callback);
    }

    @Override
    public E dispatch() throws IOException, GoPayException {
        return build().dispatch();
    }

    @Override
    public E dispatch(int maxRetry, Sleeper sleeper) throws GoPayException, InterruptedException, IOException {
        return build().dispatch(maxRetry, sleeper);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy