
com.squareup.square.InventoryClient Maven / Gradle / Ivy
Show all versions of square Show documentation
/**
* This file was auto-generated by Fern from our API Definition.
*/
package com.squareup.square;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.squareup.square.core.ClientOptions;
import com.squareup.square.core.MediaTypes;
import com.squareup.square.core.ObjectMappers;
import com.squareup.square.core.QueryStringMapper;
import com.squareup.square.core.RequestOptions;
import com.squareup.square.core.SquareApiException;
import com.squareup.square.core.SquareException;
import com.squareup.square.core.SyncPagingIterable;
import com.squareup.square.types.BatchChangeInventoryRequest;
import com.squareup.square.types.BatchChangeInventoryResponse;
import com.squareup.square.types.BatchGetInventoryChangesResponse;
import com.squareup.square.types.BatchGetInventoryCountsRequest;
import com.squareup.square.types.BatchGetInventoryCountsResponse;
import com.squareup.square.types.BatchRetrieveInventoryChangesRequest;
import com.squareup.square.types.ChangesInventoryRequest;
import com.squareup.square.types.DeprecatedGetAdjustmentInventoryRequest;
import com.squareup.square.types.DeprecatedGetPhysicalCountInventoryRequest;
import com.squareup.square.types.GetAdjustmentInventoryRequest;
import com.squareup.square.types.GetInventoryAdjustmentResponse;
import com.squareup.square.types.GetInventoryChangesResponse;
import com.squareup.square.types.GetInventoryCountResponse;
import com.squareup.square.types.GetInventoryPhysicalCountResponse;
import com.squareup.square.types.GetInventoryRequest;
import com.squareup.square.types.GetInventoryTransferResponse;
import com.squareup.square.types.GetPhysicalCountInventoryRequest;
import com.squareup.square.types.GetTransferInventoryRequest;
import com.squareup.square.types.InventoryChange;
import com.squareup.square.types.InventoryCount;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import okhttp3.Headers;
import okhttp3.HttpUrl;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
import okhttp3.ResponseBody;
public class InventoryClient {
protected final ClientOptions clientOptions;
public InventoryClient(ClientOptions clientOptions) {
this.clientOptions = clientOptions;
}
/**
* Deprecated version of RetrieveInventoryAdjustment after the endpoint URL
* is updated to conform to the standard convention.
*/
public GetInventoryAdjustmentResponse deprecatedGetAdjustment(DeprecatedGetAdjustmentInventoryRequest request) {
return deprecatedGetAdjustment(request, null);
}
/**
* Deprecated version of RetrieveInventoryAdjustment after the endpoint URL
* is updated to conform to the standard convention.
*/
public GetInventoryAdjustmentResponse deprecatedGetAdjustment(
DeprecatedGetAdjustmentInventoryRequest request, RequestOptions requestOptions) {
HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
.newBuilder()
.addPathSegments("v2/inventory/adjustment")
.addPathSegment(request.getAdjustmentId())
.build();
Request.Builder _requestBuilder = new Request.Builder()
.url(httpUrl)
.method("GET", null)
.headers(Headers.of(clientOptions.headers(requestOptions)))
.addHeader("Content-Type", "application/json")
.addHeader("Accept", "application/json");
Request okhttpRequest = _requestBuilder.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(), GetInventoryAdjustmentResponse.class);
}
String responseBodyString = responseBody != null ? responseBody.string() : "{}";
throw new SquareApiException(
"Error with status code " + response.code(),
response.code(),
ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class));
} catch (IOException e) {
throw new SquareException("Network error executing HTTP request", e);
}
}
/**
* Returns the InventoryAdjustment object
* with the provided adjustment_id
.
*/
public GetInventoryAdjustmentResponse getAdjustment(GetAdjustmentInventoryRequest request) {
return getAdjustment(request, null);
}
/**
* Returns the InventoryAdjustment object
* with the provided adjustment_id
.
*/
public GetInventoryAdjustmentResponse getAdjustment(
GetAdjustmentInventoryRequest request, RequestOptions requestOptions) {
HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
.newBuilder()
.addPathSegments("v2/inventory/adjustments")
.addPathSegment(request.getAdjustmentId())
.build();
Request.Builder _requestBuilder = new Request.Builder()
.url(httpUrl)
.method("GET", null)
.headers(Headers.of(clientOptions.headers(requestOptions)))
.addHeader("Content-Type", "application/json")
.addHeader("Accept", "application/json");
Request okhttpRequest = _requestBuilder.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(), GetInventoryAdjustmentResponse.class);
}
String responseBodyString = responseBody != null ? responseBody.string() : "{}";
throw new SquareApiException(
"Error with status code " + response.code(),
response.code(),
ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class));
} catch (IOException e) {
throw new SquareException("Network error executing HTTP request", e);
}
}
/**
* Deprecated version of BatchChangeInventory after the endpoint URL
* is updated to conform to the standard convention.
*/
public BatchChangeInventoryResponse deprecatedBatchChange(BatchChangeInventoryRequest request) {
return deprecatedBatchChange(request, null);
}
/**
* Deprecated version of BatchChangeInventory after the endpoint URL
* is updated to conform to the standard convention.
*/
public BatchChangeInventoryResponse deprecatedBatchChange(
BatchChangeInventoryRequest request, RequestOptions requestOptions) {
HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
.newBuilder()
.addPathSegments("v2/inventory/batch-change")
.build();
RequestBody body;
try {
body = RequestBody.create(
ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON);
} catch (JsonProcessingException e) {
throw new SquareException("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")
.addHeader("Accept", "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(), BatchChangeInventoryResponse.class);
}
String responseBodyString = responseBody != null ? responseBody.string() : "{}";
throw new SquareApiException(
"Error with status code " + response.code(),
response.code(),
ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class));
} catch (IOException e) {
throw new SquareException("Network error executing HTTP request", e);
}
}
/**
* Deprecated version of BatchRetrieveInventoryChanges after the endpoint URL
* is updated to conform to the standard convention.
*/
public BatchGetInventoryChangesResponse deprecatedBatchGetChanges() {
return deprecatedBatchGetChanges(
BatchRetrieveInventoryChangesRequest.builder().build());
}
/**
* Deprecated version of BatchRetrieveInventoryChanges after the endpoint URL
* is updated to conform to the standard convention.
*/
public BatchGetInventoryChangesResponse deprecatedBatchGetChanges(BatchRetrieveInventoryChangesRequest request) {
return deprecatedBatchGetChanges(request, null);
}
/**
* Deprecated version of BatchRetrieveInventoryChanges after the endpoint URL
* is updated to conform to the standard convention.
*/
public BatchGetInventoryChangesResponse deprecatedBatchGetChanges(
BatchRetrieveInventoryChangesRequest request, RequestOptions requestOptions) {
HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
.newBuilder()
.addPathSegments("v2/inventory/batch-retrieve-changes")
.build();
RequestBody body;
try {
body = RequestBody.create(
ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON);
} catch (JsonProcessingException e) {
throw new SquareException("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")
.addHeader("Accept", "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(), BatchGetInventoryChangesResponse.class);
}
String responseBodyString = responseBody != null ? responseBody.string() : "{}";
throw new SquareApiException(
"Error with status code " + response.code(),
response.code(),
ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class));
} catch (IOException e) {
throw new SquareException("Network error executing HTTP request", e);
}
}
/**
* Deprecated version of BatchRetrieveInventoryCounts after the endpoint URL
* is updated to conform to the standard convention.
*/
public BatchGetInventoryCountsResponse deprecatedBatchGetCounts() {
return deprecatedBatchGetCounts(BatchGetInventoryCountsRequest.builder().build());
}
/**
* Deprecated version of BatchRetrieveInventoryCounts after the endpoint URL
* is updated to conform to the standard convention.
*/
public BatchGetInventoryCountsResponse deprecatedBatchGetCounts(BatchGetInventoryCountsRequest request) {
return deprecatedBatchGetCounts(request, null);
}
/**
* Deprecated version of BatchRetrieveInventoryCounts after the endpoint URL
* is updated to conform to the standard convention.
*/
public BatchGetInventoryCountsResponse deprecatedBatchGetCounts(
BatchGetInventoryCountsRequest request, RequestOptions requestOptions) {
HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
.newBuilder()
.addPathSegments("v2/inventory/batch-retrieve-counts")
.build();
RequestBody body;
try {
body = RequestBody.create(
ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON);
} catch (JsonProcessingException e) {
throw new SquareException("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")
.addHeader("Accept", "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(), BatchGetInventoryCountsResponse.class);
}
String responseBodyString = responseBody != null ? responseBody.string() : "{}";
throw new SquareApiException(
"Error with status code " + response.code(),
response.code(),
ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class));
} catch (IOException e) {
throw new SquareException("Network error executing HTTP request", e);
}
}
/**
* Applies adjustments and counts to the provided item quantities.
* On success: returns the current calculated counts for all objects
* referenced in the request.
* On failure: returns a list of related errors.
*/
public BatchChangeInventoryResponse batchCreateChanges(BatchChangeInventoryRequest request) {
return batchCreateChanges(request, null);
}
/**
* Applies adjustments and counts to the provided item quantities.
* On success: returns the current calculated counts for all objects
* referenced in the request.
* On failure: returns a list of related errors.
*/
public BatchChangeInventoryResponse batchCreateChanges(
BatchChangeInventoryRequest request, RequestOptions requestOptions) {
HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
.newBuilder()
.addPathSegments("v2/inventory/changes/batch-create")
.build();
RequestBody body;
try {
body = RequestBody.create(
ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON);
} catch (JsonProcessingException e) {
throw new SquareException("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")
.addHeader("Accept", "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(), BatchChangeInventoryResponse.class);
}
String responseBodyString = responseBody != null ? responseBody.string() : "{}";
throw new SquareApiException(
"Error with status code " + response.code(),
response.code(),
ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class));
} catch (IOException e) {
throw new SquareException("Network error executing HTTP request", e);
}
}
/**
* Returns historical physical counts and adjustments based on the
* provided filter criteria.
* Results are paginated and sorted in ascending order according their
* occurred_at
timestamp (oldest first).
* BatchRetrieveInventoryChanges is a catch-all query endpoint for queries
* that cannot be handled by other, simpler endpoints.
*/
public SyncPagingIterable batchGetChanges() {
return batchGetChanges(BatchRetrieveInventoryChangesRequest.builder().build());
}
/**
* Returns historical physical counts and adjustments based on the
* provided filter criteria.
* Results are paginated and sorted in ascending order according their
* occurred_at
timestamp (oldest first).
* BatchRetrieveInventoryChanges is a catch-all query endpoint for queries
* that cannot be handled by other, simpler endpoints.
*/
public SyncPagingIterable batchGetChanges(BatchRetrieveInventoryChangesRequest request) {
return batchGetChanges(request, null);
}
/**
* Returns historical physical counts and adjustments based on the
* provided filter criteria.
* Results are paginated and sorted in ascending order according their
* occurred_at
timestamp (oldest first).
* BatchRetrieveInventoryChanges is a catch-all query endpoint for queries
* that cannot be handled by other, simpler endpoints.
*/
public SyncPagingIterable batchGetChanges(
BatchRetrieveInventoryChangesRequest request, RequestOptions requestOptions) {
HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
.newBuilder()
.addPathSegments("v2/inventory/changes/batch-retrieve")
.build();
RequestBody body;
try {
body = RequestBody.create(
ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON);
} catch (JsonProcessingException e) {
throw new SquareException("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")
.addHeader("Accept", "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()) {
BatchGetInventoryChangesResponse parsedResponse = ObjectMappers.JSON_MAPPER.readValue(
responseBody.string(), BatchGetInventoryChangesResponse.class);
Optional startingAfter = parsedResponse.getCursor();
BatchRetrieveInventoryChangesRequest nextRequest = BatchRetrieveInventoryChangesRequest.builder()
.from(request)
.cursor(startingAfter)
.build();
List result = parsedResponse.getChanges().orElse(Collections.emptyList());
return new SyncPagingIterable(
startingAfter.isPresent(), result, () -> batchGetChanges(nextRequest, requestOptions));
}
String responseBodyString = responseBody != null ? responseBody.string() : "{}";
throw new SquareApiException(
"Error with status code " + response.code(),
response.code(),
ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class));
} catch (IOException e) {
throw new SquareException("Network error executing HTTP request", e);
}
}
/**
* Returns current counts for the provided
* CatalogObjects at the requested
* Locations.
* Results are paginated and sorted in descending order according to their
* calculated_at
timestamp (newest first).
* When updated_after
is specified, only counts that have changed since that
* time (based on the server timestamp for the most recent change) are
* returned. This allows clients to perform a "sync" operation, for example
* in response to receiving a Webhook notification.
*/
public SyncPagingIterable batchGetCounts() {
return batchGetCounts(BatchGetInventoryCountsRequest.builder().build());
}
/**
* Returns current counts for the provided
* CatalogObjects at the requested
* Locations.
* Results are paginated and sorted in descending order according to their
* calculated_at
timestamp (newest first).
* When updated_after
is specified, only counts that have changed since that
* time (based on the server timestamp for the most recent change) are
* returned. This allows clients to perform a "sync" operation, for example
* in response to receiving a Webhook notification.
*/
public SyncPagingIterable batchGetCounts(BatchGetInventoryCountsRequest request) {
return batchGetCounts(request, null);
}
/**
* Returns current counts for the provided
* CatalogObjects at the requested
* Locations.
* Results are paginated and sorted in descending order according to their
* calculated_at
timestamp (newest first).
* When updated_after
is specified, only counts that have changed since that
* time (based on the server timestamp for the most recent change) are
* returned. This allows clients to perform a "sync" operation, for example
* in response to receiving a Webhook notification.
*/
public SyncPagingIterable batchGetCounts(
BatchGetInventoryCountsRequest request, RequestOptions requestOptions) {
HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
.newBuilder()
.addPathSegments("v2/inventory/counts/batch-retrieve")
.build();
RequestBody body;
try {
body = RequestBody.create(
ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON);
} catch (JsonProcessingException e) {
throw new SquareException("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")
.addHeader("Accept", "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()) {
BatchGetInventoryCountsResponse parsedResponse = ObjectMappers.JSON_MAPPER.readValue(
responseBody.string(), BatchGetInventoryCountsResponse.class);
Optional startingAfter = parsedResponse.getCursor();
BatchGetInventoryCountsRequest nextRequest = BatchGetInventoryCountsRequest.builder()
.from(request)
.cursor(startingAfter)
.build();
List result = parsedResponse.getCounts().orElse(Collections.emptyList());
return new SyncPagingIterable(
startingAfter.isPresent(), result, () -> batchGetCounts(nextRequest, requestOptions));
}
String responseBodyString = responseBody != null ? responseBody.string() : "{}";
throw new SquareApiException(
"Error with status code " + response.code(),
response.code(),
ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class));
} catch (IOException e) {
throw new SquareException("Network error executing HTTP request", e);
}
}
/**
* Deprecated version of RetrieveInventoryPhysicalCount after the endpoint URL
* is updated to conform to the standard convention.
*/
public GetInventoryPhysicalCountResponse deprecatedGetPhysicalCount(
DeprecatedGetPhysicalCountInventoryRequest request) {
return deprecatedGetPhysicalCount(request, null);
}
/**
* Deprecated version of RetrieveInventoryPhysicalCount after the endpoint URL
* is updated to conform to the standard convention.
*/
public GetInventoryPhysicalCountResponse deprecatedGetPhysicalCount(
DeprecatedGetPhysicalCountInventoryRequest request, RequestOptions requestOptions) {
HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
.newBuilder()
.addPathSegments("v2/inventory/physical-count")
.addPathSegment(request.getPhysicalCountId())
.build();
Request.Builder _requestBuilder = new Request.Builder()
.url(httpUrl)
.method("GET", null)
.headers(Headers.of(clientOptions.headers(requestOptions)))
.addHeader("Content-Type", "application/json")
.addHeader("Accept", "application/json");
Request okhttpRequest = _requestBuilder.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(), GetInventoryPhysicalCountResponse.class);
}
String responseBodyString = responseBody != null ? responseBody.string() : "{}";
throw new SquareApiException(
"Error with status code " + response.code(),
response.code(),
ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class));
} catch (IOException e) {
throw new SquareException("Network error executing HTTP request", e);
}
}
/**
* Returns the InventoryPhysicalCount
* object with the provided physical_count_id
.
*/
public GetInventoryPhysicalCountResponse getPhysicalCount(GetPhysicalCountInventoryRequest request) {
return getPhysicalCount(request, null);
}
/**
* Returns the InventoryPhysicalCount
* object with the provided physical_count_id
.
*/
public GetInventoryPhysicalCountResponse getPhysicalCount(
GetPhysicalCountInventoryRequest request, RequestOptions requestOptions) {
HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
.newBuilder()
.addPathSegments("v2/inventory/physical-counts")
.addPathSegment(request.getPhysicalCountId())
.build();
Request.Builder _requestBuilder = new Request.Builder()
.url(httpUrl)
.method("GET", null)
.headers(Headers.of(clientOptions.headers(requestOptions)))
.addHeader("Content-Type", "application/json")
.addHeader("Accept", "application/json");
Request okhttpRequest = _requestBuilder.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(), GetInventoryPhysicalCountResponse.class);
}
String responseBodyString = responseBody != null ? responseBody.string() : "{}";
throw new SquareApiException(
"Error with status code " + response.code(),
response.code(),
ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class));
} catch (IOException e) {
throw new SquareException("Network error executing HTTP request", e);
}
}
/**
* Returns the InventoryTransfer object
* with the provided transfer_id
.
*/
public GetInventoryTransferResponse getTransfer(GetTransferInventoryRequest request) {
return getTransfer(request, null);
}
/**
* Returns the InventoryTransfer object
* with the provided transfer_id
.
*/
public GetInventoryTransferResponse getTransfer(
GetTransferInventoryRequest request, RequestOptions requestOptions) {
HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
.newBuilder()
.addPathSegments("v2/inventory/transfers")
.addPathSegment(request.getTransferId())
.build();
Request.Builder _requestBuilder = new Request.Builder()
.url(httpUrl)
.method("GET", null)
.headers(Headers.of(clientOptions.headers(requestOptions)))
.addHeader("Content-Type", "application/json")
.addHeader("Accept", "application/json");
Request okhttpRequest = _requestBuilder.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(), GetInventoryTransferResponse.class);
}
String responseBodyString = responseBody != null ? responseBody.string() : "{}";
throw new SquareApiException(
"Error with status code " + response.code(),
response.code(),
ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class));
} catch (IOException e) {
throw new SquareException("Network error executing HTTP request", e);
}
}
/**
* Retrieves the current calculated stock count for a given
* CatalogObject at a given set of
* Locations. Responses are paginated and unsorted.
* For more sophisticated queries, use a batch endpoint.
*/
public SyncPagingIterable get(GetInventoryRequest request) {
return get(request, null);
}
/**
* Retrieves the current calculated stock count for a given
* CatalogObject at a given set of
* Locations. Responses are paginated and unsorted.
* For more sophisticated queries, use a batch endpoint.
*/
public SyncPagingIterable get(GetInventoryRequest request, RequestOptions requestOptions) {
HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
.newBuilder()
.addPathSegments("v2/inventory")
.addPathSegment(request.getCatalogObjectId());
if (request.getLocationIds().isPresent()) {
QueryStringMapper.addQueryParameter(
httpUrl, "location_ids", request.getLocationIds().get(), false);
}
if (request.getCursor().isPresent()) {
QueryStringMapper.addQueryParameter(
httpUrl, "cursor", request.getCursor().get(), false);
}
Request.Builder _requestBuilder = new Request.Builder()
.url(httpUrl.build())
.method("GET", null)
.headers(Headers.of(clientOptions.headers(requestOptions)))
.addHeader("Content-Type", "application/json")
.addHeader("Accept", "application/json");
Request okhttpRequest = _requestBuilder.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()) {
GetInventoryCountResponse parsedResponse =
ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), GetInventoryCountResponse.class);
Optional startingAfter = parsedResponse.getCursor();
GetInventoryRequest nextRequest = GetInventoryRequest.builder()
.from(request)
.cursor(startingAfter)
.build();
List result = parsedResponse.getCounts().orElse(Collections.emptyList());
return new SyncPagingIterable(
startingAfter.isPresent(), result, () -> get(nextRequest, requestOptions));
}
String responseBodyString = responseBody != null ? responseBody.string() : "{}";
throw new SquareApiException(
"Error with status code " + response.code(),
response.code(),
ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class));
} catch (IOException e) {
throw new SquareException("Network error executing HTTP request", e);
}
}
/**
* Returns a set of physical counts and inventory adjustments for the
* provided CatalogObject at the requested
* Locations.
* You can achieve the same result by calling BatchRetrieveInventoryChanges
* and having the catalog_object_ids
list contain a single element of the CatalogObject
ID.
* Results are paginated and sorted in descending order according to their
* occurred_at
timestamp (newest first).
* There are no limits on how far back the caller can page. This endpoint can be
* used to display recent changes for a specific item. For more
* sophisticated queries, use a batch endpoint.
*/
public SyncPagingIterable changes(ChangesInventoryRequest request) {
return changes(request, null);
}
/**
* Returns a set of physical counts and inventory adjustments for the
* provided CatalogObject at the requested
* Locations.
* You can achieve the same result by calling BatchRetrieveInventoryChanges
* and having the catalog_object_ids
list contain a single element of the CatalogObject
ID.
* Results are paginated and sorted in descending order according to their
* occurred_at
timestamp (newest first).
* There are no limits on how far back the caller can page. This endpoint can be
* used to display recent changes for a specific item. For more
* sophisticated queries, use a batch endpoint.
*/
public SyncPagingIterable changes(ChangesInventoryRequest request, RequestOptions requestOptions) {
HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
.newBuilder()
.addPathSegments("v2/inventory")
.addPathSegment(request.getCatalogObjectId())
.addPathSegments("changes");
if (request.getLocationIds().isPresent()) {
QueryStringMapper.addQueryParameter(
httpUrl, "location_ids", request.getLocationIds().get(), false);
}
if (request.getCursor().isPresent()) {
QueryStringMapper.addQueryParameter(
httpUrl, "cursor", request.getCursor().get(), false);
}
Request.Builder _requestBuilder = new Request.Builder()
.url(httpUrl.build())
.method("GET", null)
.headers(Headers.of(clientOptions.headers(requestOptions)))
.addHeader("Content-Type", "application/json")
.addHeader("Accept", "application/json");
Request okhttpRequest = _requestBuilder.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()) {
GetInventoryChangesResponse parsedResponse =
ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), GetInventoryChangesResponse.class);
Optional startingAfter = parsedResponse.getCursor();
ChangesInventoryRequest nextRequest = ChangesInventoryRequest.builder()
.from(request)
.cursor(startingAfter)
.build();
List result = parsedResponse.getChanges().orElse(Collections.emptyList());
return new SyncPagingIterable(
startingAfter.isPresent(), result, () -> changes(nextRequest, requestOptions));
}
String responseBodyString = responseBody != null ? responseBody.string() : "{}";
throw new SquareApiException(
"Error with status code " + response.code(),
response.code(),
ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class));
} catch (IOException e) {
throw new SquareException("Network error executing HTTP request", e);
}
}
}