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.User; import io.swagger.client.model.UserUpdateBody; import io.swagger.client.model.LoginResponse; import io.swagger.client.model.Login; import io.swagger.client.model.UserMetadataResponse; import io.swagger.client.model.UserMetadata; import java.lang.reflect.Type; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; public class UserApi { private ApiClient apiClient; public UserApi() { this(Configuration.getDefaultApiClient()); } public UserApi(ApiClient apiClient) { this.apiClient = apiClient; } public ApiClient getApiClient() { return apiClient; } public void setApiClient(ApiClient apiClient) { this.apiClient = apiClient; } /* Build call for userIdGet */ private com.squareup.okhttp.Call userIdGetCall(Integer id, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { Object localVarPostBody = null; // verify the required parameter 'id' is set if (id == null) { throw new ApiException("Missing the required parameter 'id' when calling userIdGet(Async)"); } // create path and map variables String localVarPath = "/user/{id}".replaceAll("\\{format\\}", "json").replaceAll("\\{" + "id" + "\\}", apiClient.escapeString(id.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); } /** * Get User information * <p><strong>Permissions:</strong> Respondent Customer Manager</p> * @param id User unique ID (required) * @return User * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body */ public User userIdGet(Integer id) throws ApiException { ApiResponse<User> resp = userIdGetWithHttpInfo(id); return resp.getData(); } /** * Get User information * <p><strong>Permissions:</strong> Respondent Customer Manager</p> * @param id User unique ID (required) * @return ApiResponse<User> * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body */ public ApiResponse<User> userIdGetWithHttpInfo(Integer id) throws ApiException { com.squareup.okhttp.Call call = userIdGetCall(id, null, null); Type localVarReturnType = new TypeToken<User>() { }.getType(); return apiClient.execute(call, localVarReturnType); } /** * Get User information (asynchronously) * <p><strong>Permissions:</strong> Respondent Customer Manager</p> * @param id User unique ID (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 userIdGetAsync(Integer id, final ApiCallback<User> 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 = userIdGetCall(id, progressListener, progressRequestListener); Type localVarReturnType = new TypeToken<User>() { }.getType(); apiClient.executeAsync(call, localVarReturnType, callback); return call; } /* Build call for userIdPut */ private com.squareup.okhttp.Call userIdPutCall(String id, UserUpdateBody body, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { Object localVarPostBody = body; // verify the required parameter 'id' is set if (id == null) { throw new ApiException("Missing the required parameter 'id' when calling userIdPut(Async)"); } // verify the required parameter 'body' is set if (body == null) { throw new ApiException("Missing the required parameter 'body' when calling userIdPut(Async)"); } // create path and map variables String localVarPath = "/user/{id}".replaceAll("\\{format\\}", "json").replaceAll("\\{" + "id" + "\\}", apiClient.escapeString(id.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 User information * <p><strong>Permissions:</strong> Respondent Customer Manager</p> * @param id ID of User to update. (required) * @param body Request body (required) * @return User * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body */ public User userIdPut(String id, UserUpdateBody body) throws ApiException { ApiResponse<User> resp = userIdPutWithHttpInfo(id, body); return resp.getData(); } /** * Edit User information * <p><strong>Permissions:</strong> Respondent Customer Manager</p> * @param id ID of User to update. (required) * @param body Request body (required) * @return ApiResponse<User> * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body */ public ApiResponse<User> userIdPutWithHttpInfo(String id, UserUpdateBody body) throws ApiException { com.squareup.okhttp.Call call = userIdPutCall(id, body, null, null); Type localVarReturnType = new TypeToken<User>() { }.getType(); return apiClient.execute(call, localVarReturnType); } /** * Edit User information (asynchronously) * <p><strong>Permissions:</strong> Respondent Customer Manager</p> * @param id ID of User to update. (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 userIdPutAsync(String id, UserUpdateBody body, final ApiCallback<User> 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 = userIdPutCall(id, body, progressListener, progressRequestListener); Type localVarReturnType = new TypeToken<User>() { }.getType(); apiClient.executeAsync(call, localVarReturnType, callback); return call; } /* Build call for userLoginPost */ private com.squareup.okhttp.Call userLoginPostCall(Login 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 userLoginPost(Async)"); } // create path and map variables String localVarPath = "/user/login".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); } /** * User Login * <p><strong>Permissions:</strong> No authorization is required</p> * @param body Request body (required) * @return LoginResponse * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body */ public LoginResponse userLoginPost(Login body) throws ApiException { ApiResponse<LoginResponse> resp = userLoginPostWithHttpInfo(body); return resp.getData(); } /** * User Login * <p><strong>Permissions:</strong> No authorization is required</p> * @param body Request body (required) * @return ApiResponse<LoginResponse> * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body */ public ApiResponse<LoginResponse> userLoginPostWithHttpInfo(Login body) throws ApiException { com.squareup.okhttp.Call call = userLoginPostCall(body, null, null); Type localVarReturnType = new TypeToken<LoginResponse>() { }.getType(); return apiClient.execute(call, localVarReturnType); } /** * User Login (asynchronously) * <p><strong>Permissions:</strong> No authorization is required</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 userLoginPostAsync(Login body, final ApiCallback<LoginResponse> 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 = userLoginPostCall(body, progressListener, progressRequestListener); Type localVarReturnType = new TypeToken<LoginResponse>() { }.getType(); apiClient.executeAsync(call, localVarReturnType, callback); return call; } /* Build call for userUserIdMetadataGet */ private com.squareup.okhttp.Call userUserIdMetadataGetCall(Integer userId, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { Object localVarPostBody = null; // verify the required parameter 'userId' is set if (userId == null) { throw new ApiException( "Missing the required parameter 'userId' when calling userUserIdMetadataGet(Async)"); } // create path and map variables String localVarPath = "/user/{user_id}/metadata".replaceAll("\\{format\\}", "json") .replaceAll("\\{" + "user_id" + "\\}", apiClient.escapeString(userId.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 User metadata * <p><strong>Permissions:</strong> Respondent Customer Manager</p> * @param userId ID of User. (required) * @return UserMetadataResponse * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body */ public UserMetadataResponse userUserIdMetadataGet(Integer userId) throws ApiException { ApiResponse<UserMetadataResponse> resp = userUserIdMetadataGetWithHttpInfo(userId); return resp.getData(); } /** * Find User metadata * <p><strong>Permissions:</strong> Respondent Customer Manager</p> * @param userId ID of User. (required) * @return ApiResponse<UserMetadataResponse> * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body */ public ApiResponse<UserMetadataResponse> userUserIdMetadataGetWithHttpInfo(Integer userId) throws ApiException { com.squareup.okhttp.Call call = userUserIdMetadataGetCall(userId, null, null); Type localVarReturnType = new TypeToken<UserMetadataResponse>() { }.getType(); return apiClient.execute(call, localVarReturnType); } /** * Find User metadata (asynchronously) * <p><strong>Permissions:</strong> Respondent Customer Manager</p> * @param userId ID of User. (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 userUserIdMetadataGetAsync(Integer userId, final ApiCallback<UserMetadataResponse> 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 = userUserIdMetadataGetCall(userId, progressListener, progressRequestListener); Type localVarReturnType = new TypeToken<UserMetadataResponse>() { }.getType(); apiClient.executeAsync(call, localVarReturnType, callback); return call; } /* Build call for userUserIdMetadataPost */ private com.squareup.okhttp.Call userUserIdMetadataPostCall(Integer userId, UserMetadata body, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { Object localVarPostBody = body; // verify the required parameter 'userId' is set if (userId == null) { throw new ApiException( "Missing the required parameter 'userId' when calling userUserIdMetadataPost(Async)"); } // verify the required parameter 'body' is set if (body == null) { throw new ApiException( "Missing the required parameter 'body' when calling userUserIdMetadataPost(Async)"); } // create path and map variables String localVarPath = "/user/{user_id}/metadata".replaceAll("\\{format\\}", "json") .replaceAll("\\{" + "user_id" + "\\}", apiClient.escapeString(userId.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, "POST", localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAuthNames, progressRequestListener); } /** * Add user metadata * <p><strong>Permissions:</strong> Respondent Customer Manager</p> * @param userId ID of User. (required) * @param body Request body (required) * @return UserMetadataResponse * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body */ public UserMetadataResponse userUserIdMetadataPost(Integer userId, UserMetadata body) throws ApiException { ApiResponse<UserMetadataResponse> resp = userUserIdMetadataPostWithHttpInfo(userId, body); return resp.getData(); } /** * Add user metadata * <p><strong>Permissions:</strong> Respondent Customer Manager</p> * @param userId ID of User. (required) * @param body Request body (required) * @return ApiResponse<UserMetadataResponse> * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body */ public ApiResponse<UserMetadataResponse> userUserIdMetadataPostWithHttpInfo(Integer userId, UserMetadata body) throws ApiException { com.squareup.okhttp.Call call = userUserIdMetadataPostCall(userId, body, null, null); Type localVarReturnType = new TypeToken<UserMetadataResponse>() { }.getType(); return apiClient.execute(call, localVarReturnType); } /** * Add user metadata (asynchronously) * <p><strong>Permissions:</strong> Respondent Customer Manager</p> * @param userId ID of User. (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 userUserIdMetadataPostAsync(Integer userId, UserMetadata body, final ApiCallback<UserMetadataResponse> 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 = userUserIdMetadataPostCall(userId, body, progressListener, progressRequestListener); Type localVarReturnType = new TypeToken<UserMetadataResponse>() { }.getType(); apiClient.executeAsync(call, localVarReturnType, callback); return call; } }