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

com.tinypass.client.publisher.api.PublisherPaymentMethodBillingAddressApi 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.UserBillingAddress;

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

public class PublisherPaymentMethodBillingAddressApi {

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

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

	public PublisherPaymentMethodBillingAddressApi(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 applyToAll
      */
	public class applyToAllRequest implements ApiRequest {

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

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

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


		public applyToAllRequest aid(String aid) {
            setQueryParam(this.formParams, "aid", aid);
			return this;
		}
		public applyToAllRequest uid(String uid) {
            setQueryParam(this.formParams, "uid", uid);
			return this;
		}
		public applyToAllRequest addressPubId(String addressPubId) {
            setQueryParam(this.formParams, "address_pub_id", addressPubId);
			return this;
		}





		public void  execute() throws ApiException{

			String path = "/publisher/payment/method/billingAddress/applyToAll".replaceAll("\\{format\\}","json");

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

	}


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



    /**
      * API Request for attach
      */
	public class attachRequest implements ApiRequest {

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

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

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


		public attachRequest aid(String aid) {
            setQueryParam(this.formParams, "aid", aid);
			return this;
		}
		public attachRequest uid(String uid) {
            setQueryParam(this.formParams, "uid", uid);
			return this;
		}
		public attachRequest upiIdentifier(String upiIdentifier) {
            setQueryParam(this.formParams, "upi_identifier", upiIdentifier);
			return this;
		}
		public attachRequest addressPubId(String addressPubId) {
            setQueryParam(this.formParams, "address_pub_id", addressPubId);
			return this;
		}





		public void  execute() throws ApiException{

			String path = "/publisher/payment/method/billingAddress/attach".replaceAll("\\{format\\}","json");

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

	}


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



    /**
      * API Request for detach
      */
	public class detachRequest implements ApiRequest {

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

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

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


		public detachRequest aid(String aid) {
            setQueryParam(this.formParams, "aid", aid);
			return this;
		}
		public detachRequest uid(String uid) {
            setQueryParam(this.formParams, "uid", uid);
			return this;
		}
		public detachRequest upiIdentifier(String upiIdentifier) {
            setQueryParam(this.formParams, "upi_identifier", upiIdentifier);
			return this;
		}





		public void  execute() throws ApiException{

			String path = "/publisher/payment/method/billingAddress/detach".replaceAll("\\{format\\}","json");

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

	}


    /**
      * Helper method to create a new request.
      */
	public detachRequest detachRequest(){
		return new detachRequest(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.formParams, "aid", aid);
			return this;
		}
		public getRequest uid(String uid) {
            setQueryParam(this.formParams, "uid", uid);
			return this;
		}
		public getRequest upiIdentifier(String upiIdentifier) {
            setQueryParam(this.formParams, "upi_identifier", upiIdentifier);
			return this;
		}





		public UserBillingAddress  execute() throws ApiException{

			String path = "/publisher/payment/method/billingAddress/get".replaceAll("\\{format\\}","json");

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

	}


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




}