co.uk.crowdemotion.TimeseriesApi.java Source code

Java tutorial

Introduction

Here is the source code for co.uk.crowdemotion.TimeseriesApi.java

Source

/**
 * CloudEmotion API v1
 * CrowdEmotion API
 *
 * OpenAPI spec version: 1.1.0
 * 
 *
 * NOTE: This class is auto generated by the swagger code generator program.
 * https://github.com/swagger-api/swagger-codegen.git
 * Do not edit the class manually.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package co.uk.crowdemotion;

import co.uk.crowdemotion.ApiCallback;
import co.uk.crowdemotion.ApiClient;
import co.uk.crowdemotion.ApiException;
import co.uk.crowdemotion.ApiResponse;
import co.uk.crowdemotion.Configuration;
import co.uk.crowdemotion.Pair;
import co.uk.crowdemotion.ProgressRequestBody;
import co.uk.crowdemotion.ProgressResponseBody;

import com.google.gson.reflect.TypeToken;

import java.io.IOException;

import io.swagger.client.model.Timeseries;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class TimeseriesApi {
    private ApiClient apiClient;

    public TimeseriesApi() {
        this(Configuration.getDefaultApiClient());
    }

    public TimeseriesApi(ApiClient apiClient) {
        this.apiClient = apiClient;
    }

    public ApiClient getApiClient() {
        return apiClient;
    }

    public void setApiClient(ApiClient apiClient) {
        this.apiClient = apiClient;
    }

    /* Build call for timeseriesDelete */
    private com.squareup.okhttp.Call timeseriesDeleteCall(Integer responseId, Integer metricId,
            final ProgressResponseBody.ProgressListener progressListener,
            final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
        Object localVarPostBody = null;

        // verify the required parameter 'responseId' is set
        if (responseId == null) {
            throw new ApiException(
                    "Missing the required parameter 'responseId' when calling timeseriesDelete(Async)");
        }

        // create path and map variables
        String localVarPath = "/timeseries".replaceAll("\\{format\\}", "json");

        List<Pair> localVarQueryParams = new ArrayList<Pair>();
        if (responseId != null)
            localVarQueryParams.addAll(apiClient.parameterToPairs("", "response_id", responseId));
        if (metricId != null)
            localVarQueryParams.addAll(apiClient.parameterToPairs("", "metric_id", metricId));

        Map<String, String> localVarHeaderParams = new HashMap<String, String>();

        Map<String, Object> localVarFormParams = new HashMap<String, Object>();

        final String[] localVarAccepts = { "application/json" };
        final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts);
        if (localVarAccept != null)
            localVarHeaderParams.put("Accept", localVarAccept);

        final String[] localVarContentTypes = { "application/json" };
        final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes);
        localVarHeaderParams.put("Content-Type", localVarContentType);

        if (progressListener != null) {
            apiClient.getHttpClient().networkInterceptors().add(new com.squareup.okhttp.Interceptor() {
                @Override
                public com.squareup.okhttp.Response intercept(com.squareup.okhttp.Interceptor.Chain chain)
                        throws IOException {
                    com.squareup.okhttp.Response originalResponse = chain.proceed(chain.request());
                    return originalResponse.newBuilder()
                            .body(new ProgressResponseBody(originalResponse.body(), progressListener)).build();
                }
            });
        }

        String[] localVarAuthNames = new String[] { "api_key" };
        return apiClient.buildCall(localVarPath, "DELETE", localVarQueryParams, localVarPostBody,
                localVarHeaderParams, localVarFormParams, localVarAuthNames, progressRequestListener);
    }

    /**
     * Delete a Timeseries
     * &lt;p&gt;&lt;strong&gt;Permissions:&lt;/strong&gt;  Respondent  Customer  Manager&lt;/p&gt;
     * @param responseId ID of the Response associated to the TimeSeries. (required)
     * @param metricId ID of the Metric of the Timeseries to be deleted. (optional)
     * @return String
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     */
    public String timeseriesDelete(Integer responseId, Integer metricId) throws ApiException {
        ApiResponse<String> resp = timeseriesDeleteWithHttpInfo(responseId, metricId);
        return resp.getData();
    }

    /**
     * Delete a Timeseries
     * &lt;p&gt;&lt;strong&gt;Permissions:&lt;/strong&gt;  Respondent  Customer  Manager&lt;/p&gt;
     * @param responseId ID of the Response associated to the TimeSeries. (required)
     * @param metricId ID of the Metric of the Timeseries to be deleted. (optional)
     * @return ApiResponse&lt;String&gt;
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     */
    public ApiResponse<String> timeseriesDeleteWithHttpInfo(Integer responseId, Integer metricId)
            throws ApiException {
        com.squareup.okhttp.Call call = timeseriesDeleteCall(responseId, metricId, null, null);
        Type localVarReturnType = new TypeToken<String>() {
        }.getType();
        return apiClient.execute(call, localVarReturnType);
    }

    /**
     * Delete a Timeseries (asynchronously)
     * &lt;p&gt;&lt;strong&gt;Permissions:&lt;/strong&gt;  Respondent  Customer  Manager&lt;/p&gt;
     * @param responseId ID of the Response associated to the TimeSeries. (required)
     * @param metricId ID of the Metric of the Timeseries to be deleted. (optional)
     * @param callback The callback to be executed when the API call finishes
     * @return The request call
     * @throws ApiException If fail to process the API call, e.g. serializing the request body object
     */
    public com.squareup.okhttp.Call timeseriesDeleteAsync(Integer responseId, Integer metricId,
            final ApiCallback<String> callback) throws ApiException {

        ProgressResponseBody.ProgressListener progressListener = null;
        ProgressRequestBody.ProgressRequestListener progressRequestListener = null;

        if (callback != null) {
            progressListener = new ProgressResponseBody.ProgressListener() {
                @Override
                public void update(long bytesRead, long contentLength, boolean done) {
                    callback.onDownloadProgress(bytesRead, contentLength, done);
                }
            };

            progressRequestListener = new ProgressRequestBody.ProgressRequestListener() {
                @Override
                public void onRequestProgress(long bytesWritten, long contentLength, boolean done) {
                    callback.onUploadProgress(bytesWritten, contentLength, done);
                }
            };
        }

        com.squareup.okhttp.Call call = timeseriesDeleteCall(responseId, metricId, progressListener,
                progressRequestListener);
        Type localVarReturnType = new TypeToken<String>() {
        }.getType();
        apiClient.executeAsync(call, localVarReturnType, callback);
        return call;
    }

    /* Build call for timeseriesGet */
    private com.squareup.okhttp.Call timeseriesGetCall(Integer responseId, Integer metricId, Boolean normalize,
            String format, final ProgressResponseBody.ProgressListener progressListener,
            final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
        Object localVarPostBody = null;

        // verify the required parameter 'responseId' is set
        if (responseId == null) {
            throw new ApiException("Missing the required parameter 'responseId' when calling timeseriesGet(Async)");
        }

        // create path and map variables
        String localVarPath = "/timeseries".replaceAll("\\{format\\}", "json");

        List<Pair> localVarQueryParams = new ArrayList<Pair>();
        if (responseId != null)
            localVarQueryParams.addAll(apiClient.parameterToPairs("", "response_id", responseId));
        if (metricId != null)
            localVarQueryParams.addAll(apiClient.parameterToPairs("", "metric_id", metricId));
        if (normalize != null)
            localVarQueryParams.addAll(apiClient.parameterToPairs("", "normalize", normalize));
        if (format != null)
            localVarQueryParams.addAll(apiClient.parameterToPairs("", "format", format));

        Map<String, String> localVarHeaderParams = new HashMap<String, String>();

        Map<String, Object> localVarFormParams = new HashMap<String, Object>();

        final String[] localVarAccepts = { "application/json" };
        final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts);
        if (localVarAccept != null)
            localVarHeaderParams.put("Accept", localVarAccept);

        final String[] localVarContentTypes = { "application/json" };
        final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes);
        localVarHeaderParams.put("Content-Type", localVarContentType);

        if (progressListener != null) {
            apiClient.getHttpClient().networkInterceptors().add(new com.squareup.okhttp.Interceptor() {
                @Override
                public com.squareup.okhttp.Response intercept(com.squareup.okhttp.Interceptor.Chain chain)
                        throws IOException {
                    com.squareup.okhttp.Response originalResponse = chain.proceed(chain.request());
                    return originalResponse.newBuilder()
                            .body(new ProgressResponseBody(originalResponse.body(), progressListener)).build();
                }
            });
        }

        String[] localVarAuthNames = new String[] { "api_key" };
        return apiClient.buildCall(localVarPath, "GET", localVarQueryParams, localVarPostBody, localVarHeaderParams,
                localVarFormParams, localVarAuthNames, progressRequestListener);
    }

    /**
     * Get all recorded timeseries for a Response
     * &lt;p&gt;&lt;strong&gt;Permissions:&lt;/strong&gt;  Respondent  Customer  Manager&lt;/p&gt;
     * @param responseId ID of the Response associated to the TimeSeries. (required)
     * @param metricId ID of the Metric associated to the TimeSeries. (optional)
     * @param normalize Return data beetwen 0 and 1. Default: false. (optional)
     * @param format If value is &#39;csv&#39; then data is passed back in CSV format insted of the default time-series format. Example: csv. (optional)
     * @return List&lt;Timeseries&gt;
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     */
    public List<Timeseries> timeseriesGet(Integer responseId, Integer metricId, Boolean normalize, String format)
            throws ApiException {
        ApiResponse<List<Timeseries>> resp = timeseriesGetWithHttpInfo(responseId, metricId, normalize, format);
        return resp.getData();
    }

    /**
     * Get all recorded timeseries for a Response
     * &lt;p&gt;&lt;strong&gt;Permissions:&lt;/strong&gt;  Respondent  Customer  Manager&lt;/p&gt;
     * @param responseId ID of the Response associated to the TimeSeries. (required)
     * @param metricId ID of the Metric associated to the TimeSeries. (optional)
     * @param normalize Return data beetwen 0 and 1. Default: false. (optional)
     * @param format If value is &#39;csv&#39; then data is passed back in CSV format insted of the default time-series format. Example: csv. (optional)
     * @return ApiResponse&lt;List&lt;Timeseries&gt;&gt;
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     */
    public ApiResponse<List<Timeseries>> timeseriesGetWithHttpInfo(Integer responseId, Integer metricId,
            Boolean normalize, String format) throws ApiException {
        com.squareup.okhttp.Call call = timeseriesGetCall(responseId, metricId, normalize, format, null, null);
        Type localVarReturnType = new TypeToken<List<Timeseries>>() {
        }.getType();
        return apiClient.execute(call, localVarReturnType);
    }

    /**
     * Get all recorded timeseries for a Response (asynchronously)
     * &lt;p&gt;&lt;strong&gt;Permissions:&lt;/strong&gt;  Respondent  Customer  Manager&lt;/p&gt;
     * @param responseId ID of the Response associated to the TimeSeries. (required)
     * @param metricId ID of the Metric associated to the TimeSeries. (optional)
     * @param normalize Return data beetwen 0 and 1. Default: false. (optional)
     * @param format If value is &#39;csv&#39; then data is passed back in CSV format insted of the default time-series format. Example: csv. (optional)
     * @param callback The callback to be executed when the API call finishes
     * @return The request call
     * @throws ApiException If fail to process the API call, e.g. serializing the request body object
     */
    public com.squareup.okhttp.Call timeseriesGetAsync(Integer responseId, Integer metricId, Boolean normalize,
            String format, final ApiCallback<List<Timeseries>> callback) throws ApiException {

        ProgressResponseBody.ProgressListener progressListener = null;
        ProgressRequestBody.ProgressRequestListener progressRequestListener = null;

        if (callback != null) {
            progressListener = new ProgressResponseBody.ProgressListener() {
                @Override
                public void update(long bytesRead, long contentLength, boolean done) {
                    callback.onDownloadProgress(bytesRead, contentLength, done);
                }
            };

            progressRequestListener = new ProgressRequestBody.ProgressRequestListener() {
                @Override
                public void onRequestProgress(long bytesWritten, long contentLength, boolean done) {
                    callback.onUploadProgress(bytesWritten, contentLength, done);
                }
            };
        }

        com.squareup.okhttp.Call call = timeseriesGetCall(responseId, metricId, normalize, format, progressListener,
                progressRequestListener);
        Type localVarReturnType = new TypeToken<List<Timeseries>>() {
        }.getType();
        apiClient.executeAsync(call, localVarReturnType, callback);
        return call;
    }
}