|
33 | 33 | import okhttp3.Response; |
34 | 34 | import okhttp3.ResponseBody; |
35 | 35 | import org.jetbrains.annotations.NotNull; |
36 | | -import so.trophy.resources.admin.points.boosts.requests.BoostsBatchArchiveRequest; |
| 36 | +import so.trophy.resources.admin.points.boosts.requests.BoostsDeleteRequest; |
37 | 37 | import so.trophy.resources.admin.points.boosts.requests.CreatePointsBoostsRequest; |
38 | 38 | import so.trophy.types.CreatePointsBoostsResponse; |
39 | 39 | import so.trophy.types.DeletePointsBoostsResponse; |
@@ -123,25 +123,25 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { |
123 | 123 | } |
124 | 124 |
|
125 | 125 | /** |
126 | | - * Archive multiple points boosts by ID. |
| 126 | + * Delete multiple points boosts by ID. |
127 | 127 | */ |
128 | | - public CompletableFuture<TrophyApiHttpResponse<DeletePointsBoostsResponse>> batchArchive() { |
129 | | - return batchArchive(BoostsBatchArchiveRequest.builder().build()); |
| 128 | + public CompletableFuture<TrophyApiHttpResponse<DeletePointsBoostsResponse>> delete() { |
| 129 | + return delete(BoostsDeleteRequest.builder().build()); |
130 | 130 | } |
131 | 131 |
|
132 | 132 | /** |
133 | | - * Archive multiple points boosts by ID. |
| 133 | + * Delete multiple points boosts by ID. |
134 | 134 | */ |
135 | | - public CompletableFuture<TrophyApiHttpResponse<DeletePointsBoostsResponse>> batchArchive( |
136 | | - BoostsBatchArchiveRequest request) { |
137 | | - return batchArchive(request,null); |
| 135 | + public CompletableFuture<TrophyApiHttpResponse<DeletePointsBoostsResponse>> delete( |
| 136 | + BoostsDeleteRequest request) { |
| 137 | + return delete(request,null); |
138 | 138 | } |
139 | 139 |
|
140 | 140 | /** |
141 | | - * Archive multiple points boosts by ID. |
| 141 | + * Delete multiple points boosts by ID. |
142 | 142 | */ |
143 | | - public CompletableFuture<TrophyApiHttpResponse<DeletePointsBoostsResponse>> batchArchive( |
144 | | - BoostsBatchArchiveRequest request, RequestOptions requestOptions) { |
| 143 | + public CompletableFuture<TrophyApiHttpResponse<DeletePointsBoostsResponse>> delete( |
| 144 | + BoostsDeleteRequest request, RequestOptions requestOptions) { |
145 | 145 | HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getAdminURL()).newBuilder() |
146 | 146 |
|
147 | 147 | .addPathSegments("points/boosts");if (request.getIds().isPresent()) { |
@@ -193,70 +193,4 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { |
193 | 193 | }); |
194 | 194 | return future; |
195 | 195 | } |
196 | | - |
197 | | - /** |
198 | | - * Archive a points boost by ID. |
199 | | - */ |
200 | | - public CompletableFuture<TrophyApiHttpResponse<DeletePointsBoostsResponse>> archive(String id) { |
201 | | - return archive(id,null); |
202 | | - } |
203 | | - |
204 | | - /** |
205 | | - * Archive a points boost by ID. |
206 | | - */ |
207 | | - public CompletableFuture<TrophyApiHttpResponse<DeletePointsBoostsResponse>> archive(String id, |
208 | | - RequestOptions requestOptions) { |
209 | | - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getAdminURL()).newBuilder() |
210 | | - |
211 | | - .addPathSegments("points/boosts") |
212 | | - .addPathSegment(id) |
213 | | - .build(); |
214 | | - Request okhttpRequest = new Request.Builder() |
215 | | - .url(httpUrl) |
216 | | - .method("DELETE", null) |
217 | | - .headers(Headers.of(clientOptions.headers(requestOptions))) |
218 | | - .addHeader("Accept", "application/json") |
219 | | - .build(); |
220 | | - OkHttpClient client = clientOptions.httpClient(); |
221 | | - if (requestOptions != null && requestOptions.getTimeout().isPresent()) { |
222 | | - client = clientOptions.httpClientWithTimeout(requestOptions); |
223 | | - } |
224 | | - CompletableFuture<TrophyApiHttpResponse<DeletePointsBoostsResponse>> future = new CompletableFuture<>(); |
225 | | - client.newCall(okhttpRequest).enqueue(new Callback() { |
226 | | - @Override |
227 | | - public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { |
228 | | - try (ResponseBody responseBody = response.body()) { |
229 | | - if (response.isSuccessful()) { |
230 | | - future.complete(new TrophyApiHttpResponse<>(ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), DeletePointsBoostsResponse.class), response)); |
231 | | - return; |
232 | | - } |
233 | | - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; |
234 | | - try { |
235 | | - switch (response.code()) { |
236 | | - case 400:future.completeExceptionally(new BadRequestError(ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ErrorBody.class), response)); |
237 | | - return; |
238 | | - case 401:future.completeExceptionally(new UnauthorizedError(ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ErrorBody.class), response)); |
239 | | - return; |
240 | | - case 404:future.completeExceptionally(new NotFoundError(ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ErrorBody.class), response)); |
241 | | - return; |
242 | | - } |
243 | | - } |
244 | | - catch (JsonProcessingException ignored) { |
245 | | - // unable to map error response, throwing generic error |
246 | | - } |
247 | | - future.completeExceptionally(new TrophyApiApiException("Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response)); |
248 | | - return; |
249 | | - } |
250 | | - catch (IOException e) { |
251 | | - future.completeExceptionally(new TrophyApiException("Network error executing HTTP request", e)); |
252 | | - } |
253 | | - } |
254 | | - |
255 | | - @Override |
256 | | - public void onFailure(@NotNull Call call, @NotNull IOException e) { |
257 | | - future.completeExceptionally(new TrophyApiException("Network error executing HTTP request", e)); |
258 | | - } |
259 | | - }); |
260 | | - return future; |
261 | | - } |
262 | 196 | } |
0 commit comments