Class: Square::Inventory::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/square/inventory/client.rb

Instance Method Summary collapse

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.



111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/square/inventory/client.rb', line 111

def batch_create_changes(request_options: {}, **params)
  _request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || Square::Environment::SANDBOX,
    method: "POST",
    path: "v2/inventory/changes/batch-create",
    body: Square::Types::BatchChangeInventoryRequest.new(params).to_h
  )
  _response = @client.send(_request)
  if _response.code >= "200" && _response.code < "300"
    return Square::Types::BatchChangeInventoryResponse.load(_response.body)
  end

  raise _response.body
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.



136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/square/inventory/client.rb', line 136

def batch_get_changes(request_options: {}, **params)
  _request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || Square::Environment::SANDBOX,
    method: "POST",
    path: "v2/inventory/changes/batch-retrieve",
    body: Square::Types::BatchRetrieveInventoryChangesRequest.new(params).to_h
  )
  _response = @client.send(_request)
  if _response.code >= "200" && _response.code < "300"
    return Square::Types::BatchGetInventoryChangesResponse.load(_response.body)
  end

  raise _response.body
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.



164
165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'lib/square/inventory/client.rb', line 164

def batch_get_counts(request_options: {}, **params)
  _request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || Square::Environment::SANDBOX,
    method: "POST",
    path: "v2/inventory/counts/batch-retrieve",
    body: Square::Types::BatchGetInventoryCountsRequest.new(params).to_h
  )
  _response = @client.send(_request)
  if _response.code >= "200" && _response.code < "300"
    return Square::Types::BatchGetInventoryCountsResponse.load(_response.body)
  end

  raise _response.body
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.



273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
# File 'lib/square/inventory/client.rb', line 273

def changes(request_options: {}, **params)
  _query_param_names = %w[location_ids cursor]
  _query = params.slice(*_query_param_names)
  params = params.except(*_query_param_names)

  _request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || Square::Environment::SANDBOX,
    method: "GET",
    path: "v2/inventory/#{params[:catalog_object_id]}/changes",
    query: _query
  )
  _response = @client.send(_request)
  if _response.code >= "200" && _response.code < "300"
    return Square::Types::GetInventoryChangesResponse.load(_response.body)
  end

  raise _response.body
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.



51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/square/inventory/client.rb', line 51

def deprecated_batch_change(request_options: {}, **params)
  _request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || Square::Environment::SANDBOX,
    method: "POST",
    path: "v2/inventory/batch-change",
    body: Square::Types::BatchChangeInventoryRequest.new(params).to_h
  )
  _response = @client.send(_request)
  if _response.code >= "200" && _response.code < "300"
    return Square::Types::BatchChangeInventoryResponse.load(_response.body)
  end

  raise _response.body
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.



70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/square/inventory/client.rb', line 70

def deprecated_batch_get_changes(request_options: {}, **params)
  _request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || Square::Environment::SANDBOX,
    method: "POST",
    path: "v2/inventory/batch-retrieve-changes",
    body: Square::Types::BatchRetrieveInventoryChangesRequest.new(params).to_h
  )
  _response = @client.send(_request)
  if _response.code >= "200" && _response.code < "300"
    return Square::Types::BatchGetInventoryChangesResponse.load(_response.body)
  end

  raise _response.body
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.



89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/square/inventory/client.rb', line 89

def deprecated_batch_get_counts(request_options: {}, **params)
  _request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || Square::Environment::SANDBOX,
    method: "POST",
    path: "v2/inventory/batch-retrieve-counts",
    body: Square::Types::BatchGetInventoryCountsRequest.new(params).to_h
  )
  _response = @client.send(_request)
  if _response.code >= "200" && _response.code < "300"
    return Square::Types::BatchGetInventoryCountsResponse.load(_response.body)
  end

  raise _response.body
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
# File 'lib/square/inventory/client.rb', line 15

def deprecated_get_adjustment(request_options: {}, **params)
  _request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || Square::Environment::SANDBOX,
    method: "GET",
    path: "v2/inventory/adjustment/#{params[:adjustment_id]}"
  )
  _response = @client.send(_request)
  if _response.code >= "200" && _response.code < "300"
    return Square::Types::GetInventoryAdjustmentResponse.load(_response.body)
  end

  raise _response.body
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.



183
184
185
186
187
188
189
190
191
192
193
194
195
# File 'lib/square/inventory/client.rb', line 183

def deprecated_get_physical_count(request_options: {}, **params)
  _request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || Square::Environment::SANDBOX,
    method: "GET",
    path: "v2/inventory/physical-count/#{params[:physical_count_id]}"
  )
  _response = @client.send(_request)
  if _response.code >= "200" && _response.code < "300"
    return Square::Types::GetInventoryPhysicalCountResponse.load(_response.body)
  end

  raise _response.body
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.



239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
# File 'lib/square/inventory/client.rb', line 239

def get(request_options: {}, **params)
  _query_param_names = %w[location_ids cursor]
  _query = params.slice(*_query_param_names)
  params = params.except(*_query_param_names)

  _request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || Square::Environment::SANDBOX,
    method: "GET",
    path: "v2/inventory/#{params[:catalog_object_id]}",
    query: _query
  )
  _response = @client.send(_request)
  if _response.code >= "200" && _response.code < "300"
    return Square::Types::GetInventoryCountResponse.load(_response.body)
  end

  raise _response.body
end

#get_adjustment(request_options: {}, **params) ⇒ Square::Types::GetInventoryAdjustmentResponse

Returns the [InventoryAdjustment](entity:InventoryAdjustment) object with the provided ‘adjustment_id`.



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/square/inventory/client.rb', line 33

def get_adjustment(request_options: {}, **params)
  _request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || Square::Environment::SANDBOX,
    method: "GET",
    path: "v2/inventory/adjustments/#{params[:adjustment_id]}"
  )
  _response = @client.send(_request)
  if _response.code >= "200" && _response.code < "300"
    return Square::Types::GetInventoryAdjustmentResponse.load(_response.body)
  end

  raise _response.body
end

#get_physical_count(request_options: {}, **params) ⇒ Square::Types::GetInventoryPhysicalCountResponse

Returns the [InventoryPhysicalCount](entity:InventoryPhysicalCount) object with the provided ‘physical_count_id`.



201
202
203
204
205
206
207
208
209
210
211
212
213
# File 'lib/square/inventory/client.rb', line 201

def get_physical_count(request_options: {}, **params)
  _request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || Square::Environment::SANDBOX,
    method: "GET",
    path: "v2/inventory/physical-counts/#{params[:physical_count_id]}"
  )
  _response = @client.send(_request)
  if _response.code >= "200" && _response.code < "300"
    return Square::Types::GetInventoryPhysicalCountResponse.load(_response.body)
  end

  raise _response.body
end

#get_transfer(request_options: {}, **params) ⇒ Square::Types::GetInventoryTransferResponse

Returns the [InventoryTransfer](entity:InventoryTransfer) object with the provided ‘transfer_id`.



219
220
221
222
223
224
225
226
227
228
229
230
231
# File 'lib/square/inventory/client.rb', line 219

def get_transfer(request_options: {}, **params)
  _request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || Square::Environment::SANDBOX,
    method: "GET",
    path: "v2/inventory/transfers/#{params[:transfer_id]}"
  )
  _response = @client.send(_request)
  if _response.code >= "200" && _response.code < "300"
    return Square::Types::GetInventoryTransferResponse.load(_response.body)
  end

  raise _response.body
end