diff --git a/.spec-sha256 b/.spec-sha256 index ebd3a33..bbe8884 100644 --- a/.spec-sha256 +++ b/.spec-sha256 @@ -1 +1 @@ -06a7c92e23df7c44f8898a2b18abec43aa5c14b8f12ea10e1ce65a94a14a0fb4 +e8f81ea407d93977cf0612e9d7e4bbda4b86c4d25de84bf44152b2ff868cde03 diff --git a/README.md b/README.md index c4f6588..477ae32 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,8 @@ client.conversations().list(null, null, null, null, null, null, "BUYER_ID", null // Writes (API key with items:write / conversations:write); the last argument, optional, is the Idempotency-Key. client.items().create(new ItemCreateRequest().name("Jacket")); // items().update(42, new ItemUpdateRequest()...) patches client.items().publish(42, new PublishRequest().accountIds(List.of(accountId))); +FileUpload photo = client.files().upload(Files.readAllBytes(Path.of("jacket.jpg")), "jacket.jpg", "image/jpeg"); // registers the photo and PUTs its bytes; files().register only registers it, files().get reads it (status is PENDING until its bytes are stored) +client.items().create(new ItemCreateRequest().name("Jacket").photoIds(List.of(photo.getId()))); client.items().publish(42, new PublishRequest().accountIds(List.of(accountId)).scheduledAt(OffsetDateTime.parse("2026-11-02T10:00:00Z"))); // publish, priceDrop and republish take an optional scheduledAt, at most 30 days ahead; without it they run now client.conversations().sendMessage(conversationId, new SendMessageRequest().text("Hello!")); diff --git a/src/main/java/com/controlresell/sdk/ControlResell.java b/src/main/java/com/controlresell/sdk/ControlResell.java index 0533c1e..3211cf1 100644 --- a/src/main/java/com/controlresell/sdk/ControlResell.java +++ b/src/main/java/com/controlresell/sdk/ControlResell.java @@ -7,6 +7,7 @@ import com.controlresell.sdk.generated.api.ConversationsApi; import com.controlresell.sdk.generated.api.CustomersApi; import com.controlresell.sdk.generated.api.FavoritesApi; +import com.controlresell.sdk.generated.api.FilesApi; import com.controlresell.sdk.generated.api.ItemsApi; import com.controlresell.sdk.generated.api.MeApi; import com.controlresell.sdk.generated.api.OrdersApi; @@ -28,6 +29,9 @@ import com.controlresell.sdk.generated.model.Customer; import com.controlresell.sdk.generated.model.CustomerPage; import com.controlresell.sdk.generated.model.Favorite; +import com.controlresell.sdk.generated.model.FileUpload; +import com.controlresell.sdk.generated.model.FileUploadRequest; +import com.controlresell.sdk.generated.model.ModelFile; import com.controlresell.sdk.generated.model.FavoritePage; import com.controlresell.sdk.generated.model.Item; import com.controlresell.sdk.generated.model.ItemCreateRequest; @@ -62,7 +66,11 @@ import com.controlresell.sdk.generated.model.WebhookSecretRotateRequest; import com.controlresell.sdk.generated.model.WebhookTestResult; import com.fasterxml.jackson.databind.ObjectMapper; +import java.io.IOException; +import java.net.URI; import java.net.http.HttpClient; +import java.net.http.HttpRequest; +import java.net.http.HttpResponse; import java.time.Duration; import java.time.OffsetDateTime; import java.util.List; @@ -101,6 +109,8 @@ public interface HttpCall { private final ApiClient apiClient; private final Retrier retrier; + private final HttpClient storage; + private final Duration timeout; /** A client for {@code apiKey}, on the production API. */ public ControlResell(String apiKey) { @@ -114,6 +124,9 @@ private ControlResell(Builder b) { } ObjectMapper mapper = ApiClient.createDefaultObjectMapper(); HttpClient.Builder http = b.httpClient != null ? b.httpClient : ApiClient.createDefaultHttpClientBuilder(); + // The bytes of a file go to the signed storage address, without the API key. + this.storage = http.build(); + this.timeout = b.timeout; this.apiClient = new ApiClient(http, mapper, b.baseUrl); this.apiClient.setReadTimeout(b.timeout); this.apiClient.setRequestInterceptor(request -> request @@ -183,6 +196,9 @@ private T callOnce(HttpCall call) { /** The other parties of the seller's sales and purchases (needs the {@code customers:read} scope). */ public Customers customers() { return new Customers(); } + /** The photos of the seller's library: register one, send its bytes, read it (needs {@code items:write} / {@code items:read}). */ + public Files files() { return new Files(); } + /** The buyers who put the seller's listings in their favorites (needs the {@code items:read} scope). */ public Favorites favorites() { return new Favorites(); } @@ -192,6 +208,64 @@ private T callOnce(HttpCall call) { /** The seller's webhook endpoints, their secrets and deliveries, and the recent events (webhooks:read, webhooks:write). */ public Webhooks webhooks() { return new Webhooks(); } + /** The photos of the seller's library. Put the identifier of a registered file in {@code photoIds} of an item. */ + public final class Files { + private final FilesApi api = new FilesApi(apiClient); + + private Files() {} + + /** + * Registers a file (jpeg, png, webp, heic or heif, at most 20 MiB): its identifier and the address where to + * {@code PUT} its bytes within 30 minutes. {@code idempotencyKey} may be {@code null}. + */ + public FileUpload register(String filename, String contentType, long size, String idempotencyKey) { + String key = key(idempotencyKey); + FileUploadRequest request = new FileUploadRequest().filename(filename).contentType(contentType).size(size); + return call(false, h -> api.uploadFile(key, request)); + } + + /** One file of the library, with a signed link to read it; its status is {@code PENDING} until its bytes are stored. */ + public ModelFile get(UUID id) { return call(false, h -> api.getFile(id, h)); } + + /** Registers a file and sends its bytes, with a random {@code Idempotency-Key}; see {@link #upload(byte[], String, String, String)}. */ + public FileUpload upload(byte[] data, String filename, String contentType) { + return upload(data, filename, contentType, null); + } + + /** + * Registers a file and sends its bytes (an HTTP {@code PUT} with the same {@code Content-Type}, no API key), and + * returns the registration: put its id in {@code photoIds}. The {@code PUT} is retried like any call; a refused + * one is thrown as a {@link ControlResellError} (the file stays {@code PENDING}). + */ + public FileUpload upload(byte[] data, String filename, String contentType, String idempotencyKey) { + FileUpload upload = register(filename, contentType, data.length, idempotencyKey); + if (upload.getUploadUrl() == null || upload.getUploadUrl().isBlank()) { + throw new IllegalStateException("The API returned no upload address for file " + upload.getId()); + } + HttpRequest request = HttpRequest.newBuilder(URI.create(upload.getUploadUrl())) + .timeout(timeout) + .header("Content-Type", contentType) + .header("User-Agent", "controlresell-java/" + VERSION) + .PUT(HttpRequest.BodyPublishers.ofByteArray(data)) + .build(); + call(false, h -> { + try { + HttpResponse response = storage.send(request, HttpResponse.BodyHandlers.ofByteArray()); + if (response.statusCode() / 100 != 2) { + throw new ApiException(response.statusCode(), "HTTP " + response.statusCode(), response.headers(), null); + } + return response.statusCode(); + } catch (IOException e) { + throw new ApiException(e); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + throw new ApiException(e); + } + }); + return upload; + } + } + /** The seller the API key acts for. */ public final class MeResource { private final MeApi api = new MeApi(apiClient); diff --git a/src/main/java/com/controlresell/sdk/generated/api/FilesApi.java b/src/main/java/com/controlresell/sdk/generated/api/FilesApi.java new file mode 100644 index 0000000..53ec2f3 --- /dev/null +++ b/src/main/java/com/controlresell/sdk/generated/api/FilesApi.java @@ -0,0 +1,421 @@ +/* + * ControlResell public API + * The public API of ControlResell. Every error answers `{\"error\": {\"code\", \"message\", \"params\", \"requestId\"}}`; a `POST` takes an `Idempotency-Key` header. + * + * The version of the OpenAPI document: 1 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.controlresell.sdk.generated.api; + +import com.controlresell.sdk.generated.ApiClient; +import com.controlresell.sdk.generated.ApiException; +import com.controlresell.sdk.generated.ApiResponse; +import com.controlresell.sdk.generated.Configuration; +import com.controlresell.sdk.generated.Pair; + +import com.controlresell.sdk.generated.model.ErrorResponse; +import com.controlresell.sdk.generated.model.FileUpload; +import com.controlresell.sdk.generated.model.FileUploadRequest; +import com.controlresell.sdk.generated.model.ModelFile; +import java.util.UUID; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; + +import java.io.InputStream; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.IOException; +import java.io.OutputStream; +import java.net.http.HttpRequest; +import java.nio.channels.Channels; +import java.nio.channels.Pipe; +import java.net.URI; +import java.net.http.HttpClient; +import java.net.http.HttpRequest; +import java.net.http.HttpResponse; +import java.time.Duration; + +import java.util.ArrayList; +import java.util.StringJoiner; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.function.Consumer; + +@jakarta.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "Generator version: 7.26.0") +public class FilesApi { + /** + * Utility class for extending HttpRequest.Builder functionality. + */ + private static class HttpRequestBuilderExtensions { + /** + * Adds additional headers to the provided HttpRequest.Builder. Useful for adding method/endpoint specific headers. + * + * @param builder the HttpRequest.Builder to which headers will be added + * @param headers a map of header names and values to add; may be null + * @return the same HttpRequest.Builder instance with the additional headers set + */ + static HttpRequest.Builder withAdditionalHeaders(HttpRequest.Builder builder, Map headers) { + if (headers != null) { + for (Map.Entry entry : headers.entrySet()) { + builder.header(entry.getKey(), entry.getValue()); + } + } + return builder; + } + } + private final HttpClient memberVarHttpClient; + private final ObjectMapper memberVarObjectMapper; + private final String memberVarBaseUri; + private final Consumer memberVarInterceptor; + private final Duration memberVarReadTimeout; + private final Consumer> memberVarResponseInterceptor; + private final Consumer> memberVarAsyncResponseInterceptor; + + public FilesApi() { + this(Configuration.getDefaultApiClient()); + } + + public FilesApi(ApiClient apiClient) { + memberVarHttpClient = apiClient.getHttpClient(); + memberVarObjectMapper = apiClient.getObjectMapper(); + memberVarBaseUri = apiClient.getBaseUri(); + memberVarInterceptor = apiClient.getRequestInterceptor(); + memberVarReadTimeout = apiClient.getReadTimeout(); + memberVarResponseInterceptor = apiClient.getResponseInterceptor(); + memberVarAsyncResponseInterceptor = apiClient.getAsyncResponseInterceptor(); + } + + + protected ApiException getApiException(String operationId, HttpResponse response) throws IOException { + InputStream responseBody = ApiClient.getResponseBody(response); + String body = null; + try { + body = responseBody == null ? null : new String(responseBody.readAllBytes()); + } finally { + if (responseBody != null) { + responseBody.close(); + } + } + String message = formatExceptionMessage(operationId, response.statusCode(), body); + return new ApiException(response.statusCode(), message, response.headers(), body); + } + + private String formatExceptionMessage(String operationId, int statusCode, String body) { + if (body == null || body.isEmpty()) { + body = "[no body]"; + } + return operationId + " call failed with: " + statusCode + " - " + body; + } + + /** + * Download file from the given response. + * + * @param response Response + * @return File + * @throws ApiException If fail to read file content from response and write to disk + */ + public File downloadFileFromResponse(HttpResponse response, InputStream responseBody) throws ApiException { + if (responseBody == null) { + throw new ApiException(new IOException("Response body is empty")); + } + try { + File file = prepareDownloadFile(response); + java.nio.file.Files.copy(responseBody, file.toPath(), java.nio.file.StandardCopyOption.REPLACE_EXISTING); + return file; + } catch (IOException e) { + throw new ApiException(e); + } + } + + /** + *

Prepare the file for download from the response.

+ * + * @param response a {@link java.net.http.HttpResponse} object. + * @return a {@link java.io.File} object. + * @throws java.io.IOException if any. + */ + private File prepareDownloadFile(HttpResponse response) throws IOException { + String filename = null; + java.util.Optional contentDisposition = response.headers().firstValue("Content-Disposition"); + if (contentDisposition.isPresent() && !"".equals(contentDisposition.get())) { + // Get filename from the Content-Disposition header. + java.util.regex.Pattern pattern = java.util.regex.Pattern.compile("filename=['\"]?([^'\"\\s]+)['\"]?"); + java.util.regex.Matcher matcher = pattern.matcher(contentDisposition.get()); + if (matcher.find()) + filename = matcher.group(1); + } + File file = null; + if (filename != null) { + java.nio.file.Path tempDir = java.nio.file.Files.createTempDirectory("swagger-gen-native"); + java.nio.file.Path filePath = java.nio.file.Files.createFile(tempDir.resolve(filename)); + file = filePath.toFile(); + tempDir.toFile().deleteOnExit(); // best effort cleanup + file.deleteOnExit(); // best effort cleanup + } else { + file = java.nio.file.Files.createTempFile("download-", "").toFile(); + file.deleteOnExit(); // best effort cleanup + } + return file; + } + + /** + * Read one file of the seller's library + * One file of the seller's library, by its identifier, with a signed link to read it (it expires: ask again rather than keep it). `status` is `PENDING` while the bytes are not on our storage yet. Requires `items:read`. + * @param id The file's identifier, a UUID. (required) + * @return ModelFile + * @throws ApiException if fails to make API call + */ + public ModelFile getFile(@jakarta.annotation.Nonnull UUID id) throws ApiException { + return getFile(id, null); + } + + /** + * Read one file of the seller's library + * One file of the seller's library, by its identifier, with a signed link to read it (it expires: ask again rather than keep it). `status` is `PENDING` while the bytes are not on our storage yet. Requires `items:read`. + * @param id The file's identifier, a UUID. (required) + * @param headers Optional headers to include in the request + * @return ModelFile + * @throws ApiException if fails to make API call + */ + public ModelFile getFile(@jakarta.annotation.Nonnull UUID id, Map headers) throws ApiException { + ApiResponse localVarResponse = getFileWithHttpInfo(id, headers); + return localVarResponse.getData(); + } + + /** + * Read one file of the seller's library + * One file of the seller's library, by its identifier, with a signed link to read it (it expires: ask again rather than keep it). `status` is `PENDING` while the bytes are not on our storage yet. Requires `items:read`. + * @param id The file's identifier, a UUID. (required) + * @return ApiResponse<ModelFile> + * @throws ApiException if fails to make API call + */ + public ApiResponse getFileWithHttpInfo(@jakarta.annotation.Nonnull UUID id) throws ApiException { + return getFileWithHttpInfo(id, null); + } + + /** + * Read one file of the seller's library + * One file of the seller's library, by its identifier, with a signed link to read it (it expires: ask again rather than keep it). `status` is `PENDING` while the bytes are not on our storage yet. Requires `items:read`. + * @param id The file's identifier, a UUID. (required) + * @param headers Optional headers to include in the request + * @return ApiResponse<ModelFile> + * @throws ApiException if fails to make API call + */ + public ApiResponse getFileWithHttpInfo(@jakarta.annotation.Nonnull UUID id, Map headers) throws ApiException { + HttpRequest.Builder localVarRequestBuilder = getFileRequestBuilder(id, headers); + try { + HttpResponse localVarResponse = memberVarHttpClient.send( + localVarRequestBuilder.build(), + HttpResponse.BodyHandlers.ofInputStream()); + if (memberVarResponseInterceptor != null) { + memberVarResponseInterceptor.accept(localVarResponse); + } + InputStream localVarResponseBody = null; + try { + if (localVarResponse.statusCode()/ 100 != 2) { + throw getApiException("getFile", localVarResponse); + } + localVarResponseBody = ApiClient.getResponseBody(localVarResponse); + if (localVarResponseBody == null) { + return new ApiResponse( + localVarResponse.statusCode(), + localVarResponse.headers().map(), + null + ); + } + + + + String responseBody = new String(localVarResponseBody.readAllBytes()); + ModelFile responseValue = responseBody.isBlank()? null: memberVarObjectMapper.readValue(responseBody, new TypeReference() {}); + + + return new ApiResponse( + localVarResponse.statusCode(), + localVarResponse.headers().map(), + responseValue + ); + } finally { + if (localVarResponseBody != null) { + localVarResponseBody.close(); + } + } + } catch (IOException e) { + throw new ApiException(e); + } + catch (InterruptedException e) { + Thread.currentThread().interrupt(); + throw new ApiException(e); + } + } + + private HttpRequest.Builder getFileRequestBuilder(@jakarta.annotation.Nonnull UUID id, Map headers) throws ApiException { + // verify the required parameter 'id' is set + if (id == null) { + throw new ApiException(400, "Missing the required parameter 'id' when calling getFile"); + } + + HttpRequest.Builder localVarRequestBuilder = HttpRequest.newBuilder(); + + String localVarPath = "/api/public/v1/files/{id}" + .replace("{id}", ApiClient.urlEncode(id.toString())); + + localVarRequestBuilder.uri(URI.create(memberVarBaseUri + localVarPath)); + + localVarRequestBuilder.header("Accept", "application/json"); + + localVarRequestBuilder.method("GET", HttpRequest.BodyPublishers.noBody()); + if (memberVarReadTimeout != null) { + localVarRequestBuilder.timeout(memberVarReadTimeout); + } + // Add custom headers if provided + localVarRequestBuilder = HttpRequestBuilderExtensions.withAdditionalHeaders(localVarRequestBuilder, headers); + if (memberVarInterceptor != null) { + memberVarInterceptor.accept(localVarRequestBuilder); + } + return localVarRequestBuilder; + } + + /** + * Register a file to send + * Registers a file in the seller's library and returns its identifier and the address where to send its bytes: an HTTP `PUT` of the file to `uploadUrl`, with the same `Content-Type` and exactly `size` bytes as the body, and no `Authorization` header, within 30 minutes. Photos only (`image/jpeg`, `image/png`, `image/webp`, `image/heic`, `image/heif`), at most 20 MiB. Then put the identifier in `photoIds` of `POST /items` or `PATCH /items/{id}`; an identifier whose bytes were never sent is refused there (`404 photo_not_found`). The address is valid for 30 minutes: a replay of the same `Idempotency-Key` returns the same address, so register the file again with a new key once it has expired. Requires `items:write` and an `Idempotency-Key`. + * @param idempotencyKey 1 to 255 characters, unique per write: a retry with the same key and the same request answers the first response again (`Idempotent-Replayed: true`), without running the write twice. (required) + * @param fileUploadRequest (required) + * @return FileUpload + * @throws ApiException if fails to make API call + */ + public FileUpload uploadFile(@jakarta.annotation.Nonnull String idempotencyKey, @jakarta.annotation.Nonnull FileUploadRequest fileUploadRequest) throws ApiException { + return uploadFile(idempotencyKey, fileUploadRequest, null); + } + + /** + * Register a file to send + * Registers a file in the seller's library and returns its identifier and the address where to send its bytes: an HTTP `PUT` of the file to `uploadUrl`, with the same `Content-Type` and exactly `size` bytes as the body, and no `Authorization` header, within 30 minutes. Photos only (`image/jpeg`, `image/png`, `image/webp`, `image/heic`, `image/heif`), at most 20 MiB. Then put the identifier in `photoIds` of `POST /items` or `PATCH /items/{id}`; an identifier whose bytes were never sent is refused there (`404 photo_not_found`). The address is valid for 30 minutes: a replay of the same `Idempotency-Key` returns the same address, so register the file again with a new key once it has expired. Requires `items:write` and an `Idempotency-Key`. + * @param idempotencyKey 1 to 255 characters, unique per write: a retry with the same key and the same request answers the first response again (`Idempotent-Replayed: true`), without running the write twice. (required) + * @param fileUploadRequest (required) + * @param headers Optional headers to include in the request + * @return FileUpload + * @throws ApiException if fails to make API call + */ + public FileUpload uploadFile(@jakarta.annotation.Nonnull String idempotencyKey, @jakarta.annotation.Nonnull FileUploadRequest fileUploadRequest, Map headers) throws ApiException { + ApiResponse localVarResponse = uploadFileWithHttpInfo(idempotencyKey, fileUploadRequest, headers); + return localVarResponse.getData(); + } + + /** + * Register a file to send + * Registers a file in the seller's library and returns its identifier and the address where to send its bytes: an HTTP `PUT` of the file to `uploadUrl`, with the same `Content-Type` and exactly `size` bytes as the body, and no `Authorization` header, within 30 minutes. Photos only (`image/jpeg`, `image/png`, `image/webp`, `image/heic`, `image/heif`), at most 20 MiB. Then put the identifier in `photoIds` of `POST /items` or `PATCH /items/{id}`; an identifier whose bytes were never sent is refused there (`404 photo_not_found`). The address is valid for 30 minutes: a replay of the same `Idempotency-Key` returns the same address, so register the file again with a new key once it has expired. Requires `items:write` and an `Idempotency-Key`. + * @param idempotencyKey 1 to 255 characters, unique per write: a retry with the same key and the same request answers the first response again (`Idempotent-Replayed: true`), without running the write twice. (required) + * @param fileUploadRequest (required) + * @return ApiResponse<FileUpload> + * @throws ApiException if fails to make API call + */ + public ApiResponse uploadFileWithHttpInfo(@jakarta.annotation.Nonnull String idempotencyKey, @jakarta.annotation.Nonnull FileUploadRequest fileUploadRequest) throws ApiException { + return uploadFileWithHttpInfo(idempotencyKey, fileUploadRequest, null); + } + + /** + * Register a file to send + * Registers a file in the seller's library and returns its identifier and the address where to send its bytes: an HTTP `PUT` of the file to `uploadUrl`, with the same `Content-Type` and exactly `size` bytes as the body, and no `Authorization` header, within 30 minutes. Photos only (`image/jpeg`, `image/png`, `image/webp`, `image/heic`, `image/heif`), at most 20 MiB. Then put the identifier in `photoIds` of `POST /items` or `PATCH /items/{id}`; an identifier whose bytes were never sent is refused there (`404 photo_not_found`). The address is valid for 30 minutes: a replay of the same `Idempotency-Key` returns the same address, so register the file again with a new key once it has expired. Requires `items:write` and an `Idempotency-Key`. + * @param idempotencyKey 1 to 255 characters, unique per write: a retry with the same key and the same request answers the first response again (`Idempotent-Replayed: true`), without running the write twice. (required) + * @param fileUploadRequest (required) + * @param headers Optional headers to include in the request + * @return ApiResponse<FileUpload> + * @throws ApiException if fails to make API call + */ + public ApiResponse uploadFileWithHttpInfo(@jakarta.annotation.Nonnull String idempotencyKey, @jakarta.annotation.Nonnull FileUploadRequest fileUploadRequest, Map headers) throws ApiException { + HttpRequest.Builder localVarRequestBuilder = uploadFileRequestBuilder(idempotencyKey, fileUploadRequest, headers); + try { + HttpResponse localVarResponse = memberVarHttpClient.send( + localVarRequestBuilder.build(), + HttpResponse.BodyHandlers.ofInputStream()); + if (memberVarResponseInterceptor != null) { + memberVarResponseInterceptor.accept(localVarResponse); + } + InputStream localVarResponseBody = null; + try { + if (localVarResponse.statusCode()/ 100 != 2) { + throw getApiException("uploadFile", localVarResponse); + } + localVarResponseBody = ApiClient.getResponseBody(localVarResponse); + if (localVarResponseBody == null) { + return new ApiResponse( + localVarResponse.statusCode(), + localVarResponse.headers().map(), + null + ); + } + + + + String responseBody = new String(localVarResponseBody.readAllBytes()); + FileUpload responseValue = responseBody.isBlank()? null: memberVarObjectMapper.readValue(responseBody, new TypeReference() {}); + + + return new ApiResponse( + localVarResponse.statusCode(), + localVarResponse.headers().map(), + responseValue + ); + } finally { + if (localVarResponseBody != null) { + localVarResponseBody.close(); + } + } + } catch (IOException e) { + throw new ApiException(e); + } + catch (InterruptedException e) { + Thread.currentThread().interrupt(); + throw new ApiException(e); + } + } + + private HttpRequest.Builder uploadFileRequestBuilder(@jakarta.annotation.Nonnull String idempotencyKey, @jakarta.annotation.Nonnull FileUploadRequest fileUploadRequest, Map headers) throws ApiException { + // verify the required parameter 'idempotencyKey' is set + if (idempotencyKey == null) { + throw new ApiException(400, "Missing the required parameter 'idempotencyKey' when calling uploadFile"); + } + // verify the required parameter 'fileUploadRequest' is set + if (fileUploadRequest == null) { + throw new ApiException(400, "Missing the required parameter 'fileUploadRequest' when calling uploadFile"); + } + + HttpRequest.Builder localVarRequestBuilder = HttpRequest.newBuilder(); + + String localVarPath = "/api/public/v1/files"; + + localVarRequestBuilder.uri(URI.create(memberVarBaseUri + localVarPath)); + + if (idempotencyKey != null) { + localVarRequestBuilder.header("Idempotency-Key", idempotencyKey.toString()); + } + localVarRequestBuilder.header("Content-Type", "application/json"); + localVarRequestBuilder.header("Accept", "application/json"); + + try { + byte[] localVarPostBody = memberVarObjectMapper.writeValueAsBytes(fileUploadRequest); + localVarRequestBuilder.method("POST", HttpRequest.BodyPublishers.ofByteArray(localVarPostBody)); + } catch (IOException e) { + throw new ApiException(e); + } + if (memberVarReadTimeout != null) { + localVarRequestBuilder.timeout(memberVarReadTimeout); + } + // Add custom headers if provided + localVarRequestBuilder = HttpRequestBuilderExtensions.withAdditionalHeaders(localVarRequestBuilder, headers); + if (memberVarInterceptor != null) { + memberVarInterceptor.accept(localVarRequestBuilder); + } + return localVarRequestBuilder; + } + +} diff --git a/src/main/java/com/controlresell/sdk/generated/api/ItemsApi.java b/src/main/java/com/controlresell/sdk/generated/api/ItemsApi.java index 0b4f3e4..ae83a47 100644 --- a/src/main/java/com/controlresell/sdk/generated/api/ItemsApi.java +++ b/src/main/java/com/controlresell/sdk/generated/api/ItemsApi.java @@ -174,7 +174,7 @@ private File prepareDownloadFile(HttpResponse response) throws IOEx /** * Create an item in the seller's stock - * Creates one item in the seller's ControlResell stock, unsold unless `sold` says otherwise, without publishing it: publish it with `POST /items/{id}/publish`. Only `name` is required. The amounts are `{amount, currency}` in the item's currency (EUR for a new item; another currency is refused with `422 currency_mismatch`). `photoIds` are files already in the seller's library: another seller's, or an unknown one, is `404 photo_not_found`. A label the seller does not have yet is created. The fields a marketplace asks for are written with the item: `packageSizeId`, `materialIds`, `measurementLength` and `measurementWidth` (centimeters), `enumValues` (the category's enumerated fields, `{enumKey, enumValue}`, one entry per picked value), `attributes` (its free-text fields, `{fieldKey, value}`, one per key) and `customFields` (the seller's own fields, `{fieldId, value}`); each list replaces the item's whole list. A place (`purchasePlaceId`, `sellingPlaceId`) or a custom field of another seller, or an unknown one, is `404 place_not_found` or `404 field_not_found`. `categoryId`, `sizeId` and `state` are ids from 1 (`0` is a 400, `null` clears them). Keys and enumerated values are trimmed and counted in characters (UTF-16 units), 1 to 100 for a key and 1 to 255 for a value; two entries that differ only by case or accents (as the database compares them) are a 400. At most 100 entries per list, and 65,535 bytes (UTF-8) per free-text value. Read back, `enumValues`, `attributes` and `customFields` are sorted by key (then value, or field id), as plain strings (upper case before lower case). Requires `items:write` and an `Idempotency-Key`. + * Creates one item in the seller's ControlResell stock, unsold unless `sold` says otherwise, without publishing it: publish it with `POST /items/{id}/publish`. Only `name` is required. The amounts are `{amount, currency}` in the item's currency (EUR for a new item; another currency is refused with `422 currency_mismatch`). `photoIds` are files already in the seller's library (`POST /files`): another seller's, an unknown one, or one whose bytes were never sent is `404 photo_not_found`. A label the seller does not have yet is created. The fields a marketplace asks for are written with the item: `packageSizeId`, `materialIds`, `measurementLength` and `measurementWidth` (centimeters), `enumValues` (the category's enumerated fields, `{enumKey, enumValue}`, one entry per picked value), `attributes` (its free-text fields, `{fieldKey, value}`, one per key) and `customFields` (the seller's own fields, `{fieldId, value}`); each list replaces the item's whole list. A place (`purchasePlaceId`, `sellingPlaceId`) or a custom field of another seller, or an unknown one, is `404 place_not_found` or `404 field_not_found`. `categoryId`, `sizeId` and `state` are ids from 1 (`0` is a 400, `null` clears them). Keys and enumerated values are trimmed and counted in characters (UTF-16 units), 1 to 100 for a key and 1 to 255 for a value; two entries that differ only by case or accents (as the database compares them) are a 400. At most 100 entries per list, and 65,535 bytes (UTF-8) per free-text value. Read back, `enumValues`, `attributes` and `customFields` are sorted by key (then value, or field id), as plain strings (upper case before lower case). Requires `items:write` and an `Idempotency-Key`. * @param idempotencyKey 1 to 255 characters, unique per write: a retry with the same key and the same request answers the first response again (`Idempotent-Replayed: true`), without running the write twice. (required) * @param itemCreateRequest (required) * @return Item @@ -186,7 +186,7 @@ public Item createItem(@jakarta.annotation.Nonnull String idempotencyKey, @jakar /** * Create an item in the seller's stock - * Creates one item in the seller's ControlResell stock, unsold unless `sold` says otherwise, without publishing it: publish it with `POST /items/{id}/publish`. Only `name` is required. The amounts are `{amount, currency}` in the item's currency (EUR for a new item; another currency is refused with `422 currency_mismatch`). `photoIds` are files already in the seller's library: another seller's, or an unknown one, is `404 photo_not_found`. A label the seller does not have yet is created. The fields a marketplace asks for are written with the item: `packageSizeId`, `materialIds`, `measurementLength` and `measurementWidth` (centimeters), `enumValues` (the category's enumerated fields, `{enumKey, enumValue}`, one entry per picked value), `attributes` (its free-text fields, `{fieldKey, value}`, one per key) and `customFields` (the seller's own fields, `{fieldId, value}`); each list replaces the item's whole list. A place (`purchasePlaceId`, `sellingPlaceId`) or a custom field of another seller, or an unknown one, is `404 place_not_found` or `404 field_not_found`. `categoryId`, `sizeId` and `state` are ids from 1 (`0` is a 400, `null` clears them). Keys and enumerated values are trimmed and counted in characters (UTF-16 units), 1 to 100 for a key and 1 to 255 for a value; two entries that differ only by case or accents (as the database compares them) are a 400. At most 100 entries per list, and 65,535 bytes (UTF-8) per free-text value. Read back, `enumValues`, `attributes` and `customFields` are sorted by key (then value, or field id), as plain strings (upper case before lower case). Requires `items:write` and an `Idempotency-Key`. + * Creates one item in the seller's ControlResell stock, unsold unless `sold` says otherwise, without publishing it: publish it with `POST /items/{id}/publish`. Only `name` is required. The amounts are `{amount, currency}` in the item's currency (EUR for a new item; another currency is refused with `422 currency_mismatch`). `photoIds` are files already in the seller's library (`POST /files`): another seller's, an unknown one, or one whose bytes were never sent is `404 photo_not_found`. A label the seller does not have yet is created. The fields a marketplace asks for are written with the item: `packageSizeId`, `materialIds`, `measurementLength` and `measurementWidth` (centimeters), `enumValues` (the category's enumerated fields, `{enumKey, enumValue}`, one entry per picked value), `attributes` (its free-text fields, `{fieldKey, value}`, one per key) and `customFields` (the seller's own fields, `{fieldId, value}`); each list replaces the item's whole list. A place (`purchasePlaceId`, `sellingPlaceId`) or a custom field of another seller, or an unknown one, is `404 place_not_found` or `404 field_not_found`. `categoryId`, `sizeId` and `state` are ids from 1 (`0` is a 400, `null` clears them). Keys and enumerated values are trimmed and counted in characters (UTF-16 units), 1 to 100 for a key and 1 to 255 for a value; two entries that differ only by case or accents (as the database compares them) are a 400. At most 100 entries per list, and 65,535 bytes (UTF-8) per free-text value. Read back, `enumValues`, `attributes` and `customFields` are sorted by key (then value, or field id), as plain strings (upper case before lower case). Requires `items:write` and an `Idempotency-Key`. * @param idempotencyKey 1 to 255 characters, unique per write: a retry with the same key and the same request answers the first response again (`Idempotent-Replayed: true`), without running the write twice. (required) * @param itemCreateRequest (required) * @param headers Optional headers to include in the request @@ -200,7 +200,7 @@ public Item createItem(@jakarta.annotation.Nonnull String idempotencyKey, @jakar /** * Create an item in the seller's stock - * Creates one item in the seller's ControlResell stock, unsold unless `sold` says otherwise, without publishing it: publish it with `POST /items/{id}/publish`. Only `name` is required. The amounts are `{amount, currency}` in the item's currency (EUR for a new item; another currency is refused with `422 currency_mismatch`). `photoIds` are files already in the seller's library: another seller's, or an unknown one, is `404 photo_not_found`. A label the seller does not have yet is created. The fields a marketplace asks for are written with the item: `packageSizeId`, `materialIds`, `measurementLength` and `measurementWidth` (centimeters), `enumValues` (the category's enumerated fields, `{enumKey, enumValue}`, one entry per picked value), `attributes` (its free-text fields, `{fieldKey, value}`, one per key) and `customFields` (the seller's own fields, `{fieldId, value}`); each list replaces the item's whole list. A place (`purchasePlaceId`, `sellingPlaceId`) or a custom field of another seller, or an unknown one, is `404 place_not_found` or `404 field_not_found`. `categoryId`, `sizeId` and `state` are ids from 1 (`0` is a 400, `null` clears them). Keys and enumerated values are trimmed and counted in characters (UTF-16 units), 1 to 100 for a key and 1 to 255 for a value; two entries that differ only by case or accents (as the database compares them) are a 400. At most 100 entries per list, and 65,535 bytes (UTF-8) per free-text value. Read back, `enumValues`, `attributes` and `customFields` are sorted by key (then value, or field id), as plain strings (upper case before lower case). Requires `items:write` and an `Idempotency-Key`. + * Creates one item in the seller's ControlResell stock, unsold unless `sold` says otherwise, without publishing it: publish it with `POST /items/{id}/publish`. Only `name` is required. The amounts are `{amount, currency}` in the item's currency (EUR for a new item; another currency is refused with `422 currency_mismatch`). `photoIds` are files already in the seller's library (`POST /files`): another seller's, an unknown one, or one whose bytes were never sent is `404 photo_not_found`. A label the seller does not have yet is created. The fields a marketplace asks for are written with the item: `packageSizeId`, `materialIds`, `measurementLength` and `measurementWidth` (centimeters), `enumValues` (the category's enumerated fields, `{enumKey, enumValue}`, one entry per picked value), `attributes` (its free-text fields, `{fieldKey, value}`, one per key) and `customFields` (the seller's own fields, `{fieldId, value}`); each list replaces the item's whole list. A place (`purchasePlaceId`, `sellingPlaceId`) or a custom field of another seller, or an unknown one, is `404 place_not_found` or `404 field_not_found`. `categoryId`, `sizeId` and `state` are ids from 1 (`0` is a 400, `null` clears them). Keys and enumerated values are trimmed and counted in characters (UTF-16 units), 1 to 100 for a key and 1 to 255 for a value; two entries that differ only by case or accents (as the database compares them) are a 400. At most 100 entries per list, and 65,535 bytes (UTF-8) per free-text value. Read back, `enumValues`, `attributes` and `customFields` are sorted by key (then value, or field id), as plain strings (upper case before lower case). Requires `items:write` and an `Idempotency-Key`. * @param idempotencyKey 1 to 255 characters, unique per write: a retry with the same key and the same request answers the first response again (`Idempotent-Replayed: true`), without running the write twice. (required) * @param itemCreateRequest (required) * @return ApiResponse<Item> @@ -212,7 +212,7 @@ public ApiResponse createItemWithHttpInfo(@jakarta.annotation.Nonnull Stri /** * Create an item in the seller's stock - * Creates one item in the seller's ControlResell stock, unsold unless `sold` says otherwise, without publishing it: publish it with `POST /items/{id}/publish`. Only `name` is required. The amounts are `{amount, currency}` in the item's currency (EUR for a new item; another currency is refused with `422 currency_mismatch`). `photoIds` are files already in the seller's library: another seller's, or an unknown one, is `404 photo_not_found`. A label the seller does not have yet is created. The fields a marketplace asks for are written with the item: `packageSizeId`, `materialIds`, `measurementLength` and `measurementWidth` (centimeters), `enumValues` (the category's enumerated fields, `{enumKey, enumValue}`, one entry per picked value), `attributes` (its free-text fields, `{fieldKey, value}`, one per key) and `customFields` (the seller's own fields, `{fieldId, value}`); each list replaces the item's whole list. A place (`purchasePlaceId`, `sellingPlaceId`) or a custom field of another seller, or an unknown one, is `404 place_not_found` or `404 field_not_found`. `categoryId`, `sizeId` and `state` are ids from 1 (`0` is a 400, `null` clears them). Keys and enumerated values are trimmed and counted in characters (UTF-16 units), 1 to 100 for a key and 1 to 255 for a value; two entries that differ only by case or accents (as the database compares them) are a 400. At most 100 entries per list, and 65,535 bytes (UTF-8) per free-text value. Read back, `enumValues`, `attributes` and `customFields` are sorted by key (then value, or field id), as plain strings (upper case before lower case). Requires `items:write` and an `Idempotency-Key`. + * Creates one item in the seller's ControlResell stock, unsold unless `sold` says otherwise, without publishing it: publish it with `POST /items/{id}/publish`. Only `name` is required. The amounts are `{amount, currency}` in the item's currency (EUR for a new item; another currency is refused with `422 currency_mismatch`). `photoIds` are files already in the seller's library (`POST /files`): another seller's, an unknown one, or one whose bytes were never sent is `404 photo_not_found`. A label the seller does not have yet is created. The fields a marketplace asks for are written with the item: `packageSizeId`, `materialIds`, `measurementLength` and `measurementWidth` (centimeters), `enumValues` (the category's enumerated fields, `{enumKey, enumValue}`, one entry per picked value), `attributes` (its free-text fields, `{fieldKey, value}`, one per key) and `customFields` (the seller's own fields, `{fieldId, value}`); each list replaces the item's whole list. A place (`purchasePlaceId`, `sellingPlaceId`) or a custom field of another seller, or an unknown one, is `404 place_not_found` or `404 field_not_found`. `categoryId`, `sizeId` and `state` are ids from 1 (`0` is a 400, `null` clears them). Keys and enumerated values are trimmed and counted in characters (UTF-16 units), 1 to 100 for a key and 1 to 255 for a value; two entries that differ only by case or accents (as the database compares them) are a 400. At most 100 entries per list, and 65,535 bytes (UTF-8) per free-text value. Read back, `enumValues`, `attributes` and `customFields` are sorted by key (then value, or field id), as plain strings (upper case before lower case). Requires `items:write` and an `Idempotency-Key`. * @param idempotencyKey 1 to 255 characters, unique per write: a retry with the same key and the same request answers the first response again (`Idempotent-Replayed: true`), without running the write twice. (required) * @param itemCreateRequest (required) * @param headers Optional headers to include in the request @@ -1219,7 +1219,7 @@ private HttpRequest.Builder republishItemRequestBuilder(@jakarta.annotation.Nonn /** * Change an item of the seller's stock - * Changes one item of the seller's stock with a JSON merge patch: a field left out keeps its value, a field set to `null` is cleared (not `name`, `sold`, nor a list: send `[]` to empty a list), a list replaces the whole list. It changes the item in ControlResell only, not its listings on the marketplaces. The amounts are `{amount, currency}` in the item's currency (EUR for a new item; another currency is refused with `422 currency_mismatch`). `photoIds` are files already in the seller's library: another seller's, or an unknown one, is `404 photo_not_found`. A label the seller does not have yet is created. The fields a marketplace asks for are written with the item: `packageSizeId`, `materialIds`, `measurementLength` and `measurementWidth` (centimeters), `enumValues` (the category's enumerated fields, `{enumKey, enumValue}`, one entry per picked value), `attributes` (its free-text fields, `{fieldKey, value}`, one per key) and `customFields` (the seller's own fields, `{fieldId, value}`); each list replaces the item's whole list. A place (`purchasePlaceId`, `sellingPlaceId`) or a custom field of another seller, or an unknown one, is `404 place_not_found` or `404 field_not_found`. `categoryId`, `sizeId` and `state` are ids from 1 (`0` is a 400, `null` clears them). Keys and enumerated values are trimmed and counted in characters (UTF-16 units), 1 to 100 for a key and 1 to 255 for a value; two entries that differ only by case or accents (as the database compares them) are a 400. At most 100 entries per list, and 65,535 bytes (UTF-8) per free-text value. Read back, `enumValues`, `attributes` and `customFields` are sorted by key (then value, or field id), as plain strings (upper case before lower case). Requires `items:write`. + * Changes one item of the seller's stock with a JSON merge patch: a field left out keeps its value, a field set to `null` is cleared (not `name`, `sold`, nor a list: send `[]` to empty a list), a list replaces the whole list. It changes the item in ControlResell only, not its listings on the marketplaces. The amounts are `{amount, currency}` in the item's currency (EUR for a new item; another currency is refused with `422 currency_mismatch`). `photoIds` are files already in the seller's library (`POST /files`): another seller's, an unknown one, or one whose bytes were never sent is `404 photo_not_found`. A label the seller does not have yet is created. The fields a marketplace asks for are written with the item: `packageSizeId`, `materialIds`, `measurementLength` and `measurementWidth` (centimeters), `enumValues` (the category's enumerated fields, `{enumKey, enumValue}`, one entry per picked value), `attributes` (its free-text fields, `{fieldKey, value}`, one per key) and `customFields` (the seller's own fields, `{fieldId, value}`); each list replaces the item's whole list. A place (`purchasePlaceId`, `sellingPlaceId`) or a custom field of another seller, or an unknown one, is `404 place_not_found` or `404 field_not_found`. `categoryId`, `sizeId` and `state` are ids from 1 (`0` is a 400, `null` clears them). Keys and enumerated values are trimmed and counted in characters (UTF-16 units), 1 to 100 for a key and 1 to 255 for a value; two entries that differ only by case or accents (as the database compares them) are a 400. At most 100 entries per list, and 65,535 bytes (UTF-8) per free-text value. Read back, `enumValues`, `attributes` and `customFields` are sorted by key (then value, or field id), as plain strings (upper case before lower case). Requires `items:write`. * @param id The item's identifier, a number. (required) * @param itemUpdateRequest (required) * @return Item @@ -1231,7 +1231,7 @@ public Item updateItem(@jakarta.annotation.Nonnull Long id, @jakarta.annotation. /** * Change an item of the seller's stock - * Changes one item of the seller's stock with a JSON merge patch: a field left out keeps its value, a field set to `null` is cleared (not `name`, `sold`, nor a list: send `[]` to empty a list), a list replaces the whole list. It changes the item in ControlResell only, not its listings on the marketplaces. The amounts are `{amount, currency}` in the item's currency (EUR for a new item; another currency is refused with `422 currency_mismatch`). `photoIds` are files already in the seller's library: another seller's, or an unknown one, is `404 photo_not_found`. A label the seller does not have yet is created. The fields a marketplace asks for are written with the item: `packageSizeId`, `materialIds`, `measurementLength` and `measurementWidth` (centimeters), `enumValues` (the category's enumerated fields, `{enumKey, enumValue}`, one entry per picked value), `attributes` (its free-text fields, `{fieldKey, value}`, one per key) and `customFields` (the seller's own fields, `{fieldId, value}`); each list replaces the item's whole list. A place (`purchasePlaceId`, `sellingPlaceId`) or a custom field of another seller, or an unknown one, is `404 place_not_found` or `404 field_not_found`. `categoryId`, `sizeId` and `state` are ids from 1 (`0` is a 400, `null` clears them). Keys and enumerated values are trimmed and counted in characters (UTF-16 units), 1 to 100 for a key and 1 to 255 for a value; two entries that differ only by case or accents (as the database compares them) are a 400. At most 100 entries per list, and 65,535 bytes (UTF-8) per free-text value. Read back, `enumValues`, `attributes` and `customFields` are sorted by key (then value, or field id), as plain strings (upper case before lower case). Requires `items:write`. + * Changes one item of the seller's stock with a JSON merge patch: a field left out keeps its value, a field set to `null` is cleared (not `name`, `sold`, nor a list: send `[]` to empty a list), a list replaces the whole list. It changes the item in ControlResell only, not its listings on the marketplaces. The amounts are `{amount, currency}` in the item's currency (EUR for a new item; another currency is refused with `422 currency_mismatch`). `photoIds` are files already in the seller's library (`POST /files`): another seller's, an unknown one, or one whose bytes were never sent is `404 photo_not_found`. A label the seller does not have yet is created. The fields a marketplace asks for are written with the item: `packageSizeId`, `materialIds`, `measurementLength` and `measurementWidth` (centimeters), `enumValues` (the category's enumerated fields, `{enumKey, enumValue}`, one entry per picked value), `attributes` (its free-text fields, `{fieldKey, value}`, one per key) and `customFields` (the seller's own fields, `{fieldId, value}`); each list replaces the item's whole list. A place (`purchasePlaceId`, `sellingPlaceId`) or a custom field of another seller, or an unknown one, is `404 place_not_found` or `404 field_not_found`. `categoryId`, `sizeId` and `state` are ids from 1 (`0` is a 400, `null` clears them). Keys and enumerated values are trimmed and counted in characters (UTF-16 units), 1 to 100 for a key and 1 to 255 for a value; two entries that differ only by case or accents (as the database compares them) are a 400. At most 100 entries per list, and 65,535 bytes (UTF-8) per free-text value. Read back, `enumValues`, `attributes` and `customFields` are sorted by key (then value, or field id), as plain strings (upper case before lower case). Requires `items:write`. * @param id The item's identifier, a number. (required) * @param itemUpdateRequest (required) * @param headers Optional headers to include in the request @@ -1245,7 +1245,7 @@ public Item updateItem(@jakarta.annotation.Nonnull Long id, @jakarta.annotation. /** * Change an item of the seller's stock - * Changes one item of the seller's stock with a JSON merge patch: a field left out keeps its value, a field set to `null` is cleared (not `name`, `sold`, nor a list: send `[]` to empty a list), a list replaces the whole list. It changes the item in ControlResell only, not its listings on the marketplaces. The amounts are `{amount, currency}` in the item's currency (EUR for a new item; another currency is refused with `422 currency_mismatch`). `photoIds` are files already in the seller's library: another seller's, or an unknown one, is `404 photo_not_found`. A label the seller does not have yet is created. The fields a marketplace asks for are written with the item: `packageSizeId`, `materialIds`, `measurementLength` and `measurementWidth` (centimeters), `enumValues` (the category's enumerated fields, `{enumKey, enumValue}`, one entry per picked value), `attributes` (its free-text fields, `{fieldKey, value}`, one per key) and `customFields` (the seller's own fields, `{fieldId, value}`); each list replaces the item's whole list. A place (`purchasePlaceId`, `sellingPlaceId`) or a custom field of another seller, or an unknown one, is `404 place_not_found` or `404 field_not_found`. `categoryId`, `sizeId` and `state` are ids from 1 (`0` is a 400, `null` clears them). Keys and enumerated values are trimmed and counted in characters (UTF-16 units), 1 to 100 for a key and 1 to 255 for a value; two entries that differ only by case or accents (as the database compares them) are a 400. At most 100 entries per list, and 65,535 bytes (UTF-8) per free-text value. Read back, `enumValues`, `attributes` and `customFields` are sorted by key (then value, or field id), as plain strings (upper case before lower case). Requires `items:write`. + * Changes one item of the seller's stock with a JSON merge patch: a field left out keeps its value, a field set to `null` is cleared (not `name`, `sold`, nor a list: send `[]` to empty a list), a list replaces the whole list. It changes the item in ControlResell only, not its listings on the marketplaces. The amounts are `{amount, currency}` in the item's currency (EUR for a new item; another currency is refused with `422 currency_mismatch`). `photoIds` are files already in the seller's library (`POST /files`): another seller's, an unknown one, or one whose bytes were never sent is `404 photo_not_found`. A label the seller does not have yet is created. The fields a marketplace asks for are written with the item: `packageSizeId`, `materialIds`, `measurementLength` and `measurementWidth` (centimeters), `enumValues` (the category's enumerated fields, `{enumKey, enumValue}`, one entry per picked value), `attributes` (its free-text fields, `{fieldKey, value}`, one per key) and `customFields` (the seller's own fields, `{fieldId, value}`); each list replaces the item's whole list. A place (`purchasePlaceId`, `sellingPlaceId`) or a custom field of another seller, or an unknown one, is `404 place_not_found` or `404 field_not_found`. `categoryId`, `sizeId` and `state` are ids from 1 (`0` is a 400, `null` clears them). Keys and enumerated values are trimmed and counted in characters (UTF-16 units), 1 to 100 for a key and 1 to 255 for a value; two entries that differ only by case or accents (as the database compares them) are a 400. At most 100 entries per list, and 65,535 bytes (UTF-8) per free-text value. Read back, `enumValues`, `attributes` and `customFields` are sorted by key (then value, or field id), as plain strings (upper case before lower case). Requires `items:write`. * @param id The item's identifier, a number. (required) * @param itemUpdateRequest (required) * @return ApiResponse<Item> @@ -1257,7 +1257,7 @@ public ApiResponse updateItemWithHttpInfo(@jakarta.annotation.Nonnull Long /** * Change an item of the seller's stock - * Changes one item of the seller's stock with a JSON merge patch: a field left out keeps its value, a field set to `null` is cleared (not `name`, `sold`, nor a list: send `[]` to empty a list), a list replaces the whole list. It changes the item in ControlResell only, not its listings on the marketplaces. The amounts are `{amount, currency}` in the item's currency (EUR for a new item; another currency is refused with `422 currency_mismatch`). `photoIds` are files already in the seller's library: another seller's, or an unknown one, is `404 photo_not_found`. A label the seller does not have yet is created. The fields a marketplace asks for are written with the item: `packageSizeId`, `materialIds`, `measurementLength` and `measurementWidth` (centimeters), `enumValues` (the category's enumerated fields, `{enumKey, enumValue}`, one entry per picked value), `attributes` (its free-text fields, `{fieldKey, value}`, one per key) and `customFields` (the seller's own fields, `{fieldId, value}`); each list replaces the item's whole list. A place (`purchasePlaceId`, `sellingPlaceId`) or a custom field of another seller, or an unknown one, is `404 place_not_found` or `404 field_not_found`. `categoryId`, `sizeId` and `state` are ids from 1 (`0` is a 400, `null` clears them). Keys and enumerated values are trimmed and counted in characters (UTF-16 units), 1 to 100 for a key and 1 to 255 for a value; two entries that differ only by case or accents (as the database compares them) are a 400. At most 100 entries per list, and 65,535 bytes (UTF-8) per free-text value. Read back, `enumValues`, `attributes` and `customFields` are sorted by key (then value, or field id), as plain strings (upper case before lower case). Requires `items:write`. + * Changes one item of the seller's stock with a JSON merge patch: a field left out keeps its value, a field set to `null` is cleared (not `name`, `sold`, nor a list: send `[]` to empty a list), a list replaces the whole list. It changes the item in ControlResell only, not its listings on the marketplaces. The amounts are `{amount, currency}` in the item's currency (EUR for a new item; another currency is refused with `422 currency_mismatch`). `photoIds` are files already in the seller's library (`POST /files`): another seller's, an unknown one, or one whose bytes were never sent is `404 photo_not_found`. A label the seller does not have yet is created. The fields a marketplace asks for are written with the item: `packageSizeId`, `materialIds`, `measurementLength` and `measurementWidth` (centimeters), `enumValues` (the category's enumerated fields, `{enumKey, enumValue}`, one entry per picked value), `attributes` (its free-text fields, `{fieldKey, value}`, one per key) and `customFields` (the seller's own fields, `{fieldId, value}`); each list replaces the item's whole list. A place (`purchasePlaceId`, `sellingPlaceId`) or a custom field of another seller, or an unknown one, is `404 place_not_found` or `404 field_not_found`. `categoryId`, `sizeId` and `state` are ids from 1 (`0` is a 400, `null` clears them). Keys and enumerated values are trimmed and counted in characters (UTF-16 units), 1 to 100 for a key and 1 to 255 for a value; two entries that differ only by case or accents (as the database compares them) are a 400. At most 100 entries per list, and 65,535 bytes (UTF-8) per free-text value. Read back, `enumValues`, `attributes` and `customFields` are sorted by key (then value, or field id), as plain strings (upper case before lower case). Requires `items:write`. * @param id The item's identifier, a number. (required) * @param itemUpdateRequest (required) * @param headers Optional headers to include in the request diff --git a/src/main/java/com/controlresell/sdk/generated/model/FileUpload.java b/src/main/java/com/controlresell/sdk/generated/model/FileUpload.java new file mode 100644 index 0000000..6403121 --- /dev/null +++ b/src/main/java/com/controlresell/sdk/generated/model/FileUpload.java @@ -0,0 +1,185 @@ +/* + * ControlResell public API + * The public API of ControlResell. Every error answers `{\"error\": {\"code\", \"message\", \"params\", \"requestId\"}}`; a `POST` takes an `Idempotency-Key` header. + * + * The version of the OpenAPI document: 1 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +package com.controlresell.sdk.generated.model; + +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; +import java.util.StringJoiner; +import java.util.Objects; +import java.util.Map; +import java.util.HashMap; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.fasterxml.jackson.annotation.JsonValue; +import java.util.Arrays; +import java.util.UUID; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; + + +import com.controlresell.sdk.generated.ApiClient; +/** + * FileUpload + */ +@JsonPropertyOrder({ + FileUpload.JSON_PROPERTY_ID, + FileUpload.JSON_PROPERTY_UPLOAD_URL +}) +@jakarta.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "Generator version: 7.26.0") +public class FileUpload { + public static final String JSON_PROPERTY_ID = "id"; + @jakarta.annotation.Nonnull + private UUID id; + + public static final String JSON_PROPERTY_UPLOAD_URL = "uploadUrl"; + @jakarta.annotation.Nonnull + private String uploadUrl; + + public FileUpload() { + } + + public FileUpload id(@jakarta.annotation.Nonnull UUID id) { + this.id = id; + return this; + } + + /** + * Get id + * @return id + */ + @jakarta.annotation.Nonnull + @JsonProperty(value = JSON_PROPERTY_ID, required = true) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + public UUID getId() { + return id; + } + + + @JsonProperty(value = JSON_PROPERTY_ID, required = true) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + public void setId(@jakarta.annotation.Nonnull UUID id) { + this.id = id; + } + + + public FileUpload uploadUrl(@jakarta.annotation.Nonnull String uploadUrl) { + this.uploadUrl = uploadUrl; + return this; + } + + /** + * Get uploadUrl + * @return uploadUrl + */ + @jakarta.annotation.Nonnull + @JsonProperty(value = JSON_PROPERTY_UPLOAD_URL, required = true) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + public String getUploadUrl() { + return uploadUrl; + } + + + @JsonProperty(value = JSON_PROPERTY_UPLOAD_URL, required = true) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + public void setUploadUrl(@jakarta.annotation.Nonnull String uploadUrl) { + this.uploadUrl = uploadUrl; + } + + + /** + * Return true if this FileUpload object is equal to o. + */ + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + FileUpload fileUpload = (FileUpload) o; + return Objects.equals(this.id, fileUpload.id) && + Objects.equals(this.uploadUrl, fileUpload.uploadUrl); + } + + @Override + public int hashCode() { + return Objects.hash(id, uploadUrl); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class FileUpload {\n"); + sb.append(" id: ").append(toIndentedString(id)).append("\n"); + sb.append(" uploadUrl: ").append(toIndentedString(uploadUrl)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(Object o) { + return o == null ? "null" : o.toString().replace("\n", "\n "); + } + + /** + * Convert the instance into URL query string. + * + * @return URL query string + */ + public String toUrlQueryString() { + return toUrlQueryString(null); + } + + /** + * Convert the instance into URL query string. + * + * @param prefix prefix of the query string + * @return URL query string + */ + public String toUrlQueryString(String prefix) { + String suffix = ""; + String containerSuffix = ""; + String containerPrefix = ""; + if (prefix == null) { + // style=form, explode=true, e.g. /pet?name=cat&type=manx + prefix = ""; + } else { + // deepObject style e.g. /pet?id[name]=cat&id[type]=manx + prefix = prefix + "["; + suffix = "]"; + containerSuffix = "]"; + containerPrefix = "["; + } + + StringJoiner joiner = new StringJoiner("&"); + + // add `id` to the URL query string + if (getId() != null) { + joiner.add(String.format(java.util.Locale.ROOT, "%sid%s=%s", prefix, suffix, ApiClient.urlEncode(ApiClient.valueToString(getId())))); + } + + // add `uploadUrl` to the URL query string + if (getUploadUrl() != null) { + joiner.add(String.format(java.util.Locale.ROOT, "%suploadUrl%s=%s", prefix, suffix, ApiClient.urlEncode(ApiClient.valueToString(getUploadUrl())))); + } + + return joiner.toString(); + } +} + diff --git a/src/main/java/com/controlresell/sdk/generated/model/FileUploadRequest.java b/src/main/java/com/controlresell/sdk/generated/model/FileUploadRequest.java new file mode 100644 index 0000000..4b73e31 --- /dev/null +++ b/src/main/java/com/controlresell/sdk/generated/model/FileUploadRequest.java @@ -0,0 +1,220 @@ +/* + * ControlResell public API + * The public API of ControlResell. Every error answers `{\"error\": {\"code\", \"message\", \"params\", \"requestId\"}}`; a `POST` takes an `Idempotency-Key` header. + * + * The version of the OpenAPI document: 1 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +package com.controlresell.sdk.generated.model; + +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; +import java.util.StringJoiner; +import java.util.Objects; +import java.util.Map; +import java.util.HashMap; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.fasterxml.jackson.annotation.JsonValue; +import java.util.Arrays; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; + + +import com.controlresell.sdk.generated.ApiClient; +/** + * FileUploadRequest + */ +@JsonPropertyOrder({ + FileUploadRequest.JSON_PROPERTY_FILENAME, + FileUploadRequest.JSON_PROPERTY_CONTENT_TYPE, + FileUploadRequest.JSON_PROPERTY_SIZE +}) +@jakarta.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "Generator version: 7.26.0") +public class FileUploadRequest { + public static final String JSON_PROPERTY_FILENAME = "filename"; + @jakarta.annotation.Nonnull + private String filename; + + public static final String JSON_PROPERTY_CONTENT_TYPE = "contentType"; + @jakarta.annotation.Nonnull + private String contentType; + + public static final String JSON_PROPERTY_SIZE = "size"; + @jakarta.annotation.Nonnull + private Long size; + + public FileUploadRequest() { + } + + public FileUploadRequest filename(@jakarta.annotation.Nonnull String filename) { + this.filename = filename; + return this; + } + + /** + * Get filename + * @return filename + */ + @jakarta.annotation.Nonnull + @JsonProperty(value = JSON_PROPERTY_FILENAME, required = true) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + public String getFilename() { + return filename; + } + + + @JsonProperty(value = JSON_PROPERTY_FILENAME, required = true) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + public void setFilename(@jakarta.annotation.Nonnull String filename) { + this.filename = filename; + } + + + public FileUploadRequest contentType(@jakarta.annotation.Nonnull String contentType) { + this.contentType = contentType; + return this; + } + + /** + * Get contentType + * @return contentType + */ + @jakarta.annotation.Nonnull + @JsonProperty(value = JSON_PROPERTY_CONTENT_TYPE, required = true) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + public String getContentType() { + return contentType; + } + + + @JsonProperty(value = JSON_PROPERTY_CONTENT_TYPE, required = true) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + public void setContentType(@jakarta.annotation.Nonnull String contentType) { + this.contentType = contentType; + } + + + public FileUploadRequest size(@jakarta.annotation.Nonnull Long size) { + this.size = size; + return this; + } + + /** + * Get size + * @return size + */ + @jakarta.annotation.Nonnull + @JsonProperty(value = JSON_PROPERTY_SIZE, required = true) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + public Long getSize() { + return size; + } + + + @JsonProperty(value = JSON_PROPERTY_SIZE, required = true) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + public void setSize(@jakarta.annotation.Nonnull Long size) { + this.size = size; + } + + + /** + * Return true if this FileUploadRequest object is equal to o. + */ + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + FileUploadRequest fileUploadRequest = (FileUploadRequest) o; + return Objects.equals(this.filename, fileUploadRequest.filename) && + Objects.equals(this.contentType, fileUploadRequest.contentType) && + Objects.equals(this.size, fileUploadRequest.size); + } + + @Override + public int hashCode() { + return Objects.hash(filename, contentType, size); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class FileUploadRequest {\n"); + sb.append(" filename: ").append(toIndentedString(filename)).append("\n"); + sb.append(" contentType: ").append(toIndentedString(contentType)).append("\n"); + sb.append(" size: ").append(toIndentedString(size)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(Object o) { + return o == null ? "null" : o.toString().replace("\n", "\n "); + } + + /** + * Convert the instance into URL query string. + * + * @return URL query string + */ + public String toUrlQueryString() { + return toUrlQueryString(null); + } + + /** + * Convert the instance into URL query string. + * + * @param prefix prefix of the query string + * @return URL query string + */ + public String toUrlQueryString(String prefix) { + String suffix = ""; + String containerSuffix = ""; + String containerPrefix = ""; + if (prefix == null) { + // style=form, explode=true, e.g. /pet?name=cat&type=manx + prefix = ""; + } else { + // deepObject style e.g. /pet?id[name]=cat&id[type]=manx + prefix = prefix + "["; + suffix = "]"; + containerSuffix = "]"; + containerPrefix = "["; + } + + StringJoiner joiner = new StringJoiner("&"); + + // add `filename` to the URL query string + if (getFilename() != null) { + joiner.add(String.format(java.util.Locale.ROOT, "%sfilename%s=%s", prefix, suffix, ApiClient.urlEncode(ApiClient.valueToString(getFilename())))); + } + + // add `contentType` to the URL query string + if (getContentType() != null) { + joiner.add(String.format(java.util.Locale.ROOT, "%scontentType%s=%s", prefix, suffix, ApiClient.urlEncode(ApiClient.valueToString(getContentType())))); + } + + // add `size` to the URL query string + if (getSize() != null) { + joiner.add(String.format(java.util.Locale.ROOT, "%ssize%s=%s", prefix, suffix, ApiClient.urlEncode(ApiClient.valueToString(getSize())))); + } + + return joiner.toString(); + } +} + diff --git a/src/main/java/com/controlresell/sdk/generated/model/ModelFile.java b/src/main/java/com/controlresell/sdk/generated/model/ModelFile.java new file mode 100644 index 0000000..cabe6e4 --- /dev/null +++ b/src/main/java/com/controlresell/sdk/generated/model/ModelFile.java @@ -0,0 +1,280 @@ +/* + * ControlResell public API + * The public API of ControlResell. Every error answers `{\"error\": {\"code\", \"message\", \"params\", \"requestId\"}}`; a `POST` takes an `Idempotency-Key` header. + * + * The version of the OpenAPI document: 1 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +package com.controlresell.sdk.generated.model; + +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; +import java.util.StringJoiner; +import java.util.Objects; +import java.util.Map; +import java.util.HashMap; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.fasterxml.jackson.annotation.JsonValue; +import java.time.OffsetDateTime; +import java.util.Arrays; +import java.util.UUID; +import org.openapitools.jackson.nullable.JsonNullable; +import com.fasterxml.jackson.annotation.JsonIgnore; +import org.openapitools.jackson.nullable.JsonNullable; +import java.util.NoSuchElementException; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; + + +import com.controlresell.sdk.generated.ApiClient; +/** + * ModelFile + */ +@JsonPropertyOrder({ + ModelFile.JSON_PROPERTY_ID, + ModelFile.JSON_PROPERTY_STATUS, + ModelFile.JSON_PROPERTY_URL, + ModelFile.JSON_PROPERTY_CREATED_AT +}) +@jakarta.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "Generator version: 7.26.0") +public class ModelFile { + public static final String JSON_PROPERTY_ID = "id"; + @jakarta.annotation.Nonnull + private UUID id; + + public static final String JSON_PROPERTY_STATUS = "status"; + private JsonNullable status = JsonNullable.undefined(); + + public static final String JSON_PROPERTY_URL = "url"; + @jakarta.annotation.Nonnull + private String url; + + public static final String JSON_PROPERTY_CREATED_AT = "createdAt"; + @jakarta.annotation.Nonnull + private OffsetDateTime createdAt; + + public ModelFile() { + } + + public ModelFile id(@jakarta.annotation.Nonnull UUID id) { + this.id = id; + return this; + } + + /** + * Get id + * @return id + */ + @jakarta.annotation.Nonnull + @JsonProperty(value = JSON_PROPERTY_ID, required = true) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + public UUID getId() { + return id; + } + + + @JsonProperty(value = JSON_PROPERTY_ID, required = true) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + public void setId(@jakarta.annotation.Nonnull UUID id) { + this.id = id; + } + + + public ModelFile status(@jakarta.annotation.Nullable String status) { + this.status = JsonNullable.of(status); + return this; + } + + /** + * Get status + * @return status + */ + @jakarta.annotation.Nullable + @JsonIgnore + public String getStatus() { + return status.orElse(null); + } + + @JsonProperty(value = JSON_PROPERTY_STATUS, required = false) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + + public JsonNullable getStatus_JsonNullable() { + return status; + } + + @JsonProperty(JSON_PROPERTY_STATUS) + public void setStatus_JsonNullable(JsonNullable status) { + this.status = status; + } + + public void setStatus(@jakarta.annotation.Nullable String status) { + this.status = JsonNullable.of(status); + } + + + public ModelFile url(@jakarta.annotation.Nonnull String url) { + this.url = url; + return this; + } + + /** + * Get url + * @return url + */ + @jakarta.annotation.Nonnull + @JsonProperty(value = JSON_PROPERTY_URL, required = true) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + public String getUrl() { + return url; + } + + + @JsonProperty(value = JSON_PROPERTY_URL, required = true) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + public void setUrl(@jakarta.annotation.Nonnull String url) { + this.url = url; + } + + + public ModelFile createdAt(@jakarta.annotation.Nonnull OffsetDateTime createdAt) { + this.createdAt = createdAt; + return this; + } + + /** + * Get createdAt + * @return createdAt + */ + @jakarta.annotation.Nonnull + @JsonProperty(value = JSON_PROPERTY_CREATED_AT, required = true) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + public OffsetDateTime getCreatedAt() { + return createdAt; + } + + + @JsonProperty(value = JSON_PROPERTY_CREATED_AT, required = true) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + public void setCreatedAt(@jakarta.annotation.Nonnull OffsetDateTime createdAt) { + this.createdAt = createdAt; + } + + + /** + * Return true if this File object is equal to o. + */ + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + ModelFile _file = (ModelFile) o; + return Objects.equals(this.id, _file.id) && + equalsNullable(this.status, _file.status) && + Objects.equals(this.url, _file.url) && + Objects.equals(this.createdAt, _file.createdAt); + } + + private static boolean equalsNullable(JsonNullable a, JsonNullable b) { + return a == b || (a != null && b != null && a.isPresent() && b.isPresent() && Objects.deepEquals(a.get(), b.get())); + } + + @Override + public int hashCode() { + return Objects.hash(id, hashCodeNullable(status), url, createdAt); + } + + private static int hashCodeNullable(JsonNullable a) { + if (a == null) { + return 1; + } + return a.isPresent() ? Arrays.deepHashCode(new Object[]{a.get()}) : 31; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class ModelFile {\n"); + sb.append(" id: ").append(toIndentedString(id)).append("\n"); + sb.append(" status: ").append(toIndentedString(status)).append("\n"); + sb.append(" url: ").append(toIndentedString(url)).append("\n"); + sb.append(" createdAt: ").append(toIndentedString(createdAt)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(Object o) { + return o == null ? "null" : o.toString().replace("\n", "\n "); + } + + /** + * Convert the instance into URL query string. + * + * @return URL query string + */ + public String toUrlQueryString() { + return toUrlQueryString(null); + } + + /** + * Convert the instance into URL query string. + * + * @param prefix prefix of the query string + * @return URL query string + */ + public String toUrlQueryString(String prefix) { + String suffix = ""; + String containerSuffix = ""; + String containerPrefix = ""; + if (prefix == null) { + // style=form, explode=true, e.g. /pet?name=cat&type=manx + prefix = ""; + } else { + // deepObject style e.g. /pet?id[name]=cat&id[type]=manx + prefix = prefix + "["; + suffix = "]"; + containerSuffix = "]"; + containerPrefix = "["; + } + + StringJoiner joiner = new StringJoiner("&"); + + // add `id` to the URL query string + if (getId() != null) { + joiner.add(String.format(java.util.Locale.ROOT, "%sid%s=%s", prefix, suffix, ApiClient.urlEncode(ApiClient.valueToString(getId())))); + } + + // add `status` to the URL query string + if (getStatus() != null) { + joiner.add(String.format(java.util.Locale.ROOT, "%sstatus%s=%s", prefix, suffix, ApiClient.urlEncode(ApiClient.valueToString(getStatus())))); + } + + // add `url` to the URL query string + if (getUrl() != null) { + joiner.add(String.format(java.util.Locale.ROOT, "%surl%s=%s", prefix, suffix, ApiClient.urlEncode(ApiClient.valueToString(getUrl())))); + } + + // add `createdAt` to the URL query string + if (getCreatedAt() != null) { + joiner.add(String.format(java.util.Locale.ROOT, "%screatedAt%s=%s", prefix, suffix, ApiClient.urlEncode(ApiClient.valueToString(getCreatedAt())))); + } + + return joiner.toString(); + } +} + diff --git a/src/test/java/com/controlresell/sdk/ControlResellTest.java b/src/test/java/com/controlresell/sdk/ControlResellTest.java index 1b5ceb2..0f3a6b2 100644 --- a/src/test/java/com/controlresell/sdk/ControlResellTest.java +++ b/src/test/java/com/controlresell/sdk/ControlResellTest.java @@ -559,4 +559,37 @@ void webhooksTestIsNotReplayedAfterALostConnection() throws Exception { assertThrows(ControlResellError.Connection.class, () -> sdk.webhooks().test(java.util.UUID.fromString(ENDPOINT_ID))); assertEquals(1, hits.get()); } + + @Test + void filesRegisterGetAndUploadSendTheBytesWithoutTheApiKeyAndRetryThePut() throws Exception { + String id = "3f0c2a52-0b0c-4d65-9f40-2d2d3b1f4a10"; + ControlResell sdk = client(n -> { + String path = exchanges.get(n - 1).getRequestURI().getPath(); + if (path.equals("/api/public/v1/files")) { + return new Reply(201, "{\"id\":\"" + id + "\",\"uploadUrl\":\"http://127.0.0.1:" + server.getAddress().getPort() + "/put\",\"unknownField\":1}"); + } + if (path.equals("/put")) return exchanges.stream().filter(e -> e.getRequestURI().getPath().equals("/put")).count() == 1 ? new Reply(503, "") : new Reply(200, ""); + return new Reply(200, "{\"id\":\"" + id + "\",\"status\":\"CONFIRMED\",\"url\":\"https://s3.test/get\",\"createdAt\":\"2026-10-28T10:00:00Z\"}"); + }); + var upload = sdk.files().upload("abc".getBytes(StandardCharsets.UTF_8), "a.jpg", "image/jpeg"); + assertEquals(id, upload.getId().toString()); + assertEquals("/api/public/v1/files", exchanges.get(0).getRequestURI().getPath()); + assertTrue(bodies.get(0).contains("\"size\":3") && bodies.get(0).contains("\"filename\":\"a.jpg\""), bodies.get(0)); + assertTrue(keys.get(0) != null); + assertEquals(3, exchanges.size(), "register, then the PUT and its retry"); + assertEquals("PUT", exchanges.get(2).getRequestMethod()); + assertEquals("abc", bodies.get(2)); + assertEquals("image/jpeg", exchanges.get(2).getRequestHeaders().getFirst("Content-Type")); + assertNull(authorizations.get(2), "no API key on the signed PUT"); + assertEquals("CONFIRMED", sdk.files().get(upload.getId()).getStatus()); + } + + @Test + void filesUploadThrowsATypedErrorWhenThePutIsRefused() throws Exception { + String id = "3f0c2a52-0b0c-4d65-9f40-2d2d3b1f4a10"; + ControlResell sdk = client(n -> n == 1 + ? new Reply(201, "{\"id\":\"" + id + "\",\"uploadUrl\":\"http://127.0.0.1:" + server.getAddress().getPort() + "/put\"}") + : new Reply(403, "")); + assertThrows(ControlResellError.PermissionDenied.class, () -> sdk.files().upload(new byte[] {1}, "a.jpg", "image/jpeg")); + } }