co.waitlisted.api.ReservationApi.java Source code

Java tutorial

Introduction

Here is the source code for co.waitlisted.api.ReservationApi.java

Source

/**
 * Waitlisted API
 * Waitlisted API
 *
 * OpenAPI spec version: 2.0.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.waitlisted.api;

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

import com.google.gson.reflect.TypeToken;

import java.io.IOException;

import co.waitlisted.models.ReservationRequest;
import co.waitlisted.models.ReservationsResponse;
import co.waitlisted.models.ErrorResponse;
import co.waitlisted.models.Reservation;

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

public class ReservationApi {
    private ApiClient wlapiClient;

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

    public ReservationApi(ApiClient apiClient) {
        this.wlapiClient = apiClient;
    }

    public ApiClient getApiClient() {
        return wlapiClient;
    }

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

    /* Build call for activateReservation */
    private com.squareup.okhttp.Call activateReservationCall(ReservationRequest body,
            final ProgressResponseBody.ProgressListener progressListener,
            final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
        Object wllocalVarPostBody = body;

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

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

        List<Pair> wllocalVarQueryParams = new ArrayList<Pair>();

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

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

        final String[] wllocalVarAccepts = { "application/json" };
        final String wllocalVarAccept = wlapiClient.selectHeaderAccept(wllocalVarAccepts);
        if (wllocalVarAccept != null)
            wllocalVarHeaderParams.put("Accept", wllocalVarAccept);

        final String[] wllocalVarContentTypes = { "application/json" };
        final String wllocalVarContentType = wlapiClient.selectHeaderContentType(wllocalVarContentTypes);
        wllocalVarHeaderParams.put("Content-Type", wllocalVarContentType);

        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[] wllocalVarAuthNames = new String[] { "api_key" };
        return wlapiClient.buildCall(wllocalVarPath, "POST", wllocalVarQueryParams, wllocalVarPostBody,
                wllocalVarHeaderParams, wllocalVarFormParams, wllocalVarAuthNames, progressRequestListener);
    }

    /**
     * 
     * Activate a reservation.
     * @param body Reservation Data (required)
     * @return ReservationsResponse
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     */
    public ReservationsResponse activateReservation(ReservationRequest body) throws ApiException {
        ApiResponse<ReservationsResponse> wlresp = activateReservationWithHttpInfo(body);
        return wlresp.getData();
    }

    /**
     * 
     * Activate a reservation.
     * @param body Reservation Data (required)
     * @return ApiResponse&lt;ReservationsResponse&gt;
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     */
    public ApiResponse<ReservationsResponse> activateReservationWithHttpInfo(ReservationRequest body)
            throws ApiException {
        com.squareup.okhttp.Call wlcall = activateReservationCall(body, null, null);
        Type wllocalVarReturnType = new TypeToken<ReservationsResponse>() {
        }.getType();
        return wlapiClient.execute(wlcall, wllocalVarReturnType);
    }

    /**
     *  (asynchronously)
     * Activate a reservation.
     * @param body Reservation Data (required)
     * @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 activateReservationAsync(ReservationRequest body,
            final ApiCallback<ReservationsResponse> wlcallback) 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 wlcall = activateReservationCall(body, progressListener, progressRequestListener);
        Type wllocalVarReturnType = new TypeToken<ReservationsResponse>() {
        }.getType();
        wlapiClient.executeAsync(wlcall, wllocalVarReturnType, wlcallback);
        return wlcall;
    }

    /* Build call for createReservation */
    private com.squareup.okhttp.Call createReservationCall(Reservation body,
            final ProgressResponseBody.ProgressListener progressListener,
            final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
        Object wllocalVarPostBody = body;

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

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

        List<Pair> wllocalVarQueryParams = new ArrayList<Pair>();

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

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

        final String[] wllocalVarAccepts = { "application/json" };
        final String wllocalVarAccept = wlapiClient.selectHeaderAccept(wllocalVarAccepts);
        if (wllocalVarAccept != null)
            wllocalVarHeaderParams.put("Accept", wllocalVarAccept);

        final String[] wllocalVarContentTypes = { "application/json" };
        final String wllocalVarContentType = wlapiClient.selectHeaderContentType(wllocalVarContentTypes);
        wllocalVarHeaderParams.put("Content-Type", wllocalVarContentType);

        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[] wllocalVarAuthNames = new String[] {};
        return wlapiClient.buildCall(wllocalVarPath, "POST", wllocalVarQueryParams, wllocalVarPostBody,
                wllocalVarHeaderParams, wllocalVarFormParams, wllocalVarAuthNames, progressRequestListener);
    }

    /**
     * 
     * Creates a new reservation.
     * @param body Reservation Data (required)
     * @return ReservationsResponse
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     */
    public ReservationsResponse createReservation(Reservation body) throws ApiException {
        ApiResponse<ReservationsResponse> wlresp = createReservationWithHttpInfo(body);
        return wlresp.getData();
    }

    /**
     * 
     * Creates a new reservation.
     * @param body Reservation Data (required)
     * @return ApiResponse&lt;ReservationsResponse&gt;
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     */
    public ApiResponse<ReservationsResponse> createReservationWithHttpInfo(Reservation body) throws ApiException {
        com.squareup.okhttp.Call wlcall = createReservationCall(body, null, null);
        Type wllocalVarReturnType = new TypeToken<ReservationsResponse>() {
        }.getType();
        return wlapiClient.execute(wlcall, wllocalVarReturnType);
    }

    /**
     *  (asynchronously)
     * Creates a new reservation.
     * @param body Reservation Data (required)
     * @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 createReservationAsync(Reservation body,
            final ApiCallback<ReservationsResponse> wlcallback) 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 wlcall = createReservationCall(body, progressListener, progressRequestListener);
        Type wllocalVarReturnType = new TypeToken<ReservationsResponse>() {
        }.getType();
        wlapiClient.executeAsync(wlcall, wllocalVarReturnType, wlcallback);
        return wlcall;
    }

    /* Build call for deleteReservation */
    private com.squareup.okhttp.Call deleteReservationCall(ReservationRequest body,
            final ProgressResponseBody.ProgressListener progressListener,
            final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
        Object wllocalVarPostBody = body;

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

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

        List<Pair> wllocalVarQueryParams = new ArrayList<Pair>();

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

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

        final String[] wllocalVarAccepts = { "application/json" };
        final String wllocalVarAccept = wlapiClient.selectHeaderAccept(wllocalVarAccepts);
        if (wllocalVarAccept != null)
            wllocalVarHeaderParams.put("Accept", wllocalVarAccept);

        final String[] wllocalVarContentTypes = { "application/json" };
        final String wllocalVarContentType = wlapiClient.selectHeaderContentType(wllocalVarContentTypes);
        wllocalVarHeaderParams.put("Content-Type", wllocalVarContentType);

        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[] wllocalVarAuthNames = new String[] { "api_key" };
        return wlapiClient.buildCall(wllocalVarPath, "DELETE", wllocalVarQueryParams, wllocalVarPostBody,
                wllocalVarHeaderParams, wllocalVarFormParams, wllocalVarAuthNames, progressRequestListener);
    }

    /**
     * 
     * Delete a reservation.
     * @param body Reservation Data (required)
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     */
    public void deleteReservation(ReservationRequest body) throws ApiException {
        deleteReservationWithHttpInfo(body);
    }

    /**
     * 
     * Delete a reservation.
     * @param body Reservation Data (required)
     * @return ApiResponse&lt;Void&gt;
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     */
    public ApiResponse<Void> deleteReservationWithHttpInfo(ReservationRequest body) throws ApiException {
        com.squareup.okhttp.Call wlcall = deleteReservationCall(body, null, null);
        return wlapiClient.execute(wlcall);
    }

    /**
     *  (asynchronously)
     * Delete a reservation.
     * @param body Reservation Data (required)
     * @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 deleteReservationAsync(ReservationRequest body,
            final ApiCallback<Void> wlcallback) 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 wlcall = deleteReservationCall(body, progressListener, progressRequestListener);
        wlapiClient.executeAsync(wlcall, wlcallback);
        return wlcall;
    }

    /* Build call for getReservation */
    private com.squareup.okhttp.Call getReservationCall(String email,
            final ProgressResponseBody.ProgressListener progressListener,
            final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
        Object wllocalVarPostBody = null;

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

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

        List<Pair> wllocalVarQueryParams = new ArrayList<Pair>();
        if (email != null)
            wllocalVarQueryParams.addAll(wlapiClient.parameterToPairs("", "email", email));

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

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

        final String[] wllocalVarAccepts = { "application/json" };
        final String wllocalVarAccept = wlapiClient.selectHeaderAccept(wllocalVarAccepts);
        if (wllocalVarAccept != null)
            wllocalVarHeaderParams.put("Accept", wllocalVarAccept);

        final String[] wllocalVarContentTypes = { "application/json" };
        final String wllocalVarContentType = wlapiClient.selectHeaderContentType(wllocalVarContentTypes);
        wllocalVarHeaderParams.put("Content-Type", wllocalVarContentType);

        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[] wllocalVarAuthNames = new String[] {};
        return wlapiClient.buildCall(wllocalVarPath, "GET", wllocalVarQueryParams, wllocalVarPostBody,
                wllocalVarHeaderParams, wllocalVarFormParams, wllocalVarAuthNames, progressRequestListener);
    }

    /**
     * 
     * Get a reservation.
     * @param email Email address (required)
     * @return ReservationsResponse
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     */
    public ReservationsResponse getReservation(String email) throws ApiException {
        ApiResponse<ReservationsResponse> wlresp = getReservationWithHttpInfo(email);
        return wlresp.getData();
    }

    /**
     * 
     * Get a reservation.
     * @param email Email address (required)
     * @return ApiResponse&lt;ReservationsResponse&gt;
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     */
    public ApiResponse<ReservationsResponse> getReservationWithHttpInfo(String email) throws ApiException {
        com.squareup.okhttp.Call wlcall = getReservationCall(email, null, null);
        Type wllocalVarReturnType = new TypeToken<ReservationsResponse>() {
        }.getType();
        return wlapiClient.execute(wlcall, wllocalVarReturnType);
    }

    /**
     *  (asynchronously)
     * Get a reservation.
     * @param email Email address (required)
     * @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 getReservationAsync(String email,
            final ApiCallback<ReservationsResponse> wlcallback) 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 wlcall = getReservationCall(email, progressListener, progressRequestListener);
        Type wllocalVarReturnType = new TypeToken<ReservationsResponse>() {
        }.getType();
        wlapiClient.executeAsync(wlcall, wllocalVarReturnType, wlcallback);
        return wlcall;
    }
}