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

io.voucherify.client.module.DistributionsModule 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.api.VoucherifyApi;
import io.voucherify.client.callback.VoucherifyCallback;
import io.voucherify.client.model.distribution.CreateExport;
import io.voucherify.client.model.distribution.ListPublicationsFilter;
import io.voucherify.client.model.distribution.PublishVoucher;
import io.voucherify.client.model.distribution.response.ExportResponse;
import io.voucherify.client.model.distribution.response.ListPublicationsResponse;
import io.voucherify.client.model.distribution.response.PublishVoucherResponse;
import io.voucherify.client.module.DistributionsModule.ExtAsync;
import io.voucherify.client.module.DistributionsModule.ExtRxJava;
import io.voucherify.client.utils.RxUtils;
import rx.Observable;

import java.util.HashMap;
import java.util.concurrent.Executor;

public final class DistributionsModule extends AbsModule {

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

  public PublishVoucherResponse publish(PublishVoucher publishVoucher) {
    return api.publishVoucher(publishVoucher);
  }

  public ExportResponse createExport(CreateExport createExport) {
    return api.createExport(createExport);
  }

  public ExportResponse getExport(String id) {
    return api.getExport(id);
  }

  public void deleteExport(String id) {
    api.deleteExport(id);
  }

  public ListPublicationsResponse list(ListPublicationsFilter filter) {
    return api.list(filter.asMap());
  }

  public ListPublicationsResponse list() {
    return api.list(new HashMap());
  }

  @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 publish(PublishVoucher publishParams, VoucherifyCallback callback) {
      RxUtils.subscribe(executor, rx().publish(publishParams), callback);
    }

    public void createExport(CreateExport createExport, VoucherifyCallback callback) {
      RxUtils.subscribe(executor, rx().createExport(createExport), callback);
    }

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

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

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

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

  public class ExtRxJava extends AbsModule.Rx {

    public Observable publish(final PublishVoucher publishVoucher) {
      return RxUtils.defer(new RxUtils.DefFunc() {

        @Override
        public PublishVoucherResponse method() {
          return DistributionsModule.this.publish(publishVoucher);
        }
      });
    }

    public Observable createExport(final CreateExport createExport) {
      return RxUtils.defer(new RxUtils.DefFunc() {

        @Override
        public ExportResponse method() {
          return DistributionsModule.this.createExport(createExport);
        }
      });
    }

    public Observable getExport(final String id) {
      return RxUtils.defer(new RxUtils.DefFunc() {

        @Override
        public ExportResponse method() {
          return DistributionsModule.this.getExport(id);
        }
      });
    }

    public Observable deleteExport(final String id) {
      return RxUtils.defer(new RxUtils.DefFunc() {

        @Override
        public Void method() {
          DistributionsModule.this.deleteExport(id);
          return null;
        }
      });
    }

    public Observable list(final ListPublicationsFilter filter) {
      return RxUtils.defer(new RxUtils.DefFunc() {

        @Override
        public ListPublicationsResponse method() {
          return DistributionsModule.this.list(filter);
        }
      });
    }

    public Observable list() {
      return RxUtils.defer(new RxUtils.DefFunc() {

        @Override
        public ListPublicationsResponse method() {
          return DistributionsModule.this.list();
        }
      });
    }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy