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

io.voucherify.client.module.OrdersModule 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.order.CreateOrder;
import io.voucherify.client.model.order.OrdersFilter;
import io.voucherify.client.model.order.UpdateOrder;
import io.voucherify.client.model.order.response.CreateOrderResponse;
import io.voucherify.client.model.order.response.GetOrderResponse;
import io.voucherify.client.model.order.response.ListOrdersResponse;
import io.voucherify.client.module.OrdersModule.ExtAsync;
import io.voucherify.client.module.OrdersModule.ExtRxJava;
import io.voucherify.client.utils.RxUtils;
import rx.Observable;

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

public class OrdersModule extends AbsModule {

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

  public CreateOrderResponse create(CreateOrder createOrder) {
    return api.createOrder(createOrder);
  }

  public GetOrderResponse get(String id) {
    return api.getOrder(id);
  }

  public GetOrderResponse update(String id, UpdateOrder updateOrder) {
    return api.updateOrder(id, updateOrder);
  }

  public ListOrdersResponse list(OrdersFilter ordersFilter) {
    return api.listOrders(ordersFilter.asMap());
  }

  public ListOrdersResponse list() {
    return api.listOrders(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 create(CreateOrder createOrder, VoucherifyCallback callback) {
      RxUtils.subscribe(executor, rx().create(createOrder), callback);
    }

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

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

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

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

  public class ExtRxJava extends AbsModule.Rx {

    public Observable create(final CreateOrder createOrder) {
      return RxUtils.defer(new RxUtils.DefFunc() {

        @Override
        public CreateOrderResponse method() {
          return OrdersModule.this.create(createOrder);
        }
      });
    }

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

        @Override
        public GetOrderResponse method() {
          return OrdersModule.this.get(id);
        }
      });
    }

    public Observable update(final String id, final UpdateOrder updateOrder) {
      return RxUtils.defer(new RxUtils.DefFunc() {

        @Override
        public GetOrderResponse method() {
          return OrdersModule.this.update(id, updateOrder);
        }
      });
    }

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

        @Override
        public ListOrdersResponse method() {
          return OrdersModule.this.list(ordersFilter);
        }
      });
    }

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

        @Override
        public ListOrdersResponse method() {
          return OrdersModule.this.list();
        }
      });
    }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy