-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e3650db
commit 855b875
Showing
7 changed files
with
807 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
140 changes: 140 additions & 0 deletions
140
src/main/java/com/basis/theory/api/resources/tokenintents/TokenIntentsClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
/** | ||
* This file was auto-generated by Fern from our API Definition. | ||
*/ | ||
package com.basis.theory.api.resources.tokenintents; | ||
|
||
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.ForbiddenError; | ||
import com.basis.theory.api.errors.NotFoundError; | ||
import com.basis.theory.api.errors.UnauthorizedError; | ||
import com.basis.theory.api.resources.tokenintents.requests.CreateTokenIntentRequest; | ||
import com.basis.theory.api.types.CreateTokenIntentResponse; | ||
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 TokenIntentsClient { | ||
protected final ClientOptions clientOptions; | ||
|
||
public TokenIntentsClient(ClientOptions clientOptions) { | ||
this.clientOptions = clientOptions; | ||
} | ||
|
||
public CreateTokenIntentResponse create(CreateTokenIntentRequest request) { | ||
return create(request, null); | ||
} | ||
|
||
public CreateTokenIntentResponse create(CreateTokenIntentRequest request, RequestOptions requestOptions) { | ||
HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) | ||
.newBuilder() | ||
.addPathSegments("token-intents") | ||
.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 ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), CreateTokenIntentResponse.class); | ||
} | ||
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)); | ||
} | ||
} 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); | ||
} | ||
} | ||
|
||
public void delete(String id) { | ||
delete(id, null); | ||
} | ||
|
||
public void delete(String id, RequestOptions requestOptions) { | ||
HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) | ||
.newBuilder() | ||
.addPathSegments("token-intents") | ||
.addPathSegment(id) | ||
.build(); | ||
Request okhttpRequest = new Request.Builder() | ||
.url(httpUrl) | ||
.method("DELETE", null) | ||
.headers(Headers.of(clientOptions.headers(requestOptions))) | ||
.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 401: | ||
throw new UnauthorizedError( | ||
ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ProblemDetails.class)); | ||
case 403: | ||
throw new ForbiddenError( | ||
ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ProblemDetails.class)); | ||
case 404: | ||
throw new NotFoundError(ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.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); | ||
} | ||
} | ||
} |
124 changes: 124 additions & 0 deletions
124
...n/java/com/basis/theory/api/resources/tokenintents/requests/CreateTokenIntentRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
/** | ||
* This file was auto-generated by Fern from our API Definition. | ||
*/ | ||
package com.basis.theory.api.resources.tokenintents.requests; | ||
|
||
import com.basis.theory.api.core.ObjectMappers; | ||
import com.fasterxml.jackson.annotation.JsonAnyGetter; | ||
import com.fasterxml.jackson.annotation.JsonAnySetter; | ||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.annotation.JsonSetter; | ||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
@JsonInclude(JsonInclude.Include.NON_ABSENT) | ||
@JsonDeserialize(builder = CreateTokenIntentRequest.Builder.class) | ||
public final class CreateTokenIntentRequest { | ||
private final String type; | ||
|
||
private final Object data; | ||
|
||
private final Map<String, Object> additionalProperties; | ||
|
||
private CreateTokenIntentRequest(String type, Object data, Map<String, Object> additionalProperties) { | ||
this.type = type; | ||
this.data = data; | ||
this.additionalProperties = additionalProperties; | ||
} | ||
|
||
@JsonProperty("type") | ||
public String getType() { | ||
return type; | ||
} | ||
|
||
@JsonProperty("data") | ||
public Object getData() { | ||
return data; | ||
} | ||
|
||
@java.lang.Override | ||
public boolean equals(Object other) { | ||
if (this == other) return true; | ||
return other instanceof CreateTokenIntentRequest && equalTo((CreateTokenIntentRequest) other); | ||
} | ||
|
||
@JsonAnyGetter | ||
public Map<String, Object> getAdditionalProperties() { | ||
return this.additionalProperties; | ||
} | ||
|
||
private boolean equalTo(CreateTokenIntentRequest other) { | ||
return type.equals(other.type) && data.equals(other.data); | ||
} | ||
|
||
@java.lang.Override | ||
public int hashCode() { | ||
return Objects.hash(this.type, this.data); | ||
} | ||
|
||
@java.lang.Override | ||
public String toString() { | ||
return ObjectMappers.stringify(this); | ||
} | ||
|
||
public static TypeStage builder() { | ||
return new Builder(); | ||
} | ||
|
||
public interface TypeStage { | ||
DataStage type(@NotNull String type); | ||
|
||
Builder from(CreateTokenIntentRequest other); | ||
} | ||
|
||
public interface DataStage { | ||
_FinalStage data(Object data); | ||
} | ||
|
||
public interface _FinalStage { | ||
CreateTokenIntentRequest build(); | ||
} | ||
|
||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
public static final class Builder implements TypeStage, DataStage, _FinalStage { | ||
private String type; | ||
|
||
private Object data; | ||
|
||
@JsonAnySetter | ||
private Map<String, Object> additionalProperties = new HashMap<>(); | ||
|
||
private Builder() {} | ||
|
||
@java.lang.Override | ||
public Builder from(CreateTokenIntentRequest other) { | ||
type(other.getType()); | ||
data(other.getData()); | ||
return this; | ||
} | ||
|
||
@java.lang.Override | ||
@JsonSetter("type") | ||
public DataStage type(@NotNull String type) { | ||
this.type = Objects.requireNonNull(type, "type must not be null"); | ||
return this; | ||
} | ||
|
||
@java.lang.Override | ||
@JsonSetter("data") | ||
public _FinalStage data(Object data) { | ||
this.data = data; | ||
return this; | ||
} | ||
|
||
@java.lang.Override | ||
public CreateTokenIntentRequest build() { | ||
return new CreateTokenIntentRequest(type, data, additionalProperties); | ||
} | ||
} | ||
} |
Oops, something went wrong.