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

com.tinypass.client.publisher.api.PublisherTermDynamicApi 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 com.tinypass.client.publisher.model.CreateBillingConfigurationRequest;
import com.tinypass.client.publisher.model.Term;
import com.tinypass.client.publisher.model.UpdateBillingConfigurationRequest;

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

public class PublisherTermDynamicApi {

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

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

	public PublisherTermDynamicApi(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 createDynamicTerm
      */
	public class createDynamicTermRequest implements ApiRequest {

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

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

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


		public createDynamicTermRequest aid(String aid) {
            setQueryParam(this.formParams, "aid", aid);
			return this;
		}
		public createDynamicTermRequest rid(String rid) {
            setQueryParam(this.formParams, "rid", rid);
			return this;
		}
		public createDynamicTermRequest name(String name) {
            setQueryParam(this.formParams, "name", name);
			return this;
		}
		public createDynamicTermRequest currency(String currency) {
            setQueryParam(this.formParams, "currency", currency);
			return this;
		}
		public createDynamicTermRequest description(String description) {
            setQueryParam(this.formParams, "description", description);
			return this;
		}
		public createDynamicTermRequest allowStartInFuture(Boolean allowStartInFuture) {
            setQueryParam(this.formParams, "allow_start_in_future", allowStartInFuture);
			return this;
		}
		public createDynamicTermRequest maximumDaysInAdvance(Integer maximumDaysInAdvance) {
            setQueryParam(this.formParams, "maximum_days_in_advance", maximumDaysInAdvance);
			return this;
		}



        public createDynamicTermRequest body(CreateBillingConfigurationRequest body) {
            this.body = body;
			return this;
		}
        public createDynamicTermRequest body(InputStream body) {
            this.body = body;
			return this;
		}
        public createDynamicTermRequest bodyString(String body) {
            this.body = body;
            return this;
        }


		public Term  execute() throws ApiException{

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

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

	}


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



    /**
      * API Request for updateDynamicTerm
      */
	public class updateDynamicTermRequest implements ApiRequest {

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

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

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


		public updateDynamicTermRequest aid(String aid) {
            setQueryParam(this.formParams, "aid", aid);
			return this;
		}
		public updateDynamicTermRequest termPubId(String termPubId) {
            setQueryParam(this.formParams, "term_pub_id", termPubId);
			return this;
		}
		public updateDynamicTermRequest rid(String rid) {
            setQueryParam(this.formParams, "rid", rid);
			return this;
		}
		public updateDynamicTermRequest name(String name) {
            setQueryParam(this.formParams, "name", name);
			return this;
		}
		public updateDynamicTermRequest currency(String currency) {
            setQueryParam(this.formParams, "currency", currency);
			return this;
		}
		public updateDynamicTermRequest description(String description) {
            setQueryParam(this.formParams, "description", description);
			return this;
		}
		public updateDynamicTermRequest paymentNewCustomersOnly(Boolean paymentNewCustomersOnly) {
            setQueryParam(this.formParams, "payment_new_customers_only", paymentNewCustomersOnly);
			return this;
		}
		public updateDynamicTermRequest paymentAllowPromoCodes(Boolean paymentAllowPromoCodes) {
            setQueryParam(this.formParams, "payment_allow_promo_codes", paymentAllowPromoCodes);
			return this;
		}
		public updateDynamicTermRequest showFullBillingPlan(Boolean showFullBillingPlan) {
            setQueryParam(this.formParams, "show_full_billing_plan", showFullBillingPlan);
			return this;
		}
		public updateDynamicTermRequest allowStartInFuture(Boolean allowStartInFuture) {
            setQueryParam(this.formParams, "allow_start_in_future", allowStartInFuture);
			return this;
		}
		public updateDynamicTermRequest maximumDaysInAdvance(Integer maximumDaysInAdvance) {
            setQueryParam(this.formParams, "maximum_days_in_advance", maximumDaysInAdvance);
			return this;
		}
		public updateDynamicTermRequest collectAddress(Boolean collectAddress) {
            setQueryParam(this.formParams, "collect_address", collectAddress);
			return this;
		}
		public updateDynamicTermRequest deliveryZone(List deliveryZone) {
            setQueryParam(this.formParams, "delivery_zone", deliveryZone);
			return this;
		}
		public updateDynamicTermRequest defaultCountry(String defaultCountry) {
            setQueryParam(this.formParams, "default_country", defaultCountry);
			return this;
		}



        public updateDynamicTermRequest body(UpdateBillingConfigurationRequest body) {
            this.body = body;
			return this;
		}
        public updateDynamicTermRequest body(InputStream body) {
            this.body = body;
			return this;
		}
        public updateDynamicTermRequest bodyString(String body) {
            this.body = body;
            return this;
        }


		public Term  execute() throws ApiException{

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

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

	}


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




}