|
| 1 | +/** |
| 2 | + * -------------------------------------------------------------------------------------------------------------------- |
| 3 | + * <copyright company="Aspose Pty Ltd" file="LicenseApi.java"> |
| 4 | + * Copyright (c) 2003-2021 Aspose Pty Ltd |
| 5 | + * </copyright> |
| 6 | + * <summary> |
| 7 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 8 | + * of this software and associated documentation files (the "Software"), to deal |
| 9 | + * in the Software without restriction, including without limitation the rights |
| 10 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 11 | + * copies of the Software, and to permit persons to whom the Software is |
| 12 | + * furnished to do so, subject to the following conditions: |
| 13 | + * |
| 14 | + * The above copyright notice and this permission notice shall be included in all |
| 15 | + * copies or substantial portions of the Software. |
| 16 | + * |
| 17 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 18 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 19 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 20 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 21 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 22 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 23 | + * SOFTWARE. |
| 24 | + * </summary> |
| 25 | + * -------------------------------------------------------------------------------------------------------------------- |
| 26 | + */ |
| 27 | + |
| 28 | +package com.groupdocs.cloud.viewer.api; |
| 29 | + |
| 30 | +import java.io.File; |
| 31 | +import java.io.IOException; |
| 32 | +import java.lang.reflect.Type; |
| 33 | +import java.util.ArrayList; |
| 34 | +import java.util.HashMap; |
| 35 | +import java.util.List; |
| 36 | +import java.util.Map; |
| 37 | + |
| 38 | +import com.google.gson.reflect.TypeToken; |
| 39 | +import com.groupdocs.cloud.viewer.client.*; |
| 40 | +import com.groupdocs.cloud.viewer.model.*; |
| 41 | +import com.groupdocs.cloud.viewer.model.requests.*; |
| 42 | + |
| 43 | +public class LicenseApi { |
| 44 | + private ApiClient apiClient; |
| 45 | + |
| 46 | + /** |
| 47 | + * Initializes new instance of LicenseApi |
| 48 | + * @param appSid Application identifier (App SID) |
| 49 | + * @param appKey Application private key (App Key) |
| 50 | + */ |
| 51 | + public LicenseApi(String appSid, String appKey) { |
| 52 | + this(new Configuration(appSid, appKey)); |
| 53 | + } |
| 54 | + |
| 55 | + /** |
| 56 | + * Initializes new instance of LicenseApi |
| 57 | + * @param configuration Configuration The configuration |
| 58 | + */ |
| 59 | + public LicenseApi(Configuration configuration) { |
| 60 | + this.apiClient = new ApiClient(configuration); |
| 61 | + } |
| 62 | + |
| 63 | + /** |
| 64 | + * Gets ApiClient |
| 65 | + * |
| 66 | + * @return ApiClient The Api client |
| 67 | + */ |
| 68 | + public ApiClient getApiClient() { |
| 69 | + return apiClient; |
| 70 | + } |
| 71 | + |
| 72 | + /** |
| 73 | + * Sets ApiClient |
| 74 | + * |
| 75 | + * @param apiClient The Api client |
| 76 | + */ |
| 77 | + public void setApiClient(ApiClient apiClient) { |
| 78 | + this.apiClient = apiClient; |
| 79 | + } |
| 80 | + |
| 81 | + /** |
| 82 | + * Build call for getConsumptionCredit |
| 83 | + * @param progressListener Progress listener |
| 84 | + * @param progressRequestListener Progress request listener |
| 85 | + * @return Call to execute |
| 86 | + * @throws ApiException If fail to serialize the request body object |
| 87 | + */ |
| 88 | + public com.squareup.okhttp.Call getConsumptionCreditCall(final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { |
| 89 | + Object localVarPostBody = null; |
| 90 | + |
| 91 | + // create path and map variables |
| 92 | + String localVarPath = "/viewer/consumption"; |
| 93 | + |
| 94 | + List<Pair> localVarQueryParams = new ArrayList<Pair>(); |
| 95 | + List<Pair> localVarCollectionQueryParams = new ArrayList<Pair>(); |
| 96 | + |
| 97 | + Map<String, String> localVarHeaderParams = new HashMap<String, String>(); |
| 98 | + |
| 99 | + Map<String, Object> localVarFormParams = new HashMap<String, Object>(); |
| 100 | + |
| 101 | + final String[] localVarAccepts = { |
| 102 | + "application/json" |
| 103 | + }; |
| 104 | + final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts); |
| 105 | + if (localVarAccept != null) localVarHeaderParams.put("Accept", localVarAccept); |
| 106 | + |
| 107 | + final String[] localVarContentTypes = { |
| 108 | + "application/json" |
| 109 | + }; |
| 110 | + final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes); |
| 111 | + localVarHeaderParams.put("Content-Type", localVarContentType); |
| 112 | + |
| 113 | + if(progressListener != null) { |
| 114 | + apiClient.getHttpClient().networkInterceptors().add(new com.squareup.okhttp.Interceptor() { |
| 115 | + @Override |
| 116 | + public com.squareup.okhttp.Response intercept(com.squareup.okhttp.Interceptor.Chain chain) throws IOException { |
| 117 | + com.squareup.okhttp.Response originalResponse = chain.proceed(chain.request()); |
| 118 | + return originalResponse.newBuilder() |
| 119 | + .body(new ProgressResponseBody(originalResponse.body(), progressListener)) |
| 120 | + .build(); |
| 121 | + } |
| 122 | + }); |
| 123 | + } |
| 124 | + |
| 125 | + String[] localVarAuthNames = new String[] { "JWT" }; |
| 126 | + return apiClient.buildCall(localVarPath, "GET", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAuthNames, progressRequestListener); |
| 127 | + } |
| 128 | + |
| 129 | + @SuppressWarnings("rawtypes") |
| 130 | + private com.squareup.okhttp.Call getConsumptionCreditValidateBeforeCall(final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { |
| 131 | + |
| 132 | + |
| 133 | + com.squareup.okhttp.Call call = getConsumptionCreditCall(progressListener, progressRequestListener); |
| 134 | + return call; |
| 135 | + |
| 136 | + } |
| 137 | + |
| 138 | + /** |
| 139 | + * Get license consumption |
| 140 | + * |
| 141 | + * @return ConsumptionResult |
| 142 | + * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body |
| 143 | + */ |
| 144 | + public ConsumptionResult getConsumptionCredit() throws ApiException { |
| 145 | + ApiResponse<ConsumptionResult> resp = getConsumptionCreditWithHttpInfo(); |
| 146 | + return resp.getData(); |
| 147 | + } |
| 148 | + |
| 149 | + /** |
| 150 | + * Get license consumption |
| 151 | + * |
| 152 | + * @return ApiResponse<ConsumptionResult> |
| 153 | + * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body |
| 154 | + */ |
| 155 | + public ApiResponse<ConsumptionResult> getConsumptionCreditWithHttpInfo() throws ApiException { |
| 156 | + com.squareup.okhttp.Call call = getConsumptionCreditValidateBeforeCall(null, null); |
| 157 | + Type localVarReturnType = new TypeToken<ConsumptionResult>(){}.getType(); |
| 158 | + return apiClient.execute(call, localVarReturnType); |
| 159 | + } |
| 160 | + |
| 161 | + /** |
| 162 | + * Get license consumption (asynchronously) |
| 163 | + * |
| 164 | + * @param callback The callback to be executed when the API call finishes |
| 165 | + * @return The request call |
| 166 | + * @throws ApiException If fail to process the API call, e.g. serializing the request body object |
| 167 | + */ |
| 168 | + public com.squareup.okhttp.Call getConsumptionCreditAsync(final ApiCallback<ConsumptionResult> callback) throws ApiException { |
| 169 | + |
| 170 | + ProgressResponseBody.ProgressListener progressListener = null; |
| 171 | + ProgressRequestBody.ProgressRequestListener progressRequestListener = null; |
| 172 | + |
| 173 | + if (callback != null) { |
| 174 | + progressListener = new ProgressResponseBody.ProgressListener() { |
| 175 | + @Override |
| 176 | + public void update(long bytesRead, long contentLength, boolean done) { |
| 177 | + callback.onDownloadProgress(bytesRead, contentLength, done); |
| 178 | + } |
| 179 | + }; |
| 180 | + |
| 181 | + progressRequestListener = new ProgressRequestBody.ProgressRequestListener() { |
| 182 | + @Override |
| 183 | + public void onRequestProgress(long bytesWritten, long contentLength, boolean done) { |
| 184 | + callback.onUploadProgress(bytesWritten, contentLength, done); |
| 185 | + } |
| 186 | + }; |
| 187 | + } |
| 188 | + |
| 189 | + com.squareup.okhttp.Call call = getConsumptionCreditValidateBeforeCall(progressListener, progressRequestListener); |
| 190 | + Type localVarReturnType = new TypeToken<ConsumptionResult>(){}.getType(); |
| 191 | + apiClient.executeAsync(call, localVarReturnType, callback); |
| 192 | + return call; |
| 193 | + } |
| 194 | +} |
| 195 | + |
0 commit comments