com.univapay.sdk.builders.RetrofitRequestBuilder Maven / Gradle / Ivy
The newest version!
package com.univapay.sdk.builders;
import com.univapay.sdk.models.errors.UnivapayException;
import com.univapay.sdk.models.response.UnivapayResponse;
import com.univapay.sdk.utils.Sleeper;
import com.univapay.sdk.utils.UnivapayCallback;
import java.io.IOException;
import java.lang.reflect.ParameterizedType;
import retrofit2.Call;
import retrofit2.Retrofit;
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 Cancelable dispatch(final UnivapayCallback callback) {
return build().dispatch(callback);
}
@Override
public E dispatch() throws IOException, UnivapayException {
return build().dispatch();
}
@Override
public E dispatch(int maxRetry, Sleeper sleeper)
throws UnivapayException, InterruptedException, IOException {
return build().dispatch(maxRetry, sleeper);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy