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

com.tinypass.client.publisher.api.PublisherSubscriptionApi Maven / Gradle / Ivy

There is a newer version: 16.331.0
Show newest version
package com.tinypass.client.publisher.api;

import com.tinypass.client.common.*;
import java.util.Date;
import com.tinypass.client.publisher.model.SubscriptionLogItem;
import com.tinypass.client.publisher.model.UserSubscription;
import com.tinypass.client.publisher.model.UserSubscriptionDto;
import com.tinypass.client.publisher.model.UserSubscriptionListItem;

import java.util.*;
import java.math.*;
import java.io.*;

public class PublisherSubscriptionApi {

	private String basePath = "https://api.piano.io/api/v3";
	private String token;
	private ApiInvoker apiInvoker = null;
	private Map headerParams = new LinkedHashMap();

	public PublisherSubscriptionApi(String basePath, String token) {
		this.basePath = basePath;
		this.token = token;
	}

	public PublisherSubscriptionApi(String basePath, String token, ApiInvoker invoker, Map headerParams) {
		this(basePath, token);
		this.apiInvoker = invoker;
		this.headerParams = headerParams;
	}

	public ApiInvoker getInvoker() {
        if(apiInvoker == null) apiInvoker = ApiInvoker.getInstance();
		return apiInvoker;
	}

	public void setApiToken(String token){
		this.token = token;
	}

	public void setBasePath(String basePath) {
		this.basePath = basePath;
	}

	public String getBasePath() {
		return basePath;
	}

	public String toQueryParam(Object arg) {
        if(arg == null)
            return null;
		if (arg instanceof Date) {
			Date date = (Date) arg;
			long epochTime = date.getTime() / 1000;
			return String.valueOf(epochTime);
		} else {
			return String.valueOf(arg);
		}

	}

    public void setQueryParam(Map> params, String paramName, Object value) {
        List currentValues = params.computeIfAbsent(paramName, k -> new ArrayList<>());
        if (value instanceof List) {
            List values = (List) value;
            values.forEach(o -> addQueryParam(currentValues, o));
        } else {
            addQueryParam(currentValues, value);
        }
    }

    private void addQueryParam(List currentValues, Object value) {
        String v = toQueryParam(value);
        if (v != null)
            currentValues.add(v);
    }


    /**
      * API Request for cancelSubscription
      */
	public class cancelSubscriptionRequest implements ApiRequest {

        Map headerParams;
        Map> queryParams = new HashMap<>();
        Map> formParams = new HashMap<>();
        Object body = null;

        public cancelSubscriptionRequest(Map headerParams) {
            this.headerParams = headerParams;
        }

        public Map> getPreparedFormParams() {
            return Collections.unmodifiableMap(formParams);
        }


		public cancelSubscriptionRequest aid(String aid) {
            setQueryParam(this.formParams, "aid", aid);
			return this;
		}
		public cancelSubscriptionRequest subscriptionId(String subscriptionId) {
            setQueryParam(this.formParams, "subscription_id", subscriptionId);
			return this;
		}
		public cancelSubscriptionRequest refundLastPayment(Boolean refundLastPayment) {
            setQueryParam(this.formParams, "refund_last_payment", refundLastPayment);
			return this;
		}





		public Boolean  execute() throws ApiException{

			String path = "/publisher/subscription/cancel".replaceAll("\\{format\\}","json");

			return getInvoker().invokeAPI(basePath, path, "POST", token,
                                                     queryParams, null,
                                                     headerParams,
                                                     formParams,
                                                     "",
                                                     Boolean.class);
		}

	}


    /**
      * Helper method to create a new request.
      */
	public cancelSubscriptionRequest cancelSubscriptionRequest(){
		return new cancelSubscriptionRequest(headerParams);
	}



    /**
      * API Request for count
      */
	public class countRequest implements ApiRequest {

        Map headerParams;
        Map> queryParams = new HashMap<>();
        Map> formParams = new HashMap<>();
        Object body = null;

        public countRequest(Map headerParams) {
            this.headerParams = headerParams;
        }

        public Map> getPreparedFormParams() {
            return Collections.unmodifiableMap(formParams);
        }


		public countRequest aid(String aid) {
            setQueryParam(this.formParams, "aid", aid);
			return this;
		}





		public Integer  execute() throws ApiException{

			String path = "/publisher/subscription/count".replaceAll("\\{format\\}","json");

			return getInvoker().invokeAPI(basePath, path, "POST", token,
                                                     queryParams, null,
                                                     headerParams,
                                                     formParams,
                                                     "",
                                                     Integer.class);
		}

	}


    /**
      * Helper method to create a new request.
      */
	public countRequest countRequest(){
		return new countRequest(headerParams);
	}



    /**
      * API Request for get
      */
	public class getRequest implements ApiRequest {

        Map headerParams;
        Map> queryParams = new HashMap<>();
        Map> formParams = new HashMap<>();
        Object body = null;

        public getRequest(Map headerParams) {
            this.headerParams = headerParams;
        }

        public Map> getPreparedFormParams() {
            return Collections.unmodifiableMap(formParams);
        }

		public getRequest aid(String aid) {
            setQueryParam(this.queryParams, "aid", aid);
			return this;
		}
		public getRequest subscriptionId(String subscriptionId) {
            setQueryParam(this.queryParams, "subscription_id", subscriptionId);
			return this;
		}






		public UserSubscription  execute() throws ApiException{

			String path = "/publisher/subscription/get".replaceAll("\\{format\\}","json");

			return getInvoker().invokeAPI(basePath, path, "GET", token,
                                                     queryParams, null,
                                                     headerParams,
                                                     formParams,
                                                     "",
                                                     UserSubscription.class);
		}

	}


    /**
      * Helper method to create a new request.
      */
	public getRequest getRequest(){
		return new getRequest(headerParams);
	}



    /**
      * API Request for isPartiallyRefundable
      */
	public class isPartiallyRefundableRequest implements ApiRequest {

        Map headerParams;
        Map> queryParams = new HashMap<>();
        Map> formParams = new HashMap<>();
        Object body = null;

        public isPartiallyRefundableRequest(Map headerParams) {
            this.headerParams = headerParams;
        }

        public Map> getPreparedFormParams() {
            return Collections.unmodifiableMap(formParams);
        }


		public isPartiallyRefundableRequest aid(String aid) {
            setQueryParam(this.formParams, "aid", aid);
			return this;
		}
		public isPartiallyRefundableRequest subscriptionId(String subscriptionId) {
            setQueryParam(this.formParams, "subscription_id", subscriptionId);
			return this;
		}





		public Boolean  execute() throws ApiException{

			String path = "/publisher/subscription/isPartiallyRefundable".replaceAll("\\{format\\}","json");

			return getInvoker().invokeAPI(basePath, path, "POST", token,
                                                     queryParams, null,
                                                     headerParams,
                                                     formParams,
                                                     "",
                                                     Boolean.class);
		}

	}


    /**
      * Helper method to create a new request.
      */
	public isPartiallyRefundableRequest isPartiallyRefundableRequest(){
		return new isPartiallyRefundableRequest(headerParams);
	}



    /**
      * API Request for list
      */
	public class listRequest implements ApiRequest {

        Map headerParams;
        Map> queryParams = new HashMap<>();
        Map> formParams = new HashMap<>();
        Object body = null;

        public listRequest(Map headerParams) {
            this.headerParams = headerParams;
        }

        public Map> getPreparedFormParams() {
            return Collections.unmodifiableMap(formParams);
        }

		public listRequest aid(String aid) {
            setQueryParam(this.queryParams, "aid", aid);
			return this;
		}
		public listRequest uid(String uid) {
            setQueryParam(this.queryParams, "uid", uid);
			return this;
		}
		public listRequest type(String type) {
            setQueryParam(this.queryParams, "type", type);
			return this;
		}
		public listRequest startDate(Date startDate) {
            setQueryParam(this.queryParams, "start_date", startDate);
			return this;
		}
		public listRequest endDate(Date endDate) {
            setQueryParam(this.queryParams, "end_date", endDate);
			return this;
		}
		public listRequest q(String q) {
            setQueryParam(this.queryParams, "q", q);
			return this;
		}
		public listRequest offset(Integer offset) {
            setQueryParam(this.queryParams, "offset", offset);
			return this;
		}
		public listRequest limit(Integer limit) {
            setQueryParam(this.queryParams, "limit", limit);
			return this;
		}
		public listRequest selectBy(String selectBy) {
            setQueryParam(this.queryParams, "select_by", selectBy);
			return this;
		}
		public listRequest status(String status) {
            setQueryParam(this.queryParams, "status", status);
			return this;
		}






		public PageList  execute() throws ApiException{

			String path = "/publisher/subscription/list".replaceAll("\\{format\\}","json");

			return getInvoker().invokeAPI(basePath, path, "GET", token,
                                                     queryParams, null,
                                                     headerParams,
                                                     formParams,
                                                     "array",
                                                     UserSubscriptionListItem.class);
		}

	}


    /**
      * Helper method to create a new request.
      */
	public listRequest listRequest(){
		return new listRequest(headerParams);
	}



    /**
      * API Request for resumeSubscription
      */
	public class resumeSubscriptionRequest implements ApiRequest {

        Map headerParams;
        Map> queryParams = new HashMap<>();
        Map> formParams = new HashMap<>();
        Object body = null;

        public resumeSubscriptionRequest(Map headerParams) {
            this.headerParams = headerParams;
        }

        public Map> getPreparedFormParams() {
            return Collections.unmodifiableMap(formParams);
        }


		public resumeSubscriptionRequest aid(String aid) {
            setQueryParam(this.formParams, "aid", aid);
			return this;
		}
		public resumeSubscriptionRequest subscriptionId(String subscriptionId) {
            setQueryParam(this.formParams, "subscription_id", subscriptionId);
			return this;
		}





		public Boolean  execute() throws ApiException{

			String path = "/publisher/subscription/resume".replaceAll("\\{format\\}","json");

			return getInvoker().invokeAPI(basePath, path, "POST", token,
                                                     queryParams, null,
                                                     headerParams,
                                                     formParams,
                                                     "",
                                                     Boolean.class);
		}

	}


    /**
      * Helper method to create a new request.
      */
	public resumeSubscriptionRequest resumeSubscriptionRequest(){
		return new resumeSubscriptionRequest(headerParams);
	}



    /**
      * API Request for search
      */
	public class searchRequest implements ApiRequest {

        Map headerParams;
        Map> queryParams = new HashMap<>();
        Map> formParams = new HashMap<>();
        Object body = null;

        public searchRequest(Map headerParams) {
            this.headerParams = headerParams;
        }

        public Map> getPreparedFormParams() {
            return Collections.unmodifiableMap(formParams);
        }

		public searchRequest aid(String aid) {
            setQueryParam(this.queryParams, "aid", aid);
			return this;
		}
		public searchRequest q(String q) {
            setQueryParam(this.queryParams, "q", q);
			return this;
		}
		public searchRequest offset(Integer offset) {
            setQueryParam(this.queryParams, "offset", offset);
			return this;
		}
		public searchRequest limit(Integer limit) {
            setQueryParam(this.queryParams, "limit", limit);
			return this;
		}
		public searchRequest orderBy(String orderBy) {
            setQueryParam(this.queryParams, "order_by", orderBy);
			return this;
		}
		public searchRequest orderDirection(String orderDirection) {
            setQueryParam(this.queryParams, "order_direction", orderDirection);
			return this;
		}
		public searchRequest searchNewSubscriptions(Boolean searchNewSubscriptions) {
            setQueryParam(this.queryParams, "search_new_subscriptions", searchNewSubscriptions);
			return this;
		}
		public searchRequest newSubscriptionsCreatedFrom(Date newSubscriptionsCreatedFrom) {
            setQueryParam(this.queryParams, "new_subscriptions_created_from", newSubscriptionsCreatedFrom);
			return this;
		}
		public searchRequest newSubscriptionsCreatedTo(Date newSubscriptionsCreatedTo) {
            setQueryParam(this.queryParams, "new_subscriptions_created_to", newSubscriptionsCreatedTo);
			return this;
		}
		public searchRequest searchActiveNowSubscriptions(Boolean searchActiveNowSubscriptions) {
            setQueryParam(this.queryParams, "search_active_now_subscriptions", searchActiveNowSubscriptions);
			return this;
		}
		public searchRequest activeNowSubscriptionsStatuses(List activeNowSubscriptionsStatuses) {
            setQueryParam(this.queryParams, "active_now_subscriptions_statuses", activeNowSubscriptionsStatuses);
			return this;
		}
		public searchRequest searchInactiveSubscriptions(Boolean searchInactiveSubscriptions) {
            setQueryParam(this.queryParams, "search_inactive_subscriptions", searchInactiveSubscriptions);
			return this;
		}
		public searchRequest inactiveSubscriptionsStatuses(List inactiveSubscriptionsStatuses) {
            setQueryParam(this.queryParams, "inactive_subscriptions_statuses", inactiveSubscriptionsStatuses);
			return this;
		}
		public searchRequest subscriptionsInactiveFrom(Date subscriptionsInactiveFrom) {
            setQueryParam(this.queryParams, "subscriptions_inactive_from", subscriptionsInactiveFrom);
			return this;
		}
		public searchRequest subscriptionsInactiveTo(Date subscriptionsInactiveTo) {
            setQueryParam(this.queryParams, "subscriptions_inactive_to", subscriptionsInactiveTo);
			return this;
		}
		public searchRequest searchUpdatedSubscriptions(Boolean searchUpdatedSubscriptions) {
            setQueryParam(this.queryParams, "search_updated_subscriptions", searchUpdatedSubscriptions);
			return this;
		}
		public searchRequest updatedSubscriptionsStatuses(List updatedSubscriptionsStatuses) {
            setQueryParam(this.queryParams, "updated_subscriptions_statuses", updatedSubscriptionsStatuses);
			return this;
		}
		public searchRequest subscriptionsUpdatedFrom(Date subscriptionsUpdatedFrom) {
            setQueryParam(this.queryParams, "subscriptions_updated_from", subscriptionsUpdatedFrom);
			return this;
		}
		public searchRequest subscriptionsUpdatedTo(Date subscriptionsUpdatedTo) {
            setQueryParam(this.queryParams, "subscriptions_updated_to", subscriptionsUpdatedTo);
			return this;
		}
		public searchRequest searchAutoRenewingSubscriptions(Boolean searchAutoRenewingSubscriptions) {
            setQueryParam(this.queryParams, "search_auto_renewing_subscriptions", searchAutoRenewingSubscriptions);
			return this;
		}
		public searchRequest subscriptionsAutoRenewing(Boolean subscriptionsAutoRenewing) {
            setQueryParam(this.queryParams, "subscriptions_auto_renewing", subscriptionsAutoRenewing);
			return this;
		}
		public searchRequest searchSubscriptionsByNextBillingDate(Boolean searchSubscriptionsByNextBillingDate) {
            setQueryParam(this.queryParams, "search_subscriptions_by_next_billing_date", searchSubscriptionsByNextBillingDate);
			return this;
		}
		public searchRequest subscriptionsNextBillingDateFrom(Date subscriptionsNextBillingDateFrom) {
            setQueryParam(this.queryParams, "subscriptions_next_billing_date_from", subscriptionsNextBillingDateFrom);
			return this;
		}
		public searchRequest subscriptionsNextBillingDateTo(Date subscriptionsNextBillingDateTo) {
            setQueryParam(this.queryParams, "subscriptions_next_billing_date_to", subscriptionsNextBillingDateTo);
			return this;
		}
		public searchRequest searchSubscriptionsByTerms(Boolean searchSubscriptionsByTerms) {
            setQueryParam(this.queryParams, "search_subscriptions_by_terms", searchSubscriptionsByTerms);
			return this;
		}
		public searchRequest subscriptionsTerms(List subscriptionsTerms) {
            setQueryParam(this.queryParams, "subscriptions_terms", subscriptionsTerms);
			return this;
		}
		public searchRequest subscriptionsTermTypes(List subscriptionsTermTypes) {
            setQueryParam(this.queryParams, "subscriptions_term_types", subscriptionsTermTypes);
			return this;
		}






		public PageList  execute() throws ApiException{

			String path = "/publisher/subscription/search".replaceAll("\\{format\\}","json");

			return getInvoker().invokeAPI(basePath, path, "GET", token,
                                                     queryParams, null,
                                                     headerParams,
                                                     formParams,
                                                     "array",
                                                     SubscriptionLogItem.class);
		}

	}


    /**
      * Helper method to create a new request.
      */
	public searchRequest searchRequest(){
		return new searchRequest(headerParams);
	}



    /**
      * API Request for stats
      */
	public class statsRequest implements ApiRequest {

        Map headerParams;
        Map> queryParams = new HashMap<>();
        Map> formParams = new HashMap<>();
        Object body = null;

        public statsRequest(Map headerParams) {
            this.headerParams = headerParams;
        }

        public Map> getPreparedFormParams() {
            return Collections.unmodifiableMap(formParams);
        }


		public statsRequest aid(String aid) {
            setQueryParam(this.formParams, "aid", aid);
			return this;
		}
		public statsRequest uid(String uid) {
            setQueryParam(this.formParams, "uid", uid);
			return this;
		}
		public statsRequest offset(Integer offset) {
            setQueryParam(this.formParams, "offset", offset);
			return this;
		}
		public statsRequest limit(Integer limit) {
            setQueryParam(this.formParams, "limit", limit);
			return this;
		}





		public PageList  execute() throws ApiException{

			String path = "/publisher/subscription/stats".replaceAll("\\{format\\}","json");

			return getInvoker().invokeAPI(basePath, path, "POST", token,
                                                     queryParams, null,
                                                     headerParams,
                                                     formParams,
                                                     "array",
                                                     UserSubscriptionDto.class);
		}

	}


    /**
      * Helper method to create a new request.
      */
	public statsRequest statsRequest(){
		return new statsRequest(headerParams);
	}



    /**
      * API Request for update
      */
	public class updateRequest implements ApiRequest {

        Map headerParams;
        Map> queryParams = new HashMap<>();
        Map> formParams = new HashMap<>();
        Object body = null;

        public updateRequest(Map headerParams) {
            this.headerParams = headerParams;
        }

        public Map> getPreparedFormParams() {
            return Collections.unmodifiableMap(formParams);
        }


		public updateRequest aid(String aid) {
            setQueryParam(this.formParams, "aid", aid);
			return this;
		}
		public updateRequest subscriptionId(String subscriptionId) {
            setQueryParam(this.formParams, "subscription_id", subscriptionId);
			return this;
		}
		public updateRequest nextBillDate(Date nextBillDate) {
            setQueryParam(this.formParams, "next_bill_date", nextBillDate);
			return this;
		}
		public updateRequest autoRenew(Boolean autoRenew) {
            setQueryParam(this.formParams, "auto_renew", autoRenew);
			return this;
		}
		public updateRequest paymentMethodId(String paymentMethodId) {
            setQueryParam(this.formParams, "payment_method_id", paymentMethodId);
			return this;
		}
		public updateRequest userAddressId(String userAddressId) {
            setQueryParam(this.formParams, "user_address_id", userAddressId);
			return this;
		}
		public updateRequest scheduledAccessPeriodId(String scheduledAccessPeriodId) {
            setQueryParam(this.formParams, "scheduled_access_period_id", scheduledAccessPeriodId);
			return this;
		}





		public Boolean  execute() throws ApiException{

			String path = "/publisher/subscription/update".replaceAll("\\{format\\}","json");

			return getInvoker().invokeAPI(basePath, path, "POST", token,
                                                     queryParams, null,
                                                     headerParams,
                                                     formParams,
                                                     "",
                                                     Boolean.class);
		}

	}


    /**
      * Helper method to create a new request.
      */
	public updateRequest updateRequest(){
		return new updateRequest(headerParams);
	}




}