Java tutorial
/** * 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.SiteResponse; import co.waitlisted.models.ErrorResponse; import java.lang.reflect.Type; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; public class SiteApi { private ApiClient wlapiClient; public SiteApi() { this(Configuration.getDefaultApiClient()); } public SiteApi(ApiClient apiClient) { this.wlapiClient = apiClient; } public ApiClient getApiClient() { return wlapiClient; } public void setApiClient(ApiClient apiClient) { this.wlapiClient = apiClient; } /* Build call for getSite */ private com.squareup.okhttp.Call getSiteCall(final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { Object wllocalVarPostBody = null; // create path and map variables String wllocalVarPath = "/site".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, "GET", wllocalVarQueryParams, wllocalVarPostBody, wllocalVarHeaderParams, wllocalVarFormParams, wllocalVarAuthNames, progressRequestListener); } /** * * Get site settings and reservation count. * @return SiteResponse * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body */ public SiteResponse getSite() throws ApiException { ApiResponse<SiteResponse> wlresp = getSiteWithHttpInfo(); return wlresp.getData(); } /** * * Get site settings and reservation count. * @return ApiResponse<SiteResponse> * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body */ public ApiResponse<SiteResponse> getSiteWithHttpInfo() throws ApiException { com.squareup.okhttp.Call wlcall = getSiteCall(null, null); Type wllocalVarReturnType = new TypeToken<SiteResponse>() { }.getType(); return wlapiClient.execute(wlcall, wllocalVarReturnType); } /** * (asynchronously) * Get site settings and reservation count. * @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 getSiteAsync(final ApiCallback<SiteResponse> 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 = getSiteCall(progressListener, progressRequestListener); Type wllocalVarReturnType = new TypeToken<SiteResponse>() { }.getType(); wlapiClient.executeAsync(wlcall, wllocalVarReturnType, wlcallback); return wlcall; } }