io.quarkiverse.apistax.apis.ReverseGeocodingApi Maven / Gradle / Ivy
/*
* APIstax
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* The version of the OpenAPI document: 1.0.1
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
package io.quarkiverse.apistax.apis;
import io.quarkiverse.apistax.ApiClient;
import io.quarkiverse.apistax.ApiException;
import io.quarkiverse.apistax.ApiResponse;
import io.quarkiverse.apistax.Pair;
import io.quarkiverse.apistax.models.GeocodeResult;
import io.quarkiverse.apistax.models.GeocodeReversePayload;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
import java.io.InputStream;
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.processing.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", date = "2022-07-29T13:29:23.813235Z[Etc/UTC]")
public class ReverseGeocodingApi {
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 ReverseGeocodingApi() {
this(new ApiClient());
}
public ReverseGeocodingApi(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;
}
/**
* Convert geo-coordinates to a postal address
*
* @param latitude The latitude coordinate of a point to search for. For example \"48.20661\" (required)
* @param longitude The longitude coordinate of a point to search for. For example \"16.36301\" (required)
* @param language The language used for result localization based on ISO 639-1. For example: \"en\" or \"fr\" (optional, default to en)
* @return GeocodeResult
* @throws ApiException if fails to make API call
*/
public GeocodeResult geocodeReverse(Double latitude, Double longitude, String language) throws ApiException {
ApiResponse localVarResponse = geocodeReverseWithHttpInfo(latitude, longitude, language);
return localVarResponse.getData();
}
/**
* Convert geo-coordinates to a postal address
*
* @param latitude The latitude coordinate of a point to search for. For example \"48.20661\" (required)
* @param longitude The longitude coordinate of a point to search for. For example \"16.36301\" (required)
* @param language The language used for result localization based on ISO 639-1. For example: \"en\" or \"fr\" (optional, default to en)
* @return ApiResponse<GeocodeResult>
* @throws ApiException if fails to make API call
*/
public ApiResponse geocodeReverseWithHttpInfo(Double latitude, Double longitude, String language) throws ApiException {
HttpRequest.Builder localVarRequestBuilder = geocodeReverseRequestBuilder(latitude, longitude, language);
try {
HttpResponse localVarResponse = memberVarHttpClient.send(
localVarRequestBuilder.build(),
HttpResponse.BodyHandlers.ofInputStream());
if (memberVarResponseInterceptor != null) {
memberVarResponseInterceptor.accept(localVarResponse);
}
try {
if (localVarResponse.statusCode()/ 100 != 2) {
throw getApiException("geocodeReverse", localVarResponse);
}
return new ApiResponse(
localVarResponse.statusCode(),
localVarResponse.headers().map(),
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 geocodeReverseRequestBuilder(Double latitude, Double longitude, String language) throws ApiException {
// verify the required parameter 'latitude' is set
if (latitude == null) {
throw new ApiException(400, "Missing the required parameter 'latitude' when calling geocodeReverse");
}
// verify the required parameter 'longitude' is set
if (longitude == null) {
throw new ApiException(400, "Missing the required parameter 'longitude' when calling geocodeReverse");
}
HttpRequest.Builder localVarRequestBuilder = HttpRequest.newBuilder();
String localVarPath = "/v1/geocode/reverse";
List localVarQueryParams = new ArrayList<>();
localVarQueryParams.addAll(ApiClient.parameterToPairs("latitude", latitude));
localVarQueryParams.addAll(ApiClient.parameterToPairs("longitude", longitude));
localVarQueryParams.addAll(ApiClient.parameterToPairs("language", language));
if (!localVarQueryParams.isEmpty()) {
StringJoiner queryJoiner = new StringJoiner("&");
localVarQueryParams.forEach(p -> queryJoiner.add(p.getName() + '=' + p.getValue()));
localVarRequestBuilder.uri(URI.create(memberVarBaseUri + localVarPath + '?' + queryJoiner.toString()));
} else {
localVarRequestBuilder.uri(URI.create(memberVarBaseUri + localVarPath));
}
localVarRequestBuilder.header("Accept", "application/json");
localVarRequestBuilder.method("GET", HttpRequest.BodyPublishers.noBody());
if (memberVarReadTimeout != null) {
localVarRequestBuilder.timeout(memberVarReadTimeout);
}
if (memberVarInterceptor != null) {
memberVarInterceptor.accept(localVarRequestBuilder);
}
return localVarRequestBuilder;
}
/**
* Convert geo-coordinates to a postal address
*
* @param geocodeReversePayload Coordinates payload to search for (required)
* @return GeocodeResult
* @throws ApiException if fails to make API call
*/
public GeocodeResult geocodeReverseJson(GeocodeReversePayload geocodeReversePayload) throws ApiException {
ApiResponse localVarResponse = geocodeReverseJsonWithHttpInfo(geocodeReversePayload);
return localVarResponse.getData();
}
/**
* Convert geo-coordinates to a postal address
*
* @param geocodeReversePayload Coordinates payload to search for (required)
* @return ApiResponse<GeocodeResult>
* @throws ApiException if fails to make API call
*/
public ApiResponse geocodeReverseJsonWithHttpInfo(GeocodeReversePayload geocodeReversePayload) throws ApiException {
HttpRequest.Builder localVarRequestBuilder = geocodeReverseJsonRequestBuilder(geocodeReversePayload);
try {
HttpResponse localVarResponse = memberVarHttpClient.send(
localVarRequestBuilder.build(),
HttpResponse.BodyHandlers.ofInputStream());
if (memberVarResponseInterceptor != null) {
memberVarResponseInterceptor.accept(localVarResponse);
}
try {
if (localVarResponse.statusCode()/ 100 != 2) {
throw getApiException("geocodeReverseJson", localVarResponse);
}
return new ApiResponse(
localVarResponse.statusCode(),
localVarResponse.headers().map(),
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 geocodeReverseJsonRequestBuilder(GeocodeReversePayload geocodeReversePayload) throws ApiException {
// verify the required parameter 'geocodeReversePayload' is set
if (geocodeReversePayload == null) {
throw new ApiException(400, "Missing the required parameter 'geocodeReversePayload' when calling geocodeReverseJson");
}
HttpRequest.Builder localVarRequestBuilder = HttpRequest.newBuilder();
String localVarPath = "/v1/geocode/reverse";
localVarRequestBuilder.uri(URI.create(memberVarBaseUri + localVarPath));
localVarRequestBuilder.header("Content-Type", "application/json");
localVarRequestBuilder.header("Accept", "application/json");
try {
byte[] localVarPostBody = memberVarObjectMapper.writeValueAsBytes(geocodeReversePayload);
localVarRequestBuilder.method("POST", HttpRequest.BodyPublishers.ofByteArray(localVarPostBody));
} catch (IOException e) {
throw new ApiException(e);
}
if (memberVarReadTimeout != null) {
localVarRequestBuilder.timeout(memberVarReadTimeout);
}
if (memberVarInterceptor != null) {
memberVarInterceptor.accept(localVarRequestBuilder);
}
return localVarRequestBuilder;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy