All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.squareup.square.bookings.CustomAttributesClient Maven / Gradle / Ivy

The newest version!
/**
 * This file was auto-generated by Fern from our API Definition.
 */
package com.squareup.square.bookings;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.squareup.square.bookings.types.BulkDeleteBookingCustomAttributesRequest;
import com.squareup.square.bookings.types.BulkUpsertBookingCustomAttributesRequest;
import com.squareup.square.bookings.types.DeleteCustomAttributesRequest;
import com.squareup.square.bookings.types.GetCustomAttributesRequest;
import com.squareup.square.bookings.types.ListCustomAttributesRequest;
import com.squareup.square.bookings.types.UpsertBookingCustomAttributeRequest;
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.BulkDeleteBookingCustomAttributesResponse;
import com.squareup.square.types.BulkUpsertBookingCustomAttributesResponse;
import com.squareup.square.types.CustomAttribute;
import com.squareup.square.types.DeleteBookingCustomAttributeResponse;
import com.squareup.square.types.ListBookingCustomAttributesResponse;
import com.squareup.square.types.RetrieveBookingCustomAttributeResponse;
import com.squareup.square.types.UpsertBookingCustomAttributeResponse;
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 CustomAttributesClient {
    protected final ClientOptions clientOptions;

    public CustomAttributesClient(ClientOptions clientOptions) {
        this.clientOptions = clientOptions;
    }

    /**
     * Bulk deletes bookings custom attributes.
     * 

To call this endpoint with buyer-level permissions, set APPOINTMENTS_WRITE for the OAuth scope. * To call this endpoint with seller-level permissions, set APPOINTMENTS_ALL_WRITE and APPOINTMENTS_WRITE for the OAuth scope.

*

For calls to this endpoint with seller-level permissions to succeed, the seller must have subscribed to Appointments Plus * or Appointments Premium.

*/ public BulkDeleteBookingCustomAttributesResponse batchDelete(BulkDeleteBookingCustomAttributesRequest request) { return batchDelete(request, null); } /** * Bulk deletes bookings custom attributes. *

To call this endpoint with buyer-level permissions, set APPOINTMENTS_WRITE for the OAuth scope. * To call this endpoint with seller-level permissions, set APPOINTMENTS_ALL_WRITE and APPOINTMENTS_WRITE for the OAuth scope.

*

For calls to this endpoint with seller-level permissions to succeed, the seller must have subscribed to Appointments Plus * or Appointments Premium.

*/ public BulkDeleteBookingCustomAttributesResponse batchDelete( BulkDeleteBookingCustomAttributesRequest request, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("v2/bookings/custom-attributes/bulk-delete") .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(), BulkDeleteBookingCustomAttributesResponse.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); } } /** * Bulk upserts bookings custom attributes. *

To call this endpoint with buyer-level permissions, set APPOINTMENTS_WRITE for the OAuth scope. * To call this endpoint with seller-level permissions, set APPOINTMENTS_ALL_WRITE and APPOINTMENTS_WRITE for the OAuth scope.

*

For calls to this endpoint with seller-level permissions to succeed, the seller must have subscribed to Appointments Plus * or Appointments Premium.

*/ public BulkUpsertBookingCustomAttributesResponse batchUpsert(BulkUpsertBookingCustomAttributesRequest request) { return batchUpsert(request, null); } /** * Bulk upserts bookings custom attributes. *

To call this endpoint with buyer-level permissions, set APPOINTMENTS_WRITE for the OAuth scope. * To call this endpoint with seller-level permissions, set APPOINTMENTS_ALL_WRITE and APPOINTMENTS_WRITE for the OAuth scope.

*

For calls to this endpoint with seller-level permissions to succeed, the seller must have subscribed to Appointments Plus * or Appointments Premium.

*/ public BulkUpsertBookingCustomAttributesResponse batchUpsert( BulkUpsertBookingCustomAttributesRequest request, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("v2/bookings/custom-attributes/bulk-upsert") .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(), BulkUpsertBookingCustomAttributesResponse.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); } } /** * Lists a booking's custom attributes. *

To call this endpoint with buyer-level permissions, set APPOINTMENTS_READ for the OAuth scope. * To call this endpoint with seller-level permissions, set APPOINTMENTS_ALL_READ and APPOINTMENTS_READ for the OAuth scope.

*/ public SyncPagingIterable list(ListCustomAttributesRequest request) { return list(request, null); } /** * Lists a booking's custom attributes. *

To call this endpoint with buyer-level permissions, set APPOINTMENTS_READ for the OAuth scope. * To call this endpoint with seller-level permissions, set APPOINTMENTS_ALL_READ and APPOINTMENTS_READ for the OAuth scope.

*/ public SyncPagingIterable list( ListCustomAttributesRequest request, RequestOptions requestOptions) { HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("v2/bookings") .addPathSegment(request.getBookingId()) .addPathSegments("custom-attributes"); if (request.getLimit().isPresent()) { QueryStringMapper.addQueryParameter( httpUrl, "limit", request.getLimit().get().toString(), false); } if (request.getCursor().isPresent()) { QueryStringMapper.addQueryParameter( httpUrl, "cursor", request.getCursor().get(), false); } if (request.getWithDefinitions().isPresent()) { QueryStringMapper.addQueryParameter( httpUrl, "with_definitions", request.getWithDefinitions().get().toString(), 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()) { ListBookingCustomAttributesResponse parsedResponse = ObjectMappers.JSON_MAPPER.readValue( responseBody.string(), ListBookingCustomAttributesResponse.class); Optional startingAfter = parsedResponse.getCursor(); ListCustomAttributesRequest nextRequest = ListCustomAttributesRequest.builder() .from(request) .cursor(startingAfter) .build(); List result = parsedResponse.getCustomAttributes().orElse(Collections.emptyList()); return new SyncPagingIterable( startingAfter.isPresent(), result, () -> list(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); } } /** * Retrieves a bookings custom attribute. *

To call this endpoint with buyer-level permissions, set APPOINTMENTS_READ for the OAuth scope. * To call this endpoint with seller-level permissions, set APPOINTMENTS_ALL_READ and APPOINTMENTS_READ for the OAuth scope.

*/ public RetrieveBookingCustomAttributeResponse get(GetCustomAttributesRequest request) { return get(request, null); } /** * Retrieves a bookings custom attribute. *

To call this endpoint with buyer-level permissions, set APPOINTMENTS_READ for the OAuth scope. * To call this endpoint with seller-level permissions, set APPOINTMENTS_ALL_READ and APPOINTMENTS_READ for the OAuth scope.

*/ public RetrieveBookingCustomAttributeResponse get( GetCustomAttributesRequest request, RequestOptions requestOptions) { HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("v2/bookings") .addPathSegment(request.getBookingId()) .addPathSegments("custom-attributes") .addPathSegment(request.getKey()); if (request.getWithDefinition().isPresent()) { QueryStringMapper.addQueryParameter( httpUrl, "with_definition", request.getWithDefinition().get().toString(), false); } if (request.getVersion().isPresent()) { QueryStringMapper.addQueryParameter( httpUrl, "version", request.getVersion().get().toString(), 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()) { return ObjectMappers.JSON_MAPPER.readValue( responseBody.string(), RetrieveBookingCustomAttributeResponse.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); } } /** * Upserts a bookings custom attribute. *

To call this endpoint with buyer-level permissions, set APPOINTMENTS_WRITE for the OAuth scope. * To call this endpoint with seller-level permissions, set APPOINTMENTS_ALL_WRITE and APPOINTMENTS_WRITE for the OAuth scope.

*

For calls to this endpoint with seller-level permissions to succeed, the seller must have subscribed to Appointments Plus * or Appointments Premium.

*/ public UpsertBookingCustomAttributeResponse upsert(UpsertBookingCustomAttributeRequest request) { return upsert(request, null); } /** * Upserts a bookings custom attribute. *

To call this endpoint with buyer-level permissions, set APPOINTMENTS_WRITE for the OAuth scope. * To call this endpoint with seller-level permissions, set APPOINTMENTS_ALL_WRITE and APPOINTMENTS_WRITE for the OAuth scope.

*

For calls to this endpoint with seller-level permissions to succeed, the seller must have subscribed to Appointments Plus * or Appointments Premium.

*/ public UpsertBookingCustomAttributeResponse upsert( UpsertBookingCustomAttributeRequest request, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("v2/bookings") .addPathSegment(request.getBookingId()) .addPathSegments("custom-attributes") .addPathSegment(request.getKey()) .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("PUT", 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(), UpsertBookingCustomAttributeResponse.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); } } /** * Deletes a bookings custom attribute. *

To call this endpoint with buyer-level permissions, set APPOINTMENTS_WRITE for the OAuth scope. * To call this endpoint with seller-level permissions, set APPOINTMENTS_ALL_WRITE and APPOINTMENTS_WRITE for the OAuth scope.

*

For calls to this endpoint with seller-level permissions to succeed, the seller must have subscribed to Appointments Plus * or Appointments Premium.

*/ public DeleteBookingCustomAttributeResponse delete(DeleteCustomAttributesRequest request) { return delete(request, null); } /** * Deletes a bookings custom attribute. *

To call this endpoint with buyer-level permissions, set APPOINTMENTS_WRITE for the OAuth scope. * To call this endpoint with seller-level permissions, set APPOINTMENTS_ALL_WRITE and APPOINTMENTS_WRITE for the OAuth scope.

*

For calls to this endpoint with seller-level permissions to succeed, the seller must have subscribed to Appointments Plus * or Appointments Premium.

*/ public DeleteBookingCustomAttributeResponse delete( DeleteCustomAttributesRequest request, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("v2/bookings") .addPathSegment(request.getBookingId()) .addPathSegments("custom-attributes") .addPathSegment(request.getKey()) .build(); Request.Builder _requestBuilder = new Request.Builder() .url(httpUrl) .method("DELETE", 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(), DeleteBookingCustomAttributeResponse.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); } } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy