Class: Square::Catalog::Object_::Client
- Inherits:
-
Object
- Object
- Square::Catalog::Object_::Client
- Defined in:
- lib/square/catalog/object/client.rb
Instance Method Summary collapse
-
#delete(request_options: {}, **params) ⇒ Square::Types::DeleteCatalogObjectResponse
Deletes a single [CatalogObject](entity:CatalogObject) based on the provided ID and returns the set of successfully deleted IDs in the response.
-
#get(request_options: {}, **params) ⇒ Square::Types::GetCatalogObjectResponse
Returns a single [CatalogItem](entity:CatalogItem) as a [CatalogObject](entity:CatalogObject) based on the provided ID.
- #initialize(client:) ⇒ void constructor
-
#upsert(request_options: {}, **params) ⇒ Square::Types::UpsertCatalogObjectResponse
Creates a new or updates the specified [CatalogObject](entity:CatalogObject).
Constructor Details
#initialize(client:) ⇒ void
10 11 12 |
# File 'lib/square/catalog/object/client.rb', line 10 def initialize(client:) @client = client end |
Instance Method Details
#delete(request_options: {}, **params) ⇒ Square::Types::DeleteCatalogObjectResponse
Deletes a single [CatalogObject](entity:CatalogObject) based on the provided ID and returns the 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](entity:CatalogItem) will also delete all of its [CatalogItemVariation](entity:CatalogItemVariation) children.
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.
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/square/catalog/object/client.rb', line 124 def delete(request_options: {}, **params) params = Square::Internal::Types::Utils.normalize_keys(params) request = Square::Internal::JSON::Request.new( base_url: [:base_url], method: "DELETE", path: "v2/catalog/object/#{params[:object_id_]}", 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::DeleteCatalogObjectResponse.load(response.body) else error_class = Square::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#get(request_options: {}, **params) ⇒ Square::Types::GetCatalogObjectResponse
Returns a single [CatalogItem](entity:CatalogItem) as a [CatalogObject](entity:CatalogObject) based on the provided ID. The returned object includes all of the relevant [CatalogItem](entity:CatalogItem) information including: [CatalogItemVariation](entity:CatalogItemVariation) children, references to its [CatalogModifierList](entity:CatalogModifierList) objects, and the ids of any [CatalogTax](entity:CatalogTax) objects that apply to it.
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/square/catalog/object/client.rb', line 73 def get(request_options: {}, **params) params = Square::Internal::Types::Utils.normalize_keys(params) query_param_names = %i[include_related_objects catalog_version include_category_path_to_root] query_params = {} query_params["include_related_objects"] = params[:include_related_objects] if params.key?(:include_related_objects) query_params["catalog_version"] = params[:catalog_version] if params.key?(:catalog_version) query_params["include_category_path_to_root"] = params[:include_category_path_to_root] if params.key?(:include_category_path_to_root) params = params.except(*query_param_names) request = Square::Internal::JSON::Request.new( base_url: [:base_url], method: "GET", path: "v2/catalog/object/#{params[:object_id_]}", 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::GetCatalogObjectResponse.load(response.body) else error_class = Square::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#upsert(request_options: {}, **params) ⇒ Square::Types::UpsertCatalogObjectResponse
Creates a new or updates the specified [CatalogObject](entity:CatalogObject).
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.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/square/catalog/object/client.rb', line 29 def 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/object", body: Square::Catalog::Object_::Types::UpsertCatalogObjectRequest.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::UpsertCatalogObjectResponse.load(response.body) else error_class = Square::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |