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

com.tinypass.client.publisher.api.PublisherUserAddressApi 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 java.util.Date;
import com.tinypass.client.publisher.model.UserAddress;
import com.tinypass.client.publisher.model.UserAddressHistory;

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

public class PublisherUserAddressApi {

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

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

	public PublisherUserAddressApi(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 createUserAddress
      */
	public class createUserAddressRequest implements ApiRequest {

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

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

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


		public createUserAddressRequest aid(String aid) {
            setQueryParam(this.formParams, "aid", aid);
			return this;
		}
		public createUserAddressRequest uid(String uid) {
            setQueryParam(this.formParams, "uid", uid);
			return this;
		}
		public createUserAddressRequest regionId(String regionId) {
            setQueryParam(this.formParams, "region_id", regionId);
			return this;
		}
		public createUserAddressRequest countryId(String countryId) {
            setQueryParam(this.formParams, "country_id", countryId);
			return this;
		}
		public createUserAddressRequest city(String city) {
            setQueryParam(this.formParams, "city", city);
			return this;
		}
		public createUserAddressRequest postalCode(String postalCode) {
            setQueryParam(this.formParams, "postal_code", postalCode);
			return this;
		}
		public createUserAddressRequest companyName(String companyName) {
            setQueryParam(this.formParams, "company_name", companyName);
			return this;
		}
		public createUserAddressRequest firstName(String firstName) {
            setQueryParam(this.formParams, "first_name", firstName);
			return this;
		}
		public createUserAddressRequest lastName(String lastName) {
            setQueryParam(this.formParams, "last_name", lastName);
			return this;
		}
		public createUserAddressRequest address1(String address1) {
            setQueryParam(this.formParams, "address1", address1);
			return this;
		}
		public createUserAddressRequest address2(String address2) {
            setQueryParam(this.formParams, "address2", address2);
			return this;
		}
		public createUserAddressRequest phone(String phone) {
            setQueryParam(this.formParams, "phone", phone);
			return this;
		}
		public createUserAddressRequest regionName(String regionName) {
            setQueryParam(this.formParams, "region_name", regionName);
			return this;
		}





		public UserAddress  execute() throws ApiException{

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

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

	}


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



    /**
      * API Request for deleteUserAddress
      */
	public class deleteUserAddressRequest implements ApiRequest {

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

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

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


		public deleteUserAddressRequest aid(String aid) {
            setQueryParam(this.formParams, "aid", aid);
			return this;
		}
		public deleteUserAddressRequest uid(String uid) {
            setQueryParam(this.formParams, "uid", uid);
			return this;
		}
		public deleteUserAddressRequest userAddressId(String userAddressId) {
            setQueryParam(this.formParams, "user_address_id", userAddressId);
			return this;
		}





		public Boolean  execute() throws ApiException{

			String path = "/publisher/user/address/delete".replaceAll("\\{format\\}","json");

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

	}


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



    /**
      * API Request for listUserAddress
      */
	public class listUserAddressRequest implements ApiRequest {

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

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

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

		public listUserAddressRequest aid(String aid) {
            setQueryParam(this.queryParams, "aid", aid);
			return this;
		}
		public listUserAddressRequest uid(String uid) {
            setQueryParam(this.queryParams, "uid", uid);
			return this;
		}
		public listUserAddressRequest offset(Integer offset) {
            setQueryParam(this.queryParams, "offset", offset);
			return this;
		}
		public listUserAddressRequest limit(Integer limit) {
            setQueryParam(this.queryParams, "limit", limit);
			return this;
		}






		public PageList  execute() throws ApiException{

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

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

	}


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



    /**
      * API Request for listUserAddressHistory
      */
	public class listUserAddressHistoryRequest implements ApiRequest {

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

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

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


		public listUserAddressHistoryRequest aid(String aid) {
            setQueryParam(this.formParams, "aid", aid);
			return this;
		}
		public listUserAddressHistoryRequest dateFrom(Date dateFrom) {
            setQueryParam(this.formParams, "date_from", dateFrom);
			return this;
		}
		public listUserAddressHistoryRequest dateTo(Date dateTo) {
            setQueryParam(this.formParams, "date_to", dateTo);
			return this;
		}
		public listUserAddressHistoryRequest offset(Integer offset) {
            setQueryParam(this.formParams, "offset", offset);
			return this;
		}
		public listUserAddressHistoryRequest limit(Integer limit) {
            setQueryParam(this.formParams, "limit", limit);
			return this;
		}





		public PageList  execute() throws ApiException{

			String path = "/publisher/user/address/history".replaceAll("\\{format\\}","json");

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

	}


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



    /**
      * API Request for updateUserAddress
      */
	public class updateUserAddressRequest implements ApiRequest {

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

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

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


		public updateUserAddressRequest aid(String aid) {
            setQueryParam(this.formParams, "aid", aid);
			return this;
		}
		public updateUserAddressRequest uid(String uid) {
            setQueryParam(this.formParams, "uid", uid);
			return this;
		}
		public updateUserAddressRequest userAddressId(String userAddressId) {
            setQueryParam(this.formParams, "user_address_id", userAddressId);
			return this;
		}
		public updateUserAddressRequest regionId(String regionId) {
            setQueryParam(this.formParams, "region_id", regionId);
			return this;
		}
		public updateUserAddressRequest countryId(String countryId) {
            setQueryParam(this.formParams, "country_id", countryId);
			return this;
		}
		public updateUserAddressRequest city(String city) {
            setQueryParam(this.formParams, "city", city);
			return this;
		}
		public updateUserAddressRequest postalCode(String postalCode) {
            setQueryParam(this.formParams, "postal_code", postalCode);
			return this;
		}
		public updateUserAddressRequest companyName(String companyName) {
            setQueryParam(this.formParams, "company_name", companyName);
			return this;
		}
		public updateUserAddressRequest firstName(String firstName) {
            setQueryParam(this.formParams, "first_name", firstName);
			return this;
		}
		public updateUserAddressRequest lastName(String lastName) {
            setQueryParam(this.formParams, "last_name", lastName);
			return this;
		}
		public updateUserAddressRequest address1(String address1) {
            setQueryParam(this.formParams, "address1", address1);
			return this;
		}
		public updateUserAddressRequest address2(String address2) {
            setQueryParam(this.formParams, "address2", address2);
			return this;
		}
		public updateUserAddressRequest phone(String phone) {
            setQueryParam(this.formParams, "phone", phone);
			return this;
		}
		public updateUserAddressRequest regionName(String regionName) {
            setQueryParam(this.formParams, "region_name", regionName);
			return this;
		}
		public updateUserAddressRequest additionalFields(String additionalFields) {
            setQueryParam(this.formParams, "additional_fields", additionalFields);
			return this;
		}





		public UserAddress  execute() throws ApiException{

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

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

	}


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




}