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

io.voucherify.client.module.CustomersModule 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.customer.Customer;
import io.voucherify.client.model.customer.CustomersFilter;
import io.voucherify.client.model.customer.response.CustomerResponse;
import io.voucherify.client.model.customer.response.CustomersResponse;
import io.voucherify.client.module.CustomersModule.ExtAsync;
import io.voucherify.client.module.CustomersModule.ExtRxJava;
import io.voucherify.client.utils.RxUtils;
import rx.Observable;

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

public final class CustomersModule extends AbsModule {

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

  public CustomerResponse get(String customerId) {
    return api.getCustomerById(customerId);
  }

  public CustomerResponse create(Customer customer) {
    return api.createCustomer(customer);
  }

  public CustomerResponse update(Customer customer) {
    return api.updateCustomer(customer.getId(), customer);
  }

  public void delete(String customerId) {
    api.deleteCustomer(customerId);
  }

  public CustomersResponse list(CustomersFilter filter) {
    return api.listCustomers(filter.asMap());
  }

  public CustomersResponse list() {
    return api.listCustomers(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 get(String customerId, VoucherifyCallback callback) {
      RxUtils.subscribe(executor, rx().get(customerId), callback);
    }

    public void create(Customer customer, VoucherifyCallback callback) {
      RxUtils.subscribe(executor, rx().create(customer), callback);
    }

    public void update(Customer customer, VoucherifyCallback callback) {
      RxUtils.subscribe(executor, rx().update(customer), callback);
    }

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

    public void list(CustomersFilter 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 get(final String customerId) {
      return RxUtils.defer(new RxUtils.DefFunc() {

        @Override
        public CustomerResponse method() {
          return CustomersModule.this.get(customerId);
        }
      });
    }

    public Observable create(final Customer customer) {
      return RxUtils.defer(new RxUtils.DefFunc() {

        @Override
        public CustomerResponse method() {
          return CustomersModule.this.create(customer);
        }
      });
    }

    public Observable update(final Customer customer) {
      return RxUtils.defer(new RxUtils.DefFunc() {

        @Override
        public CustomerResponse method() {
          return CustomersModule.this.update(customer);
        }
      });
    }

    public Observable delete(final String customerId) {
      return RxUtils.defer(new RxUtils.DefFunc() {

        @Override
        public Void method() {
          CustomersModule.this.delete(customerId);
          return null;
        }
      });
    }

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

        @Override
        public CustomersResponse method() {
          return CustomersModule.this.list(filter);
        }
      });
    }

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

        @Override
        public CustomersResponse method() {
          return CustomersModule.this.list();
        }
      });
    }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy