io.voucherify.client.module.ValidationsModule Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of voucherify-java-sdk Show documentation
Show all versions of voucherify-java-sdk Show documentation
Voucherify-java-sdk is a Java client (can be used in Android application as well) which was created to simplify integration with Voucherify backend (http://www.voucherify.io)
package io.voucherify.client.module;
import io.voucherify.client.api.VoucherifyApi;
import io.voucherify.client.callback.VoucherifyCallback;
import io.voucherify.client.model.validation.PromotionValidation;
import io.voucherify.client.model.validation.VoucherValidation;
import io.voucherify.client.model.validation.VoucherValidationResponse;
import io.voucherify.client.model.validation.response.PromotionValidationResponse;
import io.voucherify.client.module.ValidationsModule.ExtAsync;
import io.voucherify.client.module.ValidationsModule.ExtRxJava;
import io.voucherify.client.utils.RxUtils;
import rx.Observable;
import java.util.concurrent.Executor;
public final class ValidationsModule extends AbsModule {
public ValidationsModule(VoucherifyApi api, Executor executor) {
super(api, executor);
}
public VoucherValidationResponse validate(String code, VoucherValidation voucherValidation) {
return api.validateVoucher(code, voucherValidation);
}
public PromotionValidationResponse validate(PromotionValidation promotionValidation) {
return api.validatePromotion(promotionValidation);
}
@Override
ExtAsync createAsyncExtension() {
return new ExtAsync();
}
@Override
ExtRxJava createRxJavaExtension() {
return new ExtRxJava();
}
@Override
public ExtAsync async() {
return extAsync;
}
@Override
public ExtRxJava rx() {
return extRxJava;
}
public class ExtAsync extends AbsModule.Async {
public void validate(String code, VoucherValidation voucherValidation, VoucherifyCallback callback) {
RxUtils.subscribe(executor, rx().validate(code, voucherValidation), callback);
}
public void validate(PromotionValidation promotionValidation, VoucherifyCallback callback) {
RxUtils.subscribe(executor, rx().validate(promotionValidation), callback);
}
}
public class ExtRxJava extends AbsModule.Rx {
public Observable validate(final String code, final VoucherValidation voucherValidation) {
return RxUtils.defer(new RxUtils.DefFunc() {
@Override
public VoucherValidationResponse method() {
return ValidationsModule.this.validate(code, voucherValidation);
}
});
}
public Observable validate(final PromotionValidation promotionValidation) {
return RxUtils.defer(new RxUtils.DefFunc() {
@Override
public PromotionValidationResponse method() {
return ValidationsModule.this.validate(promotionValidation);
}
});
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy