Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🌿 Fern Regeneration -- September 23, 2024 #4

Merged
merged 1 commit into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/main/java/com/basis/theory/api/BasisTheoryApiClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.basis.theory.api.resources.applicationkeys.ApplicationKeysClient;
import com.basis.theory.api.resources.applications.ApplicationsClient;
import com.basis.theory.api.resources.applicationtemplates.ApplicationTemplatesClient;
import com.basis.theory.api.resources.detokenize.DetokenizeClient;
import com.basis.theory.api.resources.logs.LogsClient;
import com.basis.theory.api.resources.permissions.PermissionsClient;
import com.basis.theory.api.resources.proxies.ProxiesClient;
Expand All @@ -19,6 +20,7 @@
import com.basis.theory.api.resources.threeds.ThreedsClient;
import com.basis.theory.api.resources.tokenize.TokenizeClient;
import com.basis.theory.api.resources.tokens.TokensClient;
import com.basis.theory.api.resources.webhooks.WebhooksClient;
import java.util.function.Supplier;

public class BasisTheoryApiClient {
Expand All @@ -30,6 +32,8 @@ public class BasisTheoryApiClient {

protected final Supplier<ApplicationTemplatesClient> applicationTemplatesClient;

protected final Supplier<DetokenizeClient> detokenizeClient;

protected final Supplier<LogsClient> logsClient;

protected final Supplier<PermissionsClient> permissionsClient;
Expand All @@ -50,13 +54,16 @@ public class BasisTheoryApiClient {

protected final Supplier<TokensClient> tokensClient;

protected final Supplier<WebhooksClient> webhooksClient;

protected final Supplier<TenantsClient> tenantsClient;

public BasisTheoryApiClient(ClientOptions clientOptions) {
this.clientOptions = clientOptions;
this.applicationsClient = Suppliers.memoize(() -> new ApplicationsClient(clientOptions));
this.applicationKeysClient = Suppliers.memoize(() -> new ApplicationKeysClient(clientOptions));
this.applicationTemplatesClient = Suppliers.memoize(() -> new ApplicationTemplatesClient(clientOptions));
this.detokenizeClient = Suppliers.memoize(() -> new DetokenizeClient(clientOptions));
this.logsClient = Suppliers.memoize(() -> new LogsClient(clientOptions));
this.permissionsClient = Suppliers.memoize(() -> new PermissionsClient(clientOptions));
this.proxiesClient = Suppliers.memoize(() -> new ProxiesClient(clientOptions));
Expand All @@ -67,6 +74,7 @@ public BasisTheoryApiClient(ClientOptions clientOptions) {
this.threedsClient = Suppliers.memoize(() -> new ThreedsClient(clientOptions));
this.tokenizeClient = Suppliers.memoize(() -> new TokenizeClient(clientOptions));
this.tokensClient = Suppliers.memoize(() -> new TokensClient(clientOptions));
this.webhooksClient = Suppliers.memoize(() -> new WebhooksClient(clientOptions));
this.tenantsClient = Suppliers.memoize(() -> new TenantsClient(clientOptions));
}

Expand All @@ -82,6 +90,10 @@ public ApplicationTemplatesClient applicationTemplates() {
return this.applicationTemplatesClient.get();
}

public DetokenizeClient detokenize() {
return this.detokenizeClient.get();
}

public LogsClient logs() {
return this.logsClient.get();
}
Expand Down Expand Up @@ -122,6 +134,10 @@ public TokensClient tokens() {
return this.tokensClient.get();
}

public WebhooksClient webhooks() {
return this.webhooksClient.get();
}

public TenantsClient tenants() {
return this.tenantsClient.get();
}
Expand Down
24 changes: 24 additions & 0 deletions src/main/java/com/basis/theory/api/core/pagination/BasePage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* This file was auto-generated by Fern from our API Definition.
*/
package com.basis.theory.api.core.pagination;

import java.util.List;

public abstract class BasePage<T> {
private final boolean hasNext;
private final List<T> items;

public BasePage(boolean hasNext, List<T> items) {
this.hasNext = hasNext;
this.items = items;
}

public boolean hasNext() {
return !items.isEmpty() && hasNext;
}

public List<T> getItems() {
return items;
}
}
24 changes: 24 additions & 0 deletions src/main/java/com/basis/theory/api/core/pagination/SyncPage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* This file was auto-generated by Fern from our API Definition.
*/
package com.basis.theory.api.core.pagination;

import java.util.List;
import java.util.NoSuchElementException;
import java.util.function.Supplier;

public class SyncPage<T> extends BasePage<T> {
protected final Supplier<? extends SyncPage<T>> nextSupplier;

public SyncPage(boolean hasNext, List<T> items, Supplier<? extends SyncPage<T>> nextSupplier) {
super(hasNext, items);
this.nextSupplier = nextSupplier;
}

public SyncPage<T> nextPage() {
if (!hasNext()) {
throw new NoSuchElementException();
}
return nextSupplier.get();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/**
* This file was auto-generated by Fern from our API Definition.
*/
package com.basis.theory.api.core.pagination;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.Optional;
import java.util.function.Supplier;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;

public class SyncPagingIterable<T> extends SyncPage<T> implements Iterable<T> {

public SyncPagingIterable(boolean hasNext, List<T> items, Supplier<? extends SyncPage<T>> getNext) {
super(hasNext, items, getNext);
}

public SyncPagingIterable(boolean hasNext, Optional<List<T>> items, Supplier<? extends SyncPage<T>> getNext) {
super(hasNext, items.orElse(new ArrayList<>()), getNext);
}

public Stream<T> streamItems() {
return StreamSupport.stream(this.spliterator(), false);
}

@Override
public Iterator<T> iterator() {
return new Iterator<T>() {
private Iterator<T> itemsIterator = getItems().iterator();
private SyncPage<T> currentPage = SyncPagingIterable.this;

@Override
public boolean hasNext() {
if (itemsIterator.hasNext()) {
return true;
}
if (currentPage.hasNext()) {
advancePage();
return itemsIterator.hasNext();
}
return false;
}

@Override
public T next() {
if (!hasNext()) {
throw new NoSuchElementException();
}
return itemsIterator.next();
}

private void advancePage() {
currentPage = currentPage.nextPage();
itemsIterator = currentPage.getItems().iterator();
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.basis.theory.api.core.MediaTypes;
import com.basis.theory.api.core.ObjectMappers;
import com.basis.theory.api.core.RequestOptions;
import com.basis.theory.api.core.pagination.SyncPagingIterable;
import com.basis.theory.api.errors.BadRequestError;
import com.basis.theory.api.errors.ForbiddenError;
import com.basis.theory.api.errors.NotFoundError;
Expand All @@ -24,6 +25,8 @@
import com.basis.theory.api.types.ValidationProblemDetails;
import com.fasterxml.jackson.core.JsonProcessingException;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
import okhttp3.Headers;
import okhttp3.HttpUrl;
import okhttp3.OkHttpClient;
Expand All @@ -39,15 +42,15 @@ public ApplicationsClient(ClientOptions clientOptions) {
this.clientOptions = clientOptions;
}

public ApplicationPaginatedList list() {
public SyncPagingIterable<Application> list() {
return list(ApplicationsListRequest.builder().build());
}

public ApplicationPaginatedList list(ApplicationsListRequest request) {
public SyncPagingIterable<Application> list(ApplicationsListRequest request) {
return list(request, null);
}

public ApplicationPaginatedList list(ApplicationsListRequest request, RequestOptions requestOptions) {
public SyncPagingIterable<Application> list(ApplicationsListRequest request, RequestOptions requestOptions) {
HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
.newBuilder()
.addPathSegments("applications");
Expand Down Expand Up @@ -79,7 +82,15 @@ public ApplicationPaginatedList list(ApplicationsListRequest request, RequestOpt
try (Response response = client.newCall(okhttpRequest).execute()) {
ResponseBody responseBody = response.body();
if (response.isSuccessful()) {
return ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), ApplicationPaginatedList.class);
ApplicationPaginatedList parsedResponse =
ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), ApplicationPaginatedList.class);
int newPageNumber = request.getPage().map(page -> page + 1).orElse(1);
ApplicationsListRequest nextRequest = ApplicationsListRequest.builder()
.from(request)
.page(newPageNumber)
.build();
List<Application> result = parsedResponse.getData().orElse(Collections.emptyList());
return new SyncPagingIterable<>(true, result, () -> list(nextRequest, requestOptions));
}
String responseBodyString = responseBody != null ? responseBody.string() : "{}";
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/**
* This file was auto-generated by Fern from our API Definition.
*/
package com.basis.theory.api.resources.detokenize;

import com.basis.theory.api.core.BasisTheoryApiApiException;
import com.basis.theory.api.core.BasisTheoryException;
import com.basis.theory.api.core.ClientOptions;
import com.basis.theory.api.core.MediaTypes;
import com.basis.theory.api.core.ObjectMappers;
import com.basis.theory.api.core.RequestOptions;
import com.basis.theory.api.errors.BadRequestError;
import com.basis.theory.api.errors.ConflictError;
import com.basis.theory.api.errors.ForbiddenError;
import com.basis.theory.api.errors.UnauthorizedError;
import com.basis.theory.api.types.ProblemDetails;
import com.basis.theory.api.types.ValidationProblemDetails;
import com.fasterxml.jackson.core.JsonProcessingException;
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 DetokenizeClient {
protected final ClientOptions clientOptions;

public DetokenizeClient(ClientOptions clientOptions) {
this.clientOptions = clientOptions;
}

public void detokenize(Object request) {
detokenize(request, null);
}

public void detokenize(Object request, RequestOptions requestOptions) {
HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
.newBuilder()
.addPathSegments("detokenize")
.build();
RequestBody body;
try {
body = RequestBody.create(
ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON);
} catch (JsonProcessingException e) {
throw new BasisTheoryException("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")
.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;
}
String responseBodyString = responseBody != null ? responseBody.string() : "{}";
try {
switch (response.code()) {
case 400:
throw new BadRequestError(ObjectMappers.JSON_MAPPER.readValue(
responseBodyString, ValidationProblemDetails.class));
case 401:
throw new UnauthorizedError(
ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ProblemDetails.class));
case 403:
throw new ForbiddenError(
ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ProblemDetails.class));
case 409:
throw new ConflictError(
ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ProblemDetails.class));
}
} catch (JsonProcessingException ignored) {
// unable to map error response, throwing generic error
}
throw new BasisTheoryApiApiException(
"Error with status code " + response.code(),
response.code(),
ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class));
} catch (IOException e) {
throw new BasisTheoryException("Network error executing HTTP request", e);
}
}
}
19 changes: 15 additions & 4 deletions src/main/java/com/basis/theory/api/resources/logs/LogsClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,20 @@
import com.basis.theory.api.core.ClientOptions;
import com.basis.theory.api.core.ObjectMappers;
import com.basis.theory.api.core.RequestOptions;
import com.basis.theory.api.core.pagination.SyncPagingIterable;
import com.basis.theory.api.errors.BadRequestError;
import com.basis.theory.api.errors.ForbiddenError;
import com.basis.theory.api.errors.UnauthorizedError;
import com.basis.theory.api.resources.logs.requests.LogsListRequest;
import com.basis.theory.api.types.Log;
import com.basis.theory.api.types.LogEntityType;
import com.basis.theory.api.types.LogPaginatedList;
import com.basis.theory.api.types.ProblemDetails;
import com.basis.theory.api.types.ValidationProblemDetails;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
import okhttp3.Headers;
import okhttp3.HttpUrl;
Expand All @@ -34,15 +37,15 @@ public LogsClient(ClientOptions clientOptions) {
this.clientOptions = clientOptions;
}

public LogPaginatedList list() {
public SyncPagingIterable<Log> list() {
return list(LogsListRequest.builder().build());
}

public LogPaginatedList list(LogsListRequest request) {
public SyncPagingIterable<Log> list(LogsListRequest request) {
return list(request, null);
}

public LogPaginatedList list(LogsListRequest request, RequestOptions requestOptions) {
public SyncPagingIterable<Log> list(LogsListRequest request, RequestOptions requestOptions) {
HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
.newBuilder()
.addPathSegments("logs");
Expand Down Expand Up @@ -80,7 +83,15 @@ public LogPaginatedList list(LogsListRequest request, RequestOptions requestOpti
try (Response response = client.newCall(okhttpRequest).execute()) {
ResponseBody responseBody = response.body();
if (response.isSuccessful()) {
return ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), LogPaginatedList.class);
LogPaginatedList parsedResponse =
ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), LogPaginatedList.class);
int newPageNumber = request.getPage().map(page -> page + 1).orElse(1);
LogsListRequest nextRequest = LogsListRequest.builder()
.from(request)
.page(newPageNumber)
.build();
List<Log> result = parsedResponse.getData().orElse(Collections.emptyList());
return new SyncPagingIterable<>(true, result, () -> list(nextRequest, requestOptions));
}
String responseBodyString = responseBody != null ? responseBody.string() : "{}";
try {
Expand Down
Loading
Loading