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

com.tinypass.client.publisher.api.PublisherOfferTemplateVariantApi 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.OfferTemplateVariant;

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

public class PublisherOfferTemplateVariantApi {

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

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

	public PublisherOfferTemplateVariantApi(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 archive
      */
	public class archiveRequest implements ApiRequest {

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

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

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

		public archiveRequest aid(String aid) {
            setQueryParam(this.queryParams, "aid", aid);
			return this;
		}
		public archiveRequest offerTemplateVariantId(String offerTemplateVariantId) {
            setQueryParam(this.queryParams, "offer_template_variant_id", offerTemplateVariantId);
			return this;
		}
		public archiveRequest historyComment(String historyComment) {
            setQueryParam(this.queryParams, "history_comment", historyComment);
			return this;
		}






		public void  execute() throws ApiException{

			String path = "/publisher/offer/template/variant/archive".replaceAll("\\{format\\}","json");

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

	}


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



    /**
      * API Request for create
      */
	public class createRequest implements ApiRequest {

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

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

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


		public createRequest aid(String aid) {
            setQueryParam(this.formParams, "aid", aid);
			return this;
		}
		public createRequest offerTemplateId(String offerTemplateId) {
            setQueryParam(this.formParams, "offer_template_id", offerTemplateId);
			return this;
		}
		public createRequest name(String name) {
            setQueryParam(this.formParams, "name", name);
			return this;
		}
		public createRequest description(String description) {
            setQueryParam(this.formParams, "description", description);
			return this;
		}
		public createRequest historyComment(String historyComment) {
            setQueryParam(this.formParams, "history_comment", historyComment);
			return this;
		}





		public OfferTemplateVariant  execute() throws ApiException{

			String path = "/publisher/offer/template/variant/create".replaceAll("\\{format\\}","json");

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

	}


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



    /**
      * API Request for delete
      */
	public class deleteRequest implements ApiRequest {

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

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

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


		public deleteRequest aid(String aid) {
            setQueryParam(this.formParams, "aid", aid);
			return this;
		}
		public deleteRequest offerTemplateVariantId(String offerTemplateVariantId) {
            setQueryParam(this.formParams, "offer_template_variant_id", offerTemplateVariantId);
			return this;
		}
		public deleteRequest historyComment(String historyComment) {
            setQueryParam(this.formParams, "history_comment", historyComment);
			return this;
		}





		public void  execute() throws ApiException{

			String path = "/publisher/offer/template/variant/delete".replaceAll("\\{format\\}","json");

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

	}


    /**
      * Helper method to create a new request.
      */
	public deleteRequest deleteRequest(){
		return new deleteRequest(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 offerTemplateVariantId(String offerTemplateVariantId) {
            setQueryParam(this.queryParams, "offer_template_variant_id", offerTemplateVariantId);
			return this;
		}






		public OfferTemplateVariant  execute() throws ApiException{

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

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

	}


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



    /**
      * API Request for getDuplicate
      */
	public class getDuplicateRequest implements ApiRequest {

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

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

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

		public getDuplicateRequest aid(String aid) {
            setQueryParam(this.queryParams, "aid", aid);
			return this;
		}
		public getDuplicateRequest offerTemplateVariantId(String offerTemplateVariantId) {
            setQueryParam(this.queryParams, "offer_template_variant_id", offerTemplateVariantId);
			return this;
		}
		public getDuplicateRequest historyComment(String historyComment) {
            setQueryParam(this.queryParams, "history_comment", historyComment);
			return this;
		}






		public OfferTemplateVariant  execute() throws ApiException{

			String path = "/publisher/offer/template/variant/duplicate".replaceAll("\\{format\\}","json");

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

	}


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



    /**
      * API Request for restore
      */
	public class restoreRequest implements ApiRequest {

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

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

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

		public restoreRequest aid(String aid) {
            setQueryParam(this.queryParams, "aid", aid);
			return this;
		}
		public restoreRequest offerTemplateVariantId(String offerTemplateVariantId) {
            setQueryParam(this.queryParams, "offer_template_variant_id", offerTemplateVariantId);
			return this;
		}
		public restoreRequest historyComment(String historyComment) {
            setQueryParam(this.queryParams, "history_comment", historyComment);
			return this;
		}






		public void  execute() throws ApiException{

			String path = "/publisher/offer/template/variant/restore".replaceAll("\\{format\\}","json");

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

	}


    /**
      * Helper method to create a new request.
      */
	public restoreRequest restoreRequest(){
		return new restoreRequest(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 offerTemplateVariantId(String offerTemplateVariantId) {
            setQueryParam(this.formParams, "offer_template_variant_id", offerTemplateVariantId);
			return this;
		}
		public updateRequest name(String name) {
            setQueryParam(this.formParams, "name", name);
			return this;
		}
		public updateRequest description(String description) {
            setQueryParam(this.formParams, "description", description);
			return this;
		}
		public updateRequest contentFieldList(String contentFieldList) {
            setQueryParam(this.formParams, "content_field_list", contentFieldList);
			return this;
		}
		public updateRequest historyComment(String historyComment) {
            setQueryParam(this.formParams, "history_comment", historyComment);
			return this;
		}
		public updateRequest isValidate(Boolean isValidate) {
            setQueryParam(this.formParams, "is_validate", isValidate);
			return this;
		}





		public OfferTemplateVariant  execute() throws ApiException{

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

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

	}


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




}