jp.gopay.sdk.builders.RetrofitRequestBuilder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gopay-java-sdk Show documentation
Show all versions of gopay-java-sdk Show documentation
Official Gyro-n Payments Java SDK
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);
}
}