nl.reinkrul.nuts.network.TransactionsApi Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of java-client Show documentation
Show all versions of java-client Show documentation
Java client library for using the Nuts Node's REST API.
/*
* Nuts Network API spec
* API specification for RPC services available at the nuts-network
*
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
package nl.reinkrul.nuts.network;
import nl.reinkrul.nuts.ApiClient;
import nl.reinkrul.nuts.ApiException;
import nl.reinkrul.nuts.ApiResponse;
import nl.reinkrul.nuts.Pair;
import nl.reinkrul.nuts.network.ListTransactionsDefaultResponse;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.InputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.net.http.HttpRequest;
import java.nio.channels.Channels;
import java.nio.channels.Pipe;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.time.Duration;
import java.util.ArrayList;
import java.util.StringJoiner;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Consumer;
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", date = "2023-05-12T15:13:44.607072+02:00[Europe/Amsterdam]")
public class TransactionsApi {
private final HttpClient memberVarHttpClient;
private final ObjectMapper memberVarObjectMapper;
private final String memberVarBaseUri;
private final Consumer memberVarInterceptor;
private final Duration memberVarReadTimeout;
private final Consumer> memberVarResponseInterceptor;
private final Consumer> memberVarAsyncResponseInterceptor;
public TransactionsApi() {
this(new ApiClient());
}
public TransactionsApi(ApiClient apiClient) {
memberVarHttpClient = apiClient.getHttpClient();
memberVarObjectMapper = apiClient.getObjectMapper();
memberVarBaseUri = apiClient.getBaseUri();
memberVarInterceptor = apiClient.getRequestInterceptor();
memberVarReadTimeout = apiClient.getReadTimeout();
memberVarResponseInterceptor = apiClient.getResponseInterceptor();
memberVarAsyncResponseInterceptor = apiClient.getAsyncResponseInterceptor();
}
protected ApiException getApiException(String operationId, HttpResponse response) throws IOException {
String body = response.body() == null ? null : new String(response.body().readAllBytes());
String message = formatExceptionMessage(operationId, response.statusCode(), body);
return new ApiException(response.statusCode(), message, response.headers(), body);
}
private String formatExceptionMessage(String operationId, int statusCode, String body) {
if (body == null || body.isEmpty()) {
body = "[no body]";
}
return operationId + " call failed with: " + statusCode + " - " + body;
}
/**
* Retrieves a transaction
* Retrieves a transaction. error returns: * 400 - invalid transaction reference * 404 - transaction not found * 500 - internal server error
* @param ref Reference of the transaction (required)
* @return String
* @throws ApiException if fails to make API call
*/
public String getTransaction(String ref) throws ApiException {
ApiResponse localVarResponse = getTransactionWithHttpInfo(ref);
return localVarResponse.getData();
}
/**
* Retrieves a transaction
* Retrieves a transaction. error returns: * 400 - invalid transaction reference * 404 - transaction not found * 500 - internal server error
* @param ref Reference of the transaction (required)
* @return ApiResponse<String>
* @throws ApiException if fails to make API call
*/
public ApiResponse getTransactionWithHttpInfo(String ref) throws ApiException {
HttpRequest.Builder localVarRequestBuilder = getTransactionRequestBuilder(ref);
try {
HttpResponse localVarResponse = memberVarHttpClient.send(
localVarRequestBuilder.build(),
HttpResponse.BodyHandlers.ofInputStream());
if (memberVarResponseInterceptor != null) {
memberVarResponseInterceptor.accept(localVarResponse);
}
try {
if (localVarResponse.statusCode()/ 100 != 2) {
throw getApiException("getTransaction", localVarResponse);
}
return new ApiResponse(
localVarResponse.statusCode(),
localVarResponse.headers().map(),
localVarResponse.body() == null ? null : memberVarObjectMapper.readValue(localVarResponse.body(), new TypeReference() {}) // closes the InputStream
);
} finally {
}
} catch (IOException e) {
throw new ApiException(e);
}
catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new ApiException(e);
}
}
private HttpRequest.Builder getTransactionRequestBuilder(String ref) throws ApiException {
// verify the required parameter 'ref' is set
if (ref == null) {
throw new ApiException(400, "Missing the required parameter 'ref' when calling getTransaction");
}
HttpRequest.Builder localVarRequestBuilder = HttpRequest.newBuilder();
String localVarPath = "/internal/network/v1/transaction/{ref}"
.replace("{ref}", ApiClient.urlEncode(ref.toString()));
localVarRequestBuilder.uri(URI.create(memberVarBaseUri + localVarPath));
localVarRequestBuilder.header("Accept", "application/jose, application/problem+json");
localVarRequestBuilder.method("GET", HttpRequest.BodyPublishers.noBody());
if (memberVarReadTimeout != null) {
localVarRequestBuilder.timeout(memberVarReadTimeout);
}
if (memberVarInterceptor != null) {
memberVarInterceptor.accept(localVarRequestBuilder);
}
return localVarRequestBuilder;
}
/**
* Gets the transaction payload
* Gets the transaction payload. error returns: * 400 - invalid transaction reference * 404 - transaction or payload not found * 500 - internal server error
* @param ref Reference of the transaction (required)
* @throws ApiException if fails to make API call
*/
public void getTransactionPayload(String ref) throws ApiException {
getTransactionPayloadWithHttpInfo(ref);
}
/**
* Gets the transaction payload
* Gets the transaction payload. error returns: * 400 - invalid transaction reference * 404 - transaction or payload not found * 500 - internal server error
* @param ref Reference of the transaction (required)
* @return ApiResponse<Void>
* @throws ApiException if fails to make API call
*/
public ApiResponse getTransactionPayloadWithHttpInfo(String ref) throws ApiException {
HttpRequest.Builder localVarRequestBuilder = getTransactionPayloadRequestBuilder(ref);
try {
HttpResponse localVarResponse = memberVarHttpClient.send(
localVarRequestBuilder.build(),
HttpResponse.BodyHandlers.ofInputStream());
if (memberVarResponseInterceptor != null) {
memberVarResponseInterceptor.accept(localVarResponse);
}
try {
if (localVarResponse.statusCode()/ 100 != 2) {
throw getApiException("getTransactionPayload", localVarResponse);
}
return new ApiResponse(
localVarResponse.statusCode(),
localVarResponse.headers().map(),
null
);
} finally {
// Drain the InputStream
while (localVarResponse.body().read() != -1) {
// Ignore
}
localVarResponse.body().close();
}
} catch (IOException e) {
throw new ApiException(e);
}
catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new ApiException(e);
}
}
private HttpRequest.Builder getTransactionPayloadRequestBuilder(String ref) throws ApiException {
// verify the required parameter 'ref' is set
if (ref == null) {
throw new ApiException(400, "Missing the required parameter 'ref' when calling getTransactionPayload");
}
HttpRequest.Builder localVarRequestBuilder = HttpRequest.newBuilder();
String localVarPath = "/internal/network/v1/transaction/{ref}/payload"
.replace("{ref}", ApiClient.urlEncode(ref.toString()));
localVarRequestBuilder.uri(URI.create(memberVarBaseUri + localVarPath));
localVarRequestBuilder.header("Accept", "application/octet-stream, application/problem+json");
localVarRequestBuilder.method("GET", HttpRequest.BodyPublishers.noBody());
if (memberVarReadTimeout != null) {
localVarRequestBuilder.timeout(memberVarReadTimeout);
}
if (memberVarInterceptor != null) {
memberVarInterceptor.accept(localVarRequestBuilder);
}
return localVarRequestBuilder;
}
/**
* Lists transactions on the DAG
* Lists transactions on the DAG. Since this call returns all transactions on the DAG, care should be taken when there are many of them. A range (start,end) are recommended at all times to avoid overloading the endpoint. error returns: * 500 - internal server error
* @param start Inclusive start of range (in lamport clock); default=0 (optional)
* @param end Exclusive stop of range (in lamport clock); default=∞ (optional)
* @return List<String>
* @throws ApiException if fails to make API call
*/
public List listTransactions(Integer start, Integer end) throws ApiException {
ApiResponse> localVarResponse = listTransactionsWithHttpInfo(start, end);
return localVarResponse.getData();
}
/**
* Lists transactions on the DAG
* Lists transactions on the DAG. Since this call returns all transactions on the DAG, care should be taken when there are many of them. A range (start,end) are recommended at all times to avoid overloading the endpoint. error returns: * 500 - internal server error
* @param start Inclusive start of range (in lamport clock); default=0 (optional)
* @param end Exclusive stop of range (in lamport clock); default=∞ (optional)
* @return ApiResponse<List<String>>
* @throws ApiException if fails to make API call
*/
public ApiResponse> listTransactionsWithHttpInfo(Integer start, Integer end) throws ApiException {
HttpRequest.Builder localVarRequestBuilder = listTransactionsRequestBuilder(start, end);
try {
HttpResponse localVarResponse = memberVarHttpClient.send(
localVarRequestBuilder.build(),
HttpResponse.BodyHandlers.ofInputStream());
if (memberVarResponseInterceptor != null) {
memberVarResponseInterceptor.accept(localVarResponse);
}
try {
if (localVarResponse.statusCode()/ 100 != 2) {
throw getApiException("listTransactions", localVarResponse);
}
return new ApiResponse>(
localVarResponse.statusCode(),
localVarResponse.headers().map(),
localVarResponse.body() == null ? null : memberVarObjectMapper.readValue(localVarResponse.body(), new TypeReference>() {}) // closes the InputStream
);
} finally {
}
} catch (IOException e) {
throw new ApiException(e);
}
catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new ApiException(e);
}
}
private HttpRequest.Builder listTransactionsRequestBuilder(Integer start, Integer end) throws ApiException {
HttpRequest.Builder localVarRequestBuilder = HttpRequest.newBuilder();
String localVarPath = "/internal/network/v1/transaction";
List localVarQueryParams = new ArrayList<>();
StringJoiner localVarQueryStringJoiner = new StringJoiner("&");
String localVarQueryParameterBaseName;
localVarQueryParameterBaseName = "start";
localVarQueryParams.addAll(ApiClient.parameterToPairs("start", start));
localVarQueryParameterBaseName = "end";
localVarQueryParams.addAll(ApiClient.parameterToPairs("end", end));
if (!localVarQueryParams.isEmpty() || localVarQueryStringJoiner.length() != 0) {
StringJoiner queryJoiner = new StringJoiner("&");
localVarQueryParams.forEach(p -> queryJoiner.add(p.getName() + '=' + p.getValue()));
if (localVarQueryStringJoiner.length() != 0) {
queryJoiner.add(localVarQueryStringJoiner.toString());
}
localVarRequestBuilder.uri(URI.create(memberVarBaseUri + localVarPath + '?' + queryJoiner.toString()));
} else {
localVarRequestBuilder.uri(URI.create(memberVarBaseUri + localVarPath));
}
localVarRequestBuilder.header("Accept", "application/json, application/problem+json");
localVarRequestBuilder.method("GET", HttpRequest.BodyPublishers.noBody());
if (memberVarReadTimeout != null) {
localVarRequestBuilder.timeout(memberVarReadTimeout);
}
if (memberVarInterceptor != null) {
memberVarInterceptor.accept(localVarRequestBuilder);
}
return localVarRequestBuilder;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy