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

com.tinypass.client.publisher.api.PublisherExportCreateAccessReportExportApi 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.Export;

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

public class PublisherExportCreateAccessReportExportApi {

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

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

	public PublisherExportCreateAccessReportExportApi(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 createAccessReportExportTZ
      */
	public class createAccessReportExportTZRequest implements ApiRequest {

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

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

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

		public createAccessReportExportTZRequest aid(String aid) {
            setQueryParam(this.queryParams, "aid", aid);
			return this;
		}
		public createAccessReportExportTZRequest exportName(String exportName) {
            setQueryParam(this.queryParams, "export_name", exportName);
			return this;
		}
		public createAccessReportExportTZRequest accessStatus(String accessStatus) {
            setQueryParam(this.queryParams, "access_status", accessStatus);
			return this;
		}
		public createAccessReportExportTZRequest termType(List termType) {
            setQueryParam(this.queryParams, "term_type", termType);
			return this;
		}
		public createAccessReportExportTZRequest termId(List termId) {
            setQueryParam(this.queryParams, "term_id", termId);
			return this;
		}
		public createAccessReportExportTZRequest nextBillingDate(Date nextBillingDate) {
            setQueryParam(this.queryParams, "next_billing_date", nextBillingDate);
			return this;
		}
		public createAccessReportExportTZRequest lastPaymentStatus(String lastPaymentStatus) {
            setQueryParam(this.queryParams, "last_payment_status", lastPaymentStatus);
			return this;
		}
		public createAccessReportExportTZRequest dateFrom(Date dateFrom) {
            setQueryParam(this.queryParams, "date_from", dateFrom);
			return this;
		}
		public createAccessReportExportTZRequest dateTo(Date dateTo) {
            setQueryParam(this.queryParams, "date_to", dateTo);
			return this;
		}
		public createAccessReportExportTZRequest endDateFrom(Date endDateFrom) {
            setQueryParam(this.queryParams, "end_date_from", endDateFrom);
			return this;
		}
		public createAccessReportExportTZRequest endDateTo(Date endDateTo) {
            setQueryParam(this.queryParams, "end_date_to", endDateTo);
			return this;
		}






		public Export  execute() throws ApiException{

			String path = "/publisher/export/create/accessReportExport/v2".replaceAll("\\{format\\}","json");

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

	}


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




}