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

io.voucherify.client.module.RedemptionsModule Maven / Gradle / Ivy

Go to download

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)

There is a newer version: 16.0.2
Show newest version
package io.voucherify.client.module;

import io.voucherify.client.model.redemption.RedeemPromotion;
import io.voucherify.client.model.redemption.RollbackRedemption;
import io.voucherify.client.model.redemption.response.RedeemPromotionResponse;
import io.voucherify.client.model.redemption.response.RedemptionEntryResponse;
import io.voucherify.client.model.redemption.response.RedemptionsResponse;
import io.voucherify.client.model.redemption.response.RollbackRedemptionResponse;
import io.voucherify.client.model.redemption.response.VoucherRedemptionsResponse;
import io.voucherify.client.api.VoucherifyApi;
import io.voucherify.client.callback.VoucherifyCallback;
import io.voucherify.client.model.redemption.RedeemVoucher;
import io.voucherify.client.model.redemption.RedemptionsFilter;
import io.voucherify.client.model.redemption.response.RedeemVoucherResponse;
import io.voucherify.client.module.RedemptionsModule.ExtAsync;
import io.voucherify.client.module.RedemptionsModule.ExtRxJava;
import io.voucherify.client.utils.RxUtils;
import rx.Observable;

import java.util.concurrent.Executor;

public final class RedemptionsModule extends AbsModule {

  public RedemptionsModule(VoucherifyApi api, Executor executor) {
    super(api, executor);
  }

  public RedeemVoucherResponse redeem(String code, RedeemVoucher redeemVoucher) {
    return api.redeem(code, redeemVoucher);
  }

  public RedeemPromotionResponse redeem(String id, RedeemPromotion redeemPromotion) {
    return api.redeem(id, redeemPromotion);
  }

  public RedemptionEntryResponse get(String redemptionId) {
    return api.getRedemption(redemptionId);
  }

  public RedemptionsResponse list(RedemptionsFilter redemptionsFilter) {
    return api.listRedemptions(redemptionsFilter.asMap());
  }

  public VoucherRedemptionsResponse getForVoucher(String code) {
    return api.getVoucherRedemptions(code);
  }

  public RollbackRedemptionResponse rollback(String redemptionId, String reason, RollbackRedemption rollbackRedemption) {
    return api.rollbackRedemption(redemptionId, reason, rollbackRedemption);
  }

  @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 redeem(String code, RedeemVoucher redeemVoucher, VoucherifyCallback callback) {
      RxUtils.subscribe(executor, rx().redeem(code, redeemVoucher), callback);
    }

    public void redeem(String id, RedeemPromotion redeemPromotion, VoucherifyCallback callback) {
      RxUtils.subscribe(executor, rx().redeem(id, redeemPromotion), callback);
    }

    public void list(RedemptionsFilter redemptionsFilter, VoucherifyCallback callback) {
      RxUtils.subscribe(executor, rx().list(redemptionsFilter), callback);
    }

    public void get(String redemptionId, VoucherifyCallback callback) {
      RxUtils.subscribe(executor, rx().get(redemptionId), callback);
    }

    public void getForVoucher(String code, VoucherifyCallback callback) {
      RxUtils.subscribe(executor, rx().getForVoucher(code), callback);
    }

    public void rollback(String redemptionId, String reason, RollbackRedemption rollbackRedemption, VoucherifyCallback callback) {
      RxUtils.subscribe(executor, rx().rollback(redemptionId, reason, rollbackRedemption), callback);
    }
  }

  public class ExtRxJava extends AbsModule.Rx {

    public Observable redeem(final String code, final RedeemVoucher redeemVoucher) {
      return RxUtils.defer(new RxUtils.DefFunc() {
        @Override
        public RedeemVoucherResponse method() {
          return RedemptionsModule.this.redeem(code, redeemVoucher);
        }
      });
    }

    public Observable redeem(final String id, final RedeemPromotion redeemPromotion) {
      return RxUtils.defer(new RxUtils.DefFunc() {
        @Override
        public RedeemPromotionResponse method() {
          return RedemptionsModule.this.redeem(id, redeemPromotion);
        }
      });
    }

    public Observable get(final String redemptionId) {
      return RxUtils.defer(new RxUtils.DefFunc() {
        @Override
        public RedemptionEntryResponse method() {
          return RedemptionsModule.this.get(redemptionId);
        }
      });
    }

    public Observable list(final RedemptionsFilter redemptionsFilter) {
      return RxUtils.defer(new RxUtils.DefFunc() {
        @Override
        public RedemptionsResponse method() {
          return RedemptionsModule.this.list(redemptionsFilter);
        }
      });
    }

    public Observable getForVoucher(final String code) {
      return RxUtils.defer(new RxUtils.DefFunc() {
        @Override
        public VoucherRedemptionsResponse method() {
          return RedemptionsModule.this.getForVoucher(code);
        }
      });
    }

    public Observable rollback(final String redemptionId, final String reason, final RollbackRedemption rollbackRedemption) {
      return RxUtils.defer(new RxUtils.DefFunc() {
        @Override
        public RollbackRedemptionResponse method() {
          return RedemptionsModule.this.rollback(redemptionId, reason, rollbackRedemption);
        }
      });
    }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy