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

io.voucherify.client.module.RewardsModule Maven / Gradle / Ivy

package io.voucherify.client.module;

import io.voucherify.client.api.VoucherifyApi;
import io.voucherify.client.callback.VoucherifyCallback;
import io.voucherify.client.model.rewards.CreateReward;
import io.voucherify.client.model.rewards.CreateRewardAssignment;
import io.voucherify.client.model.rewards.RewardsAssignmentsFilter;
import io.voucherify.client.model.rewards.RewardsFilter;
import io.voucherify.client.model.rewards.UpdateReward;
import io.voucherify.client.model.rewards.UpdateRewardAssignment;
import io.voucherify.client.model.rewards.response.ListRewardAssignmentsResponse;
import io.voucherify.client.model.rewards.response.ListRewardsResponse;
import io.voucherify.client.model.rewards.response.RewardAssignmentResponse;
import io.voucherify.client.model.rewards.response.RewardResponse;
import io.voucherify.client.module.RewardsModule.ExtAsync;
import io.voucherify.client.module.RewardsModule.ExtRxJava;
import io.voucherify.client.utils.RxUtils;
import rx.Observable;

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

public class RewardsModule extends AbsModule {

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

    public ListRewardsResponse list(RewardsFilter filter) {
        return api.listRewards(filter != null ? filter.asMap() : new HashMap());
    }

    public RewardResponse create(CreateReward createReward) {
        return api.createReward(createReward);
    }

    public RewardResponse get(String id) {
        return api.getReward(id);
    }

    public RewardResponse update(String id, UpdateReward updateReward) {
        return api.updateReward(id, updateReward);
    }

    public void delete(String id) {
        api.deleteReward(id);
    }

    public ListRewardAssignmentsResponse listAssignments(String id, RewardsAssignmentsFilter filter) {
        return api.listRewardAssignments(id, filter != null ? filter.asMap() : new HashMap());
    }

    public RewardAssignmentResponse createAssignment(String rewardId, CreateRewardAssignment createRewardAssignment) {
        return api.createRewardAssignment(rewardId, createRewardAssignment);
    }

    public RewardAssignmentResponse updateAssignment(String rewardId, String assignmentId, UpdateRewardAssignment updateRewardAssignment) {
        return api.updateRewardAssignment(rewardId, assignmentId, updateRewardAssignment);
    }

    public void deleteAssignment(String rewardId, String assignmentId) {
        api.deleteRewardAssignment(rewardId, assignmentId);
    }

    @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 list(RewardsFilter filter, VoucherifyCallback callback) {
            RxUtils.subscribe(executor, rx().list(filter), callback);
        }

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

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

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

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

        public void listAssignments(String rewardId, RewardsAssignmentsFilter filter, VoucherifyCallback callback) {
            RxUtils.subscribe(executor, rx().listAssignments(rewardId, filter), callback);
        }

        public void createAssignment(String rewardId, CreateRewardAssignment createRewardAssignment, VoucherifyCallback callback) {
            RxUtils.subscribe(executor, rx().createAssignment(rewardId, createRewardAssignment), callback);
        }

        public void updateAssignment(String rewardId, String assignmentId, UpdateRewardAssignment updateRewardAssignment, VoucherifyCallback callback) {
            RxUtils.subscribe(executor, rx().updateAssignment(rewardId, assignmentId, updateRewardAssignment), callback);
        }

        public void deleteAssignment(String rewardId, String assignmentId, VoucherifyCallback callback) {
            RxUtils.subscribe(executor, rx().deleteAssignment(rewardId, assignmentId), callback);
        }

    }

    public class ExtRxJava extends AbsModule.Rx {

        public Observable list(final RewardsFilter filter) {
            return RxUtils.defer(new RxUtils.DefFunc() {
                @Override
                public ListRewardsResponse method() {
                    return RewardsModule.this.list(filter);
                }
            });
        }

        public Observable create(final CreateReward createReward) {
            return RxUtils.defer(new RxUtils.DefFunc() {
                @Override
                public RewardResponse method() {
                    return RewardsModule.this.create(createReward);
                }
            });
        }

        public Observable update(final String id, final UpdateReward updateReward) {
            return RxUtils.defer(new RxUtils.DefFunc() {
                @Override
                public RewardResponse method() {
                    return RewardsModule.this.update(id, updateReward);
                }
            });
        }

        public Observable get(final String id) {
            return RxUtils.defer(new RxUtils.DefFunc() {
                @Override
                public RewardResponse method() {
                    return RewardsModule.this.get(id);
                }
            });
        }

        public Observable delete(final String id) {
            return RxUtils.defer(new RxUtils.DefFunc() {
                @Override
                public Void method() {
                    RewardsModule.this.delete(id);
                    return null;
                }
            });
        }

        public Observable listAssignments(final String rewardId, final RewardsAssignmentsFilter filter) {
            return RxUtils.defer(new RxUtils.DefFunc() {
                @Override
                public ListRewardAssignmentsResponse method() {
                    return RewardsModule.this.listAssignments(rewardId, filter);
                }
            });
        }

        public Observable createAssignment(final String rewardId, final CreateRewardAssignment createRewardAssignment) {
            return RxUtils.defer(new RxUtils.DefFunc() {
                @Override
                public RewardAssignmentResponse method() {
                    return RewardsModule.this.createAssignment(rewardId, createRewardAssignment);
                }
            });
        }

        public Observable updateAssignment(final String rewardId, final String assignmentId, final UpdateRewardAssignment updateRewardAssignment) {
            return RxUtils.defer(new RxUtils.DefFunc() {
                @Override
                public RewardAssignmentResponse method() {
                    return RewardsModule.this.updateAssignment(rewardId, assignmentId, updateRewardAssignment);
                }
            });
        }

        public Observable deleteAssignment(final String rewardId, final String assignmentId) {
            return RxUtils.defer(new RxUtils.DefFunc() {
                @Override
                public Void method() {
                    RewardsModule.this.deleteAssignment(rewardId, assignmentId);
                    return null;
                }
            });
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy