Class: Square::Catalog::Client
- Inherits:
-
Object
- Object
- Square::Catalog::Client
- Defined in:
- lib/square/catalog/client.rb
Instance Method Summary collapse
-
#batch_delete(request_options: {}, **params) ⇒ Square::Types::BatchDeleteCatalogObjectsResponse
Deletes a set of CatalogItems based on the provided list of target IDs and returns a set of successfully deleted IDs in the response.
-
#batch_get(request_options: {}, **params) ⇒ Square::Types::BatchGetCatalogObjectsResponse
Returns a set of objects based on the provided ID.
-
#batch_upsert(request_options: {}, **params) ⇒ Square::Types::BatchUpsertCatalogObjectsResponse
Creates or updates up to 10,000 target objects based on the provided list of objects.
- #images ⇒ Square::Images::Client
-
#info(request_options: {}, **params) ⇒ Square::Types::CatalogInfoResponse
Retrieves information about the Square Catalog API, such as batch size limits that can be used by the
BatchUpsertCatalogObjectsendpoint. - #initialize(client:) ⇒ void constructor
-
#list(request_options: {}, **params) ⇒ Square::Types::ListCatalogResponse
Returns a list of all CatalogObjects of the specified types in the catalog.
- #object ⇒ Square::Object_::Client
-
#search(request_options: {}, **params) ⇒ Square::Types::SearchCatalogObjectsResponse
Searches for CatalogObject of any type by matching supported search attribute values, excluding custom attribute values on items or item variations, against one or more of the specified query filters.
-
#search_items(request_options: {}, **params) ⇒ Square::Types::SearchCatalogItemsResponse
Searches for catalog items or item variations by matching supported search attribute values, including custom attribute values, against one or more of the specified query filters.
-
#update_item_modifier_lists(request_options: {}, **params) ⇒ Square::Types::UpdateItemModifierListsResponse
Updates the CatalogModifierList objects that apply to the targeted CatalogItem without having to perform an upsert on the entire item.
-
#update_item_taxes(request_options: {}, **params) ⇒ Square::Types::UpdateItemTaxesResponse
Updates the CatalogTax objects that apply to the targeted CatalogItem without having to perform an upsert on the entire item.
Constructor Details
#initialize(client:) ⇒ void
9 10 11 |
# File 'lib/square/catalog/client.rb', line 9 def initialize(client:) @client = client end |
Instance Method Details
#batch_delete(request_options: {}, **params) ⇒ Square::Types::BatchDeleteCatalogObjectsResponse
Deletes a set of CatalogItems based on the provided list of target IDs and returns a set of successfully deleted IDs in the response. Deletion is a cascading event such that all children of the targeted object are also deleted. For example, deleting a CatalogItem will also delete all of its CatalogItemVariation children.
BatchDeleteCatalogObjects succeeds even if only a portion of the targeted
IDs can be deleted. The response will only include IDs that were
actually deleted.
To ensure consistency, only one delete request is processed at a time per seller account.
While one (batch or non-batch) delete request is being processed, other (batched and non-batched)
delete requests are rejected with the 429 error code.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/square/catalog/client.rb', line 37 def batch_delete(request_options: {}, **params) params = Square::Internal::Types::Utils.normalize_keys(params) request = Square::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "v2/catalog/batch-delete", body: Square::Catalog::Types::BatchDeleteCatalogObjectsRequest.new(params).to_h, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Square::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Square::Types::BatchDeleteCatalogObjectsResponse.load(response.body) else error_class = Square::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#batch_get(request_options: {}, **params) ⇒ Square::Types::BatchGetCatalogObjectsResponse
Returns a set of objects based on the provided ID. Each CatalogItem returned in the set includes all of its child information including: all of its CatalogItemVariation objects, references to its CatalogModifierList objects, and the ids of any CatalogTax objects that apply to it.
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/square/catalog/client.rb', line 76 def batch_get(request_options: {}, **params) params = Square::Internal::Types::Utils.normalize_keys(params) request = Square::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "v2/catalog/batch-retrieve", body: Square::Catalog::Types::BatchGetCatalogObjectsRequest.new(params).to_h, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Square::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Square::Types::BatchGetCatalogObjectsResponse.load(response.body) else error_class = Square::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#batch_upsert(request_options: {}, **params) ⇒ Square::Types::BatchUpsertCatalogObjectsResponse
Creates or updates up to 10,000 target objects based on the provided list of objects. The target objects are grouped into batches and each batch is inserted/updated in an all-or-nothing manner. If an object within a batch is malformed in some way, or violates a database constraint, the entire batch containing that item will be disregarded. However, other batches in the same request may still succeed. Each batch may contain up to 1,000 objects, and batches will be processed in order as long as the total object count for the request (items, variations, modifier lists, discounts, and taxes) is no more than 10,000.
This endpoint uses full-replacement semantics. The client must send the complete object, and any field absent from the request is interpreted as an intentional clear. This logic applies to nested objects as well. For example, omitting inlined children like variations will delete them.
To ensure consistency, only one update request is processed at a time per seller account.
While one (batch or non-batch) update request is being processed, other (batched and non-batched)
update requests are rejected with the 429 error code. Prefer batching related changes into a
single call rather than issuing many small writes, since each write acquires the lock separately
and parallel writes to the same seller will contend with each other, producing 429 errors.
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/square/catalog/client.rb', line 128 def batch_upsert(request_options: {}, **params) params = Square::Internal::Types::Utils.normalize_keys(params) request = Square::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "v2/catalog/batch-upsert", body: Square::Catalog::Types::BatchUpsertCatalogObjectsRequest.new(params).to_h, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Square::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Square::Types::BatchUpsertCatalogObjectsResponse.load(response.body) else error_class = Square::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#images ⇒ Square::Images::Client
419 420 421 |
# File 'lib/square/catalog/client.rb', line 419 def images @images ||= Square::Catalog::Images::Client.new(client: @client) end |
#info(request_options: {}, **params) ⇒ Square::Types::CatalogInfoResponse
Retrieves information about the Square Catalog API, such as batch size
limits that can be used by the BatchUpsertCatalogObjects endpoint.
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/square/catalog/client.rb', line 163 def info(request_options: {}, **params) Square::Internal::Types::Utils.normalize_keys(params) request = Square::Internal::JSON::Request.new( base_url: [:base_url], method: "GET", path: "v2/catalog/info", request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Square::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Square::Types::CatalogInfoResponse.load(response.body) else error_class = Square::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#list(request_options: {}, **params) ⇒ Square::Types::ListCatalogResponse
Returns a list of all CatalogObjects of the specified types in the catalog.
The types parameter is specified as a comma-separated list of the
CatalogObjectType values,
for example, "ITEM, ITEM_VARIATION, MODIFIER, MODIFIER_LIST, CATEGORY, DISCOUNT, TAX, IMAGE".
Always specify types explicitly. When upgrading to a newer API version, omitting types may
cause new object types to appear in results that were not returned under the previous version.
Important: ListCatalog does not return deleted catalog items. To retrieve
deleted catalog items, use SearchCatalogObjects
and set the include_deleted_objects attribute value to true.
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 |
# File 'lib/square/catalog/client.rb', line 209 def list(request_options: {}, **params) params = Square::Internal::Types::Utils.normalize_keys(params) query_param_names = %i[cursor types catalog_version] query_params = {} query_params["cursor"] = params[:cursor] if params.key?(:cursor) query_params["types"] = params[:types] if params.key?(:types) query_params["catalog_version"] = params[:catalog_version] if params.key?(:catalog_version) params.except(*query_param_names) Square::Internal::CursorItemIterator.new( cursor_field: :cursor, item_field: :objects, initial_cursor: query_params[:cursor] ) do |next_cursor| query_params[:cursor] = next_cursor request = Square::Internal::JSON::Request.new( base_url: [:base_url], method: "GET", path: "v2/catalog/list", query: query_params, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Square::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Square::Types::ListCatalogResponse.load(response.body) else error_class = Square::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end end |
#object ⇒ Square::Object_::Client
424 425 426 |
# File 'lib/square/catalog/client.rb', line 424 def object @object ||= Square::Catalog::Object_::Client.new(client: @client) end |
#search(request_options: {}, **params) ⇒ Square::Types::SearchCatalogObjectsResponse
Searches for CatalogObject of any type by matching supported search attribute values, excluding custom attribute values on items or item variations, against one or more of the specified query filters.
This (SearchCatalogObjects) endpoint differs from the
SearchCatalogItems
endpoint in the following aspects:
SearchCatalogItemscan only search for items or item variations, whereasSearchCatalogObjectscan search for any type of catalog objects.SearchCatalogItemssupports the custom attribute query filters to return items or item variations that contain custom attribute values, whereSearchCatalogObjectsdoes not.SearchCatalogItemsdoes not support theinclude_deleted_objectsfilter to search for deleted items or item variations, whereasSearchCatalogObjectsdoes.- The both endpoints have different call conventions, including the query filter formats.
The object_types parameter is specified as a list of CatalogObjectType values.
Always specify object_types explicitly. When upgrading to a newer API version, omitting
object_types may cause new object types to appear in results that were not returned under
the previous version.
276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 |
# File 'lib/square/catalog/client.rb', line 276 def search(request_options: {}, **params) params = Square::Internal::Types::Utils.normalize_keys(params) request = Square::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "v2/catalog/search", body: Square::Catalog::Types::SearchCatalogObjectsRequest.new(params).to_h, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Square::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Square::Types::SearchCatalogObjectsResponse.load(response.body) else error_class = Square::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#search_items(request_options: {}, **params) ⇒ Square::Types::SearchCatalogItemsResponse
Searches for catalog items or item variations by matching supported search attribute values, including custom attribute values, against one or more of the specified query filters.
This (SearchCatalogItems) endpoint differs from the
SearchCatalogObjects
endpoint in the following aspects:
SearchCatalogItemscan only search for items or item variations, whereasSearchCatalogObjectscan search for any type of catalog objects.SearchCatalogItemssupports the custom attribute query filters to return items or item variations that contain custom attribute values, whereSearchCatalogObjectsdoes not.SearchCatalogItemsdoes not support theinclude_deleted_objectsfilter to search for deleted items or item variations, whereasSearchCatalogObjectsdoes.- The both endpoints use different call conventions, including the query filter formats.
323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 |
# File 'lib/square/catalog/client.rb', line 323 def search_items(request_options: {}, **params) params = Square::Internal::Types::Utils.normalize_keys(params) request = Square::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "v2/catalog/search-catalog-items", body: Square::Catalog::Types::SearchCatalogItemsRequest.new(params).to_h, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Square::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Square::Types::SearchCatalogItemsResponse.load(response.body) else error_class = Square::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#update_item_modifier_lists(request_options: {}, **params) ⇒ Square::Types::UpdateItemModifierListsResponse
Updates the CatalogModifierList objects that apply to the targeted CatalogItem without having to perform an upsert on the entire item.
359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 |
# File 'lib/square/catalog/client.rb', line 359 def update_item_modifier_lists(request_options: {}, **params) params = Square::Internal::Types::Utils.normalize_keys(params) request = Square::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "v2/catalog/update-item-modifier-lists", body: Square::Catalog::Types::UpdateItemModifierListsRequest.new(params).to_h, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Square::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Square::Types::UpdateItemModifierListsResponse.load(response.body) else error_class = Square::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#update_item_taxes(request_options: {}, **params) ⇒ Square::Types::UpdateItemTaxesResponse
Updates the CatalogTax objects that apply to the targeted CatalogItem without having to perform an upsert on the entire item.
395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 |
# File 'lib/square/catalog/client.rb', line 395 def update_item_taxes(request_options: {}, **params) params = Square::Internal::Types::Utils.normalize_keys(params) request = Square::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "v2/catalog/update-item-taxes", body: Square::Catalog::Types::UpdateItemTaxesRequest.new(params).to_h, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Square::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Square::Types::UpdateItemTaxesResponse.load(response.body) else error_class = Square::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |