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

com.tinypass.client.publisher.api.PublisherTermGiftApi 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.math.BigDecimal;
import com.tinypass.client.publisher.model.Term;

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

public class PublisherTermGiftApi {

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

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

	public PublisherTermGiftApi(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 createGiftTerm
      */
	public class createGiftTermRequest implements ApiRequest {

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

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

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


		public createGiftTermRequest aid(String aid) {
            setQueryParam(this.formParams, "aid", aid);
			return this;
		}
		public createGiftTermRequest name(String name) {
            setQueryParam(this.formParams, "name", name);
			return this;
		}
		public createGiftTermRequest description(String description) {
            setQueryParam(this.formParams, "description", description);
			return this;
		}
		public createGiftTermRequest productCategory(String productCategory) {
            setQueryParam(this.formParams, "product_category", productCategory);
			return this;
		}
		public createGiftTermRequest rid(String rid) {
            setQueryParam(this.formParams, "rid", rid);
			return this;
		}
		public createGiftTermRequest billingPlanPeriod(String billingPlanPeriod) {
            setQueryParam(this.formParams, "billing_plan_period", billingPlanPeriod);
			return this;
		}
		public createGiftTermRequest billingPlanPrice(BigDecimal billingPlanPrice) {
            setQueryParam(this.formParams, "billing_plan_price", billingPlanPrice);
			return this;
		}
		public createGiftTermRequest billingPlanCurrency(String billingPlanCurrency) {
            setQueryParam(this.formParams, "billing_plan_currency", billingPlanCurrency);
			return this;
		}
		public createGiftTermRequest paymentAllowPromoCodes(Boolean paymentAllowPromoCodes) {
            setQueryParam(this.formParams, "payment_allow_promo_codes", paymentAllowPromoCodes);
			return this;
		}
		public createGiftTermRequest voucheringPolicyRedemptionUrl(String voucheringPolicyRedemptionUrl) {
            setQueryParam(this.formParams, "vouchering_policy_redemption_url", voucheringPolicyRedemptionUrl);
			return this;
		}
		public createGiftTermRequest scheduleId(String scheduleId) {
            setQueryParam(this.formParams, "schedule_id", scheduleId);
			return this;
		}
		public createGiftTermRequest scheduleBillingModel(String scheduleBillingModel) {
            setQueryParam(this.formParams, "schedule_billing_model", scheduleBillingModel);
			return this;
		}
		public createGiftTermRequest termType(String termType) {
            setQueryParam(this.formParams, "term_type", termType);
			return this;
		}
		public createGiftTermRequest sharedAccountCount(Integer sharedAccountCount) {
            setQueryParam(this.formParams, "shared_account_count", sharedAccountCount);
			return this;
		}
		public createGiftTermRequest sharedRedemptionUrl(String sharedRedemptionUrl) {
            setQueryParam(this.formParams, "shared_redemption_url", sharedRedemptionUrl);
			return this;
		}
		public createGiftTermRequest collectShippingAddress(Boolean collectShippingAddress) {
            setQueryParam(this.formParams, "collect_shipping_address", collectShippingAddress);
			return this;
		}
		public createGiftTermRequest collectAddress(Boolean collectAddress) {
            setQueryParam(this.formParams, "collect_address", collectAddress);
			return this;
		}
		public createGiftTermRequest deliveryZone(List deliveryZone) {
            setQueryParam(this.formParams, "delivery_zone", deliveryZone);
			return this;
		}
		public createGiftTermRequest defaultCountry(String defaultCountry) {
            setQueryParam(this.formParams, "default_country", defaultCountry);
			return this;
		}





		public Term  execute() throws ApiException{

			String path = "/publisher/term/gift/create".replaceAll("\\{format\\}","json");

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

	}


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



    /**
      * API Request for updateGiftTerm
      */
	public class updateGiftTermRequest implements ApiRequest {

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

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

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


		public updateGiftTermRequest aid(String aid) {
            setQueryParam(this.formParams, "aid", aid);
			return this;
		}
		public updateGiftTermRequest termId(String termId) {
            setQueryParam(this.formParams, "term_id", termId);
			return this;
		}
		public updateGiftTermRequest name(String name) {
            setQueryParam(this.formParams, "name", name);
			return this;
		}
		public updateGiftTermRequest description(String description) {
            setQueryParam(this.formParams, "description", description);
			return this;
		}
		public updateGiftTermRequest productCategory(String productCategory) {
            setQueryParam(this.formParams, "product_category", productCategory);
			return this;
		}
		public updateGiftTermRequest rid(String rid) {
            setQueryParam(this.formParams, "rid", rid);
			return this;
		}
		public updateGiftTermRequest billingPlanPeriod(String billingPlanPeriod) {
            setQueryParam(this.formParams, "billing_plan_period", billingPlanPeriod);
			return this;
		}
		public updateGiftTermRequest billingPlanPrice(BigDecimal billingPlanPrice) {
            setQueryParam(this.formParams, "billing_plan_price", billingPlanPrice);
			return this;
		}
		public updateGiftTermRequest billingPlanCurrency(String billingPlanCurrency) {
            setQueryParam(this.formParams, "billing_plan_currency", billingPlanCurrency);
			return this;
		}
		public updateGiftTermRequest paymentAllowPromoCodes(Boolean paymentAllowPromoCodes) {
            setQueryParam(this.formParams, "payment_allow_promo_codes", paymentAllowPromoCodes);
			return this;
		}
		public updateGiftTermRequest voucheringPolicyRedemptionUrl(String voucheringPolicyRedemptionUrl) {
            setQueryParam(this.formParams, "vouchering_policy_redemption_url", voucheringPolicyRedemptionUrl);
			return this;
		}
		public updateGiftTermRequest scheduleId(String scheduleId) {
            setQueryParam(this.formParams, "schedule_id", scheduleId);
			return this;
		}
		public updateGiftTermRequest scheduleBillingModel(String scheduleBillingModel) {
            setQueryParam(this.formParams, "schedule_billing_model", scheduleBillingModel);
			return this;
		}
		public updateGiftTermRequest termType(String termType) {
            setQueryParam(this.formParams, "term_type", termType);
			return this;
		}
		public updateGiftTermRequest sharedAccountCount(Integer sharedAccountCount) {
            setQueryParam(this.formParams, "shared_account_count", sharedAccountCount);
			return this;
		}
		public updateGiftTermRequest sharedRedemptionUrl(String sharedRedemptionUrl) {
            setQueryParam(this.formParams, "shared_redemption_url", sharedRedemptionUrl);
			return this;
		}
		public updateGiftTermRequest collectShippingAddress(Boolean collectShippingAddress) {
            setQueryParam(this.formParams, "collect_shipping_address", collectShippingAddress);
			return this;
		}
		public updateGiftTermRequest collectAddress(Boolean collectAddress) {
            setQueryParam(this.formParams, "collect_address", collectAddress);
			return this;
		}
		public updateGiftTermRequest deliveryZone(List deliveryZone) {
            setQueryParam(this.formParams, "delivery_zone", deliveryZone);
			return this;
		}
		public updateGiftTermRequest defaultCountry(String defaultCountry) {
            setQueryParam(this.formParams, "default_country", defaultCountry);
			return this;
		}





		public Term  execute() throws ApiException{

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

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

	}


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




}