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

com.tinypass.client.publisher.api.PublisherTermExternalApi 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.Term;

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

public class PublisherTermExternalApi {

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

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

	public PublisherTermExternalApi(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 createExternalVerificationTerm
      */
	public class createExternalVerificationTermRequest implements ApiRequest {

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

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

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


		public createExternalVerificationTermRequest aid(String aid) {
            setQueryParam(this.formParams, "aid", aid);
			return this;
		}
		public createExternalVerificationTermRequest rid(String rid) {
            setQueryParam(this.formParams, "rid", rid);
			return this;
		}
		public createExternalVerificationTermRequest externalApiId(String externalApiId) {
            setQueryParam(this.formParams, "external_api_id", externalApiId);
			return this;
		}
		public createExternalVerificationTermRequest name(String name) {
            setQueryParam(this.formParams, "name", name);
			return this;
		}
		public createExternalVerificationTermRequest description(String description) {
            setQueryParam(this.formParams, "description", description);
			return this;
		}
		public createExternalVerificationTermRequest evtFixedTimeAccessPeriod(Integer evtFixedTimeAccessPeriod) {
            setQueryParam(this.formParams, "evt_fixed_time_access_period", evtFixedTimeAccessPeriod);
			return this;
		}
		public createExternalVerificationTermRequest evtGracePeriod(Integer evtGracePeriod) {
            setQueryParam(this.formParams, "evt_grace_period", evtGracePeriod);
			return this;
		}
		public createExternalVerificationTermRequest evtVerificationPeriod(Integer evtVerificationPeriod) {
            setQueryParam(this.formParams, "evt_verification_period", evtVerificationPeriod);
			return this;
		}
		public createExternalVerificationTermRequest evtItunesBundleId(String evtItunesBundleId) {
            setQueryParam(this.formParams, "evt_itunes_bundle_id", evtItunesBundleId);
			return this;
		}
		public createExternalVerificationTermRequest evtItunesProductId(String evtItunesProductId) {
            setQueryParam(this.formParams, "evt_itunes_product_id", evtItunesProductId);
			return this;
		}
		public createExternalVerificationTermRequest evtGooglePlayProductId(String evtGooglePlayProductId) {
            setQueryParam(this.formParams, "evt_google_play_product_id", evtGooglePlayProductId);
			return this;
		}
		public createExternalVerificationTermRequest sharedAccountCount(Integer sharedAccountCount) {
            setQueryParam(this.formParams, "shared_account_count", sharedAccountCount);
			return this;
		}
		public createExternalVerificationTermRequest sharedRedemptionUrl(String sharedRedemptionUrl) {
            setQueryParam(this.formParams, "shared_redemption_url", sharedRedemptionUrl);
			return this;
		}





		public Term  execute() throws ApiException{

			String path = "/publisher/term/external/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 createExternalVerificationTermRequest createExternalVerificationTermRequest(){
		return new createExternalVerificationTermRequest(headerParams);
	}



    /**
      * API Request for updateExternalVerificationTerm
      */
	public class updateExternalVerificationTermRequest implements ApiRequest {

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

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

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


		public updateExternalVerificationTermRequest termId(String termId) {
            setQueryParam(this.formParams, "term_id", termId);
			return this;
		}
		public updateExternalVerificationTermRequest rid(String rid) {
            setQueryParam(this.formParams, "rid", rid);
			return this;
		}
		public updateExternalVerificationTermRequest externalApiId(String externalApiId) {
            setQueryParam(this.formParams, "external_api_id", externalApiId);
			return this;
		}
		public updateExternalVerificationTermRequest name(String name) {
            setQueryParam(this.formParams, "name", name);
			return this;
		}
		public updateExternalVerificationTermRequest description(String description) {
            setQueryParam(this.formParams, "description", description);
			return this;
		}
		public updateExternalVerificationTermRequest evtFixedTimeAccessPeriod(Integer evtFixedTimeAccessPeriod) {
            setQueryParam(this.formParams, "evt_fixed_time_access_period", evtFixedTimeAccessPeriod);
			return this;
		}
		public updateExternalVerificationTermRequest evtGracePeriod(Integer evtGracePeriod) {
            setQueryParam(this.formParams, "evt_grace_period", evtGracePeriod);
			return this;
		}
		public updateExternalVerificationTermRequest evtVerificationPeriod(Integer evtVerificationPeriod) {
            setQueryParam(this.formParams, "evt_verification_period", evtVerificationPeriod);
			return this;
		}
		public updateExternalVerificationTermRequest evtItunesBundleId(String evtItunesBundleId) {
            setQueryParam(this.formParams, "evt_itunes_bundle_id", evtItunesBundleId);
			return this;
		}
		public updateExternalVerificationTermRequest evtItunesProductId(String evtItunesProductId) {
            setQueryParam(this.formParams, "evt_itunes_product_id", evtItunesProductId);
			return this;
		}
		public updateExternalVerificationTermRequest evtGooglePlayProductId(String evtGooglePlayProductId) {
            setQueryParam(this.formParams, "evt_google_play_product_id", evtGooglePlayProductId);
			return this;
		}
		public updateExternalVerificationTermRequest sharedAccountCount(Integer sharedAccountCount) {
            setQueryParam(this.formParams, "shared_account_count", sharedAccountCount);
			return this;
		}
		public updateExternalVerificationTermRequest sharedRedemptionUrl(String sharedRedemptionUrl) {
            setQueryParam(this.formParams, "shared_redemption_url", sharedRedemptionUrl);
			return this;
		}





		public Term  execute() throws ApiException{

			String path = "/publisher/term/external/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 updateExternalVerificationTermRequest updateExternalVerificationTermRequest(){
		return new updateExternalVerificationTermRequest(headerParams);
	}




}