nextBackoff(Response response) {
+ if (retryNumber >= maxNumRetries) {
return Optional.empty();
}
- int upperBound = (int) Math.pow(2, retryNumber);
- return Optional.of(ONE_SECOND.multipliedBy(random.nextInt(upperBound)));
+ Duration delay = getRetryDelayFromHeaders(response, retryNumber);
+ retryNumber += 1;
+ return Optional.of(delay);
}
}
}
diff --git a/src/main/java/com/schematic/api/core/Stream.java b/src/main/java/com/schematic/api/core/Stream.java
index 89ae9c7..b4e9ab3 100644
--- a/src/main/java/com/schematic/api/core/Stream.java
+++ b/src/main/java/com/schematic/api/core/Stream.java
@@ -3,6 +3,8 @@
*/
package com.schematic.api.core;
+import java.io.Closeable;
+import java.io.IOException;
import java.io.Reader;
import java.util.Iterator;
import java.util.NoSuchElementException;
@@ -14,18 +16,28 @@
*
* {@code Stream} assumes that data is being pushed to the provided {@link Reader} asynchronously and utilizes a
* {@code Scanner} to block during iteration if the next object is not available.
+ * Iterable stream for parsing JSON and Server-Sent Events (SSE) data.
+ * Supports both newline-delimited JSON and SSE with optional stream termination.
*
* @param The type of objects in the stream.
*/
-public final class Stream implements Iterable {
- /**
- * The {@link Class} of the objects in the stream.
- */
+public final class Stream implements Iterable, Closeable {
+
+ private static final String NEWLINE = "\n";
+ private static final String DATA_PREFIX = "data:";
+
+ public enum StreamType {
+ JSON,
+ SSE
+ }
+
private final Class valueType;
- /**
- * The {@link Scanner} used for reading from the input stream and blocking when needed during iteration.
- */
private final Scanner scanner;
+ private final StreamType streamType;
+ private final String messageTerminator;
+ private final String streamTerminator;
+ private final Reader sseReader;
+ private boolean isClosed = false;
/**
* Constructs a new {@code Stream} with the specified value type, reader, and delimiter.
@@ -35,8 +47,61 @@ public final class Stream implements Iterable {
* @param delimiter The delimiter used to separate elements in the stream.
*/
public Stream(Class valueType, Reader reader, String delimiter) {
+ this.valueType = valueType;
this.scanner = new Scanner(reader).useDelimiter(delimiter);
+ this.streamType = StreamType.JSON;
+ this.messageTerminator = delimiter;
+ this.streamTerminator = null;
+ this.sseReader = null;
+ }
+
+ private Stream(Class valueType, StreamType type, Reader reader, String terminator) {
this.valueType = valueType;
+ this.streamType = type;
+ if (type == StreamType.JSON) {
+ this.scanner = new Scanner(reader).useDelimiter(terminator);
+ this.messageTerminator = terminator;
+ this.streamTerminator = null;
+ this.sseReader = null;
+ } else {
+ this.scanner = null;
+ this.messageTerminator = NEWLINE;
+ this.streamTerminator = terminator;
+ this.sseReader = reader;
+ }
+ }
+
+ public static Stream fromJson(Class valueType, Reader reader, String delimiter) {
+ return new Stream<>(valueType, reader, delimiter);
+ }
+
+ public static Stream fromJson(Class valueType, Reader reader) {
+ return new Stream<>(valueType, reader, NEWLINE);
+ }
+
+ public static Stream fromSse(Class valueType, Reader sseReader) {
+ return new Stream<>(valueType, StreamType.SSE, sseReader, null);
+ }
+
+ public static Stream fromSse(Class valueType, Reader sseReader, String streamTerminator) {
+ return new Stream<>(valueType, StreamType.SSE, sseReader, streamTerminator);
+ }
+
+ @Override
+ public void close() throws IOException {
+ if (!isClosed) {
+ isClosed = true;
+ if (scanner != null) {
+ scanner.close();
+ }
+ if (sseReader != null) {
+ sseReader.close();
+ }
+ }
+ }
+
+ private boolean isStreamClosed() {
+ return isClosed;
}
/**
@@ -47,51 +112,191 @@ public Stream(Class valueType, Reader reader, String delimiter) {
*/
@Override
public Iterator iterator() {
- return new Iterator() {
- /**
- * Returns {@code true} if there are more elements in the stream.
- *
- * Will block and wait for input if the stream has not ended and the next object is not yet available.
- *
- * @return {@code true} if there are more elements, {@code false} otherwise.
- */
- @Override
- public boolean hasNext() {
- return scanner.hasNext();
+ if (streamType == StreamType.SSE) {
+ return new SSEIterator();
+ } else {
+ return new JsonIterator();
+ }
+ }
+
+ private final class JsonIterator implements Iterator {
+
+ /**
+ * Returns {@code true} if there are more elements in the stream.
+ *
+ * Will block and wait for input if the stream has not ended and the next object is not yet available.
+ *
+ * @return {@code true} if there are more elements, {@code false} otherwise.
+ */
+ @Override
+ public boolean hasNext() {
+ if (isStreamClosed()) {
+ return false;
+ }
+ return scanner.hasNext();
+ }
+
+ /**
+ * Returns the next element in the stream.
+ *
+ * Will block and wait for input if the stream has not ended and the next object is not yet available.
+ *
+ * @return The next element in the stream.
+ * @throws NoSuchElementException If there are no more elements in the stream.
+ */
+ @Override
+ public T next() {
+ if (isStreamClosed()) {
+ throw new NoSuchElementException("Stream is closed");
+ }
+
+ if (!scanner.hasNext()) {
+ throw new NoSuchElementException();
+ } else {
+ try {
+ T parsedResponse =
+ ObjectMappers.JSON_MAPPER.readValue(scanner.next().trim(), valueType);
+ return parsedResponse;
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+ }
+
+ @Override
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+ }
+
+ private final class SSEIterator implements Iterator {
+ private Scanner sseScanner;
+ private T nextItem;
+ private boolean hasNextItem = false;
+ private boolean endOfStream = false;
+ private StringBuilder eventDataBuffer = new StringBuilder();
+ private String currentEventType = null;
+
+ private SSEIterator() {
+ if (sseReader != null && !isStreamClosed()) {
+ this.sseScanner = new Scanner(sseReader);
+ } else {
+ this.endOfStream = true;
+ }
+ }
+
+ @Override
+ public boolean hasNext() {
+ if (isStreamClosed() || endOfStream) {
+ return false;
+ }
+
+ if (hasNextItem) {
+ return true;
+ }
+
+ return readNextMessage();
+ }
+
+ @Override
+ public T next() {
+ if (!hasNext()) {
+ throw new NoSuchElementException("No more elements in stream");
+ }
+
+ T result = nextItem;
+ nextItem = null;
+ hasNextItem = false;
+ return result;
+ }
+
+ @Override
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+
+ private boolean readNextMessage() {
+ if (sseScanner == null || isStreamClosed()) {
+ endOfStream = true;
+ return false;
}
- /**
- * Returns the next element in the stream.
- *
- * Will block and wait for input if the stream has not ended and the next object is not yet available.
- *
- * @return The next element in the stream.
- * @throws NoSuchElementException If there are no more elements in the stream.
- */
- @Override
- public T next() {
- if (!scanner.hasNext()) {
- throw new NoSuchElementException();
- } else {
+ try {
+ while (sseScanner.hasNextLine()) {
+ String line = sseScanner.nextLine();
+
+ if (line.trim().isEmpty()) {
+ if (eventDataBuffer.length() > 0) {
+ try {
+ nextItem = ObjectMappers.JSON_MAPPER.readValue(eventDataBuffer.toString(), valueType);
+ hasNextItem = true;
+ eventDataBuffer.setLength(0);
+ currentEventType = null;
+ return true;
+ } catch (Exception parseEx) {
+ System.err.println("Failed to parse SSE event: " + parseEx.getMessage());
+ eventDataBuffer.setLength(0);
+ currentEventType = null;
+ continue;
+ }
+ }
+ continue;
+ }
+
+ if (line.startsWith(DATA_PREFIX)) {
+ String dataContent = line.substring(DATA_PREFIX.length());
+ if (dataContent.startsWith(" ")) {
+ dataContent = dataContent.substring(1);
+ }
+
+ if (eventDataBuffer.length() == 0
+ && streamTerminator != null
+ && dataContent.trim().equals(streamTerminator)) {
+ endOfStream = true;
+ return false;
+ }
+
+ if (eventDataBuffer.length() > 0) {
+ eventDataBuffer.append('\n');
+ }
+ eventDataBuffer.append(dataContent);
+ } else if (line.startsWith("event:")) {
+ String eventValue = line.length() > 6 ? line.substring(6) : "";
+ if (eventValue.startsWith(" ")) {
+ eventValue = eventValue.substring(1);
+ }
+ currentEventType = eventValue;
+ } else if (line.startsWith("id:")) {
+ // Event ID field (ignored)
+ } else if (line.startsWith("retry:")) {
+ // Retry field (ignored)
+ } else if (line.startsWith(":")) {
+ // Comment line (ignored)
+ }
+ }
+
+ if (eventDataBuffer.length() > 0) {
try {
- T parsedResponse = ObjectMappers.JSON_MAPPER.readValue(
- scanner.next().trim(), valueType);
- return parsedResponse;
- } catch (Exception e) {
- throw new RuntimeException(e);
+ nextItem = ObjectMappers.JSON_MAPPER.readValue(eventDataBuffer.toString(), valueType);
+ hasNextItem = true;
+ eventDataBuffer.setLength(0);
+ currentEventType = null;
+ return true;
+ } catch (Exception parseEx) {
+ System.err.println("Failed to parse final SSE event: " + parseEx.getMessage());
+ eventDataBuffer.setLength(0);
+ currentEventType = null;
}
}
- }
- /**
- * Removing elements from {@code Stream} is not supported.
- *
- * @throws UnsupportedOperationException Always, as removal is not supported.
- */
- @Override
- public void remove() {
- throw new UnsupportedOperationException();
+ endOfStream = true;
+ return false;
+
+ } catch (Exception e) {
+ System.err.println("Failed to parse SSE stream: " + e.getMessage());
+ endOfStream = true;
+ return false;
}
- };
+ }
}
}
diff --git a/src/main/java/com/schematic/api/errors/BadRequestError.java b/src/main/java/com/schematic/api/errors/BadRequestError.java
index f51e164..40a637d 100644
--- a/src/main/java/com/schematic/api/errors/BadRequestError.java
+++ b/src/main/java/com/schematic/api/errors/BadRequestError.java
@@ -5,6 +5,7 @@
import com.schematic.api.core.BaseSchematicApiException;
import com.schematic.api.types.ApiError;
+import okhttp3.Response;
public final class BadRequestError extends BaseSchematicApiException {
/**
@@ -17,6 +18,11 @@ public BadRequestError(ApiError body) {
this.body = body;
}
+ public BadRequestError(ApiError body, Response rawResponse) {
+ super("BadRequestError", 400, body, rawResponse);
+ this.body = body;
+ }
+
/**
* @return the body
*/
diff --git a/src/main/java/com/schematic/api/errors/ForbiddenError.java b/src/main/java/com/schematic/api/errors/ForbiddenError.java
index 0294ce2..eb08c0f 100644
--- a/src/main/java/com/schematic/api/errors/ForbiddenError.java
+++ b/src/main/java/com/schematic/api/errors/ForbiddenError.java
@@ -5,6 +5,7 @@
import com.schematic.api.core.BaseSchematicApiException;
import com.schematic.api.types.ApiError;
+import okhttp3.Response;
public final class ForbiddenError extends BaseSchematicApiException {
/**
@@ -17,6 +18,11 @@ public ForbiddenError(ApiError body) {
this.body = body;
}
+ public ForbiddenError(ApiError body, Response rawResponse) {
+ super("ForbiddenError", 403, body, rawResponse);
+ this.body = body;
+ }
+
/**
* @return the body
*/
diff --git a/src/main/java/com/schematic/api/errors/InternalServerError.java b/src/main/java/com/schematic/api/errors/InternalServerError.java
index f39e7dd..eceb750 100644
--- a/src/main/java/com/schematic/api/errors/InternalServerError.java
+++ b/src/main/java/com/schematic/api/errors/InternalServerError.java
@@ -5,6 +5,7 @@
import com.schematic.api.core.BaseSchematicApiException;
import com.schematic.api.types.ApiError;
+import okhttp3.Response;
public final class InternalServerError extends BaseSchematicApiException {
/**
@@ -17,6 +18,11 @@ public InternalServerError(ApiError body) {
this.body = body;
}
+ public InternalServerError(ApiError body, Response rawResponse) {
+ super("InternalServerError", 500, body, rawResponse);
+ this.body = body;
+ }
+
/**
* @return the body
*/
diff --git a/src/main/java/com/schematic/api/errors/NotFoundError.java b/src/main/java/com/schematic/api/errors/NotFoundError.java
index e3a83dc..203741d 100644
--- a/src/main/java/com/schematic/api/errors/NotFoundError.java
+++ b/src/main/java/com/schematic/api/errors/NotFoundError.java
@@ -5,6 +5,7 @@
import com.schematic.api.core.BaseSchematicApiException;
import com.schematic.api.types.ApiError;
+import okhttp3.Response;
public final class NotFoundError extends BaseSchematicApiException {
/**
@@ -17,6 +18,11 @@ public NotFoundError(ApiError body) {
this.body = body;
}
+ public NotFoundError(ApiError body, Response rawResponse) {
+ super("NotFoundError", 404, body, rawResponse);
+ this.body = body;
+ }
+
/**
* @return the body
*/
diff --git a/src/main/java/com/schematic/api/errors/UnauthorizedError.java b/src/main/java/com/schematic/api/errors/UnauthorizedError.java
index d25c733..18fad20 100644
--- a/src/main/java/com/schematic/api/errors/UnauthorizedError.java
+++ b/src/main/java/com/schematic/api/errors/UnauthorizedError.java
@@ -5,6 +5,7 @@
import com.schematic.api.core.BaseSchematicApiException;
import com.schematic.api.types.ApiError;
+import okhttp3.Response;
public final class UnauthorizedError extends BaseSchematicApiException {
/**
@@ -17,6 +18,11 @@ public UnauthorizedError(ApiError body) {
this.body = body;
}
+ public UnauthorizedError(ApiError body, Response rawResponse) {
+ super("UnauthorizedError", 401, body, rawResponse);
+ this.body = body;
+ }
+
/**
* @return the body
*/
diff --git a/src/main/java/com/schematic/api/resources/accesstokens/AccesstokensClient.java b/src/main/java/com/schematic/api/resources/accesstokens/AccesstokensClient.java
index 6f6bd7a..2f3d47f 100644
--- a/src/main/java/com/schematic/api/resources/accesstokens/AccesstokensClient.java
+++ b/src/main/java/com/schematic/api/resources/accesstokens/AccesstokensClient.java
@@ -3,95 +3,34 @@
*/
package com.schematic.api.resources.accesstokens;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.schematic.api.core.BaseSchematicApiException;
-import com.schematic.api.core.BaseSchematicException;
import com.schematic.api.core.ClientOptions;
-import com.schematic.api.core.MediaTypes;
-import com.schematic.api.core.ObjectMappers;
import com.schematic.api.core.RequestOptions;
-import com.schematic.api.errors.BadRequestError;
-import com.schematic.api.errors.ForbiddenError;
-import com.schematic.api.errors.InternalServerError;
-import com.schematic.api.errors.UnauthorizedError;
import com.schematic.api.resources.accesstokens.requests.IssueTemporaryAccessTokenRequestBody;
import com.schematic.api.resources.accesstokens.types.IssueTemporaryAccessTokenResponse;
-import com.schematic.api.types.ApiError;
-import java.io.IOException;
-import okhttp3.Headers;
-import okhttp3.HttpUrl;
-import okhttp3.OkHttpClient;
-import okhttp3.Request;
-import okhttp3.RequestBody;
-import okhttp3.Response;
-import okhttp3.ResponseBody;
public class AccesstokensClient {
protected final ClientOptions clientOptions;
+ private final RawAccesstokensClient rawClient;
+
public AccesstokensClient(ClientOptions clientOptions) {
this.clientOptions = clientOptions;
+ this.rawClient = new RawAccesstokensClient(clientOptions);
+ }
+
+ /**
+ * Get responses with HTTP metadata like headers
+ */
+ public RawAccesstokensClient withRawResponse() {
+ return this.rawClient;
}
public IssueTemporaryAccessTokenResponse issueTemporaryAccessToken(IssueTemporaryAccessTokenRequestBody request) {
- return issueTemporaryAccessToken(request, null);
+ return this.rawClient.issueTemporaryAccessToken(request).body();
}
public IssueTemporaryAccessTokenResponse issueTemporaryAccessToken(
IssueTemporaryAccessTokenRequestBody request, RequestOptions requestOptions) {
- HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
- .newBuilder()
- .addPathSegments("temporary-access-tokens")
- .build();
- RequestBody body;
- try {
- body = RequestBody.create(
- ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON);
- } catch (JsonProcessingException e) {
- throw new BaseSchematicException("Failed to serialize request", e);
- }
- Request okhttpRequest = new Request.Builder()
- .url(httpUrl)
- .method("POST", body)
- .headers(Headers.of(clientOptions.headers(requestOptions)))
- .addHeader("Content-Type", "application/json")
- .addHeader("Accept", "application/json")
- .build();
- OkHttpClient client = clientOptions.httpClient();
- if (requestOptions != null && requestOptions.getTimeout().isPresent()) {
- client = clientOptions.httpClientWithTimeout(requestOptions);
- }
- try (Response response = client.newCall(okhttpRequest).execute()) {
- ResponseBody responseBody = response.body();
- if (response.isSuccessful()) {
- return ObjectMappers.JSON_MAPPER.readValue(
- responseBody.string(), IssueTemporaryAccessTokenResponse.class);
- }
- String responseBodyString = responseBody != null ? responseBody.string() : "{}";
- try {
- switch (response.code()) {
- case 400:
- throw new BadRequestError(
- ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class));
- case 401:
- throw new UnauthorizedError(
- ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class));
- case 403:
- throw new ForbiddenError(
- ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class));
- case 500:
- throw new InternalServerError(
- ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class));
- }
- } catch (JsonProcessingException ignored) {
- // unable to map error response, throwing generic error
- }
- throw new BaseSchematicApiException(
- "Error with status code " + response.code(),
- response.code(),
- ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class));
- } catch (IOException e) {
- throw new BaseSchematicException("Network error executing HTTP request", e);
- }
+ return this.rawClient.issueTemporaryAccessToken(request, requestOptions).body();
}
}
diff --git a/src/main/java/com/schematic/api/resources/accesstokens/AsyncAccesstokensClient.java b/src/main/java/com/schematic/api/resources/accesstokens/AsyncAccesstokensClient.java
new file mode 100644
index 0000000..4b5174d
--- /dev/null
+++ b/src/main/java/com/schematic/api/resources/accesstokens/AsyncAccesstokensClient.java
@@ -0,0 +1,38 @@
+/**
+ * This file was auto-generated by Fern from our API Definition.
+ */
+package com.schematic.api.resources.accesstokens;
+
+import com.schematic.api.core.ClientOptions;
+import com.schematic.api.core.RequestOptions;
+import com.schematic.api.resources.accesstokens.requests.IssueTemporaryAccessTokenRequestBody;
+import com.schematic.api.resources.accesstokens.types.IssueTemporaryAccessTokenResponse;
+import java.util.concurrent.CompletableFuture;
+
+public class AsyncAccesstokensClient {
+ protected final ClientOptions clientOptions;
+
+ private final AsyncRawAccesstokensClient rawClient;
+
+ public AsyncAccesstokensClient(ClientOptions clientOptions) {
+ this.clientOptions = clientOptions;
+ this.rawClient = new AsyncRawAccesstokensClient(clientOptions);
+ }
+
+ /**
+ * Get responses with HTTP metadata like headers
+ */
+ public AsyncRawAccesstokensClient withRawResponse() {
+ return this.rawClient;
+ }
+
+ public CompletableFuture issueTemporaryAccessToken(
+ IssueTemporaryAccessTokenRequestBody request) {
+ return this.rawClient.issueTemporaryAccessToken(request).thenApply(response -> response.body());
+ }
+
+ public CompletableFuture issueTemporaryAccessToken(
+ IssueTemporaryAccessTokenRequestBody request, RequestOptions requestOptions) {
+ return this.rawClient.issueTemporaryAccessToken(request, requestOptions).thenApply(response -> response.body());
+ }
+}
diff --git a/src/main/java/com/schematic/api/resources/accesstokens/AsyncRawAccesstokensClient.java b/src/main/java/com/schematic/api/resources/accesstokens/AsyncRawAccesstokensClient.java
new file mode 100644
index 0000000..95f064e
--- /dev/null
+++ b/src/main/java/com/schematic/api/resources/accesstokens/AsyncRawAccesstokensClient.java
@@ -0,0 +1,134 @@
+/**
+ * This file was auto-generated by Fern from our API Definition.
+ */
+package com.schematic.api.resources.accesstokens;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.schematic.api.core.BaseSchematicApiException;
+import com.schematic.api.core.BaseSchematicException;
+import com.schematic.api.core.BaseSchematicHttpResponse;
+import com.schematic.api.core.ClientOptions;
+import com.schematic.api.core.MediaTypes;
+import com.schematic.api.core.ObjectMappers;
+import com.schematic.api.core.RequestOptions;
+import com.schematic.api.errors.BadRequestError;
+import com.schematic.api.errors.ForbiddenError;
+import com.schematic.api.errors.InternalServerError;
+import com.schematic.api.errors.NotFoundError;
+import com.schematic.api.errors.UnauthorizedError;
+import com.schematic.api.resources.accesstokens.requests.IssueTemporaryAccessTokenRequestBody;
+import com.schematic.api.resources.accesstokens.types.IssueTemporaryAccessTokenResponse;
+import com.schematic.api.types.ApiError;
+import java.io.IOException;
+import java.util.concurrent.CompletableFuture;
+import okhttp3.Call;
+import okhttp3.Callback;
+import okhttp3.Headers;
+import okhttp3.HttpUrl;
+import okhttp3.OkHttpClient;
+import okhttp3.Request;
+import okhttp3.RequestBody;
+import okhttp3.Response;
+import okhttp3.ResponseBody;
+import org.jetbrains.annotations.NotNull;
+
+public class AsyncRawAccesstokensClient {
+ protected final ClientOptions clientOptions;
+
+ public AsyncRawAccesstokensClient(ClientOptions clientOptions) {
+ this.clientOptions = clientOptions;
+ }
+
+ public CompletableFuture> issueTemporaryAccessToken(
+ IssueTemporaryAccessTokenRequestBody request) {
+ return issueTemporaryAccessToken(request, null);
+ }
+
+ public CompletableFuture> issueTemporaryAccessToken(
+ IssueTemporaryAccessTokenRequestBody request, RequestOptions requestOptions) {
+ HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
+ .newBuilder()
+ .addPathSegments("temporary-access-tokens")
+ .build();
+ RequestBody body;
+ try {
+ body = RequestBody.create(
+ ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON);
+ } catch (JsonProcessingException e) {
+ throw new BaseSchematicException("Failed to serialize request", e);
+ }
+ Request okhttpRequest = new Request.Builder()
+ .url(httpUrl)
+ .method("POST", body)
+ .headers(Headers.of(clientOptions.headers(requestOptions)))
+ .addHeader("Content-Type", "application/json")
+ .addHeader("Accept", "application/json")
+ .build();
+ OkHttpClient client = clientOptions.httpClient();
+ if (requestOptions != null && requestOptions.getTimeout().isPresent()) {
+ client = clientOptions.httpClientWithTimeout(requestOptions);
+ }
+ CompletableFuture> future =
+ new CompletableFuture<>();
+ client.newCall(okhttpRequest).enqueue(new Callback() {
+ @Override
+ public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException {
+ try (ResponseBody responseBody = response.body()) {
+ if (response.isSuccessful()) {
+ future.complete(new BaseSchematicHttpResponse<>(
+ ObjectMappers.JSON_MAPPER.readValue(
+ responseBody.string(), IssueTemporaryAccessTokenResponse.class),
+ response));
+ return;
+ }
+ String responseBodyString = responseBody != null ? responseBody.string() : "{}";
+ try {
+ switch (response.code()) {
+ case 400:
+ future.completeExceptionally(new BadRequestError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class),
+ response));
+ return;
+ case 401:
+ future.completeExceptionally(new UnauthorizedError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class),
+ response));
+ return;
+ case 403:
+ future.completeExceptionally(new ForbiddenError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class),
+ response));
+ return;
+ case 404:
+ future.completeExceptionally(new NotFoundError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class),
+ response));
+ return;
+ case 500:
+ future.completeExceptionally(new InternalServerError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class),
+ response));
+ return;
+ }
+ } catch (JsonProcessingException ignored) {
+ // unable to map error response, throwing generic error
+ }
+ future.completeExceptionally(new BaseSchematicApiException(
+ "Error with status code " + response.code(),
+ response.code(),
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class),
+ response));
+ return;
+ } catch (IOException e) {
+ future.completeExceptionally(new BaseSchematicException("Network error executing HTTP request", e));
+ }
+ }
+
+ @Override
+ public void onFailure(@NotNull Call call, @NotNull IOException e) {
+ future.completeExceptionally(new BaseSchematicException("Network error executing HTTP request", e));
+ }
+ });
+ return future;
+ }
+}
diff --git a/src/main/java/com/schematic/api/resources/accesstokens/RawAccesstokensClient.java b/src/main/java/com/schematic/api/resources/accesstokens/RawAccesstokensClient.java
new file mode 100644
index 0000000..d9553c9
--- /dev/null
+++ b/src/main/java/com/schematic/api/resources/accesstokens/RawAccesstokensClient.java
@@ -0,0 +1,106 @@
+/**
+ * This file was auto-generated by Fern from our API Definition.
+ */
+package com.schematic.api.resources.accesstokens;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.schematic.api.core.BaseSchematicApiException;
+import com.schematic.api.core.BaseSchematicException;
+import com.schematic.api.core.BaseSchematicHttpResponse;
+import com.schematic.api.core.ClientOptions;
+import com.schematic.api.core.MediaTypes;
+import com.schematic.api.core.ObjectMappers;
+import com.schematic.api.core.RequestOptions;
+import com.schematic.api.errors.BadRequestError;
+import com.schematic.api.errors.ForbiddenError;
+import com.schematic.api.errors.InternalServerError;
+import com.schematic.api.errors.NotFoundError;
+import com.schematic.api.errors.UnauthorizedError;
+import com.schematic.api.resources.accesstokens.requests.IssueTemporaryAccessTokenRequestBody;
+import com.schematic.api.resources.accesstokens.types.IssueTemporaryAccessTokenResponse;
+import com.schematic.api.types.ApiError;
+import java.io.IOException;
+import okhttp3.Headers;
+import okhttp3.HttpUrl;
+import okhttp3.OkHttpClient;
+import okhttp3.Request;
+import okhttp3.RequestBody;
+import okhttp3.Response;
+import okhttp3.ResponseBody;
+
+public class RawAccesstokensClient {
+ protected final ClientOptions clientOptions;
+
+ public RawAccesstokensClient(ClientOptions clientOptions) {
+ this.clientOptions = clientOptions;
+ }
+
+ public BaseSchematicHttpResponse issueTemporaryAccessToken(
+ IssueTemporaryAccessTokenRequestBody request) {
+ return issueTemporaryAccessToken(request, null);
+ }
+
+ public BaseSchematicHttpResponse issueTemporaryAccessToken(
+ IssueTemporaryAccessTokenRequestBody request, RequestOptions requestOptions) {
+ HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
+ .newBuilder()
+ .addPathSegments("temporary-access-tokens")
+ .build();
+ RequestBody body;
+ try {
+ body = RequestBody.create(
+ ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON);
+ } catch (JsonProcessingException e) {
+ throw new BaseSchematicException("Failed to serialize request", e);
+ }
+ Request okhttpRequest = new Request.Builder()
+ .url(httpUrl)
+ .method("POST", body)
+ .headers(Headers.of(clientOptions.headers(requestOptions)))
+ .addHeader("Content-Type", "application/json")
+ .addHeader("Accept", "application/json")
+ .build();
+ OkHttpClient client = clientOptions.httpClient();
+ if (requestOptions != null && requestOptions.getTimeout().isPresent()) {
+ client = clientOptions.httpClientWithTimeout(requestOptions);
+ }
+ try (Response response = client.newCall(okhttpRequest).execute()) {
+ ResponseBody responseBody = response.body();
+ if (response.isSuccessful()) {
+ return new BaseSchematicHttpResponse<>(
+ ObjectMappers.JSON_MAPPER.readValue(
+ responseBody.string(), IssueTemporaryAccessTokenResponse.class),
+ response);
+ }
+ String responseBodyString = responseBody != null ? responseBody.string() : "{}";
+ try {
+ switch (response.code()) {
+ case 400:
+ throw new BadRequestError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class), response);
+ case 401:
+ throw new UnauthorizedError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class), response);
+ case 403:
+ throw new ForbiddenError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class), response);
+ case 404:
+ throw new NotFoundError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class), response);
+ case 500:
+ throw new InternalServerError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class), response);
+ }
+ } catch (JsonProcessingException ignored) {
+ // unable to map error response, throwing generic error
+ }
+ throw new BaseSchematicApiException(
+ "Error with status code " + response.code(),
+ response.code(),
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class),
+ response);
+ } catch (IOException e) {
+ throw new BaseSchematicException("Network error executing HTTP request", e);
+ }
+ }
+}
diff --git a/src/main/java/com/schematic/api/resources/accesstokens/requests/IssueTemporaryAccessTokenRequestBody.java b/src/main/java/com/schematic/api/resources/accesstokens/requests/IssueTemporaryAccessTokenRequestBody.java
index 8ff89c2..0aa459d 100644
--- a/src/main/java/com/schematic/api/resources/accesstokens/requests/IssueTemporaryAccessTokenRequestBody.java
+++ b/src/main/java/com/schematic/api/resources/accesstokens/requests/IssueTemporaryAccessTokenRequestBody.java
@@ -16,21 +16,16 @@
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Objects;
-import org.jetbrains.annotations.NotNull;
@JsonInclude(JsonInclude.Include.NON_ABSENT)
@JsonDeserialize(builder = IssueTemporaryAccessTokenRequestBody.Builder.class)
public final class IssueTemporaryAccessTokenRequestBody {
private final Map lookup;
- private final String resourceType;
-
private final Map additionalProperties;
- private IssueTemporaryAccessTokenRequestBody(
- Map lookup, String resourceType, Map additionalProperties) {
+ private IssueTemporaryAccessTokenRequestBody(Map lookup, Map additionalProperties) {
this.lookup = lookup;
- this.resourceType = resourceType;
this.additionalProperties = additionalProperties;
}
@@ -41,7 +36,7 @@ public Map getLookup() {
@JsonProperty("resource_type")
public String getResourceType() {
- return resourceType;
+ return "company";
}
@java.lang.Override
@@ -57,12 +52,12 @@ public Map getAdditionalProperties() {
}
private boolean equalTo(IssueTemporaryAccessTokenRequestBody other) {
- return lookup.equals(other.lookup) && resourceType.equals(other.resourceType);
+ return lookup.equals(other.lookup);
}
@java.lang.Override
public int hashCode() {
- return Objects.hash(this.lookup, this.resourceType);
+ return Objects.hash(this.lookup);
}
@java.lang.Override
@@ -70,30 +65,12 @@ public String toString() {
return ObjectMappers.stringify(this);
}
- public static ResourceTypeStage builder() {
+ public static Builder builder() {
return new Builder();
}
- public interface ResourceTypeStage {
- _FinalStage resourceType(@NotNull String resourceType);
-
- Builder from(IssueTemporaryAccessTokenRequestBody other);
- }
-
- public interface _FinalStage {
- IssueTemporaryAccessTokenRequestBody build();
-
- _FinalStage lookup(Map lookup);
-
- _FinalStage putAllLookup(Map lookup);
-
- _FinalStage lookup(String key, String value);
- }
-
@JsonIgnoreProperties(ignoreUnknown = true)
- public static final class Builder implements ResourceTypeStage, _FinalStage {
- private String resourceType;
-
+ public static final class Builder {
private Map lookup = new LinkedHashMap<>();
@JsonAnySetter
@@ -101,43 +78,34 @@ public static final class Builder implements ResourceTypeStage, _FinalStage {
private Builder() {}
- @java.lang.Override
public Builder from(IssueTemporaryAccessTokenRequestBody other) {
lookup(other.getLookup());
- resourceType(other.getResourceType());
return this;
}
- @java.lang.Override
- @JsonSetter("resource_type")
- public _FinalStage resourceType(@NotNull String resourceType) {
- this.resourceType = Objects.requireNonNull(resourceType, "resourceType must not be null");
- return this;
- }
-
- @java.lang.Override
- public _FinalStage lookup(String key, String value) {
- this.lookup.put(key, value);
+ @JsonSetter(value = "lookup", nulls = Nulls.SKIP)
+ public Builder lookup(Map lookup) {
+ this.lookup.clear();
+ if (lookup != null) {
+ this.lookup.putAll(lookup);
+ }
return this;
}
- @java.lang.Override
- public _FinalStage putAllLookup(Map lookup) {
- this.lookup.putAll(lookup);
+ public Builder putAllLookup(Map lookup) {
+ if (lookup != null) {
+ this.lookup.putAll(lookup);
+ }
return this;
}
- @java.lang.Override
- @JsonSetter(value = "lookup", nulls = Nulls.SKIP)
- public _FinalStage lookup(Map lookup) {
- this.lookup.clear();
- this.lookup.putAll(lookup);
+ public Builder lookup(String key, String value) {
+ this.lookup.put(key, value);
return this;
}
- @java.lang.Override
public IssueTemporaryAccessTokenRequestBody build() {
- return new IssueTemporaryAccessTokenRequestBody(lookup, resourceType, additionalProperties);
+ return new IssueTemporaryAccessTokenRequestBody(lookup, additionalProperties);
}
}
}
diff --git a/src/main/java/com/schematic/api/resources/accesstokens/types/IssueTemporaryAccessTokenResponse.java b/src/main/java/com/schematic/api/resources/accesstokens/types/IssueTemporaryAccessTokenResponse.java
index 863fbf0..a2583ef 100644
--- a/src/main/java/com/schematic/api/resources/accesstokens/types/IssueTemporaryAccessTokenResponse.java
+++ b/src/main/java/com/schematic/api/resources/accesstokens/types/IssueTemporaryAccessTokenResponse.java
@@ -89,6 +89,9 @@ public interface DataStage {
public interface _FinalStage {
IssueTemporaryAccessTokenResponse build();
+ /**
+ * Input parameters
+ */
_FinalStage params(Map params);
_FinalStage putAllParams(Map params);
@@ -137,15 +140,22 @@ public _FinalStage params(String key, JsonNode value) {
*/
@java.lang.Override
public _FinalStage putAllParams(Map params) {
- this.params.putAll(params);
+ if (params != null) {
+ this.params.putAll(params);
+ }
return this;
}
+ /**
+ * Input parameters
+ */
@java.lang.Override
@JsonSetter(value = "params", nulls = Nulls.SKIP)
public _FinalStage params(Map params) {
this.params.clear();
- this.params.putAll(params);
+ if (params != null) {
+ this.params.putAll(params);
+ }
return this;
}
diff --git a/src/main/java/com/schematic/api/resources/accounts/AsyncAccountsClient.java b/src/main/java/com/schematic/api/resources/accounts/AsyncAccountsClient.java
new file mode 100644
index 0000000..a7b11ac
--- /dev/null
+++ b/src/main/java/com/schematic/api/resources/accounts/AsyncAccountsClient.java
@@ -0,0 +1,204 @@
+/**
+ * This file was auto-generated by Fern from our API Definition.
+ */
+package com.schematic.api.resources.accounts;
+
+import com.schematic.api.core.ClientOptions;
+import com.schematic.api.core.RequestOptions;
+import com.schematic.api.resources.accounts.requests.CountApiKeysRequest;
+import com.schematic.api.resources.accounts.requests.CountApiRequestsRequest;
+import com.schematic.api.resources.accounts.requests.CreateApiKeyRequestBody;
+import com.schematic.api.resources.accounts.requests.CreateEnvironmentRequestBody;
+import com.schematic.api.resources.accounts.requests.ListApiKeysRequest;
+import com.schematic.api.resources.accounts.requests.ListApiRequestsRequest;
+import com.schematic.api.resources.accounts.requests.ListEnvironmentsRequest;
+import com.schematic.api.resources.accounts.requests.UpdateApiKeyRequestBody;
+import com.schematic.api.resources.accounts.requests.UpdateEnvironmentRequestBody;
+import com.schematic.api.resources.accounts.types.CountApiKeysResponse;
+import com.schematic.api.resources.accounts.types.CountApiRequestsResponse;
+import com.schematic.api.resources.accounts.types.CreateApiKeyResponse;
+import com.schematic.api.resources.accounts.types.CreateEnvironmentResponse;
+import com.schematic.api.resources.accounts.types.DeleteApiKeyResponse;
+import com.schematic.api.resources.accounts.types.DeleteEnvironmentResponse;
+import com.schematic.api.resources.accounts.types.GetApiKeyResponse;
+import com.schematic.api.resources.accounts.types.GetApiRequestResponse;
+import com.schematic.api.resources.accounts.types.GetEnvironmentResponse;
+import com.schematic.api.resources.accounts.types.ListApiKeysResponse;
+import com.schematic.api.resources.accounts.types.ListApiRequestsResponse;
+import com.schematic.api.resources.accounts.types.ListEnvironmentsResponse;
+import com.schematic.api.resources.accounts.types.QuickstartResponse;
+import com.schematic.api.resources.accounts.types.UpdateApiKeyResponse;
+import com.schematic.api.resources.accounts.types.UpdateEnvironmentResponse;
+import java.util.concurrent.CompletableFuture;
+
+public class AsyncAccountsClient {
+ protected final ClientOptions clientOptions;
+
+ private final AsyncRawAccountsClient rawClient;
+
+ public AsyncAccountsClient(ClientOptions clientOptions) {
+ this.clientOptions = clientOptions;
+ this.rawClient = new AsyncRawAccountsClient(clientOptions);
+ }
+
+ /**
+ * Get responses with HTTP metadata like headers
+ */
+ public AsyncRawAccountsClient withRawResponse() {
+ return this.rawClient;
+ }
+
+ public CompletableFuture listApiKeys(ListApiKeysRequest request) {
+ return this.rawClient.listApiKeys(request).thenApply(response -> response.body());
+ }
+
+ public CompletableFuture listApiKeys(
+ ListApiKeysRequest request, RequestOptions requestOptions) {
+ return this.rawClient.listApiKeys(request, requestOptions).thenApply(response -> response.body());
+ }
+
+ public CompletableFuture createApiKey(CreateApiKeyRequestBody request) {
+ return this.rawClient.createApiKey(request).thenApply(response -> response.body());
+ }
+
+ public CompletableFuture createApiKey(
+ CreateApiKeyRequestBody request, RequestOptions requestOptions) {
+ return this.rawClient.createApiKey(request, requestOptions).thenApply(response -> response.body());
+ }
+
+ public CompletableFuture getApiKey(String apiKeyId) {
+ return this.rawClient.getApiKey(apiKeyId).thenApply(response -> response.body());
+ }
+
+ public CompletableFuture getApiKey(String apiKeyId, RequestOptions requestOptions) {
+ return this.rawClient.getApiKey(apiKeyId, requestOptions).thenApply(response -> response.body());
+ }
+
+ public CompletableFuture updateApiKey(String apiKeyId) {
+ return this.rawClient.updateApiKey(apiKeyId).thenApply(response -> response.body());
+ }
+
+ public CompletableFuture updateApiKey(String apiKeyId, UpdateApiKeyRequestBody request) {
+ return this.rawClient.updateApiKey(apiKeyId, request).thenApply(response -> response.body());
+ }
+
+ public CompletableFuture updateApiKey(
+ String apiKeyId, UpdateApiKeyRequestBody request, RequestOptions requestOptions) {
+ return this.rawClient.updateApiKey(apiKeyId, request, requestOptions).thenApply(response -> response.body());
+ }
+
+ public CompletableFuture deleteApiKey(String apiKeyId) {
+ return this.rawClient.deleteApiKey(apiKeyId).thenApply(response -> response.body());
+ }
+
+ public CompletableFuture deleteApiKey(String apiKeyId, RequestOptions requestOptions) {
+ return this.rawClient.deleteApiKey(apiKeyId, requestOptions).thenApply(response -> response.body());
+ }
+
+ public CompletableFuture countApiKeys(CountApiKeysRequest request) {
+ return this.rawClient.countApiKeys(request).thenApply(response -> response.body());
+ }
+
+ public CompletableFuture countApiKeys(
+ CountApiKeysRequest request, RequestOptions requestOptions) {
+ return this.rawClient.countApiKeys(request, requestOptions).thenApply(response -> response.body());
+ }
+
+ public CompletableFuture listApiRequests() {
+ return this.rawClient.listApiRequests().thenApply(response -> response.body());
+ }
+
+ public CompletableFuture listApiRequests(ListApiRequestsRequest request) {
+ return this.rawClient.listApiRequests(request).thenApply(response -> response.body());
+ }
+
+ public CompletableFuture listApiRequests(
+ ListApiRequestsRequest request, RequestOptions requestOptions) {
+ return this.rawClient.listApiRequests(request, requestOptions).thenApply(response -> response.body());
+ }
+
+ public CompletableFuture getApiRequest(String apiRequestId) {
+ return this.rawClient.getApiRequest(apiRequestId).thenApply(response -> response.body());
+ }
+
+ public CompletableFuture getApiRequest(String apiRequestId, RequestOptions requestOptions) {
+ return this.rawClient.getApiRequest(apiRequestId, requestOptions).thenApply(response -> response.body());
+ }
+
+ public CompletableFuture countApiRequests() {
+ return this.rawClient.countApiRequests().thenApply(response -> response.body());
+ }
+
+ public CompletableFuture countApiRequests(CountApiRequestsRequest request) {
+ return this.rawClient.countApiRequests(request).thenApply(response -> response.body());
+ }
+
+ public CompletableFuture countApiRequests(
+ CountApiRequestsRequest request, RequestOptions requestOptions) {
+ return this.rawClient.countApiRequests(request, requestOptions).thenApply(response -> response.body());
+ }
+
+ public CompletableFuture listEnvironments() {
+ return this.rawClient.listEnvironments().thenApply(response -> response.body());
+ }
+
+ public CompletableFuture listEnvironments(ListEnvironmentsRequest request) {
+ return this.rawClient.listEnvironments(request).thenApply(response -> response.body());
+ }
+
+ public CompletableFuture listEnvironments(
+ ListEnvironmentsRequest request, RequestOptions requestOptions) {
+ return this.rawClient.listEnvironments(request, requestOptions).thenApply(response -> response.body());
+ }
+
+ public CompletableFuture createEnvironment(CreateEnvironmentRequestBody request) {
+ return this.rawClient.createEnvironment(request).thenApply(response -> response.body());
+ }
+
+ public CompletableFuture createEnvironment(
+ CreateEnvironmentRequestBody request, RequestOptions requestOptions) {
+ return this.rawClient.createEnvironment(request, requestOptions).thenApply(response -> response.body());
+ }
+
+ public CompletableFuture getEnvironment(String environmentId) {
+ return this.rawClient.getEnvironment(environmentId).thenApply(response -> response.body());
+ }
+
+ public CompletableFuture getEnvironment(
+ String environmentId, RequestOptions requestOptions) {
+ return this.rawClient.getEnvironment(environmentId, requestOptions).thenApply(response -> response.body());
+ }
+
+ public CompletableFuture updateEnvironment(String environmentId) {
+ return this.rawClient.updateEnvironment(environmentId).thenApply(response -> response.body());
+ }
+
+ public CompletableFuture updateEnvironment(
+ String environmentId, UpdateEnvironmentRequestBody request) {
+ return this.rawClient.updateEnvironment(environmentId, request).thenApply(response -> response.body());
+ }
+
+ public CompletableFuture updateEnvironment(
+ String environmentId, UpdateEnvironmentRequestBody request, RequestOptions requestOptions) {
+ return this.rawClient
+ .updateEnvironment(environmentId, request, requestOptions)
+ .thenApply(response -> response.body());
+ }
+
+ public CompletableFuture deleteEnvironment(String environmentId) {
+ return this.rawClient.deleteEnvironment(environmentId).thenApply(response -> response.body());
+ }
+
+ public CompletableFuture deleteEnvironment(
+ String environmentId, RequestOptions requestOptions) {
+ return this.rawClient.deleteEnvironment(environmentId, requestOptions).thenApply(response -> response.body());
+ }
+
+ public CompletableFuture quickstart() {
+ return this.rawClient.quickstart().thenApply(response -> response.body());
+ }
+
+ public CompletableFuture quickstart(RequestOptions requestOptions) {
+ return this.rawClient.quickstart(requestOptions).thenApply(response -> response.body());
+ }
+}
diff --git a/src/main/java/com/schematic/api/resources/accounts/AsyncRawAccountsClient.java b/src/main/java/com/schematic/api/resources/accounts/AsyncRawAccountsClient.java
new file mode 100644
index 0000000..caf2ae4
--- /dev/null
+++ b/src/main/java/com/schematic/api/resources/accounts/AsyncRawAccountsClient.java
@@ -0,0 +1,1425 @@
+/**
+ * This file was auto-generated by Fern from our API Definition.
+ */
+package com.schematic.api.resources.accounts;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.schematic.api.core.BaseSchematicApiException;
+import com.schematic.api.core.BaseSchematicException;
+import com.schematic.api.core.BaseSchematicHttpResponse;
+import com.schematic.api.core.ClientOptions;
+import com.schematic.api.core.MediaTypes;
+import com.schematic.api.core.ObjectMappers;
+import com.schematic.api.core.QueryStringMapper;
+import com.schematic.api.core.RequestOptions;
+import com.schematic.api.errors.BadRequestError;
+import com.schematic.api.errors.ForbiddenError;
+import com.schematic.api.errors.InternalServerError;
+import com.schematic.api.errors.NotFoundError;
+import com.schematic.api.errors.UnauthorizedError;
+import com.schematic.api.resources.accounts.requests.CountApiKeysRequest;
+import com.schematic.api.resources.accounts.requests.CountApiRequestsRequest;
+import com.schematic.api.resources.accounts.requests.CreateApiKeyRequestBody;
+import com.schematic.api.resources.accounts.requests.CreateEnvironmentRequestBody;
+import com.schematic.api.resources.accounts.requests.ListApiKeysRequest;
+import com.schematic.api.resources.accounts.requests.ListApiRequestsRequest;
+import com.schematic.api.resources.accounts.requests.ListEnvironmentsRequest;
+import com.schematic.api.resources.accounts.requests.UpdateApiKeyRequestBody;
+import com.schematic.api.resources.accounts.requests.UpdateEnvironmentRequestBody;
+import com.schematic.api.resources.accounts.types.CountApiKeysResponse;
+import com.schematic.api.resources.accounts.types.CountApiRequestsResponse;
+import com.schematic.api.resources.accounts.types.CreateApiKeyResponse;
+import com.schematic.api.resources.accounts.types.CreateEnvironmentResponse;
+import com.schematic.api.resources.accounts.types.DeleteApiKeyResponse;
+import com.schematic.api.resources.accounts.types.DeleteEnvironmentResponse;
+import com.schematic.api.resources.accounts.types.GetApiKeyResponse;
+import com.schematic.api.resources.accounts.types.GetApiRequestResponse;
+import com.schematic.api.resources.accounts.types.GetEnvironmentResponse;
+import com.schematic.api.resources.accounts.types.ListApiKeysResponse;
+import com.schematic.api.resources.accounts.types.ListApiRequestsResponse;
+import com.schematic.api.resources.accounts.types.ListEnvironmentsResponse;
+import com.schematic.api.resources.accounts.types.QuickstartResponse;
+import com.schematic.api.resources.accounts.types.UpdateApiKeyResponse;
+import com.schematic.api.resources.accounts.types.UpdateEnvironmentResponse;
+import com.schematic.api.types.ApiError;
+import java.io.IOException;
+import java.util.concurrent.CompletableFuture;
+import okhttp3.Call;
+import okhttp3.Callback;
+import okhttp3.Headers;
+import okhttp3.HttpUrl;
+import okhttp3.OkHttpClient;
+import okhttp3.Request;
+import okhttp3.RequestBody;
+import okhttp3.Response;
+import okhttp3.ResponseBody;
+import org.jetbrains.annotations.NotNull;
+
+public class AsyncRawAccountsClient {
+ protected final ClientOptions clientOptions;
+
+ public AsyncRawAccountsClient(ClientOptions clientOptions) {
+ this.clientOptions = clientOptions;
+ }
+
+ public CompletableFuture> listApiKeys(ListApiKeysRequest request) {
+ return listApiKeys(request, null);
+ }
+
+ public CompletableFuture> listApiKeys(
+ ListApiKeysRequest request, RequestOptions requestOptions) {
+ HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
+ .newBuilder()
+ .addPathSegments("api-keys");
+ if (request.getEnvironmentId().isPresent()) {
+ QueryStringMapper.addQueryParameter(
+ httpUrl, "environment_id", request.getEnvironmentId().get(), false);
+ }
+ QueryStringMapper.addQueryParameter(httpUrl, "require_environment", request.getRequireEnvironment(), false);
+ if (request.getLimit().isPresent()) {
+ QueryStringMapper.addQueryParameter(
+ httpUrl, "limit", request.getLimit().get(), false);
+ }
+ if (request.getOffset().isPresent()) {
+ QueryStringMapper.addQueryParameter(
+ httpUrl, "offset", request.getOffset().get(), false);
+ }
+ Request.Builder _requestBuilder = new Request.Builder()
+ .url(httpUrl.build())
+ .method("GET", null)
+ .headers(Headers.of(clientOptions.headers(requestOptions)))
+ .addHeader("Accept", "application/json");
+ Request okhttpRequest = _requestBuilder.build();
+ OkHttpClient client = clientOptions.httpClient();
+ if (requestOptions != null && requestOptions.getTimeout().isPresent()) {
+ client = clientOptions.httpClientWithTimeout(requestOptions);
+ }
+ CompletableFuture> future = new CompletableFuture<>();
+ client.newCall(okhttpRequest).enqueue(new Callback() {
+ @Override
+ public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException {
+ try (ResponseBody responseBody = response.body()) {
+ if (response.isSuccessful()) {
+ future.complete(new BaseSchematicHttpResponse<>(
+ ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), ListApiKeysResponse.class),
+ response));
+ return;
+ }
+ String responseBodyString = responseBody != null ? responseBody.string() : "{}";
+ try {
+ switch (response.code()) {
+ case 400:
+ future.completeExceptionally(new BadRequestError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class),
+ response));
+ return;
+ case 401:
+ future.completeExceptionally(new UnauthorizedError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class),
+ response));
+ return;
+ case 403:
+ future.completeExceptionally(new ForbiddenError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class),
+ response));
+ return;
+ case 404:
+ future.completeExceptionally(new NotFoundError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class),
+ response));
+ return;
+ case 500:
+ future.completeExceptionally(new InternalServerError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class),
+ response));
+ return;
+ }
+ } catch (JsonProcessingException ignored) {
+ // unable to map error response, throwing generic error
+ }
+ future.completeExceptionally(new BaseSchematicApiException(
+ "Error with status code " + response.code(),
+ response.code(),
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class),
+ response));
+ return;
+ } catch (IOException e) {
+ future.completeExceptionally(new BaseSchematicException("Network error executing HTTP request", e));
+ }
+ }
+
+ @Override
+ public void onFailure(@NotNull Call call, @NotNull IOException e) {
+ future.completeExceptionally(new BaseSchematicException("Network error executing HTTP request", e));
+ }
+ });
+ return future;
+ }
+
+ public CompletableFuture> createApiKey(
+ CreateApiKeyRequestBody request) {
+ return createApiKey(request, null);
+ }
+
+ public CompletableFuture> createApiKey(
+ CreateApiKeyRequestBody request, RequestOptions requestOptions) {
+ HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
+ .newBuilder()
+ .addPathSegments("api-keys")
+ .build();
+ RequestBody body;
+ try {
+ body = RequestBody.create(
+ ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON);
+ } catch (JsonProcessingException e) {
+ throw new BaseSchematicException("Failed to serialize request", e);
+ }
+ Request okhttpRequest = new Request.Builder()
+ .url(httpUrl)
+ .method("POST", body)
+ .headers(Headers.of(clientOptions.headers(requestOptions)))
+ .addHeader("Content-Type", "application/json")
+ .addHeader("Accept", "application/json")
+ .build();
+ OkHttpClient client = clientOptions.httpClient();
+ if (requestOptions != null && requestOptions.getTimeout().isPresent()) {
+ client = clientOptions.httpClientWithTimeout(requestOptions);
+ }
+ CompletableFuture> future = new CompletableFuture<>();
+ client.newCall(okhttpRequest).enqueue(new Callback() {
+ @Override
+ public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException {
+ try (ResponseBody responseBody = response.body()) {
+ if (response.isSuccessful()) {
+ future.complete(new BaseSchematicHttpResponse<>(
+ ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), CreateApiKeyResponse.class),
+ response));
+ return;
+ }
+ String responseBodyString = responseBody != null ? responseBody.string() : "{}";
+ try {
+ switch (response.code()) {
+ case 400:
+ future.completeExceptionally(new BadRequestError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class),
+ response));
+ return;
+ case 401:
+ future.completeExceptionally(new UnauthorizedError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class),
+ response));
+ return;
+ case 403:
+ future.completeExceptionally(new ForbiddenError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class),
+ response));
+ return;
+ case 404:
+ future.completeExceptionally(new NotFoundError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class),
+ response));
+ return;
+ case 500:
+ future.completeExceptionally(new InternalServerError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class),
+ response));
+ return;
+ }
+ } catch (JsonProcessingException ignored) {
+ // unable to map error response, throwing generic error
+ }
+ future.completeExceptionally(new BaseSchematicApiException(
+ "Error with status code " + response.code(),
+ response.code(),
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class),
+ response));
+ return;
+ } catch (IOException e) {
+ future.completeExceptionally(new BaseSchematicException("Network error executing HTTP request", e));
+ }
+ }
+
+ @Override
+ public void onFailure(@NotNull Call call, @NotNull IOException e) {
+ future.completeExceptionally(new BaseSchematicException("Network error executing HTTP request", e));
+ }
+ });
+ return future;
+ }
+
+ public CompletableFuture> getApiKey(String apiKeyId) {
+ return getApiKey(apiKeyId, null);
+ }
+
+ public CompletableFuture> getApiKey(
+ String apiKeyId, RequestOptions requestOptions) {
+ HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
+ .newBuilder()
+ .addPathSegments("api-keys")
+ .addPathSegment(apiKeyId)
+ .build();
+ Request okhttpRequest = new Request.Builder()
+ .url(httpUrl)
+ .method("GET", null)
+ .headers(Headers.of(clientOptions.headers(requestOptions)))
+ .addHeader("Accept", "application/json")
+ .build();
+ OkHttpClient client = clientOptions.httpClient();
+ if (requestOptions != null && requestOptions.getTimeout().isPresent()) {
+ client = clientOptions.httpClientWithTimeout(requestOptions);
+ }
+ CompletableFuture> future = new CompletableFuture<>();
+ client.newCall(okhttpRequest).enqueue(new Callback() {
+ @Override
+ public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException {
+ try (ResponseBody responseBody = response.body()) {
+ if (response.isSuccessful()) {
+ future.complete(new BaseSchematicHttpResponse<>(
+ ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), GetApiKeyResponse.class),
+ response));
+ return;
+ }
+ String responseBodyString = responseBody != null ? responseBody.string() : "{}";
+ try {
+ switch (response.code()) {
+ case 401:
+ future.completeExceptionally(new UnauthorizedError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class),
+ response));
+ return;
+ case 403:
+ future.completeExceptionally(new ForbiddenError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class),
+ response));
+ return;
+ case 404:
+ future.completeExceptionally(new NotFoundError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class),
+ response));
+ return;
+ case 500:
+ future.completeExceptionally(new InternalServerError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class),
+ response));
+ return;
+ }
+ } catch (JsonProcessingException ignored) {
+ // unable to map error response, throwing generic error
+ }
+ future.completeExceptionally(new BaseSchematicApiException(
+ "Error with status code " + response.code(),
+ response.code(),
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class),
+ response));
+ return;
+ } catch (IOException e) {
+ future.completeExceptionally(new BaseSchematicException("Network error executing HTTP request", e));
+ }
+ }
+
+ @Override
+ public void onFailure(@NotNull Call call, @NotNull IOException e) {
+ future.completeExceptionally(new BaseSchematicException("Network error executing HTTP request", e));
+ }
+ });
+ return future;
+ }
+
+ public CompletableFuture> updateApiKey(String apiKeyId) {
+ return updateApiKey(apiKeyId, UpdateApiKeyRequestBody.builder().build());
+ }
+
+ public CompletableFuture> updateApiKey(
+ String apiKeyId, UpdateApiKeyRequestBody request) {
+ return updateApiKey(apiKeyId, request, null);
+ }
+
+ public CompletableFuture> updateApiKey(
+ String apiKeyId, UpdateApiKeyRequestBody request, RequestOptions requestOptions) {
+ HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
+ .newBuilder()
+ .addPathSegments("api-keys")
+ .addPathSegment(apiKeyId)
+ .build();
+ RequestBody body;
+ try {
+ body = RequestBody.create(
+ ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON);
+ } catch (JsonProcessingException e) {
+ throw new BaseSchematicException("Failed to serialize request", e);
+ }
+ Request okhttpRequest = new Request.Builder()
+ .url(httpUrl)
+ .method("PUT", body)
+ .headers(Headers.of(clientOptions.headers(requestOptions)))
+ .addHeader("Content-Type", "application/json")
+ .addHeader("Accept", "application/json")
+ .build();
+ OkHttpClient client = clientOptions.httpClient();
+ if (requestOptions != null && requestOptions.getTimeout().isPresent()) {
+ client = clientOptions.httpClientWithTimeout(requestOptions);
+ }
+ CompletableFuture> future = new CompletableFuture<>();
+ client.newCall(okhttpRequest).enqueue(new Callback() {
+ @Override
+ public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException {
+ try (ResponseBody responseBody = response.body()) {
+ if (response.isSuccessful()) {
+ future.complete(new BaseSchematicHttpResponse<>(
+ ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), UpdateApiKeyResponse.class),
+ response));
+ return;
+ }
+ String responseBodyString = responseBody != null ? responseBody.string() : "{}";
+ try {
+ switch (response.code()) {
+ case 400:
+ future.completeExceptionally(new BadRequestError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class),
+ response));
+ return;
+ case 401:
+ future.completeExceptionally(new UnauthorizedError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class),
+ response));
+ return;
+ case 403:
+ future.completeExceptionally(new ForbiddenError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class),
+ response));
+ return;
+ case 404:
+ future.completeExceptionally(new NotFoundError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class),
+ response));
+ return;
+ case 500:
+ future.completeExceptionally(new InternalServerError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class),
+ response));
+ return;
+ }
+ } catch (JsonProcessingException ignored) {
+ // unable to map error response, throwing generic error
+ }
+ future.completeExceptionally(new BaseSchematicApiException(
+ "Error with status code " + response.code(),
+ response.code(),
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class),
+ response));
+ return;
+ } catch (IOException e) {
+ future.completeExceptionally(new BaseSchematicException("Network error executing HTTP request", e));
+ }
+ }
+
+ @Override
+ public void onFailure(@NotNull Call call, @NotNull IOException e) {
+ future.completeExceptionally(new BaseSchematicException("Network error executing HTTP request", e));
+ }
+ });
+ return future;
+ }
+
+ public CompletableFuture> deleteApiKey(String apiKeyId) {
+ return deleteApiKey(apiKeyId, null);
+ }
+
+ public CompletableFuture> deleteApiKey(
+ String apiKeyId, RequestOptions requestOptions) {
+ HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
+ .newBuilder()
+ .addPathSegments("api-keys")
+ .addPathSegment(apiKeyId)
+ .build();
+ Request okhttpRequest = new Request.Builder()
+ .url(httpUrl)
+ .method("DELETE", null)
+ .headers(Headers.of(clientOptions.headers(requestOptions)))
+ .addHeader("Accept", "application/json")
+ .build();
+ OkHttpClient client = clientOptions.httpClient();
+ if (requestOptions != null && requestOptions.getTimeout().isPresent()) {
+ client = clientOptions.httpClientWithTimeout(requestOptions);
+ }
+ CompletableFuture> future = new CompletableFuture<>();
+ client.newCall(okhttpRequest).enqueue(new Callback() {
+ @Override
+ public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException {
+ try (ResponseBody responseBody = response.body()) {
+ if (response.isSuccessful()) {
+ future.complete(new BaseSchematicHttpResponse<>(
+ ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), DeleteApiKeyResponse.class),
+ response));
+ return;
+ }
+ String responseBodyString = responseBody != null ? responseBody.string() : "{}";
+ try {
+ switch (response.code()) {
+ case 400:
+ future.completeExceptionally(new BadRequestError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class),
+ response));
+ return;
+ case 401:
+ future.completeExceptionally(new UnauthorizedError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class),
+ response));
+ return;
+ case 403:
+ future.completeExceptionally(new ForbiddenError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class),
+ response));
+ return;
+ case 404:
+ future.completeExceptionally(new NotFoundError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class),
+ response));
+ return;
+ case 500:
+ future.completeExceptionally(new InternalServerError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class),
+ response));
+ return;
+ }
+ } catch (JsonProcessingException ignored) {
+ // unable to map error response, throwing generic error
+ }
+ future.completeExceptionally(new BaseSchematicApiException(
+ "Error with status code " + response.code(),
+ response.code(),
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class),
+ response));
+ return;
+ } catch (IOException e) {
+ future.completeExceptionally(new BaseSchematicException("Network error executing HTTP request", e));
+ }
+ }
+
+ @Override
+ public void onFailure(@NotNull Call call, @NotNull IOException e) {
+ future.completeExceptionally(new BaseSchematicException("Network error executing HTTP request", e));
+ }
+ });
+ return future;
+ }
+
+ public CompletableFuture> countApiKeys(
+ CountApiKeysRequest request) {
+ return countApiKeys(request, null);
+ }
+
+ public CompletableFuture> countApiKeys(
+ CountApiKeysRequest request, RequestOptions requestOptions) {
+ HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
+ .newBuilder()
+ .addPathSegments("api-keys/count");
+ if (request.getEnvironmentId().isPresent()) {
+ QueryStringMapper.addQueryParameter(
+ httpUrl, "environment_id", request.getEnvironmentId().get(), false);
+ }
+ QueryStringMapper.addQueryParameter(httpUrl, "require_environment", request.getRequireEnvironment(), false);
+ if (request.getLimit().isPresent()) {
+ QueryStringMapper.addQueryParameter(
+ httpUrl, "limit", request.getLimit().get(), false);
+ }
+ if (request.getOffset().isPresent()) {
+ QueryStringMapper.addQueryParameter(
+ httpUrl, "offset", request.getOffset().get(), false);
+ }
+ Request.Builder _requestBuilder = new Request.Builder()
+ .url(httpUrl.build())
+ .method("GET", null)
+ .headers(Headers.of(clientOptions.headers(requestOptions)))
+ .addHeader("Accept", "application/json");
+ Request okhttpRequest = _requestBuilder.build();
+ OkHttpClient client = clientOptions.httpClient();
+ if (requestOptions != null && requestOptions.getTimeout().isPresent()) {
+ client = clientOptions.httpClientWithTimeout(requestOptions);
+ }
+ CompletableFuture> future = new CompletableFuture<>();
+ client.newCall(okhttpRequest).enqueue(new Callback() {
+ @Override
+ public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException {
+ try (ResponseBody responseBody = response.body()) {
+ if (response.isSuccessful()) {
+ future.complete(new BaseSchematicHttpResponse<>(
+ ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), CountApiKeysResponse.class),
+ response));
+ return;
+ }
+ String responseBodyString = responseBody != null ? responseBody.string() : "{}";
+ try {
+ switch (response.code()) {
+ case 400:
+ future.completeExceptionally(new BadRequestError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class),
+ response));
+ return;
+ case 401:
+ future.completeExceptionally(new UnauthorizedError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class),
+ response));
+ return;
+ case 403:
+ future.completeExceptionally(new ForbiddenError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class),
+ response));
+ return;
+ case 404:
+ future.completeExceptionally(new NotFoundError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class),
+ response));
+ return;
+ case 500:
+ future.completeExceptionally(new InternalServerError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class),
+ response));
+ return;
+ }
+ } catch (JsonProcessingException ignored) {
+ // unable to map error response, throwing generic error
+ }
+ future.completeExceptionally(new BaseSchematicApiException(
+ "Error with status code " + response.code(),
+ response.code(),
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class),
+ response));
+ return;
+ } catch (IOException e) {
+ future.completeExceptionally(new BaseSchematicException("Network error executing HTTP request", e));
+ }
+ }
+
+ @Override
+ public void onFailure(@NotNull Call call, @NotNull IOException e) {
+ future.completeExceptionally(new BaseSchematicException("Network error executing HTTP request", e));
+ }
+ });
+ return future;
+ }
+
+ public CompletableFuture> listApiRequests() {
+ return listApiRequests(ListApiRequestsRequest.builder().build());
+ }
+
+ public CompletableFuture> listApiRequests(
+ ListApiRequestsRequest request) {
+ return listApiRequests(request, null);
+ }
+
+ public CompletableFuture> listApiRequests(
+ ListApiRequestsRequest request, RequestOptions requestOptions) {
+ HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
+ .newBuilder()
+ .addPathSegments("api-requests");
+ if (request.getQ().isPresent()) {
+ QueryStringMapper.addQueryParameter(httpUrl, "q", request.getQ().get(), false);
+ }
+ if (request.getRequestType().isPresent()) {
+ QueryStringMapper.addQueryParameter(
+ httpUrl, "request_type", request.getRequestType().get(), false);
+ }
+ if (request.getEnvironmentId().isPresent()) {
+ QueryStringMapper.addQueryParameter(
+ httpUrl, "environment_id", request.getEnvironmentId().get(), false);
+ }
+ if (request.getLimit().isPresent()) {
+ QueryStringMapper.addQueryParameter(
+ httpUrl, "limit", request.getLimit().get(), false);
+ }
+ if (request.getOffset().isPresent()) {
+ QueryStringMapper.addQueryParameter(
+ httpUrl, "offset", request.getOffset().get(), false);
+ }
+ Request.Builder _requestBuilder = new Request.Builder()
+ .url(httpUrl.build())
+ .method("GET", null)
+ .headers(Headers.of(clientOptions.headers(requestOptions)))
+ .addHeader("Accept", "application/json");
+ Request okhttpRequest = _requestBuilder.build();
+ OkHttpClient client = clientOptions.httpClient();
+ if (requestOptions != null && requestOptions.getTimeout().isPresent()) {
+ client = clientOptions.httpClientWithTimeout(requestOptions);
+ }
+ CompletableFuture> future = new CompletableFuture<>();
+ client.newCall(okhttpRequest).enqueue(new Callback() {
+ @Override
+ public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException {
+ try (ResponseBody responseBody = response.body()) {
+ if (response.isSuccessful()) {
+ future.complete(new BaseSchematicHttpResponse<>(
+ ObjectMappers.JSON_MAPPER.readValue(
+ responseBody.string(), ListApiRequestsResponse.class),
+ response));
+ return;
+ }
+ String responseBodyString = responseBody != null ? responseBody.string() : "{}";
+ try {
+ switch (response.code()) {
+ case 400:
+ future.completeExceptionally(new BadRequestError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class),
+ response));
+ return;
+ case 401:
+ future.completeExceptionally(new UnauthorizedError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class),
+ response));
+ return;
+ case 403:
+ future.completeExceptionally(new ForbiddenError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class),
+ response));
+ return;
+ case 404:
+ future.completeExceptionally(new NotFoundError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class),
+ response));
+ return;
+ case 500:
+ future.completeExceptionally(new InternalServerError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class),
+ response));
+ return;
+ }
+ } catch (JsonProcessingException ignored) {
+ // unable to map error response, throwing generic error
+ }
+ future.completeExceptionally(new BaseSchematicApiException(
+ "Error with status code " + response.code(),
+ response.code(),
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class),
+ response));
+ return;
+ } catch (IOException e) {
+ future.completeExceptionally(new BaseSchematicException("Network error executing HTTP request", e));
+ }
+ }
+
+ @Override
+ public void onFailure(@NotNull Call call, @NotNull IOException e) {
+ future.completeExceptionally(new BaseSchematicException("Network error executing HTTP request", e));
+ }
+ });
+ return future;
+ }
+
+ public CompletableFuture> getApiRequest(String apiRequestId) {
+ return getApiRequest(apiRequestId, null);
+ }
+
+ public CompletableFuture> getApiRequest(
+ String apiRequestId, RequestOptions requestOptions) {
+ HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
+ .newBuilder()
+ .addPathSegments("api-requests")
+ .addPathSegment(apiRequestId)
+ .build();
+ Request okhttpRequest = new Request.Builder()
+ .url(httpUrl)
+ .method("GET", null)
+ .headers(Headers.of(clientOptions.headers(requestOptions)))
+ .addHeader("Accept", "application/json")
+ .build();
+ OkHttpClient client = clientOptions.httpClient();
+ if (requestOptions != null && requestOptions.getTimeout().isPresent()) {
+ client = clientOptions.httpClientWithTimeout(requestOptions);
+ }
+ CompletableFuture> future = new CompletableFuture<>();
+ client.newCall(okhttpRequest).enqueue(new Callback() {
+ @Override
+ public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException {
+ try (ResponseBody responseBody = response.body()) {
+ if (response.isSuccessful()) {
+ future.complete(new BaseSchematicHttpResponse<>(
+ ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), GetApiRequestResponse.class),
+ response));
+ return;
+ }
+ String responseBodyString = responseBody != null ? responseBody.string() : "{}";
+ try {
+ switch (response.code()) {
+ case 401:
+ future.completeExceptionally(new UnauthorizedError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class),
+ response));
+ return;
+ case 403:
+ future.completeExceptionally(new ForbiddenError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class),
+ response));
+ return;
+ case 404:
+ future.completeExceptionally(new NotFoundError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class),
+ response));
+ return;
+ case 500:
+ future.completeExceptionally(new InternalServerError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class),
+ response));
+ return;
+ }
+ } catch (JsonProcessingException ignored) {
+ // unable to map error response, throwing generic error
+ }
+ future.completeExceptionally(new BaseSchematicApiException(
+ "Error with status code " + response.code(),
+ response.code(),
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class),
+ response));
+ return;
+ } catch (IOException e) {
+ future.completeExceptionally(new BaseSchematicException("Network error executing HTTP request", e));
+ }
+ }
+
+ @Override
+ public void onFailure(@NotNull Call call, @NotNull IOException e) {
+ future.completeExceptionally(new BaseSchematicException("Network error executing HTTP request", e));
+ }
+ });
+ return future;
+ }
+
+ public CompletableFuture> countApiRequests() {
+ return countApiRequests(CountApiRequestsRequest.builder().build());
+ }
+
+ public CompletableFuture> countApiRequests(
+ CountApiRequestsRequest request) {
+ return countApiRequests(request, null);
+ }
+
+ public CompletableFuture> countApiRequests(
+ CountApiRequestsRequest request, RequestOptions requestOptions) {
+ HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
+ .newBuilder()
+ .addPathSegments("api-requests/count");
+ if (request.getQ().isPresent()) {
+ QueryStringMapper.addQueryParameter(httpUrl, "q", request.getQ().get(), false);
+ }
+ if (request.getRequestType().isPresent()) {
+ QueryStringMapper.addQueryParameter(
+ httpUrl, "request_type", request.getRequestType().get(), false);
+ }
+ if (request.getEnvironmentId().isPresent()) {
+ QueryStringMapper.addQueryParameter(
+ httpUrl, "environment_id", request.getEnvironmentId().get(), false);
+ }
+ if (request.getLimit().isPresent()) {
+ QueryStringMapper.addQueryParameter(
+ httpUrl, "limit", request.getLimit().get(), false);
+ }
+ if (request.getOffset().isPresent()) {
+ QueryStringMapper.addQueryParameter(
+ httpUrl, "offset", request.getOffset().get(), false);
+ }
+ Request.Builder _requestBuilder = new Request.Builder()
+ .url(httpUrl.build())
+ .method("GET", null)
+ .headers(Headers.of(clientOptions.headers(requestOptions)))
+ .addHeader("Accept", "application/json");
+ Request okhttpRequest = _requestBuilder.build();
+ OkHttpClient client = clientOptions.httpClient();
+ if (requestOptions != null && requestOptions.getTimeout().isPresent()) {
+ client = clientOptions.httpClientWithTimeout(requestOptions);
+ }
+ CompletableFuture> future = new CompletableFuture<>();
+ client.newCall(okhttpRequest).enqueue(new Callback() {
+ @Override
+ public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException {
+ try (ResponseBody responseBody = response.body()) {
+ if (response.isSuccessful()) {
+ future.complete(new BaseSchematicHttpResponse<>(
+ ObjectMappers.JSON_MAPPER.readValue(
+ responseBody.string(), CountApiRequestsResponse.class),
+ response));
+ return;
+ }
+ String responseBodyString = responseBody != null ? responseBody.string() : "{}";
+ try {
+ switch (response.code()) {
+ case 400:
+ future.completeExceptionally(new BadRequestError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class),
+ response));
+ return;
+ case 401:
+ future.completeExceptionally(new UnauthorizedError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class),
+ response));
+ return;
+ case 403:
+ future.completeExceptionally(new ForbiddenError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class),
+ response));
+ return;
+ case 404:
+ future.completeExceptionally(new NotFoundError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class),
+ response));
+ return;
+ case 500:
+ future.completeExceptionally(new InternalServerError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class),
+ response));
+ return;
+ }
+ } catch (JsonProcessingException ignored) {
+ // unable to map error response, throwing generic error
+ }
+ future.completeExceptionally(new BaseSchematicApiException(
+ "Error with status code " + response.code(),
+ response.code(),
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class),
+ response));
+ return;
+ } catch (IOException e) {
+ future.completeExceptionally(new BaseSchematicException("Network error executing HTTP request", e));
+ }
+ }
+
+ @Override
+ public void onFailure(@NotNull Call call, @NotNull IOException e) {
+ future.completeExceptionally(new BaseSchematicException("Network error executing HTTP request", e));
+ }
+ });
+ return future;
+ }
+
+ public CompletableFuture> listEnvironments() {
+ return listEnvironments(ListEnvironmentsRequest.builder().build());
+ }
+
+ public CompletableFuture> listEnvironments(
+ ListEnvironmentsRequest request) {
+ return listEnvironments(request, null);
+ }
+
+ public CompletableFuture> listEnvironments(
+ ListEnvironmentsRequest request, RequestOptions requestOptions) {
+ HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
+ .newBuilder()
+ .addPathSegments("environments");
+ if (request.getLimit().isPresent()) {
+ QueryStringMapper.addQueryParameter(
+ httpUrl, "limit", request.getLimit().get(), false);
+ }
+ if (request.getOffset().isPresent()) {
+ QueryStringMapper.addQueryParameter(
+ httpUrl, "offset", request.getOffset().get(), false);
+ }
+ if (request.getIds().isPresent()) {
+ QueryStringMapper.addQueryParameter(httpUrl, "ids", request.getIds().get(), true);
+ }
+ Request.Builder _requestBuilder = new Request.Builder()
+ .url(httpUrl.build())
+ .method("GET", null)
+ .headers(Headers.of(clientOptions.headers(requestOptions)))
+ .addHeader("Accept", "application/json");
+ Request okhttpRequest = _requestBuilder.build();
+ OkHttpClient client = clientOptions.httpClient();
+ if (requestOptions != null && requestOptions.getTimeout().isPresent()) {
+ client = clientOptions.httpClientWithTimeout(requestOptions);
+ }
+ CompletableFuture> future = new CompletableFuture<>();
+ client.newCall(okhttpRequest).enqueue(new Callback() {
+ @Override
+ public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException {
+ try (ResponseBody responseBody = response.body()) {
+ if (response.isSuccessful()) {
+ future.complete(new BaseSchematicHttpResponse<>(
+ ObjectMappers.JSON_MAPPER.readValue(
+ responseBody.string(), ListEnvironmentsResponse.class),
+ response));
+ return;
+ }
+ String responseBodyString = responseBody != null ? responseBody.string() : "{}";
+ try {
+ switch (response.code()) {
+ case 400:
+ future.completeExceptionally(new BadRequestError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class),
+ response));
+ return;
+ case 401:
+ future.completeExceptionally(new UnauthorizedError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class),
+ response));
+ return;
+ case 403:
+ future.completeExceptionally(new ForbiddenError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class),
+ response));
+ return;
+ case 404:
+ future.completeExceptionally(new NotFoundError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class),
+ response));
+ return;
+ case 500:
+ future.completeExceptionally(new InternalServerError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class),
+ response));
+ return;
+ }
+ } catch (JsonProcessingException ignored) {
+ // unable to map error response, throwing generic error
+ }
+ future.completeExceptionally(new BaseSchematicApiException(
+ "Error with status code " + response.code(),
+ response.code(),
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class),
+ response));
+ return;
+ } catch (IOException e) {
+ future.completeExceptionally(new BaseSchematicException("Network error executing HTTP request", e));
+ }
+ }
+
+ @Override
+ public void onFailure(@NotNull Call call, @NotNull IOException e) {
+ future.completeExceptionally(new BaseSchematicException("Network error executing HTTP request", e));
+ }
+ });
+ return future;
+ }
+
+ public CompletableFuture> createEnvironment(
+ CreateEnvironmentRequestBody request) {
+ return createEnvironment(request, null);
+ }
+
+ public CompletableFuture> createEnvironment(
+ CreateEnvironmentRequestBody request, RequestOptions requestOptions) {
+ HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
+ .newBuilder()
+ .addPathSegments("environments")
+ .build();
+ RequestBody body;
+ try {
+ body = RequestBody.create(
+ ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON);
+ } catch (JsonProcessingException e) {
+ throw new BaseSchematicException("Failed to serialize request", e);
+ }
+ Request okhttpRequest = new Request.Builder()
+ .url(httpUrl)
+ .method("POST", body)
+ .headers(Headers.of(clientOptions.headers(requestOptions)))
+ .addHeader("Content-Type", "application/json")
+ .addHeader("Accept", "application/json")
+ .build();
+ OkHttpClient client = clientOptions.httpClient();
+ if (requestOptions != null && requestOptions.getTimeout().isPresent()) {
+ client = clientOptions.httpClientWithTimeout(requestOptions);
+ }
+ CompletableFuture> future = new CompletableFuture<>();
+ client.newCall(okhttpRequest).enqueue(new Callback() {
+ @Override
+ public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException {
+ try (ResponseBody responseBody = response.body()) {
+ if (response.isSuccessful()) {
+ future.complete(new BaseSchematicHttpResponse<>(
+ ObjectMappers.JSON_MAPPER.readValue(
+ responseBody.string(), CreateEnvironmentResponse.class),
+ response));
+ return;
+ }
+ String responseBodyString = responseBody != null ? responseBody.string() : "{}";
+ try {
+ switch (response.code()) {
+ case 400:
+ future.completeExceptionally(new BadRequestError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class),
+ response));
+ return;
+ case 401:
+ future.completeExceptionally(new UnauthorizedError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class),
+ response));
+ return;
+ case 403:
+ future.completeExceptionally(new ForbiddenError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class),
+ response));
+ return;
+ case 404:
+ future.completeExceptionally(new NotFoundError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class),
+ response));
+ return;
+ case 500:
+ future.completeExceptionally(new InternalServerError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class),
+ response));
+ return;
+ }
+ } catch (JsonProcessingException ignored) {
+ // unable to map error response, throwing generic error
+ }
+ future.completeExceptionally(new BaseSchematicApiException(
+ "Error with status code " + response.code(),
+ response.code(),
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class),
+ response));
+ return;
+ } catch (IOException e) {
+ future.completeExceptionally(new BaseSchematicException("Network error executing HTTP request", e));
+ }
+ }
+
+ @Override
+ public void onFailure(@NotNull Call call, @NotNull IOException e) {
+ future.completeExceptionally(new BaseSchematicException("Network error executing HTTP request", e));
+ }
+ });
+ return future;
+ }
+
+ public CompletableFuture> getEnvironment(String environmentId) {
+ return getEnvironment(environmentId, null);
+ }
+
+ public CompletableFuture> getEnvironment(
+ String environmentId, RequestOptions requestOptions) {
+ HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
+ .newBuilder()
+ .addPathSegments("environments")
+ .addPathSegment(environmentId)
+ .build();
+ Request okhttpRequest = new Request.Builder()
+ .url(httpUrl)
+ .method("GET", null)
+ .headers(Headers.of(clientOptions.headers(requestOptions)))
+ .addHeader("Accept", "application/json")
+ .build();
+ OkHttpClient client = clientOptions.httpClient();
+ if (requestOptions != null && requestOptions.getTimeout().isPresent()) {
+ client = clientOptions.httpClientWithTimeout(requestOptions);
+ }
+ CompletableFuture> future = new CompletableFuture<>();
+ client.newCall(okhttpRequest).enqueue(new Callback() {
+ @Override
+ public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException {
+ try (ResponseBody responseBody = response.body()) {
+ if (response.isSuccessful()) {
+ future.complete(new BaseSchematicHttpResponse<>(
+ ObjectMappers.JSON_MAPPER.readValue(
+ responseBody.string(), GetEnvironmentResponse.class),
+ response));
+ return;
+ }
+ String responseBodyString = responseBody != null ? responseBody.string() : "{}";
+ try {
+ switch (response.code()) {
+ case 401:
+ future.completeExceptionally(new UnauthorizedError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class),
+ response));
+ return;
+ case 403:
+ future.completeExceptionally(new ForbiddenError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class),
+ response));
+ return;
+ case 404:
+ future.completeExceptionally(new NotFoundError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class),
+ response));
+ return;
+ case 500:
+ future.completeExceptionally(new InternalServerError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class),
+ response));
+ return;
+ }
+ } catch (JsonProcessingException ignored) {
+ // unable to map error response, throwing generic error
+ }
+ future.completeExceptionally(new BaseSchematicApiException(
+ "Error with status code " + response.code(),
+ response.code(),
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class),
+ response));
+ return;
+ } catch (IOException e) {
+ future.completeExceptionally(new BaseSchematicException("Network error executing HTTP request", e));
+ }
+ }
+
+ @Override
+ public void onFailure(@NotNull Call call, @NotNull IOException e) {
+ future.completeExceptionally(new BaseSchematicException("Network error executing HTTP request", e));
+ }
+ });
+ return future;
+ }
+
+ public CompletableFuture> updateEnvironment(
+ String environmentId) {
+ return updateEnvironment(
+ environmentId, UpdateEnvironmentRequestBody.builder().build());
+ }
+
+ public CompletableFuture> updateEnvironment(
+ String environmentId, UpdateEnvironmentRequestBody request) {
+ return updateEnvironment(environmentId, request, null);
+ }
+
+ public CompletableFuture> updateEnvironment(
+ String environmentId, UpdateEnvironmentRequestBody request, RequestOptions requestOptions) {
+ HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
+ .newBuilder()
+ .addPathSegments("environments")
+ .addPathSegment(environmentId)
+ .build();
+ RequestBody body;
+ try {
+ body = RequestBody.create(
+ ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON);
+ } catch (JsonProcessingException e) {
+ throw new BaseSchematicException("Failed to serialize request", e);
+ }
+ Request okhttpRequest = new Request.Builder()
+ .url(httpUrl)
+ .method("PUT", body)
+ .headers(Headers.of(clientOptions.headers(requestOptions)))
+ .addHeader("Content-Type", "application/json")
+ .addHeader("Accept", "application/json")
+ .build();
+ OkHttpClient client = clientOptions.httpClient();
+ if (requestOptions != null && requestOptions.getTimeout().isPresent()) {
+ client = clientOptions.httpClientWithTimeout(requestOptions);
+ }
+ CompletableFuture> future = new CompletableFuture<>();
+ client.newCall(okhttpRequest).enqueue(new Callback() {
+ @Override
+ public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException {
+ try (ResponseBody responseBody = response.body()) {
+ if (response.isSuccessful()) {
+ future.complete(new BaseSchematicHttpResponse<>(
+ ObjectMappers.JSON_MAPPER.readValue(
+ responseBody.string(), UpdateEnvironmentResponse.class),
+ response));
+ return;
+ }
+ String responseBodyString = responseBody != null ? responseBody.string() : "{}";
+ try {
+ switch (response.code()) {
+ case 400:
+ future.completeExceptionally(new BadRequestError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class),
+ response));
+ return;
+ case 401:
+ future.completeExceptionally(new UnauthorizedError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class),
+ response));
+ return;
+ case 403:
+ future.completeExceptionally(new ForbiddenError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class),
+ response));
+ return;
+ case 404:
+ future.completeExceptionally(new NotFoundError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class),
+ response));
+ return;
+ case 500:
+ future.completeExceptionally(new InternalServerError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class),
+ response));
+ return;
+ }
+ } catch (JsonProcessingException ignored) {
+ // unable to map error response, throwing generic error
+ }
+ future.completeExceptionally(new BaseSchematicApiException(
+ "Error with status code " + response.code(),
+ response.code(),
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class),
+ response));
+ return;
+ } catch (IOException e) {
+ future.completeExceptionally(new BaseSchematicException("Network error executing HTTP request", e));
+ }
+ }
+
+ @Override
+ public void onFailure(@NotNull Call call, @NotNull IOException e) {
+ future.completeExceptionally(new BaseSchematicException("Network error executing HTTP request", e));
+ }
+ });
+ return future;
+ }
+
+ public CompletableFuture> deleteEnvironment(
+ String environmentId) {
+ return deleteEnvironment(environmentId, null);
+ }
+
+ public CompletableFuture> deleteEnvironment(
+ String environmentId, RequestOptions requestOptions) {
+ HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
+ .newBuilder()
+ .addPathSegments("environments")
+ .addPathSegment(environmentId)
+ .build();
+ Request okhttpRequest = new Request.Builder()
+ .url(httpUrl)
+ .method("DELETE", null)
+ .headers(Headers.of(clientOptions.headers(requestOptions)))
+ .addHeader("Accept", "application/json")
+ .build();
+ OkHttpClient client = clientOptions.httpClient();
+ if (requestOptions != null && requestOptions.getTimeout().isPresent()) {
+ client = clientOptions.httpClientWithTimeout(requestOptions);
+ }
+ CompletableFuture> future = new CompletableFuture<>();
+ client.newCall(okhttpRequest).enqueue(new Callback() {
+ @Override
+ public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException {
+ try (ResponseBody responseBody = response.body()) {
+ if (response.isSuccessful()) {
+ future.complete(new BaseSchematicHttpResponse<>(
+ ObjectMappers.JSON_MAPPER.readValue(
+ responseBody.string(), DeleteEnvironmentResponse.class),
+ response));
+ return;
+ }
+ String responseBodyString = responseBody != null ? responseBody.string() : "{}";
+ try {
+ switch (response.code()) {
+ case 400:
+ future.completeExceptionally(new BadRequestError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class),
+ response));
+ return;
+ case 401:
+ future.completeExceptionally(new UnauthorizedError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class),
+ response));
+ return;
+ case 403:
+ future.completeExceptionally(new ForbiddenError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class),
+ response));
+ return;
+ case 404:
+ future.completeExceptionally(new NotFoundError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class),
+ response));
+ return;
+ case 500:
+ future.completeExceptionally(new InternalServerError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class),
+ response));
+ return;
+ }
+ } catch (JsonProcessingException ignored) {
+ // unable to map error response, throwing generic error
+ }
+ future.completeExceptionally(new BaseSchematicApiException(
+ "Error with status code " + response.code(),
+ response.code(),
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class),
+ response));
+ return;
+ } catch (IOException e) {
+ future.completeExceptionally(new BaseSchematicException("Network error executing HTTP request", e));
+ }
+ }
+
+ @Override
+ public void onFailure(@NotNull Call call, @NotNull IOException e) {
+ future.completeExceptionally(new BaseSchematicException("Network error executing HTTP request", e));
+ }
+ });
+ return future;
+ }
+
+ public CompletableFuture> quickstart() {
+ return quickstart(null);
+ }
+
+ public CompletableFuture> quickstart(RequestOptions requestOptions) {
+ HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
+ .newBuilder()
+ .addPathSegments("quickstart")
+ .build();
+ Request okhttpRequest = new Request.Builder()
+ .url(httpUrl)
+ .method("POST", RequestBody.create("", null))
+ .headers(Headers.of(clientOptions.headers(requestOptions)))
+ .addHeader("Accept", "application/json")
+ .build();
+ OkHttpClient client = clientOptions.httpClient();
+ if (requestOptions != null && requestOptions.getTimeout().isPresent()) {
+ client = clientOptions.httpClientWithTimeout(requestOptions);
+ }
+ CompletableFuture> future = new CompletableFuture<>();
+ client.newCall(okhttpRequest).enqueue(new Callback() {
+ @Override
+ public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException {
+ try (ResponseBody responseBody = response.body()) {
+ if (response.isSuccessful()) {
+ future.complete(new BaseSchematicHttpResponse<>(
+ ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), QuickstartResponse.class),
+ response));
+ return;
+ }
+ String responseBodyString = responseBody != null ? responseBody.string() : "{}";
+ try {
+ switch (response.code()) {
+ case 400:
+ future.completeExceptionally(new BadRequestError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class),
+ response));
+ return;
+ case 401:
+ future.completeExceptionally(new UnauthorizedError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class),
+ response));
+ return;
+ case 403:
+ future.completeExceptionally(new ForbiddenError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class),
+ response));
+ return;
+ case 404:
+ future.completeExceptionally(new NotFoundError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class),
+ response));
+ return;
+ case 500:
+ future.completeExceptionally(new InternalServerError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class),
+ response));
+ return;
+ }
+ } catch (JsonProcessingException ignored) {
+ // unable to map error response, throwing generic error
+ }
+ future.completeExceptionally(new BaseSchematicApiException(
+ "Error with status code " + response.code(),
+ response.code(),
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class),
+ response));
+ return;
+ } catch (IOException e) {
+ future.completeExceptionally(new BaseSchematicException("Network error executing HTTP request", e));
+ }
+ }
+
+ @Override
+ public void onFailure(@NotNull Call call, @NotNull IOException e) {
+ future.completeExceptionally(new BaseSchematicException("Network error executing HTTP request", e));
+ }
+ });
+ return future;
+ }
+}
diff --git a/src/main/java/com/schematic/api/resources/accounts/RawAccountsClient.java b/src/main/java/com/schematic/api/resources/accounts/RawAccountsClient.java
new file mode 100644
index 0000000..808a848
--- /dev/null
+++ b/src/main/java/com/schematic/api/resources/accounts/RawAccountsClient.java
@@ -0,0 +1,1065 @@
+/**
+ * This file was auto-generated by Fern from our API Definition.
+ */
+package com.schematic.api.resources.accounts;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.schematic.api.core.BaseSchematicApiException;
+import com.schematic.api.core.BaseSchematicException;
+import com.schematic.api.core.BaseSchematicHttpResponse;
+import com.schematic.api.core.ClientOptions;
+import com.schematic.api.core.MediaTypes;
+import com.schematic.api.core.ObjectMappers;
+import com.schematic.api.core.QueryStringMapper;
+import com.schematic.api.core.RequestOptions;
+import com.schematic.api.errors.BadRequestError;
+import com.schematic.api.errors.ForbiddenError;
+import com.schematic.api.errors.InternalServerError;
+import com.schematic.api.errors.NotFoundError;
+import com.schematic.api.errors.UnauthorizedError;
+import com.schematic.api.resources.accounts.requests.CountApiKeysRequest;
+import com.schematic.api.resources.accounts.requests.CountApiRequestsRequest;
+import com.schematic.api.resources.accounts.requests.CreateApiKeyRequestBody;
+import com.schematic.api.resources.accounts.requests.CreateEnvironmentRequestBody;
+import com.schematic.api.resources.accounts.requests.ListApiKeysRequest;
+import com.schematic.api.resources.accounts.requests.ListApiRequestsRequest;
+import com.schematic.api.resources.accounts.requests.ListEnvironmentsRequest;
+import com.schematic.api.resources.accounts.requests.UpdateApiKeyRequestBody;
+import com.schematic.api.resources.accounts.requests.UpdateEnvironmentRequestBody;
+import com.schematic.api.resources.accounts.types.CountApiKeysResponse;
+import com.schematic.api.resources.accounts.types.CountApiRequestsResponse;
+import com.schematic.api.resources.accounts.types.CreateApiKeyResponse;
+import com.schematic.api.resources.accounts.types.CreateEnvironmentResponse;
+import com.schematic.api.resources.accounts.types.DeleteApiKeyResponse;
+import com.schematic.api.resources.accounts.types.DeleteEnvironmentResponse;
+import com.schematic.api.resources.accounts.types.GetApiKeyResponse;
+import com.schematic.api.resources.accounts.types.GetApiRequestResponse;
+import com.schematic.api.resources.accounts.types.GetEnvironmentResponse;
+import com.schematic.api.resources.accounts.types.ListApiKeysResponse;
+import com.schematic.api.resources.accounts.types.ListApiRequestsResponse;
+import com.schematic.api.resources.accounts.types.ListEnvironmentsResponse;
+import com.schematic.api.resources.accounts.types.QuickstartResponse;
+import com.schematic.api.resources.accounts.types.UpdateApiKeyResponse;
+import com.schematic.api.resources.accounts.types.UpdateEnvironmentResponse;
+import com.schematic.api.types.ApiError;
+import java.io.IOException;
+import okhttp3.Headers;
+import okhttp3.HttpUrl;
+import okhttp3.OkHttpClient;
+import okhttp3.Request;
+import okhttp3.RequestBody;
+import okhttp3.Response;
+import okhttp3.ResponseBody;
+
+public class RawAccountsClient {
+ protected final ClientOptions clientOptions;
+
+ public RawAccountsClient(ClientOptions clientOptions) {
+ this.clientOptions = clientOptions;
+ }
+
+ public BaseSchematicHttpResponse listApiKeys(ListApiKeysRequest request) {
+ return listApiKeys(request, null);
+ }
+
+ public BaseSchematicHttpResponse listApiKeys(
+ ListApiKeysRequest request, RequestOptions requestOptions) {
+ HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
+ .newBuilder()
+ .addPathSegments("api-keys");
+ if (request.getEnvironmentId().isPresent()) {
+ QueryStringMapper.addQueryParameter(
+ httpUrl, "environment_id", request.getEnvironmentId().get(), false);
+ }
+ QueryStringMapper.addQueryParameter(httpUrl, "require_environment", request.getRequireEnvironment(), false);
+ if (request.getLimit().isPresent()) {
+ QueryStringMapper.addQueryParameter(
+ httpUrl, "limit", request.getLimit().get(), false);
+ }
+ if (request.getOffset().isPresent()) {
+ QueryStringMapper.addQueryParameter(
+ httpUrl, "offset", request.getOffset().get(), false);
+ }
+ Request.Builder _requestBuilder = new Request.Builder()
+ .url(httpUrl.build())
+ .method("GET", null)
+ .headers(Headers.of(clientOptions.headers(requestOptions)))
+ .addHeader("Accept", "application/json");
+ Request okhttpRequest = _requestBuilder.build();
+ OkHttpClient client = clientOptions.httpClient();
+ if (requestOptions != null && requestOptions.getTimeout().isPresent()) {
+ client = clientOptions.httpClientWithTimeout(requestOptions);
+ }
+ try (Response response = client.newCall(okhttpRequest).execute()) {
+ ResponseBody responseBody = response.body();
+ if (response.isSuccessful()) {
+ return new BaseSchematicHttpResponse<>(
+ ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), ListApiKeysResponse.class),
+ response);
+ }
+ String responseBodyString = responseBody != null ? responseBody.string() : "{}";
+ try {
+ switch (response.code()) {
+ case 400:
+ throw new BadRequestError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class), response);
+ case 401:
+ throw new UnauthorizedError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class), response);
+ case 403:
+ throw new ForbiddenError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class), response);
+ case 404:
+ throw new NotFoundError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class), response);
+ case 500:
+ throw new InternalServerError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class), response);
+ }
+ } catch (JsonProcessingException ignored) {
+ // unable to map error response, throwing generic error
+ }
+ throw new BaseSchematicApiException(
+ "Error with status code " + response.code(),
+ response.code(),
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class),
+ response);
+ } catch (IOException e) {
+ throw new BaseSchematicException("Network error executing HTTP request", e);
+ }
+ }
+
+ public BaseSchematicHttpResponse createApiKey(CreateApiKeyRequestBody request) {
+ return createApiKey(request, null);
+ }
+
+ public BaseSchematicHttpResponse createApiKey(
+ CreateApiKeyRequestBody request, RequestOptions requestOptions) {
+ HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
+ .newBuilder()
+ .addPathSegments("api-keys")
+ .build();
+ RequestBody body;
+ try {
+ body = RequestBody.create(
+ ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON);
+ } catch (JsonProcessingException e) {
+ throw new BaseSchematicException("Failed to serialize request", e);
+ }
+ Request okhttpRequest = new Request.Builder()
+ .url(httpUrl)
+ .method("POST", body)
+ .headers(Headers.of(clientOptions.headers(requestOptions)))
+ .addHeader("Content-Type", "application/json")
+ .addHeader("Accept", "application/json")
+ .build();
+ OkHttpClient client = clientOptions.httpClient();
+ if (requestOptions != null && requestOptions.getTimeout().isPresent()) {
+ client = clientOptions.httpClientWithTimeout(requestOptions);
+ }
+ try (Response response = client.newCall(okhttpRequest).execute()) {
+ ResponseBody responseBody = response.body();
+ if (response.isSuccessful()) {
+ return new BaseSchematicHttpResponse<>(
+ ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), CreateApiKeyResponse.class),
+ response);
+ }
+ String responseBodyString = responseBody != null ? responseBody.string() : "{}";
+ try {
+ switch (response.code()) {
+ case 400:
+ throw new BadRequestError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class), response);
+ case 401:
+ throw new UnauthorizedError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class), response);
+ case 403:
+ throw new ForbiddenError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class), response);
+ case 404:
+ throw new NotFoundError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class), response);
+ case 500:
+ throw new InternalServerError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class), response);
+ }
+ } catch (JsonProcessingException ignored) {
+ // unable to map error response, throwing generic error
+ }
+ throw new BaseSchematicApiException(
+ "Error with status code " + response.code(),
+ response.code(),
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class),
+ response);
+ } catch (IOException e) {
+ throw new BaseSchematicException("Network error executing HTTP request", e);
+ }
+ }
+
+ public BaseSchematicHttpResponse getApiKey(String apiKeyId) {
+ return getApiKey(apiKeyId, null);
+ }
+
+ public BaseSchematicHttpResponse getApiKey(String apiKeyId, RequestOptions requestOptions) {
+ HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
+ .newBuilder()
+ .addPathSegments("api-keys")
+ .addPathSegment(apiKeyId)
+ .build();
+ Request okhttpRequest = new Request.Builder()
+ .url(httpUrl)
+ .method("GET", null)
+ .headers(Headers.of(clientOptions.headers(requestOptions)))
+ .addHeader("Accept", "application/json")
+ .build();
+ OkHttpClient client = clientOptions.httpClient();
+ if (requestOptions != null && requestOptions.getTimeout().isPresent()) {
+ client = clientOptions.httpClientWithTimeout(requestOptions);
+ }
+ try (Response response = client.newCall(okhttpRequest).execute()) {
+ ResponseBody responseBody = response.body();
+ if (response.isSuccessful()) {
+ return new BaseSchematicHttpResponse<>(
+ ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), GetApiKeyResponse.class), response);
+ }
+ String responseBodyString = responseBody != null ? responseBody.string() : "{}";
+ try {
+ switch (response.code()) {
+ case 401:
+ throw new UnauthorizedError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class), response);
+ case 403:
+ throw new ForbiddenError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class), response);
+ case 404:
+ throw new NotFoundError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class), response);
+ case 500:
+ throw new InternalServerError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class), response);
+ }
+ } catch (JsonProcessingException ignored) {
+ // unable to map error response, throwing generic error
+ }
+ throw new BaseSchematicApiException(
+ "Error with status code " + response.code(),
+ response.code(),
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class),
+ response);
+ } catch (IOException e) {
+ throw new BaseSchematicException("Network error executing HTTP request", e);
+ }
+ }
+
+ public BaseSchematicHttpResponse updateApiKey(String apiKeyId) {
+ return updateApiKey(apiKeyId, UpdateApiKeyRequestBody.builder().build());
+ }
+
+ public BaseSchematicHttpResponse updateApiKey(
+ String apiKeyId, UpdateApiKeyRequestBody request) {
+ return updateApiKey(apiKeyId, request, null);
+ }
+
+ public BaseSchematicHttpResponse updateApiKey(
+ String apiKeyId, UpdateApiKeyRequestBody request, RequestOptions requestOptions) {
+ HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
+ .newBuilder()
+ .addPathSegments("api-keys")
+ .addPathSegment(apiKeyId)
+ .build();
+ RequestBody body;
+ try {
+ body = RequestBody.create(
+ ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON);
+ } catch (JsonProcessingException e) {
+ throw new BaseSchematicException("Failed to serialize request", e);
+ }
+ Request okhttpRequest = new Request.Builder()
+ .url(httpUrl)
+ .method("PUT", body)
+ .headers(Headers.of(clientOptions.headers(requestOptions)))
+ .addHeader("Content-Type", "application/json")
+ .addHeader("Accept", "application/json")
+ .build();
+ OkHttpClient client = clientOptions.httpClient();
+ if (requestOptions != null && requestOptions.getTimeout().isPresent()) {
+ client = clientOptions.httpClientWithTimeout(requestOptions);
+ }
+ try (Response response = client.newCall(okhttpRequest).execute()) {
+ ResponseBody responseBody = response.body();
+ if (response.isSuccessful()) {
+ return new BaseSchematicHttpResponse<>(
+ ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), UpdateApiKeyResponse.class),
+ response);
+ }
+ String responseBodyString = responseBody != null ? responseBody.string() : "{}";
+ try {
+ switch (response.code()) {
+ case 400:
+ throw new BadRequestError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class), response);
+ case 401:
+ throw new UnauthorizedError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class), response);
+ case 403:
+ throw new ForbiddenError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class), response);
+ case 404:
+ throw new NotFoundError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class), response);
+ case 500:
+ throw new InternalServerError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class), response);
+ }
+ } catch (JsonProcessingException ignored) {
+ // unable to map error response, throwing generic error
+ }
+ throw new BaseSchematicApiException(
+ "Error with status code " + response.code(),
+ response.code(),
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class),
+ response);
+ } catch (IOException e) {
+ throw new BaseSchematicException("Network error executing HTTP request", e);
+ }
+ }
+
+ public BaseSchematicHttpResponse deleteApiKey(String apiKeyId) {
+ return deleteApiKey(apiKeyId, null);
+ }
+
+ public BaseSchematicHttpResponse deleteApiKey(
+ String apiKeyId, RequestOptions requestOptions) {
+ HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
+ .newBuilder()
+ .addPathSegments("api-keys")
+ .addPathSegment(apiKeyId)
+ .build();
+ Request okhttpRequest = new Request.Builder()
+ .url(httpUrl)
+ .method("DELETE", null)
+ .headers(Headers.of(clientOptions.headers(requestOptions)))
+ .addHeader("Accept", "application/json")
+ .build();
+ OkHttpClient client = clientOptions.httpClient();
+ if (requestOptions != null && requestOptions.getTimeout().isPresent()) {
+ client = clientOptions.httpClientWithTimeout(requestOptions);
+ }
+ try (Response response = client.newCall(okhttpRequest).execute()) {
+ ResponseBody responseBody = response.body();
+ if (response.isSuccessful()) {
+ return new BaseSchematicHttpResponse<>(
+ ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), DeleteApiKeyResponse.class),
+ response);
+ }
+ String responseBodyString = responseBody != null ? responseBody.string() : "{}";
+ try {
+ switch (response.code()) {
+ case 400:
+ throw new BadRequestError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class), response);
+ case 401:
+ throw new UnauthorizedError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class), response);
+ case 403:
+ throw new ForbiddenError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class), response);
+ case 404:
+ throw new NotFoundError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class), response);
+ case 500:
+ throw new InternalServerError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class), response);
+ }
+ } catch (JsonProcessingException ignored) {
+ // unable to map error response, throwing generic error
+ }
+ throw new BaseSchematicApiException(
+ "Error with status code " + response.code(),
+ response.code(),
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class),
+ response);
+ } catch (IOException e) {
+ throw new BaseSchematicException("Network error executing HTTP request", e);
+ }
+ }
+
+ public BaseSchematicHttpResponse countApiKeys(CountApiKeysRequest request) {
+ return countApiKeys(request, null);
+ }
+
+ public BaseSchematicHttpResponse countApiKeys(
+ CountApiKeysRequest request, RequestOptions requestOptions) {
+ HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
+ .newBuilder()
+ .addPathSegments("api-keys/count");
+ if (request.getEnvironmentId().isPresent()) {
+ QueryStringMapper.addQueryParameter(
+ httpUrl, "environment_id", request.getEnvironmentId().get(), false);
+ }
+ QueryStringMapper.addQueryParameter(httpUrl, "require_environment", request.getRequireEnvironment(), false);
+ if (request.getLimit().isPresent()) {
+ QueryStringMapper.addQueryParameter(
+ httpUrl, "limit", request.getLimit().get(), false);
+ }
+ if (request.getOffset().isPresent()) {
+ QueryStringMapper.addQueryParameter(
+ httpUrl, "offset", request.getOffset().get(), false);
+ }
+ Request.Builder _requestBuilder = new Request.Builder()
+ .url(httpUrl.build())
+ .method("GET", null)
+ .headers(Headers.of(clientOptions.headers(requestOptions)))
+ .addHeader("Accept", "application/json");
+ Request okhttpRequest = _requestBuilder.build();
+ OkHttpClient client = clientOptions.httpClient();
+ if (requestOptions != null && requestOptions.getTimeout().isPresent()) {
+ client = clientOptions.httpClientWithTimeout(requestOptions);
+ }
+ try (Response response = client.newCall(okhttpRequest).execute()) {
+ ResponseBody responseBody = response.body();
+ if (response.isSuccessful()) {
+ return new BaseSchematicHttpResponse<>(
+ ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), CountApiKeysResponse.class),
+ response);
+ }
+ String responseBodyString = responseBody != null ? responseBody.string() : "{}";
+ try {
+ switch (response.code()) {
+ case 400:
+ throw new BadRequestError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class), response);
+ case 401:
+ throw new UnauthorizedError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class), response);
+ case 403:
+ throw new ForbiddenError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class), response);
+ case 404:
+ throw new NotFoundError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class), response);
+ case 500:
+ throw new InternalServerError(
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class), response);
+ }
+ } catch (JsonProcessingException ignored) {
+ // unable to map error response, throwing generic error
+ }
+ throw new BaseSchematicApiException(
+ "Error with status code " + response.code(),
+ response.code(),
+ ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class),
+ response);
+ } catch (IOException e) {
+ throw new BaseSchematicException("Network error executing HTTP request", e);
+ }
+ }
+
+ public BaseSchematicHttpResponse listApiRequests() {
+ return listApiRequests(ListApiRequestsRequest.builder().build());
+ }
+
+ public BaseSchematicHttpResponse listApiRequests(ListApiRequestsRequest request) {
+ return listApiRequests(request, null);
+ }
+
+ public BaseSchematicHttpResponse