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

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

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

import com.tinypass.client.common.*;
import com.tinypass.client.publisher.model.ContractIpRange;

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

public class PublisherLicensingContractIpRangeApi {

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

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

	public PublisherLicensingContractIpRangeApi(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 createContractIpRange
      */
	public class createContractIpRangeRequest implements ApiRequest {

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

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

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


		public createContractIpRangeRequest aid(String aid) {
            setQueryParam(this.formParams, "aid", aid);
			return this;
		}
		public createContractIpRangeRequest contractId(String contractId) {
            setQueryParam(this.formParams, "contract_id", contractId);
			return this;
		}
		public createContractIpRangeRequest ipRange(String ipRange) {
            setQueryParam(this.formParams, "ip_range", ipRange);
			return this;
		}





		public ContractIpRange  execute() throws ApiException{

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

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

	}


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



    /**
      * API Request for getContractIpRangeList
      */
	public class getContractIpRangeListRequest implements ApiRequest {

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

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

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

		public getContractIpRangeListRequest aid(String aid) {
            setQueryParam(this.queryParams, "aid", aid);
			return this;
		}
		public getContractIpRangeListRequest contractId(String contractId) {
            setQueryParam(this.queryParams, "contract_id", contractId);
			return this;
		}
		public getContractIpRangeListRequest q(String q) {
            setQueryParam(this.queryParams, "q", q);
			return this;
		}
		public getContractIpRangeListRequest offset(Integer offset) {
            setQueryParam(this.queryParams, "offset", offset);
			return this;
		}
		public getContractIpRangeListRequest limit(Integer limit) {
            setQueryParam(this.queryParams, "limit", limit);
			return this;
		}






		public PageList  execute() throws ApiException{

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

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

	}


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



    /**
      * API Request for removeContractIpRange
      */
	public class removeContractIpRangeRequest implements ApiRequest {

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

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

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


		public removeContractIpRangeRequest aid(String aid) {
            setQueryParam(this.formParams, "aid", aid);
			return this;
		}
		public removeContractIpRangeRequest contractId(String contractId) {
            setQueryParam(this.formParams, "contract_id", contractId);
			return this;
		}
		public removeContractIpRangeRequest contractIpRangeId(String contractIpRangeId) {
            setQueryParam(this.formParams, "contract_ip_range_id", contractIpRangeId);
			return this;
		}





		public void  execute() throws ApiException{

			String path = "/publisher/licensing/contractIpRange/remove".replaceAll("\\{format\\}","json");

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

	}


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



    /**
      * API Request for updateContractIpRange
      */
	public class updateContractIpRangeRequest implements ApiRequest {

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

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

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


		public updateContractIpRangeRequest aid(String aid) {
            setQueryParam(this.formParams, "aid", aid);
			return this;
		}
		public updateContractIpRangeRequest contractId(String contractId) {
            setQueryParam(this.formParams, "contract_id", contractId);
			return this;
		}
		public updateContractIpRangeRequest contractIpRangeId(String contractIpRangeId) {
            setQueryParam(this.formParams, "contract_ip_range_id", contractIpRangeId);
			return this;
		}
		public updateContractIpRangeRequest ipRange(String ipRange) {
            setQueryParam(this.formParams, "ip_range", ipRange);
			return this;
		}





		public ContractIpRange  execute() throws ApiException{

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

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

	}


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




}