Java tutorial
/** * 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.Research; import io.swagger.client.model.ResearchCreation; import java.lang.reflect.Type; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; public class ResearchApi { private ApiClient apiClient; public ResearchApi() { this(Configuration.getDefaultApiClient()); } public ResearchApi(ApiClient apiClient) { this.apiClient = apiClient; } public ApiClient getApiClient() { return apiClient; } public void setApiClient(ApiClient apiClient) { this.apiClient = apiClient; } /* Build call for researchGet */ private com.squareup.okhttp.Call researchGetCall(Integer skip, Integer limit, String where, String sort, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { Object localVarPostBody = null; // create path and map variables String localVarPath = "/research".replaceAll("\\{format\\}", "json"); List<Pair> localVarQueryParams = new ArrayList<Pair>(); if (skip != null) localVarQueryParams.addAll(apiClient.parameterToPairs("", "skip", skip)); if (limit != null) localVarQueryParams.addAll(apiClient.parameterToPairs("", "limit", limit)); if (where != null) localVarQueryParams.addAll(apiClient.parameterToPairs("", "where", where)); if (sort != null) localVarQueryParams.addAll(apiClient.parameterToPairs("", "sort", sort)); 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); } /** * Find all Research * <p>Returns all the Research created by an admin user.</p> <p><strong>Permissions:</strong> Respondent Customer Manager</p> * @param skip The number of results to skip. (optional) * @param limit The maximum number of results to return. (optional) * @param where JSON formatted string condition. (optional) * @param sort Attribute used to sort results. (optional) * @return List<Research> * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body */ public List<Research> researchGet(Integer skip, Integer limit, String where, String sort) throws ApiException { ApiResponse<List<Research>> resp = researchGetWithHttpInfo(skip, limit, where, sort); return resp.getData(); } /** * Find all Research * <p>Returns all the Research created by an admin user.</p> <p><strong>Permissions:</strong> Respondent Customer Manager</p> * @param skip The number of results to skip. (optional) * @param limit The maximum number of results to return. (optional) * @param where JSON formatted string condition. (optional) * @param sort Attribute used to sort results. (optional) * @return ApiResponse<List<Research>> * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body */ public ApiResponse<List<Research>> researchGetWithHttpInfo(Integer skip, Integer limit, String where, String sort) throws ApiException { com.squareup.okhttp.Call call = researchGetCall(skip, limit, where, sort, null, null); Type localVarReturnType = new TypeToken<List<Research>>() { }.getType(); return apiClient.execute(call, localVarReturnType); } /** * Find all Research (asynchronously) * <p>Returns all the Research created by an admin user.</p> <p><strong>Permissions:</strong> Respondent Customer Manager</p> * @param skip The number of results to skip. (optional) * @param limit The maximum number of results to return. (optional) * @param where JSON formatted string condition. (optional) * @param sort Attribute used to sort results. (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 researchGetAsync(Integer skip, Integer limit, String where, String sort, final ApiCallback<List<Research>> 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 = researchGetCall(skip, limit, where, sort, progressListener, progressRequestListener); Type localVarReturnType = new TypeToken<List<Research>>() { }.getType(); apiClient.executeAsync(call, localVarReturnType, callback); return call; } /* Build call for researchPost */ private com.squareup.okhttp.Call researchPostCall(ResearchCreation body, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { Object localVarPostBody = body; // verify the required parameter 'body' is set if (body == null) { throw new ApiException("Missing the required parameter 'body' when calling researchPost(Async)"); } // create path and map variables String localVarPath = "/research".replaceAll("\\{format\\}", "json"); List<Pair> localVarQueryParams = new ArrayList<Pair>(); 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, "POST", localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAuthNames, progressRequestListener); } /** * Create a Research Project * <p>New research projects can only be created with an admin account.</p> <p><strong>Permissions:</strong> Respondent Customer Manager</p> * @param body Request body (required) * @return Research * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body */ public Research researchPost(ResearchCreation body) throws ApiException { ApiResponse<Research> resp = researchPostWithHttpInfo(body); return resp.getData(); } /** * Create a Research Project * <p>New research projects can only be created with an admin account.</p> <p><strong>Permissions:</strong> Respondent Customer Manager</p> * @param body Request body (required) * @return ApiResponse<Research> * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body */ public ApiResponse<Research> researchPostWithHttpInfo(ResearchCreation body) throws ApiException { com.squareup.okhttp.Call call = researchPostCall(body, null, null); Type localVarReturnType = new TypeToken<Research>() { }.getType(); return apiClient.execute(call, localVarReturnType); } /** * Create a Research Project (asynchronously) * <p>New research projects can only be created with an admin account.</p> <p><strong>Permissions:</strong> Respondent Customer Manager</p> * @param body Request body (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 researchPostAsync(ResearchCreation body, final ApiCallback<Research> 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 = researchPostCall(body, progressListener, progressRequestListener); Type localVarReturnType = new TypeToken<Research>() { }.getType(); apiClient.executeAsync(call, localVarReturnType, callback); return call; } /* Build call for researchResearchIdDelete */ private com.squareup.okhttp.Call researchResearchIdDeleteCall(Integer researchId, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { Object localVarPostBody = null; // verify the required parameter 'researchId' is set if (researchId == null) { throw new ApiException( "Missing the required parameter 'researchId' when calling researchResearchIdDelete(Async)"); } // create path and map variables String localVarPath = "/research/{research_id}".replaceAll("\\{format\\}", "json") .replaceAll("\\{" + "research_id" + "\\}", apiClient.escapeString(researchId.toString())); List<Pair> localVarQueryParams = new ArrayList<Pair>(); 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 Research Project * <p><strong>Permissions:</strong> Respondent Customer Manager</p> * @param researchId (required) * @return String * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body */ public String researchResearchIdDelete(Integer researchId) throws ApiException { ApiResponse<String> resp = researchResearchIdDeleteWithHttpInfo(researchId); return resp.getData(); } /** * Delete Research Project * <p><strong>Permissions:</strong> Respondent Customer Manager</p> * @param researchId (required) * @return ApiResponse<String> * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body */ public ApiResponse<String> researchResearchIdDeleteWithHttpInfo(Integer researchId) throws ApiException { com.squareup.okhttp.Call call = researchResearchIdDeleteCall(researchId, null, null); Type localVarReturnType = new TypeToken<String>() { }.getType(); return apiClient.execute(call, localVarReturnType); } /** * Delete Research Project (asynchronously) * <p><strong>Permissions:</strong> Respondent Customer Manager</p> * @param researchId (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 researchResearchIdDeleteAsync(Integer researchId, 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 = researchResearchIdDeleteCall(researchId, progressListener, progressRequestListener); Type localVarReturnType = new TypeToken<String>() { }.getType(); apiClient.executeAsync(call, localVarReturnType, callback); return call; } /* Build call for researchResearchIdGet */ private com.squareup.okhttp.Call researchResearchIdGetCall(Integer researchId, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { Object localVarPostBody = null; // verify the required parameter 'researchId' is set if (researchId == null) { throw new ApiException( "Missing the required parameter 'researchId' when calling researchResearchIdGet(Async)"); } // create path and map variables String localVarPath = "/research/{research_id}".replaceAll("\\{format\\}", "json") .replaceAll("\\{" + "research_id" + "\\}", apiClient.escapeString(researchId.toString())); List<Pair> localVarQueryParams = new ArrayList<Pair>(); 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); } /** * Find a Research Project * <p><strong>Permissions:</strong> Respondent Customer Manager</p> * @param researchId ID of Research Project to be found. (required) * @return Research * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body */ public Research researchResearchIdGet(Integer researchId) throws ApiException { ApiResponse<Research> resp = researchResearchIdGetWithHttpInfo(researchId); return resp.getData(); } /** * Find a Research Project * <p><strong>Permissions:</strong> Respondent Customer Manager</p> * @param researchId ID of Research Project to be found. (required) * @return ApiResponse<Research> * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body */ public ApiResponse<Research> researchResearchIdGetWithHttpInfo(Integer researchId) throws ApiException { com.squareup.okhttp.Call call = researchResearchIdGetCall(researchId, null, null); Type localVarReturnType = new TypeToken<Research>() { }.getType(); return apiClient.execute(call, localVarReturnType); } /** * Find a Research Project (asynchronously) * <p><strong>Permissions:</strong> Respondent Customer Manager</p> * @param researchId ID of Research Project to be found. (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 researchResearchIdGetAsync(Integer researchId, final ApiCallback<Research> 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 = researchResearchIdGetCall(researchId, progressListener, progressRequestListener); Type localVarReturnType = new TypeToken<Research>() { }.getType(); apiClient.executeAsync(call, localVarReturnType, callback); return call; } /* Build call for researchResearchIdPut */ private com.squareup.okhttp.Call researchResearchIdPutCall(Integer researchId, ResearchCreation body, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { Object localVarPostBody = body; // verify the required parameter 'researchId' is set if (researchId == null) { throw new ApiException( "Missing the required parameter 'researchId' when calling researchResearchIdPut(Async)"); } // verify the required parameter 'body' is set if (body == null) { throw new ApiException( "Missing the required parameter 'body' when calling researchResearchIdPut(Async)"); } // create path and map variables String localVarPath = "/research/{research_id}".replaceAll("\\{format\\}", "json") .replaceAll("\\{" + "research_id" + "\\}", apiClient.escapeString(researchId.toString())); List<Pair> localVarQueryParams = new ArrayList<Pair>(); 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, "PUT", localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAuthNames, progressRequestListener); } /** * Edit Research Project details * <p><strong>Permissions:</strong> Respondent Customer Manager</p> * @param researchId (required) * @param body Request body (required) * @return Research * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body */ public Research researchResearchIdPut(Integer researchId, ResearchCreation body) throws ApiException { ApiResponse<Research> resp = researchResearchIdPutWithHttpInfo(researchId, body); return resp.getData(); } /** * Edit Research Project details * <p><strong>Permissions:</strong> Respondent Customer Manager</p> * @param researchId (required) * @param body Request body (required) * @return ApiResponse<Research> * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body */ public ApiResponse<Research> researchResearchIdPutWithHttpInfo(Integer researchId, ResearchCreation body) throws ApiException { com.squareup.okhttp.Call call = researchResearchIdPutCall(researchId, body, null, null); Type localVarReturnType = new TypeToken<Research>() { }.getType(); return apiClient.execute(call, localVarReturnType); } /** * Edit Research Project details (asynchronously) * <p><strong>Permissions:</strong> Respondent Customer Manager</p> * @param researchId (required) * @param body Request body (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 researchResearchIdPutAsync(Integer researchId, ResearchCreation body, final ApiCallback<Research> 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 = researchResearchIdPutCall(researchId, body, progressListener, progressRequestListener); Type localVarReturnType = new TypeToken<Research>() { }.getType(); apiClient.executeAsync(call, localVarReturnType, callback); return call; } }