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

io.voucherify.client.module.ProductsModule 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.product.ProductsFilter;
import io.voucherify.client.model.product.SKU;
import io.voucherify.client.model.product.response.ProductsResponse;
import io.voucherify.client.api.VoucherifyApi;
import io.voucherify.client.callback.VoucherifyCallback;
import io.voucherify.client.model.product.DeleteProductParams;
import io.voucherify.client.model.product.DeleteSKUParams;
import io.voucherify.client.model.product.Product;
import io.voucherify.client.model.product.response.ProductResponse;
import io.voucherify.client.model.product.response.SKUResponse;
import io.voucherify.client.model.product.response.SKUsResponse;
import io.voucherify.client.module.ProductsModule.ExtAsync;
import io.voucherify.client.module.ProductsModule.ExtRxJava;
import io.voucherify.client.utils.RxUtils;
import rx.Observable;

import java.util.concurrent.Executor;

public class ProductsModule extends AbsModule {

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

  public ProductResponse create(Product product) {
    return api.createProduct(product);
  }

  public ProductResponse get(String id) {
    return api.getProduct(id);
  }

  public ProductResponse update(Product product) {
    return api.updateProduct(product.getId(), product);
  }

  public ProductsResponse list(ProductsFilter filter) {
    return api.getProducts(filter.asMap());
  }

  public void delete(String id, DeleteProductParams params) {
    api.deleteProduct(id, params.asMap());
  }

  public SKUResponse createSKU(String productId, SKU sku) {
    return api.createSKU(productId, sku);
  }

  public SKUResponse getSKU(String productId, String skuId) {
    return api.getSKU(productId, skuId);
  }

  public SKUResponse updateSKU(String productId, SKU sku) {
    return api.updateSKU(productId, sku.getId(), sku);
  }

  public SKUsResponse listSKU(String productId) {
    return api.getSKUs(productId);
  }

  public void deleteSKU(String productId, String skuId, DeleteSKUParams params) {
    api.deleteSKU(productId, skuId, params.asMap());
  }

  @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 create(Product product, VoucherifyCallback callback) {
      RxUtils.subscribe(executor, rx().create(product), callback);
    }

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

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

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

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

    public void createSKU(String productId, SKU sku, VoucherifyCallback callback) {
      RxUtils.subscribe(executor, rx().createSKU(productId, sku), callback);
    }

    public void getSKU(String productId, String skuId, VoucherifyCallback callback) {
      RxUtils.subscribe(executor, rx().getSKU(productId, skuId), callback);
    }

    public void updateSKU(String productId, SKU sku, VoucherifyCallback callback) {
      RxUtils.subscribe(executor, rx().updateSKU(productId, sku), callback);
    }

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

    public void deleteSKU(String productId, String skuId, DeleteSKUParams params, VoucherifyCallback callback) {
      RxUtils.subscribe(executor, rx().deleteSKU(productId, skuId, params), callback);
    }
  }

  public class ExtRxJava extends AbsModule.Rx {

    public Observable create(final Product product) {
      return RxUtils.defer(new RxUtils.DefFunc() {

        @Override
        public ProductResponse method() {
          return ProductsModule.this.create(product);
        }
      });
    }

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

        @Override
        public ProductResponse method() {
          return ProductsModule.this.get(id);
        }
      });
    }

    public Observable update(final Product product) {
      return RxUtils.defer(new RxUtils.DefFunc() {

        @Override
        public ProductResponse method() {
          return ProductsModule.this.update(product);
        }
      });
    }

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

        @Override
        public ProductsResponse method() {
          return ProductsModule.this.list(filter);
        }
      });
    }

    public Observable delete(final String id, final DeleteProductParams params) {
      return RxUtils.defer(new RxUtils.DefFunc() {

        @Override
        public Void method() {
          ProductsModule.this.delete(id, params);
          return null;
        }
      });
    }

    public Observable createSKU(final String productId, final SKU sku) {
      return RxUtils.defer(new RxUtils.DefFunc() {

        @Override
        public SKUResponse method() {
          return ProductsModule.this.createSKU(productId, sku);
        }
      });
    }

    public Observable getSKU(final String productId, final String skuId) {
      return RxUtils.defer(new RxUtils.DefFunc() {

        @Override
        public SKUResponse method() {
          return ProductsModule.this.getSKU(productId, skuId);
        }
      });
    }

    public Observable updateSKU(final String productId, final SKU sku) {
      return RxUtils.defer(new RxUtils.DefFunc() {

        @Override
        public SKUResponse method() {
          return ProductsModule.this.updateSKU(productId, sku);
        }
      });
    }

    public Observable listSKU(final String productId) {
      return RxUtils.defer(new RxUtils.DefFunc() {

        @Override
        public SKUsResponse method() {
          return ProductsModule.this.listSKU(productId);
        }
      });
    }

    public Observable deleteSKU(final String productId, final String skuId, final DeleteSKUParams params) {
      return RxUtils.defer(new RxUtils.DefFunc() {

        @Override
        public Void method() {
          ProductsModule.this.deleteSKU(productId, skuId, params);
          return null;
        }
      });
    }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy