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.
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/square/inventory/client.rb', line 146 def batch_create_changes(request_options: {}, **params) _request = Square::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "v2/inventory/changes/batch-create", body: Square::Types::BatchChangeInventoryRequest.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::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.
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
# File 'lib/square/inventory/client.rb', line 178 def batch_get_changes(request_options: {}, **params) Square::Internal::CursorItemIterator.new( cursor_field: :cursor, item_field: :changes, initial_cursor: params[:cursor] ) do |next_cursor| params[:cursor] = next_cursor _request = Square::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "v2/inventory/changes/batch-retrieve", body: Square::Types::BatchRetrieveInventoryChangesRequest.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::BatchGetInventoryChangesResponse.load(_response.body) else error_class = Square::Errors::ResponseError.subclass_for_code(code) raise error_class.new(_response.body, code: code) end 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.
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 245 246 247 |
# File 'lib/square/inventory/client.rb', line 220 def batch_get_counts(request_options: {}, **params) Square::Internal::CursorItemIterator.new( cursor_field: :cursor, item_field: :counts, initial_cursor: params[:cursor] ) do |next_cursor| params[:cursor] = next_cursor _request = Square::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "v2/inventory/counts/batch-retrieve", body: Square::Types::BatchGetInventoryCountsRequest.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::BatchGetInventoryCountsResponse.load(_response.body) else error_class = Square::Errors::ResponseError.subclass_for_code(code) raise error_class.new(_response.body, code: code) end 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.
379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 |
# File 'lib/square/inventory/client.rb', line 379 def changes(request_options: {}, **params) params = Square::Internal::Types::Utils.symbolize_keys(params) _query_param_names = %i[location_ids cursor] _query = params.slice(*_query_param_names) params = params.except(*_query_param_names) Square::Internal::CursorItemIterator.new( cursor_field: :cursor, item_field: :changes, initial_cursor: _query[:cursor] ) do |next_cursor| _query[:cursor] = next_cursor _request = Square::Internal::JSON::Request.new( base_url: [:base_url], method: "GET", path: "v2/inventory/#{params[:catalog_object_id]}/changes", query: _query, 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::GetInventoryChangesResponse.load(_response.body) else error_class = Square::Errors::ResponseError.subclass_for_code(code) raise error_class.new(_response.body, code: code) end 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.
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/square/inventory/client.rb', line 65 def deprecated_batch_change(request_options: {}, **params) _request = Square::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "v2/inventory/batch-change", body: Square::Types::BatchChangeInventoryRequest.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::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.
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/square/inventory/client.rb', line 91 def deprecated_batch_get_changes(request_options: {}, **params) _request = Square::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "v2/inventory/batch-retrieve-changes", body: Square::Types::BatchRetrieveInventoryChangesRequest.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::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.
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/square/inventory/client.rb', line 117 def deprecated_batch_get_counts(request_options: {}, **params) _request = Square::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "v2/inventory/batch-retrieve-counts", body: Square::Types::BatchGetInventoryCountsRequest.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::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 34 |
# 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], method: "GET", path: "v2/inventory/adjustment/#{params[:adjustment_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::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.
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 |
# File 'lib/square/inventory/client.rb', line 253 def deprecated_get_physical_count(request_options: {}, **params) _request = Square::Internal::JSON::Request.new( base_url: [:base_url], method: "GET", path: "v2/inventory/physical-count/#{params[:physical_count_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::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.
330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 |
# File 'lib/square/inventory/client.rb', line 330 def get(request_options: {}, **params) params = Square::Internal::Types::Utils.symbolize_keys(params) _query_param_names = %i[location_ids cursor] _query = params.slice(*_query_param_names) params = params.except(*_query_param_names) Square::Internal::CursorItemIterator.new( cursor_field: :cursor, item_field: :counts, initial_cursor: _query[:cursor] ) do |next_cursor| _query[:cursor] = next_cursor _request = Square::Internal::JSON::Request.new( base_url: [:base_url], method: "GET", path: "v2/inventory/#{params[:catalog_object_id]}", query: _query, 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::GetInventoryCountResponse.load(_response.body) else error_class = Square::Errors::ResponseError.subclass_for_code(code) raise error_class.new(_response.body, code: code) end end end |
#get_adjustment(request_options: {}, **params) ⇒ Square::Types::GetInventoryAdjustmentResponse
Returns the [InventoryAdjustment](entity:InventoryAdjustment) object with the provided ‘adjustment_id`.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/square/inventory/client.rb', line 40 def get_adjustment(request_options: {}, **params) _request = Square::Internal::JSON::Request.new( base_url: [:base_url], method: "GET", path: "v2/inventory/adjustments/#{params[:adjustment_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::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`.
278 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 278 def get_physical_count(request_options: {}, **params) _request = Square::Internal::JSON::Request.new( base_url: [:base_url], method: "GET", path: "v2/inventory/physical-counts/#{params[:physical_count_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::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`.
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 |
# File 'lib/square/inventory/client.rb', line 303 def get_transfer(request_options: {}, **params) _request = Square::Internal::JSON::Request.new( base_url: [:base_url], method: "GET", path: "v2/inventory/transfers/#{params[:transfer_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::GetInventoryTransferResponse.load(_response.body) else error_class = Square::Errors::ResponseError.subclass_for_code(code) raise error_class.new(_response.body, code: code) end end |