Class: Square::Inventory::Client
- Inherits:
-
Object
- Object
- Square::Inventory::Client
- Defined in:
- lib/square/inventory/client.rb
Instance Method Summary collapse
-
#batch_create_changes(request_options: {}, **params) ⇒ Square::Types::BatchChangeInventoryResponse
Applies adjustments and counts to the provided item quantities.
-
#batch_get_changes(request_options: {}, **params) ⇒ Square::Types::BatchGetInventoryChangesResponse
Returns historical physical counts and adjustments based on the provided filter criteria.
-
#batch_get_counts(request_options: {}, **params) ⇒ Square::Types::BatchGetInventoryCountsResponse
Returns current counts for the provided [CatalogObject](entity:CatalogObject)s at the requested [Location](entity:Location)s.
-
#changes(request_options: {}, **params) ⇒ Square::Types::GetInventoryChangesResponse
Returns a set of physical counts and inventory adjustments for the provided [CatalogObject](entity:CatalogObject) at the requested [Location](entity:Location)s.
-
#deprecated_batch_change(request_options: {}, **params) ⇒ Square::Types::BatchChangeInventoryResponse
Deprecated version of [BatchChangeInventory](api-endpoint:Inventory-BatchChangeInventory) after the endpoint URL is updated to conform to the standard convention.
-
#deprecated_batch_get_changes(request_options: {}, **params) ⇒ Square::Types::BatchGetInventoryChangesResponse
Deprecated version of [BatchRetrieveInventoryChanges](api-endpoint:Inventory-BatchRetrieveInventoryChanges) after the endpoint URL is updated to conform to the standard convention.
-
#deprecated_batch_get_counts(request_options: {}, **params) ⇒ Square::Types::BatchGetInventoryCountsResponse
Deprecated version of [BatchRetrieveInventoryCounts](api-endpoint:Inventory-BatchRetrieveInventoryCounts) after the endpoint URL is updated to conform to the standard convention.
-
#deprecated_get_adjustment(request_options: {}, **params) ⇒ Square::Types::GetInventoryAdjustmentResponse
Deprecated version of [RetrieveInventoryAdjustment](api-endpoint:Inventory-RetrieveInventoryAdjustment) after the endpoint URL is updated to conform to the standard convention.
-
#deprecated_get_physical_count(request_options: {}, **params) ⇒ Square::Types::GetInventoryPhysicalCountResponse
Deprecated version of [RetrieveInventoryPhysicalCount](api-endpoint:Inventory-RetrieveInventoryPhysicalCount) after the endpoint URL is updated to conform to the standard convention.
-
#get(request_options: {}, **params) ⇒ Square::Types::GetInventoryCountResponse
Retrieves the current calculated stock count for a given [CatalogObject](entity:CatalogObject) at a given set of [Location](entity:Location)s.
-
#get_adjustment(request_options: {}, **params) ⇒ Square::Types::GetInventoryAdjustmentResponse
Returns the [InventoryAdjustment](entity:InventoryAdjustment) object with the provided ‘adjustment_id`.
-
#get_physical_count(request_options: {}, **params) ⇒ Square::Types::GetInventoryPhysicalCountResponse
Returns the [InventoryPhysicalCount](entity:InventoryPhysicalCount) object with the provided ‘physical_count_id`.
-
#get_transfer(request_options: {}, **params) ⇒ Square::Types::GetInventoryTransferResponse
Returns the [InventoryTransfer](entity:InventoryTransfer) object with the provided ‘transfer_id`.
- #initialize(client:) ⇒ Square::Inventory::Client constructor
Constructor Details
#initialize(client:) ⇒ Square::Inventory::Client
7 8 9 |
# File 'lib/square/inventory/client.rb', line 7 def initialize(client:) @client = client end |
Instance Method Details
#batch_create_changes(request_options: {}, **params) ⇒ Square::Types::BatchChangeInventoryResponse
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.
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/square/inventory/client.rb', line 141 def batch_create_changes(request_options: {}, **params) _request = Square::Internal::JSON::Request.new( base_url: [:base_url] || Square::Environment::PRODUCTION, method: "POST", path: "v2/inventory/changes/batch-create", body: Square::Types::BatchChangeInventoryRequest.new(params).to_h ) 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::BatchChangeInventoryResponse.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_changes(request_options: {}, **params) ⇒ Square::Types::BatchGetInventoryChangesResponse
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.
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
# File 'lib/square/inventory/client.rb', line 172 def batch_get_changes(request_options: {}, **params) _request = Square::Internal::JSON::Request.new( base_url: [:base_url] || Square::Environment::PRODUCTION, method: "POST", path: "v2/inventory/changes/batch-retrieve", body: Square::Types::BatchRetrieveInventoryChangesRequest.new(params).to_h ) 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::BatchGetInventoryChangesResponse.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_counts(request_options: {}, **params) ⇒ Square::Types::BatchGetInventoryCountsResponse
Returns current counts for the provided [CatalogObject](entity:CatalogObject)s at the requested [Location](entity:Location)s.
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.
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 |
# File 'lib/square/inventory/client.rb', line 206 def batch_get_counts(request_options: {}, **params) _request = Square::Internal::JSON::Request.new( base_url: [:base_url] || Square::Environment::PRODUCTION, method: "POST", path: "v2/inventory/counts/batch-retrieve", body: Square::Types::BatchGetInventoryCountsRequest.new(params).to_h ) 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::BatchGetInventoryCountsResponse.load(_response.body) else error_class = Square::Errors::ResponseError.subclass_for_code(code) raise error_class.new(_response.body, code: code) end end |
#changes(request_options: {}, **params) ⇒ Square::Types::GetInventoryChangesResponse
Returns a set of physical counts and inventory adjustments for the provided [CatalogObject](entity:CatalogObject) at the requested [Location](entity:Location)s.
You can achieve the same result by calling [BatchRetrieveInventoryChanges](api-endpoint:Inventory-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.
348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 |
# File 'lib/square/inventory/client.rb', line 348 def changes(request_options: {}, **params) _query_param_names = [ %w[location_ids cursor], %i[location_ids cursor] ].flatten _query = params.slice(*_query_param_names) params = params.except(*_query_param_names) _request = Square::Internal::JSON::Request.new( base_url: [:base_url] || Square::Environment::PRODUCTION, method: "GET", path: "v2/inventory/#{params[:catalog_object_id]}/changes", query: _query ) 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::GetInventoryChangesResponse.load(_response.body) else error_class = Square::Errors::ResponseError.subclass_for_code(code) raise error_class.new(_response.body, code: code) end end |
#deprecated_batch_change(request_options: {}, **params) ⇒ Square::Types::BatchChangeInventoryResponse
Deprecated version of [BatchChangeInventory](api-endpoint:Inventory-BatchChangeInventory) after the endpoint URL is updated to conform to the standard convention.
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/square/inventory/client.rb', line 63 def deprecated_batch_change(request_options: {}, **params) _request = Square::Internal::JSON::Request.new( base_url: [:base_url] || Square::Environment::PRODUCTION, method: "POST", path: "v2/inventory/batch-change", body: Square::Types::BatchChangeInventoryRequest.new(params).to_h ) 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::BatchChangeInventoryResponse.load(_response.body) else error_class = Square::Errors::ResponseError.subclass_for_code(code) raise error_class.new(_response.body, code: code) end end |
#deprecated_batch_get_changes(request_options: {}, **params) ⇒ Square::Types::BatchGetInventoryChangesResponse
Deprecated version of [BatchRetrieveInventoryChanges](api-endpoint:Inventory-BatchRetrieveInventoryChanges) after the endpoint URL is updated to conform to the standard convention.
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/square/inventory/client.rb', line 88 def deprecated_batch_get_changes(request_options: {}, **params) _request = Square::Internal::JSON::Request.new( base_url: [:base_url] || Square::Environment::PRODUCTION, method: "POST", path: "v2/inventory/batch-retrieve-changes", body: Square::Types::BatchRetrieveInventoryChangesRequest.new(params).to_h ) 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::BatchGetInventoryChangesResponse.load(_response.body) else error_class = Square::Errors::ResponseError.subclass_for_code(code) raise error_class.new(_response.body, code: code) end end |
#deprecated_batch_get_counts(request_options: {}, **params) ⇒ Square::Types::BatchGetInventoryCountsResponse
Deprecated version of [BatchRetrieveInventoryCounts](api-endpoint:Inventory-BatchRetrieveInventoryCounts) after the endpoint URL is updated to conform to the standard convention.
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/square/inventory/client.rb', line 113 def deprecated_batch_get_counts(request_options: {}, **params) _request = Square::Internal::JSON::Request.new( base_url: [:base_url] || Square::Environment::PRODUCTION, method: "POST", path: "v2/inventory/batch-retrieve-counts", body: Square::Types::BatchGetInventoryCountsRequest.new(params).to_h ) 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::BatchGetInventoryCountsResponse.load(_response.body) else error_class = Square::Errors::ResponseError.subclass_for_code(code) raise error_class.new(_response.body, code: code) end end |
#deprecated_get_adjustment(request_options: {}, **params) ⇒ Square::Types::GetInventoryAdjustmentResponse
Deprecated version of [RetrieveInventoryAdjustment](api-endpoint:Inventory-RetrieveInventoryAdjustment) after the endpoint URL is updated to conform to the standard convention.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/square/inventory/client.rb', line 15 def deprecated_get_adjustment(request_options: {}, **params) _request = Square::Internal::JSON::Request.new( base_url: [:base_url] || Square::Environment::PRODUCTION, method: "GET", path: "v2/inventory/adjustment/#{params[:adjustment_id]}" ) 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::GetInventoryAdjustmentResponse.load(_response.body) else error_class = Square::Errors::ResponseError.subclass_for_code(code) raise error_class.new(_response.body, code: code) end end |
#deprecated_get_physical_count(request_options: {}, **params) ⇒ Square::Types::GetInventoryPhysicalCountResponse
Deprecated version of [RetrieveInventoryPhysicalCount](api-endpoint:Inventory-RetrieveInventoryPhysicalCount) after the endpoint URL is updated to conform to the standard convention.
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 |
# File 'lib/square/inventory/client.rb', line 231 def deprecated_get_physical_count(request_options: {}, **params) _request = Square::Internal::JSON::Request.new( base_url: [:base_url] || Square::Environment::PRODUCTION, method: "GET", path: "v2/inventory/physical-count/#{params[:physical_count_id]}" ) 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::GetInventoryPhysicalCountResponse.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::GetInventoryCountResponse
Retrieves the current calculated stock count for a given [CatalogObject](entity:CatalogObject) at a given set of [Location](entity:Location)s. Responses are paginated and unsorted. For more sophisticated queries, use a batch endpoint.
305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 |
# File 'lib/square/inventory/client.rb', line 305 def get(request_options: {}, **params) _query_param_names = [ %w[location_ids cursor], %i[location_ids cursor] ].flatten _query = params.slice(*_query_param_names) params = params.except(*_query_param_names) _request = Square::Internal::JSON::Request.new( base_url: [:base_url] || Square::Environment::PRODUCTION, method: "GET", path: "v2/inventory/#{params[:catalog_object_id]}", query: _query ) 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::GetInventoryCountResponse.load(_response.body) else error_class = Square::Errors::ResponseError.subclass_for_code(code) raise error_class.new(_response.body, code: code) end end |
#get_adjustment(request_options: {}, **params) ⇒ Square::Types::GetInventoryAdjustmentResponse
Returns the [InventoryAdjustment](entity:InventoryAdjustment) object with the provided ‘adjustment_id`.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/square/inventory/client.rb', line 39 def get_adjustment(request_options: {}, **params) _request = Square::Internal::JSON::Request.new( base_url: [:base_url] || Square::Environment::PRODUCTION, method: "GET", path: "v2/inventory/adjustments/#{params[:adjustment_id]}" ) 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::GetInventoryAdjustmentResponse.load(_response.body) else error_class = Square::Errors::ResponseError.subclass_for_code(code) raise error_class.new(_response.body, code: code) end end |
#get_physical_count(request_options: {}, **params) ⇒ Square::Types::GetInventoryPhysicalCountResponse
Returns the [InventoryPhysicalCount](entity:InventoryPhysicalCount) object with the provided ‘physical_count_id`.
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 |
# File 'lib/square/inventory/client.rb', line 255 def get_physical_count(request_options: {}, **params) _request = Square::Internal::JSON::Request.new( base_url: [:base_url] || Square::Environment::PRODUCTION, method: "GET", path: "v2/inventory/physical-counts/#{params[:physical_count_id]}" ) 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::GetInventoryPhysicalCountResponse.load(_response.body) else error_class = Square::Errors::ResponseError.subclass_for_code(code) raise error_class.new(_response.body, code: code) end end |
#get_transfer(request_options: {}, **params) ⇒ Square::Types::GetInventoryTransferResponse
Returns the [InventoryTransfer](entity:InventoryTransfer) object with the provided ‘transfer_id`.
279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 |
# File 'lib/square/inventory/client.rb', line 279 def get_transfer(request_options: {}, **params) _request = Square::Internal::JSON::Request.new( base_url: [:base_url] || Square::Environment::PRODUCTION, method: "GET", path: "v2/inventory/transfers/#{params[:transfer_id]}" ) 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::GetInventoryTransferResponse.load(_response.body) else error_class = Square::Errors::ResponseError.subclass_for_code(code) raise error_class.new(_response.body, code: code) end end |