
com.flexport.api.resources.invoices.InvoicesClient Maven / Gradle / Ivy
The newest version!
package com.flexport.api.resources.invoices;
import com.flexport.api.core.ClientOptions;
import com.flexport.api.core.ObjectMappers;
import com.flexport.api.types.InvoicesRetrieveResponse;
import okhttp3.Headers;
import okhttp3.HttpUrl;
import okhttp3.Request;
import okhttp3.Response;
public class InvoicesClient {
protected final ClientOptions clientOptions;
public InvoicesClient(ClientOptions clientOptions) {
this.clientOptions = clientOptions;
}
public InvoicesRetrieveResponse retrieve(String id) {
HttpUrl _httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
.newBuilder()
.addPathSegments("invoices")
.addPathSegment(id)
.build();
Request _request = new Request.Builder()
.url(_httpUrl)
.method("GET", null)
.headers(Headers.of(clientOptions.headers()))
.addHeader("Content-Type", "application/json")
.build();
try {
Response _response = clientOptions.httpClient().newCall(_request).execute();
if (_response.isSuccessful()) {
return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), InvoicesRetrieveResponse.class);
}
throw new RuntimeException();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy