square.rb 3.3.0.20191217
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE +10 -0
- data/README.md +285 -0
- data/lib/square/api/apple_pay_api.rb +50 -0
- data/lib/square/api/base_api.rb +43 -0
- data/lib/square/api/cash_drawers_api.rb +150 -0
- data/lib/square/api/catalog_api.rb +545 -0
- data/lib/square/api/checkout_api.rb +49 -0
- data/lib/square/api/customers_api.rb +327 -0
- data/lib/square/api/employees_api.rb +86 -0
- data/lib/square/api/inventory_api.rb +295 -0
- data/lib/square/api/labor_api.rb +553 -0
- data/lib/square/api/locations_api.rb +146 -0
- data/lib/square/api/merchants_api.rb +82 -0
- data/lib/square/api/mobile_authorization_api.rb +52 -0
- data/lib/square/api/o_auth_api.rb +163 -0
- data/lib/square/api/orders_api.rb +266 -0
- data/lib/square/api/payments_api.rb +277 -0
- data/lib/square/api/refunds_api.rb +144 -0
- data/lib/square/api/reporting_api.rb +138 -0
- data/lib/square/api/transactions_api.rb +377 -0
- data/lib/square/api/v1_employees_api.rb +715 -0
- data/lib/square/api/v1_items_api.rb +2046 -0
- data/lib/square/api/v1_locations_api.rb +83 -0
- data/lib/square/api/v1_transactions_api.rb +568 -0
- data/lib/square/api_helper.rb +276 -0
- data/lib/square/client.rb +156 -0
- data/lib/square/configuration.rb +93 -0
- data/lib/square/exceptions/api_exception.rb +15 -0
- data/lib/square/http/api_response.rb +45 -0
- data/lib/square/http/auth/o_auth2.rb +12 -0
- data/lib/square/http/faraday_client.rb +59 -0
- data/lib/square/http/http_call_back.rb +19 -0
- data/lib/square/http/http_client.rb +99 -0
- data/lib/square/http/http_method_enum.rb +8 -0
- data/lib/square/http/http_request.rb +45 -0
- data/lib/square/http/http_response.rb +24 -0
- data/lib/square.rb +49 -0
- data/spec/user_journey_spec.rb +145 -0
- data/test/api/api_test_base.rb +24 -0
- data/test/api/test_catalog_api.rb +59 -0
- data/test/api/test_customers_api.rb +45 -0
- data/test/api/test_employees_api.rb +36 -0
- data/test/api/test_labor_api.rb +74 -0
- data/test/api/test_locations_api.rb +35 -0
- data/test/api/test_merchants_api.rb +40 -0
- data/test/api/test_payments_api.rb +42 -0
- data/test/api/test_refunds_api.rb +41 -0
- data/test/http_response_catcher.rb +19 -0
- data/test/test_helper.rb +94 -0
- metadata +190 -0
@@ -0,0 +1,295 @@
|
|
1
|
+
module Square
|
2
|
+
# InventoryApi
|
3
|
+
class InventoryApi < BaseApi
|
4
|
+
def initialize(config, http_call_back: nil)
|
5
|
+
super(config, http_call_back: http_call_back)
|
6
|
+
end
|
7
|
+
|
8
|
+
# Returns the [InventoryAdjustment](#type-inventoryadjustment) object
|
9
|
+
# with the provided `adjustment_id`.
|
10
|
+
# @param [String] adjustment_id Required parameter: ID of the
|
11
|
+
# [InventoryAdjustment](#type-inventoryadjustment) to retrieve.
|
12
|
+
# @return [RetrieveInventoryAdjustmentResponse Hash] response from the API call
|
13
|
+
def retrieve_inventory_adjustment(adjustment_id:)
|
14
|
+
# Prepare query url.
|
15
|
+
_query_builder = config.get_base_uri
|
16
|
+
_query_builder << '/v2/inventory/adjustment/{adjustment_id}'
|
17
|
+
_query_builder = APIHelper.append_url_with_template_parameters(
|
18
|
+
_query_builder,
|
19
|
+
'adjustment_id' => adjustment_id
|
20
|
+
)
|
21
|
+
_query_url = APIHelper.clean_url _query_builder
|
22
|
+
|
23
|
+
# Prepare headers.
|
24
|
+
_headers = {
|
25
|
+
'accept' => 'application/json'
|
26
|
+
}
|
27
|
+
|
28
|
+
# Prepare and execute HttpRequest.
|
29
|
+
_request = config.http_client.get(
|
30
|
+
_query_url,
|
31
|
+
headers: _headers
|
32
|
+
)
|
33
|
+
OAuth2.apply(config, _request)
|
34
|
+
_response = execute_request(_request)
|
35
|
+
|
36
|
+
# Return appropriate response type.
|
37
|
+
decoded = APIHelper.json_deserialize(_response.raw_body)
|
38
|
+
_errors = APIHelper.map_response(decoded, ['errors'])
|
39
|
+
ApiResponse.new(_response, data: decoded, errors: _errors)
|
40
|
+
end
|
41
|
+
|
42
|
+
# Applies adjustments and counts to the provided item quantities.
|
43
|
+
# On success: returns the current calculated counts for all objects
|
44
|
+
# referenced in the request.
|
45
|
+
# On failure: returns a list of related errors.
|
46
|
+
# @param [BatchChangeInventoryRequest] body Required parameter: An object
|
47
|
+
# containing the fields to POST for the request. See the corresponding
|
48
|
+
# object definition for field details.
|
49
|
+
# @return [BatchChangeInventoryResponse Hash] response from the API call
|
50
|
+
def batch_change_inventory(body:)
|
51
|
+
# Prepare query url.
|
52
|
+
_query_builder = config.get_base_uri
|
53
|
+
_query_builder << '/v2/inventory/batch-change'
|
54
|
+
_query_url = APIHelper.clean_url _query_builder
|
55
|
+
|
56
|
+
# Prepare headers.
|
57
|
+
_headers = {
|
58
|
+
'accept' => 'application/json',
|
59
|
+
'content-type' => 'application/json; charset=utf-8'
|
60
|
+
}
|
61
|
+
|
62
|
+
# Prepare and execute HttpRequest.
|
63
|
+
_request = config.http_client.post(
|
64
|
+
_query_url,
|
65
|
+
headers: _headers,
|
66
|
+
parameters: body.to_json
|
67
|
+
)
|
68
|
+
OAuth2.apply(config, _request)
|
69
|
+
_response = execute_request(_request)
|
70
|
+
|
71
|
+
# Return appropriate response type.
|
72
|
+
decoded = APIHelper.json_deserialize(_response.raw_body)
|
73
|
+
_errors = APIHelper.map_response(decoded, ['errors'])
|
74
|
+
ApiResponse.new(_response, data: decoded, errors: _errors)
|
75
|
+
end
|
76
|
+
|
77
|
+
# Returns historical physical counts and adjustments based on the
|
78
|
+
# provided filter criteria.
|
79
|
+
# Results are paginated and sorted in ascending order according their
|
80
|
+
# `occurred_at` timestamp (oldest first).
|
81
|
+
# BatchRetrieveInventoryChanges is a catch-all query endpoint for queries
|
82
|
+
# that cannot be handled by other, simpler endpoints.
|
83
|
+
# @param [BatchRetrieveInventoryChangesRequest] body Required parameter: An
|
84
|
+
# object containing the fields to POST for the request. See the
|
85
|
+
# corresponding object definition for field details.
|
86
|
+
# @return [BatchRetrieveInventoryChangesResponse Hash] response from the API call
|
87
|
+
def batch_retrieve_inventory_changes(body:)
|
88
|
+
# Prepare query url.
|
89
|
+
_query_builder = config.get_base_uri
|
90
|
+
_query_builder << '/v2/inventory/batch-retrieve-changes'
|
91
|
+
_query_url = APIHelper.clean_url _query_builder
|
92
|
+
|
93
|
+
# Prepare headers.
|
94
|
+
_headers = {
|
95
|
+
'accept' => 'application/json',
|
96
|
+
'content-type' => 'application/json; charset=utf-8'
|
97
|
+
}
|
98
|
+
|
99
|
+
# Prepare and execute HttpRequest.
|
100
|
+
_request = config.http_client.post(
|
101
|
+
_query_url,
|
102
|
+
headers: _headers,
|
103
|
+
parameters: body.to_json
|
104
|
+
)
|
105
|
+
OAuth2.apply(config, _request)
|
106
|
+
_response = execute_request(_request)
|
107
|
+
|
108
|
+
# Return appropriate response type.
|
109
|
+
decoded = APIHelper.json_deserialize(_response.raw_body)
|
110
|
+
_errors = APIHelper.map_response(decoded, ['errors'])
|
111
|
+
ApiResponse.new(_response, data: decoded, errors: _errors)
|
112
|
+
end
|
113
|
+
|
114
|
+
# Returns current counts for the provided
|
115
|
+
# [CatalogObject](#type-catalogobject)s at the requested
|
116
|
+
# [Location](#type-location)s.
|
117
|
+
# Results are paginated and sorted in descending order according to their
|
118
|
+
# `calculated_at` timestamp (newest first).
|
119
|
+
# When `updated_after` is specified, only counts that have changed since
|
120
|
+
# that
|
121
|
+
# time (based on the server timestamp for the most recent change) are
|
122
|
+
# returned. This allows clients to perform a "sync" operation, for example
|
123
|
+
# in response to receiving a Webhook notification.
|
124
|
+
# @param [BatchRetrieveInventoryCountsRequest] body Required parameter: An
|
125
|
+
# object containing the fields to POST for the request. See the
|
126
|
+
# corresponding object definition for field details.
|
127
|
+
# @return [BatchRetrieveInventoryCountsResponse Hash] response from the API call
|
128
|
+
def batch_retrieve_inventory_counts(body:)
|
129
|
+
# Prepare query url.
|
130
|
+
_query_builder = config.get_base_uri
|
131
|
+
_query_builder << '/v2/inventory/batch-retrieve-counts'
|
132
|
+
_query_url = APIHelper.clean_url _query_builder
|
133
|
+
|
134
|
+
# Prepare headers.
|
135
|
+
_headers = {
|
136
|
+
'accept' => 'application/json',
|
137
|
+
'content-type' => 'application/json; charset=utf-8'
|
138
|
+
}
|
139
|
+
|
140
|
+
# Prepare and execute HttpRequest.
|
141
|
+
_request = config.http_client.post(
|
142
|
+
_query_url,
|
143
|
+
headers: _headers,
|
144
|
+
parameters: body.to_json
|
145
|
+
)
|
146
|
+
OAuth2.apply(config, _request)
|
147
|
+
_response = execute_request(_request)
|
148
|
+
|
149
|
+
# Return appropriate response type.
|
150
|
+
decoded = APIHelper.json_deserialize(_response.raw_body)
|
151
|
+
_errors = APIHelper.map_response(decoded, ['errors'])
|
152
|
+
ApiResponse.new(_response, data: decoded, errors: _errors)
|
153
|
+
end
|
154
|
+
|
155
|
+
# Returns the [InventoryPhysicalCount](#type-inventoryphysicalcount)
|
156
|
+
# object with the provided `physical_count_id`.
|
157
|
+
# @param [String] physical_count_id Required parameter: ID of the
|
158
|
+
# [InventoryPhysicalCount](#type-inventoryphysicalcount) to retrieve.
|
159
|
+
# @return [RetrieveInventoryPhysicalCountResponse Hash] response from the API call
|
160
|
+
def retrieve_inventory_physical_count(physical_count_id:)
|
161
|
+
# Prepare query url.
|
162
|
+
_query_builder = config.get_base_uri
|
163
|
+
_query_builder << '/v2/inventory/physical-count/{physical_count_id}'
|
164
|
+
_query_builder = APIHelper.append_url_with_template_parameters(
|
165
|
+
_query_builder,
|
166
|
+
'physical_count_id' => physical_count_id
|
167
|
+
)
|
168
|
+
_query_url = APIHelper.clean_url _query_builder
|
169
|
+
|
170
|
+
# Prepare headers.
|
171
|
+
_headers = {
|
172
|
+
'accept' => 'application/json'
|
173
|
+
}
|
174
|
+
|
175
|
+
# Prepare and execute HttpRequest.
|
176
|
+
_request = config.http_client.get(
|
177
|
+
_query_url,
|
178
|
+
headers: _headers
|
179
|
+
)
|
180
|
+
OAuth2.apply(config, _request)
|
181
|
+
_response = execute_request(_request)
|
182
|
+
|
183
|
+
# Return appropriate response type.
|
184
|
+
decoded = APIHelper.json_deserialize(_response.raw_body)
|
185
|
+
_errors = APIHelper.map_response(decoded, ['errors'])
|
186
|
+
ApiResponse.new(_response, data: decoded, errors: _errors)
|
187
|
+
end
|
188
|
+
|
189
|
+
# Retrieves the current calculated stock count for a given
|
190
|
+
# [CatalogObject](#type-catalogobject) at a given set of
|
191
|
+
# [Location](#type-location)s. Responses are paginated and unsorted.
|
192
|
+
# For more sophisticated queries, use a batch endpoint.
|
193
|
+
# @param [String] catalog_object_id Required parameter: ID of the
|
194
|
+
# [CatalogObject](#type-catalogobject) to retrieve.
|
195
|
+
# @param [String] location_ids Optional parameter: The
|
196
|
+
# [Location](#type-location) IDs to look up as a comma-separated list. An
|
197
|
+
# empty list queries all locations.
|
198
|
+
# @param [String] cursor Optional parameter: A pagination cursor returned by
|
199
|
+
# a previous call to this endpoint. Provide this to retrieve the next set of
|
200
|
+
# results for the original query. See the
|
201
|
+
# [Pagination](https://developer.squareup.com/docs/docs/working-with-apis/pa
|
202
|
+
# gination) guide for more information.
|
203
|
+
# @return [RetrieveInventoryCountResponse Hash] response from the API call
|
204
|
+
def retrieve_inventory_count(catalog_object_id:,
|
205
|
+
location_ids: nil,
|
206
|
+
cursor: nil)
|
207
|
+
# Prepare query url.
|
208
|
+
_query_builder = config.get_base_uri
|
209
|
+
_query_builder << '/v2/inventory/{catalog_object_id}'
|
210
|
+
_query_builder = APIHelper.append_url_with_template_parameters(
|
211
|
+
_query_builder,
|
212
|
+
'catalog_object_id' => catalog_object_id
|
213
|
+
)
|
214
|
+
_query_builder = APIHelper.append_url_with_query_parameters(
|
215
|
+
_query_builder,
|
216
|
+
'location_ids' => location_ids,
|
217
|
+
'cursor' => cursor
|
218
|
+
)
|
219
|
+
_query_url = APIHelper.clean_url _query_builder
|
220
|
+
|
221
|
+
# Prepare headers.
|
222
|
+
_headers = {
|
223
|
+
'accept' => 'application/json'
|
224
|
+
}
|
225
|
+
|
226
|
+
# Prepare and execute HttpRequest.
|
227
|
+
_request = config.http_client.get(
|
228
|
+
_query_url,
|
229
|
+
headers: _headers
|
230
|
+
)
|
231
|
+
OAuth2.apply(config, _request)
|
232
|
+
_response = execute_request(_request)
|
233
|
+
|
234
|
+
# Return appropriate response type.
|
235
|
+
decoded = APIHelper.json_deserialize(_response.raw_body)
|
236
|
+
_errors = APIHelper.map_response(decoded, ['errors'])
|
237
|
+
ApiResponse.new(_response, data: decoded, errors: _errors)
|
238
|
+
end
|
239
|
+
|
240
|
+
# Returns a set of physical counts and inventory adjustments for the
|
241
|
+
# provided [CatalogObject](#type-catalogobject) at the requested
|
242
|
+
# [Location](#type-location)s.
|
243
|
+
# Results are paginated and sorted in descending order according to their
|
244
|
+
# `occurred_at` timestamp (newest first).
|
245
|
+
# There are no limits on how far back the caller can page. This endpoint is
|
246
|
+
# useful when displaying recent changes for a specific item. For more
|
247
|
+
# sophisticated queries, use a batch endpoint.
|
248
|
+
# @param [String] catalog_object_id Required parameter: ID of the
|
249
|
+
# [CatalogObject](#type-catalogobject) to retrieve.
|
250
|
+
# @param [String] location_ids Optional parameter: The
|
251
|
+
# [Location](#type-location) IDs to look up as a comma-separated list. An
|
252
|
+
# empty list queries all locations.
|
253
|
+
# @param [String] cursor Optional parameter: A pagination cursor returned by
|
254
|
+
# a previous call to this endpoint. Provide this to retrieve the next set of
|
255
|
+
# results for the original query. See the
|
256
|
+
# [Pagination](https://developer.squareup.com/docs/docs/working-with-apis/pa
|
257
|
+
# gination) guide for more information.
|
258
|
+
# @return [RetrieveInventoryChangesResponse Hash] response from the API call
|
259
|
+
def retrieve_inventory_changes(catalog_object_id:,
|
260
|
+
location_ids: nil,
|
261
|
+
cursor: nil)
|
262
|
+
# Prepare query url.
|
263
|
+
_query_builder = config.get_base_uri
|
264
|
+
_query_builder << '/v2/inventory/{catalog_object_id}/changes'
|
265
|
+
_query_builder = APIHelper.append_url_with_template_parameters(
|
266
|
+
_query_builder,
|
267
|
+
'catalog_object_id' => catalog_object_id
|
268
|
+
)
|
269
|
+
_query_builder = APIHelper.append_url_with_query_parameters(
|
270
|
+
_query_builder,
|
271
|
+
'location_ids' => location_ids,
|
272
|
+
'cursor' => cursor
|
273
|
+
)
|
274
|
+
_query_url = APIHelper.clean_url _query_builder
|
275
|
+
|
276
|
+
# Prepare headers.
|
277
|
+
_headers = {
|
278
|
+
'accept' => 'application/json'
|
279
|
+
}
|
280
|
+
|
281
|
+
# Prepare and execute HttpRequest.
|
282
|
+
_request = config.http_client.get(
|
283
|
+
_query_url,
|
284
|
+
headers: _headers
|
285
|
+
)
|
286
|
+
OAuth2.apply(config, _request)
|
287
|
+
_response = execute_request(_request)
|
288
|
+
|
289
|
+
# Return appropriate response type.
|
290
|
+
decoded = APIHelper.json_deserialize(_response.raw_body)
|
291
|
+
_errors = APIHelper.map_response(decoded, ['errors'])
|
292
|
+
ApiResponse.new(_response, data: decoded, errors: _errors)
|
293
|
+
end
|
294
|
+
end
|
295
|
+
end
|