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.Media; import io.swagger.client.model.MediaCreation; import java.lang.reflect.Type; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; public class MediaApi { private ApiClient apiClient; public MediaApi() { this(Configuration.getDefaultApiClient()); } public MediaApi(ApiClient apiClient) { this.apiClient = apiClient; } public ApiClient getApiClient() { return apiClient; } public void setApiClient(ApiClient apiClient) { this.apiClient = apiClient; } /* Build call for mediaGet */ private com.squareup.okhttp.Call mediaGetCall(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 = "/media".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 registered Media * <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 Media * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body */ public Media mediaGet(Integer skip, Integer limit, String where, String sort) throws ApiException { ApiResponse<Media> resp = mediaGetWithHttpInfo(skip, limit, where, sort); return resp.getData(); } /** * Find all registered Media * <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<Media> * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body */ public ApiResponse<Media> mediaGetWithHttpInfo(Integer skip, Integer limit, String where, String sort) throws ApiException { com.squareup.okhttp.Call call = mediaGetCall(skip, limit, where, sort, null, null); Type localVarReturnType = new TypeToken<Media>() { }.getType(); return apiClient.execute(call, localVarReturnType); } /** * Find all registered Media (asynchronously) * <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 mediaGetAsync(Integer skip, Integer limit, String where, String sort, final ApiCallback<Media> 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 = mediaGetCall(skip, limit, where, sort, progressListener, progressRequestListener); Type localVarReturnType = new TypeToken<Media>() { }.getType(); apiClient.executeAsync(call, localVarReturnType, callback); return call; } /* Build call for mediaMediaIdDelete */ private com.squareup.okhttp.Call mediaMediaIdDeleteCall(Integer mediaId, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { Object localVarPostBody = null; // verify the required parameter 'mediaId' is set if (mediaId == null) { throw new ApiException( "Missing the required parameter 'mediaId' when calling mediaMediaIdDelete(Async)"); } // create path and map variables String localVarPath = "/media/{media_id}".replaceAll("\\{format\\}", "json") .replaceAll("\\{" + "media_id" + "\\}", apiClient.escapeString(mediaId.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 Media * <p><strong>Permissions:</strong> Respondent Customer Manager</p> * @param mediaId (required) * @return String * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body */ public String mediaMediaIdDelete(Integer mediaId) throws ApiException { ApiResponse<String> resp = mediaMediaIdDeleteWithHttpInfo(mediaId); return resp.getData(); } /** * Delete Media * <p><strong>Permissions:</strong> Respondent Customer Manager</p> * @param mediaId (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> mediaMediaIdDeleteWithHttpInfo(Integer mediaId) throws ApiException { com.squareup.okhttp.Call call = mediaMediaIdDeleteCall(mediaId, null, null); Type localVarReturnType = new TypeToken<String>() { }.getType(); return apiClient.execute(call, localVarReturnType); } /** * Delete Media (asynchronously) * <p><strong>Permissions:</strong> Respondent Customer Manager</p> * @param mediaId (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 mediaMediaIdDeleteAsync(Integer mediaId, 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 = mediaMediaIdDeleteCall(mediaId, progressListener, progressRequestListener); Type localVarReturnType = new TypeToken<String>() { }.getType(); apiClient.executeAsync(call, localVarReturnType, callback); return call; } /* Build call for mediaMediaIdGet */ private com.squareup.okhttp.Call mediaMediaIdGetCall(Integer mediaId, Boolean presignedUrl, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { Object localVarPostBody = null; // verify the required parameter 'mediaId' is set if (mediaId == null) { throw new ApiException("Missing the required parameter 'mediaId' when calling mediaMediaIdGet(Async)"); } // create path and map variables String localVarPath = "/media/{media_id}".replaceAll("\\{format\\}", "json") .replaceAll("\\{" + "media_id" + "\\}", apiClient.escapeString(mediaId.toString())); List<Pair> localVarQueryParams = new ArrayList<Pair>(); if (presignedUrl != null) localVarQueryParams.addAll(apiClient.parameterToPairs("", "presignedUrl", presignedUrl)); 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 Media * <p><strong>Permissions:</strong> Respondent Customer Manager</p> * @param mediaId ID of Media to search. (required) * @param presignedUrl Returns the presignedUrl whose value is a signed (protected) URL to hosted video on our premises. (optional) * @return List<Media> * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body */ public List<Media> mediaMediaIdGet(Integer mediaId, Boolean presignedUrl) throws ApiException { ApiResponse<List<Media>> resp = mediaMediaIdGetWithHttpInfo(mediaId, presignedUrl); return resp.getData(); } /** * Find a Media * <p><strong>Permissions:</strong> Respondent Customer Manager</p> * @param mediaId ID of Media to search. (required) * @param presignedUrl Returns the presignedUrl whose value is a signed (protected) URL to hosted video on our premises. (optional) * @return ApiResponse<List<Media>> * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body */ public ApiResponse<List<Media>> mediaMediaIdGetWithHttpInfo(Integer mediaId, Boolean presignedUrl) throws ApiException { com.squareup.okhttp.Call call = mediaMediaIdGetCall(mediaId, presignedUrl, null, null); Type localVarReturnType = new TypeToken<List<Media>>() { }.getType(); return apiClient.execute(call, localVarReturnType); } /** * Find a Media (asynchronously) * <p><strong>Permissions:</strong> Respondent Customer Manager</p> * @param mediaId ID of Media to search. (required) * @param presignedUrl Returns the presignedUrl whose value is a signed (protected) URL to hosted video on our premises. (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 mediaMediaIdGetAsync(Integer mediaId, Boolean presignedUrl, final ApiCallback<List<Media>> 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 = mediaMediaIdGetCall(mediaId, presignedUrl, progressListener, progressRequestListener); Type localVarReturnType = new TypeToken<List<Media>>() { }.getType(); apiClient.executeAsync(call, localVarReturnType, callback); return call; } /* Build call for mediaMediaIdPut */ private com.squareup.okhttp.Call mediaMediaIdPutCall(Integer mediaId, MediaCreation body, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { Object localVarPostBody = body; // verify the required parameter 'mediaId' is set if (mediaId == null) { throw new ApiException("Missing the required parameter 'mediaId' when calling mediaMediaIdPut(Async)"); } // verify the required parameter 'body' is set if (body == null) { throw new ApiException("Missing the required parameter 'body' when calling mediaMediaIdPut(Async)"); } // create path and map variables String localVarPath = "/media/{media_id}".replaceAll("\\{format\\}", "json") .replaceAll("\\{" + "media_id" + "\\}", apiClient.escapeString(mediaId.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); } /** * Update a Media * <p><strong>Permissions:</strong> Respondent Customer Manager</p> * @param mediaId (required) * @param body Request body (required) * @return Media * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body */ public Media mediaMediaIdPut(Integer mediaId, MediaCreation body) throws ApiException { ApiResponse<Media> resp = mediaMediaIdPutWithHttpInfo(mediaId, body); return resp.getData(); } /** * Update a Media * <p><strong>Permissions:</strong> Respondent Customer Manager</p> * @param mediaId (required) * @param body Request body (required) * @return ApiResponse<Media> * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body */ public ApiResponse<Media> mediaMediaIdPutWithHttpInfo(Integer mediaId, MediaCreation body) throws ApiException { com.squareup.okhttp.Call call = mediaMediaIdPutCall(mediaId, body, null, null); Type localVarReturnType = new TypeToken<Media>() { }.getType(); return apiClient.execute(call, localVarReturnType); } /** * Update a Media (asynchronously) * <p><strong>Permissions:</strong> Respondent Customer Manager</p> * @param mediaId (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 mediaMediaIdPutAsync(Integer mediaId, MediaCreation body, final ApiCallback<Media> 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 = mediaMediaIdPutCall(mediaId, body, progressListener, progressRequestListener); Type localVarReturnType = new TypeToken<Media>() { }.getType(); apiClient.executeAsync(call, localVarReturnType, callback); return call; } /* Build call for mediaPost */ private com.squareup.okhttp.Call mediaPostCall(MediaCreation 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 mediaPost(Async)"); } // create path and map variables String localVarPath = "/media".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 new Media * <p><strong>Permissions:</strong> Respondent Customer Manager</p> * @param body Request body (required) * @return Media * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body */ public Media mediaPost(MediaCreation body) throws ApiException { ApiResponse<Media> resp = mediaPostWithHttpInfo(body); return resp.getData(); } /** * Create new Media * <p><strong>Permissions:</strong> Respondent Customer Manager</p> * @param body Request body (required) * @return ApiResponse<Media> * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body */ public ApiResponse<Media> mediaPostWithHttpInfo(MediaCreation body) throws ApiException { com.squareup.okhttp.Call call = mediaPostCall(body, null, null); Type localVarReturnType = new TypeToken<Media>() { }.getType(); return apiClient.execute(call, localVarReturnType); } /** * Create new Media (asynchronously) * <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 mediaPostAsync(MediaCreation body, final ApiCallback<Media> 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 = mediaPostCall(body, progressListener, progressRequestListener); Type localVarReturnType = new TypeToken<Media>() { }.getType(); apiClient.executeAsync(call, localVarReturnType, callback); return call; } }