io.voucherify.client.module.CampaignsModule Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of voucherify-java-sdk Show documentation
Show all versions of voucherify-java-sdk Show documentation
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)
package io.voucherify.client.module;
import io.voucherify.client.api.VoucherifyApi;
import io.voucherify.client.callback.VoucherifyCallback;
import io.voucherify.client.model.campaign.AddVoucherToCampaign;
import io.voucherify.client.model.campaign.CampaignImportVouchers;
import io.voucherify.client.model.campaign.CampaignsFilter;
import io.voucherify.client.model.campaign.CreateCampaign;
import io.voucherify.client.model.campaign.DeleteCampaignParams;
import io.voucherify.client.model.campaign.UpdateCampaign;
import io.voucherify.client.model.campaign.response.AddVoucherToCampaignResponse;
import io.voucherify.client.model.campaign.response.CampaignResponse;
import io.voucherify.client.model.campaign.response.CampaignsResponse;
import io.voucherify.client.module.CampaignsModule.ExtAsync;
import io.voucherify.client.module.CampaignsModule.ExtRxJava;
import io.voucherify.client.utils.RxUtils;
import rx.Observable;
import java.util.concurrent.Executor;
public final class CampaignsModule extends AbsModule {
public CampaignsModule(VoucherifyApi api, Executor executor) {
super(api, executor);
}
public CampaignResponse create(CreateCampaign createCampaign) {
return api.createCampaign(createCampaign);
}
public CampaignResponse get(String name) {
return api.getCampaign(name);
}
public CampaignResponse update(String name, UpdateCampaign updateCampaign) {
return api.updateCampaign(name, updateCampaign);
}
public void delete(String campaignName, DeleteCampaignParams deleteCampaignParams) {
api.deleteCampaign(campaignName, deleteCampaignParams.getForce());
}
public AddVoucherToCampaignResponse addVoucher(String campaignName, AddVoucherToCampaign addVoucherToCampaign) {
return api.addVoucherToCampaign(campaignName, addVoucherToCampaign);
}
public AddVoucherToCampaignResponse addVoucherWithCode(String campaignName, String code, AddVoucherToCampaign addVoucherToCampaign) {
return api.addVoucherToCampaignWithCode(campaignName, code, addVoucherToCampaign);
}
public void importVouchers(String campaignName, CampaignImportVouchers importVouchers) {
api.importVouchersToCampaign(campaignName, importVouchers);
}
public CampaignsResponse list(CampaignsFilter campaignsFilter) {
return api.listCampaigns(campaignsFilter.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(CreateCampaign createCampaign, VoucherifyCallback callback) {
RxUtils.subscribe(executor, rx().create(createCampaign), callback);
}
public void addVoucher(String campaignName, AddVoucherToCampaign addVoucherToCampaign, VoucherifyCallback callback) {
RxUtils.subscribe(executor, rx().addVoucher(campaignName, addVoucherToCampaign), callback);
}
public void addVoucherWithCode(String campaignName, String code, AddVoucherToCampaign addVoucherToCampaign, VoucherifyCallback callback) {
RxUtils.subscribe(executor, rx().addVoucherWithCode(campaignName, code, addVoucherToCampaign), callback);
}
public void delete(String campaignName, DeleteCampaignParams deleteCampaignParams, VoucherifyCallback callback) {
RxUtils.subscribe(executor, rx().delete(campaignName, deleteCampaignParams), callback);
}
public void importVouchers(String campaignName, CampaignImportVouchers importVouchers, VoucherifyCallback callback) {
RxUtils.subscribe(executor, rx().importVouchers(campaignName, importVouchers), callback);
}
public void list(CampaignsFilter campaignsFilter, VoucherifyCallback callback) {
RxUtils.subscribe(executor, rx().list(campaignsFilter), callback);
}
public void get(String name, VoucherifyCallback callback) {
RxUtils.subscribe(executor, rx().get(name), callback);
}
public void update(String name, UpdateCampaign updateCampaign, VoucherifyCallback callback) {
RxUtils.subscribe(executor, rx().update(name, updateCampaign), callback);
}
}
public class ExtRxJava extends AbsModule.Rx {
public Observable create(final CreateCampaign createCampaign) {
return RxUtils.defer(new RxUtils.DefFunc() {
@Override
public CampaignResponse method() {
return CampaignsModule.this.create(createCampaign);
}
});
}
public Observable addVoucher(final String campaignName, final AddVoucherToCampaign addVoucherToCampaign) {
return RxUtils.defer(new RxUtils.DefFunc() {
@Override
public AddVoucherToCampaignResponse method() {
return CampaignsModule.this.addVoucher(campaignName, addVoucherToCampaign);
}
});
}
public Observable addVoucherWithCode(final String campaignName, final String code, final AddVoucherToCampaign addVoucherToCampaign) {
return RxUtils.defer(new RxUtils.DefFunc() {
@Override
public AddVoucherToCampaignResponse method() {
return CampaignsModule.this.addVoucherWithCode(campaignName, code, addVoucherToCampaign);
}
});
}
public Observable delete(final String campaignName, final DeleteCampaignParams deleteCampaignParams) {
return RxUtils.defer(new RxUtils.DefFunc() {
@Override
public Void method() {
CampaignsModule.this.delete(campaignName, deleteCampaignParams);
return null;
}
});
}
public Observable importVouchers(final String campaignName, final CampaignImportVouchers importVouchers) {
return RxUtils.defer(new RxUtils.DefFunc() {
@Override
public Void method() {
CampaignsModule.this.importVouchers(campaignName, importVouchers);
return null;
}
});
}
public Observable list(final CampaignsFilter campaignsFilter) {
return RxUtils.defer(new RxUtils.DefFunc() {
@Override
public CampaignsResponse method() {
return CampaignsModule.this.list(campaignsFilter);
}
});
}
public Observable get(final String name) {
return RxUtils.defer(new RxUtils.DefFunc() {
@Override
public CampaignResponse method() {
return CampaignsModule.this.get(name);
}
});
}
public Observable update(final String name, final UpdateCampaign updateCampaign) {
return RxUtils.defer(new RxUtils.DefFunc() {
@Override
public CampaignResponse method() {
return CampaignsModule.this.update(name, updateCampaign);
}
});
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy