square.rb 12.0.0.20210616 → 13.0.0.20210721
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 +4 -4
- data/lib/square.rb +1 -0
- data/lib/square/api/base_api.rb +1 -1
- data/lib/square/api/inventory_api.rb +244 -5
- data/lib/square/api/loyalty_api.rb +15 -5
- data/lib/square/api_helper.rb +0 -12
- data/lib/square/client.rb +2 -2
- data/lib/square/configuration.rb +1 -1
- data/lib/square/utilities/date_time_helper.rb +151 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0f0db97e9e88ea1a9f5f7f9db716b8f2ce36473400c34f57ec01622e2b0b584b
|
4
|
+
data.tar.gz: 999b75d8c4ded30c3895d6cecf97d18883a6018ec9b79a53b85f1bed20f56de4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2a74a9814e8d3d9edb5f9a36439c85f41c593f91941a3938c869b602b8fa65f2cf1ce6b115f43ed65c6a76ec6d36c8e237a5f855e3d12dbe90f6c906c9c7390d
|
7
|
+
data.tar.gz: a9d2ecd07e5616d2341b095519414007ab0e4bfc5159a90e3fb7e4b9d6337add73859641da52ccda4ee4bffb8ea39a59a37f487638c931f75c0ab1c77bb4dbce
|
data/lib/square.rb
CHANGED
data/lib/square/api/base_api.rb
CHANGED
@@ -5,6 +5,46 @@ module Square
|
|
5
5
|
super(config, http_call_back: http_call_back)
|
6
6
|
end
|
7
7
|
|
8
|
+
# Deprecated version of
|
9
|
+
# [RetrieveInventoryAdjustment]($e/Inventory/RetrieveInventoryAdjustment)
|
10
|
+
# after the endpoint URL
|
11
|
+
# is updated to conform to the standard convention.
|
12
|
+
# @param [String] adjustment_id Required parameter: ID of the
|
13
|
+
# [InventoryAdjustment]($m/InventoryAdjustment) to retrieve.
|
14
|
+
# @return [RetrieveInventoryAdjustmentResponse Hash] response from the API call
|
15
|
+
def deprecated_retrieve_inventory_adjustment(adjustment_id:)
|
16
|
+
warn 'Endpoint deprecated_retrieve_inventory_adjustment in InventoryApi '\
|
17
|
+
'is deprecated'
|
18
|
+
# Prepare query url.
|
19
|
+
_query_builder = config.get_base_uri
|
20
|
+
_query_builder << '/v2/inventory/adjustment/{adjustment_id}'
|
21
|
+
_query_builder = APIHelper.append_url_with_template_parameters(
|
22
|
+
_query_builder,
|
23
|
+
'adjustment_id' => { 'value' => adjustment_id, 'encode' => true }
|
24
|
+
)
|
25
|
+
_query_url = APIHelper.clean_url _query_builder
|
26
|
+
|
27
|
+
# Prepare headers.
|
28
|
+
_headers = {
|
29
|
+
'accept' => 'application/json'
|
30
|
+
}
|
31
|
+
|
32
|
+
# Prepare and execute HttpRequest.
|
33
|
+
_request = config.http_client.get(
|
34
|
+
_query_url,
|
35
|
+
headers: _headers
|
36
|
+
)
|
37
|
+
OAuth2.apply(config, _request)
|
38
|
+
_response = execute_request(_request)
|
39
|
+
|
40
|
+
# Return appropriate response type.
|
41
|
+
decoded = APIHelper.json_deserialize(_response.raw_body)
|
42
|
+
_errors = APIHelper.map_response(decoded, ['errors'])
|
43
|
+
ApiResponse.new(
|
44
|
+
_response, data: decoded, errors: _errors
|
45
|
+
)
|
46
|
+
end
|
47
|
+
|
8
48
|
# Returns the [InventoryAdjustment]($m/InventoryAdjustment) object
|
9
49
|
# with the provided `adjustment_id`.
|
10
50
|
# @param [String] adjustment_id Required parameter: ID of the
|
@@ -13,7 +53,7 @@ module Square
|
|
13
53
|
def retrieve_inventory_adjustment(adjustment_id:)
|
14
54
|
# Prepare query url.
|
15
55
|
_query_builder = config.get_base_uri
|
16
|
-
_query_builder << '/v2/inventory/
|
56
|
+
_query_builder << '/v2/inventory/adjustments/{adjustment_id}'
|
17
57
|
_query_builder = APIHelper.append_url_with_template_parameters(
|
18
58
|
_query_builder,
|
19
59
|
'adjustment_id' => { 'value' => adjustment_id, 'encode' => true }
|
@@ -41,6 +81,123 @@ module Square
|
|
41
81
|
)
|
42
82
|
end
|
43
83
|
|
84
|
+
# Deprecated version of
|
85
|
+
# [BatchChangeInventory]($e/Inventory/BatchChangeInventory) after the
|
86
|
+
# endpoint URL
|
87
|
+
# is updated to conform to the standard convention.
|
88
|
+
# @param [BatchChangeInventoryRequest] body Required parameter: An object
|
89
|
+
# containing the fields to POST for the request. See the corresponding
|
90
|
+
# object definition for field details.
|
91
|
+
# @return [BatchChangeInventoryResponse Hash] response from the API call
|
92
|
+
def deprecated_batch_change_inventory(body:)
|
93
|
+
warn 'Endpoint deprecated_batch_change_inventory in InventoryApi is depr'\
|
94
|
+
'ecated'
|
95
|
+
# Prepare query url.
|
96
|
+
_query_builder = config.get_base_uri
|
97
|
+
_query_builder << '/v2/inventory/batch-change'
|
98
|
+
_query_url = APIHelper.clean_url _query_builder
|
99
|
+
|
100
|
+
# Prepare headers.
|
101
|
+
_headers = {
|
102
|
+
'accept' => 'application/json',
|
103
|
+
'content-type' => 'application/json; charset=utf-8'
|
104
|
+
}
|
105
|
+
|
106
|
+
# Prepare and execute HttpRequest.
|
107
|
+
_request = config.http_client.post(
|
108
|
+
_query_url,
|
109
|
+
headers: _headers,
|
110
|
+
parameters: body.to_json
|
111
|
+
)
|
112
|
+
OAuth2.apply(config, _request)
|
113
|
+
_response = execute_request(_request)
|
114
|
+
|
115
|
+
# Return appropriate response type.
|
116
|
+
decoded = APIHelper.json_deserialize(_response.raw_body)
|
117
|
+
_errors = APIHelper.map_response(decoded, ['errors'])
|
118
|
+
ApiResponse.new(
|
119
|
+
_response, data: decoded, errors: _errors
|
120
|
+
)
|
121
|
+
end
|
122
|
+
|
123
|
+
# Deprecated version of
|
124
|
+
# [BatchRetrieveInventoryChanges]($e/Inventory/BatchRetrieveInventoryChanges
|
125
|
+
# ) after the endpoint URL
|
126
|
+
# is updated to conform to the standard convention.
|
127
|
+
# @param [BatchRetrieveInventoryChangesRequest] body Required parameter: An
|
128
|
+
# object containing the fields to POST for the request. See the
|
129
|
+
# corresponding object definition for field details.
|
130
|
+
# @return [BatchRetrieveInventoryChangesResponse Hash] response from the API call
|
131
|
+
def deprecated_batch_retrieve_inventory_changes(body:)
|
132
|
+
warn 'Endpoint deprecated_batch_retrieve_inventory_changes in InventoryA'\
|
133
|
+
'pi is deprecated'
|
134
|
+
# Prepare query url.
|
135
|
+
_query_builder = config.get_base_uri
|
136
|
+
_query_builder << '/v2/inventory/batch-retrieve-changes'
|
137
|
+
_query_url = APIHelper.clean_url _query_builder
|
138
|
+
|
139
|
+
# Prepare headers.
|
140
|
+
_headers = {
|
141
|
+
'accept' => 'application/json',
|
142
|
+
'content-type' => 'application/json; charset=utf-8'
|
143
|
+
}
|
144
|
+
|
145
|
+
# Prepare and execute HttpRequest.
|
146
|
+
_request = config.http_client.post(
|
147
|
+
_query_url,
|
148
|
+
headers: _headers,
|
149
|
+
parameters: body.to_json
|
150
|
+
)
|
151
|
+
OAuth2.apply(config, _request)
|
152
|
+
_response = execute_request(_request)
|
153
|
+
|
154
|
+
# Return appropriate response type.
|
155
|
+
decoded = APIHelper.json_deserialize(_response.raw_body)
|
156
|
+
_errors = APIHelper.map_response(decoded, ['errors'])
|
157
|
+
ApiResponse.new(
|
158
|
+
_response, data: decoded, errors: _errors
|
159
|
+
)
|
160
|
+
end
|
161
|
+
|
162
|
+
# Deprecated version of
|
163
|
+
# [BatchRetrieveInventoryCounts]($e/Inventory/BatchRetrieveInventoryCounts)
|
164
|
+
# after the endpoint URL
|
165
|
+
# is updated to conform to the standard convention.
|
166
|
+
# @param [BatchRetrieveInventoryCountsRequest] body Required parameter: An
|
167
|
+
# object containing the fields to POST for the request. See the
|
168
|
+
# corresponding object definition for field details.
|
169
|
+
# @return [BatchRetrieveInventoryCountsResponse Hash] response from the API call
|
170
|
+
def deprecated_batch_retrieve_inventory_counts(body:)
|
171
|
+
warn 'Endpoint deprecated_batch_retrieve_inventory_counts in InventoryAp'\
|
172
|
+
'i is deprecated'
|
173
|
+
# Prepare query url.
|
174
|
+
_query_builder = config.get_base_uri
|
175
|
+
_query_builder << '/v2/inventory/batch-retrieve-counts'
|
176
|
+
_query_url = APIHelper.clean_url _query_builder
|
177
|
+
|
178
|
+
# Prepare headers.
|
179
|
+
_headers = {
|
180
|
+
'accept' => 'application/json',
|
181
|
+
'content-type' => 'application/json; charset=utf-8'
|
182
|
+
}
|
183
|
+
|
184
|
+
# Prepare and execute HttpRequest.
|
185
|
+
_request = config.http_client.post(
|
186
|
+
_query_url,
|
187
|
+
headers: _headers,
|
188
|
+
parameters: body.to_json
|
189
|
+
)
|
190
|
+
OAuth2.apply(config, _request)
|
191
|
+
_response = execute_request(_request)
|
192
|
+
|
193
|
+
# Return appropriate response type.
|
194
|
+
decoded = APIHelper.json_deserialize(_response.raw_body)
|
195
|
+
_errors = APIHelper.map_response(decoded, ['errors'])
|
196
|
+
ApiResponse.new(
|
197
|
+
_response, data: decoded, errors: _errors
|
198
|
+
)
|
199
|
+
end
|
200
|
+
|
44
201
|
# Applies adjustments and counts to the provided item quantities.
|
45
202
|
# On success: returns the current calculated counts for all objects
|
46
203
|
# referenced in the request.
|
@@ -52,7 +209,7 @@ module Square
|
|
52
209
|
def batch_change_inventory(body:)
|
53
210
|
# Prepare query url.
|
54
211
|
_query_builder = config.get_base_uri
|
55
|
-
_query_builder << '/v2/inventory/batch-
|
212
|
+
_query_builder << '/v2/inventory/changes/batch-create'
|
56
213
|
_query_url = APIHelper.clean_url _query_builder
|
57
214
|
|
58
215
|
# Prepare headers.
|
@@ -91,7 +248,7 @@ module Square
|
|
91
248
|
def batch_retrieve_inventory_changes(body:)
|
92
249
|
# Prepare query url.
|
93
250
|
_query_builder = config.get_base_uri
|
94
|
-
_query_builder << '/v2/inventory/batch-retrieve
|
251
|
+
_query_builder << '/v2/inventory/changes/batch-retrieve'
|
95
252
|
_query_url = APIHelper.clean_url _query_builder
|
96
253
|
|
97
254
|
# Prepare headers.
|
@@ -134,7 +291,7 @@ module Square
|
|
134
291
|
def batch_retrieve_inventory_counts(body:)
|
135
292
|
# Prepare query url.
|
136
293
|
_query_builder = config.get_base_uri
|
137
|
-
_query_builder << '/v2/inventory/batch-retrieve
|
294
|
+
_query_builder << '/v2/inventory/counts/batch-retrieve'
|
138
295
|
_query_url = APIHelper.clean_url _query_builder
|
139
296
|
|
140
297
|
# Prepare headers.
|
@@ -160,6 +317,46 @@ module Square
|
|
160
317
|
)
|
161
318
|
end
|
162
319
|
|
320
|
+
# Deprecated version of
|
321
|
+
# [RetrieveInventoryPhysicalCount]($e/Inventory/RetrieveInventoryPhysicalCou
|
322
|
+
# nt) after the endpoint URL
|
323
|
+
# is updated to conform to the standard convention.
|
324
|
+
# @param [String] physical_count_id Required parameter: ID of the
|
325
|
+
# [InventoryPhysicalCount]($m/InventoryPhysicalCount) to retrieve.
|
326
|
+
# @return [RetrieveInventoryPhysicalCountResponse Hash] response from the API call
|
327
|
+
def deprecated_retrieve_inventory_physical_count(physical_count_id:)
|
328
|
+
warn 'Endpoint deprecated_retrieve_inventory_physical_count in Inventory'\
|
329
|
+
'Api is deprecated'
|
330
|
+
# Prepare query url.
|
331
|
+
_query_builder = config.get_base_uri
|
332
|
+
_query_builder << '/v2/inventory/physical-count/{physical_count_id}'
|
333
|
+
_query_builder = APIHelper.append_url_with_template_parameters(
|
334
|
+
_query_builder,
|
335
|
+
'physical_count_id' => { 'value' => physical_count_id, 'encode' => true }
|
336
|
+
)
|
337
|
+
_query_url = APIHelper.clean_url _query_builder
|
338
|
+
|
339
|
+
# Prepare headers.
|
340
|
+
_headers = {
|
341
|
+
'accept' => 'application/json'
|
342
|
+
}
|
343
|
+
|
344
|
+
# Prepare and execute HttpRequest.
|
345
|
+
_request = config.http_client.get(
|
346
|
+
_query_url,
|
347
|
+
headers: _headers
|
348
|
+
)
|
349
|
+
OAuth2.apply(config, _request)
|
350
|
+
_response = execute_request(_request)
|
351
|
+
|
352
|
+
# Return appropriate response type.
|
353
|
+
decoded = APIHelper.json_deserialize(_response.raw_body)
|
354
|
+
_errors = APIHelper.map_response(decoded, ['errors'])
|
355
|
+
ApiResponse.new(
|
356
|
+
_response, data: decoded, errors: _errors
|
357
|
+
)
|
358
|
+
end
|
359
|
+
|
163
360
|
# Returns the [InventoryPhysicalCount]($m/InventoryPhysicalCount)
|
164
361
|
# object with the provided `physical_count_id`.
|
165
362
|
# @param [String] physical_count_id Required parameter: ID of the
|
@@ -168,7 +365,7 @@ module Square
|
|
168
365
|
def retrieve_inventory_physical_count(physical_count_id:)
|
169
366
|
# Prepare query url.
|
170
367
|
_query_builder = config.get_base_uri
|
171
|
-
_query_builder << '/v2/inventory/physical-
|
368
|
+
_query_builder << '/v2/inventory/physical-counts/{physical_count_id}'
|
172
369
|
_query_builder = APIHelper.append_url_with_template_parameters(
|
173
370
|
_query_builder,
|
174
371
|
'physical_count_id' => { 'value' => physical_count_id, 'encode' => true }
|
@@ -196,6 +393,42 @@ module Square
|
|
196
393
|
)
|
197
394
|
end
|
198
395
|
|
396
|
+
# Returns the [InventoryTransfer]($m/InventoryTransfer) object
|
397
|
+
# with the provided `transfer_id`.
|
398
|
+
# @param [String] transfer_id Required parameter: ID of the
|
399
|
+
# [InventoryTransfer]($m/InventoryTransfer) to retrieve.
|
400
|
+
# @return [RetrieveInventoryTransferResponse Hash] response from the API call
|
401
|
+
def retrieve_inventory_transfer(transfer_id:)
|
402
|
+
# Prepare query url.
|
403
|
+
_query_builder = config.get_base_uri
|
404
|
+
_query_builder << '/v2/inventory/transfers/{transfer_id}'
|
405
|
+
_query_builder = APIHelper.append_url_with_template_parameters(
|
406
|
+
_query_builder,
|
407
|
+
'transfer_id' => { 'value' => transfer_id, 'encode' => true }
|
408
|
+
)
|
409
|
+
_query_url = APIHelper.clean_url _query_builder
|
410
|
+
|
411
|
+
# Prepare headers.
|
412
|
+
_headers = {
|
413
|
+
'accept' => 'application/json'
|
414
|
+
}
|
415
|
+
|
416
|
+
# Prepare and execute HttpRequest.
|
417
|
+
_request = config.http_client.get(
|
418
|
+
_query_url,
|
419
|
+
headers: _headers
|
420
|
+
)
|
421
|
+
OAuth2.apply(config, _request)
|
422
|
+
_response = execute_request(_request)
|
423
|
+
|
424
|
+
# Return appropriate response type.
|
425
|
+
decoded = APIHelper.json_deserialize(_response.raw_body)
|
426
|
+
_errors = APIHelper.map_response(decoded, ['errors'])
|
427
|
+
ApiResponse.new(
|
428
|
+
_response, data: decoded, errors: _errors
|
429
|
+
)
|
430
|
+
end
|
431
|
+
|
199
432
|
# Retrieves the current calculated stock count for a given
|
200
433
|
# [CatalogObject]($m/CatalogObject) at a given set of
|
201
434
|
# [Location]($m/Location)s. Responses are paginated and unsorted.
|
@@ -252,6 +485,11 @@ module Square
|
|
252
485
|
# Returns a set of physical counts and inventory adjustments for the
|
253
486
|
# provided [CatalogObject]($m/CatalogObject) at the requested
|
254
487
|
# [Location]($m/Location)s.
|
488
|
+
# You can achieve the same result by calling
|
489
|
+
# [BatchRetrieveInventoryChanges]($e/Inventory/BatchRetrieveInventoryChanges
|
490
|
+
# )
|
491
|
+
# and having the `catalog_object_ids` list contain a single element of the
|
492
|
+
# `CatalogObject` ID.
|
255
493
|
# Results are paginated and sorted in descending order according to their
|
256
494
|
# `occurred_at` timestamp (newest first).
|
257
495
|
# There are no limits on how far back the caller can page. This endpoint can
|
@@ -272,6 +510,7 @@ module Square
|
|
272
510
|
def retrieve_inventory_changes(catalog_object_id:,
|
273
511
|
location_ids: nil,
|
274
512
|
cursor: nil)
|
513
|
+
warn 'Endpoint retrieve_inventory_changes in InventoryApi is deprecated'
|
275
514
|
# Prepare query url.
|
276
515
|
_query_builder = config.get_base_uri
|
277
516
|
_query_builder << '/v2/inventory/{catalog_object_id}/changes'
|
@@ -120,12 +120,16 @@ module Square
|
|
120
120
|
# account.
|
121
121
|
# - If you are not using the Orders API to manage orders,
|
122
122
|
# you first perform a client-side computation to compute the points.
|
123
|
-
# For spend-based and visit-based programs, you can call
|
123
|
+
# For spend-based and visit-based programs, you can first call
|
124
124
|
# [CalculateLoyaltyPoints]($e/Loyalty/CalculateLoyaltyPoints) to compute the
|
125
|
-
# points
|
126
|
-
#
|
127
|
-
#
|
128
|
-
#
|
125
|
+
# points
|
126
|
+
# that you provide to this endpoint.
|
127
|
+
# __Note:__ The country of the seller's Square account determines whether
|
128
|
+
# tax is included in the purchase amount when accruing points for
|
129
|
+
# spend-based and visit-based programs.
|
130
|
+
# For more information, see [Availability of Square
|
131
|
+
# Loyalty](https://developer.squareup.com/docs/loyalty-api/overview#loyalty-
|
132
|
+
# market-availability).
|
129
133
|
# @param [String] account_id Required parameter: The [loyalty
|
130
134
|
# account]($m/LoyaltyAccount) ID to which to add the points.
|
131
135
|
# @param [AccumulateLoyaltyPointsRequest] body Required parameter: An object
|
@@ -341,6 +345,12 @@ module Square
|
|
341
345
|
# An application might call this endpoint to show the points that a buyer
|
342
346
|
# can earn with the
|
343
347
|
# specific purchase.
|
348
|
+
# __Note:__ The country of the seller's Square account determines whether
|
349
|
+
# tax is included in the purchase amount when accruing points for
|
350
|
+
# spend-based and visit-based programs.
|
351
|
+
# For more information, see [Availability of Square
|
352
|
+
# Loyalty](https://developer.squareup.com/docs/loyalty-api/overview#loyalty-
|
353
|
+
# market-availability).
|
344
354
|
# @param [String] program_id Required parameter: The [loyalty
|
345
355
|
# program]($m/LoyaltyProgram) ID, which defines the rules for accruing
|
346
356
|
# points.
|
data/lib/square/api_helper.rb
CHANGED
@@ -265,17 +265,5 @@ module Square
|
|
265
265
|
end
|
266
266
|
val
|
267
267
|
end
|
268
|
-
|
269
|
-
# Safely converts a string into an rfc3339 DateTime object
|
270
|
-
# @param [String] The datetime string
|
271
|
-
# @return [DateTime] A DateTime object of rfc3339 format
|
272
|
-
def self.rfc3339(date_time)
|
273
|
-
# missing timezone information
|
274
|
-
if date_time.end_with?('Z') || date_time.index('+')
|
275
|
-
DateTime.rfc3339(date_time)
|
276
|
-
else
|
277
|
-
DateTime.rfc3339(date_time + 'Z')
|
278
|
-
end
|
279
|
-
end
|
280
268
|
end
|
281
269
|
end
|
data/lib/square/client.rb
CHANGED
@@ -4,7 +4,7 @@ module Square
|
|
4
4
|
attr_reader :config
|
5
5
|
|
6
6
|
def sdk_version
|
7
|
-
'
|
7
|
+
'13.0.0.20210721'
|
8
8
|
end
|
9
9
|
|
10
10
|
def square_version
|
@@ -220,7 +220,7 @@ module Square
|
|
220
220
|
retry_statuses: [408, 413, 429, 500, 502, 503, 504, 521, 522, 524],
|
221
221
|
retry_methods: %i[get put], environment: 'production',
|
222
222
|
custom_url: 'https://connect.squareup.com',
|
223
|
-
square_version: '2021-
|
223
|
+
square_version: '2021-07-21', access_token: 'TODO: Replace',
|
224
224
|
additional_headers: {}, config: nil)
|
225
225
|
@config = if config.nil?
|
226
226
|
Configuration.new(timeout: timeout, max_retries: max_retries,
|
data/lib/square/configuration.rb
CHANGED
@@ -28,7 +28,7 @@ module Square
|
|
28
28
|
retry_statuses: [408, 413, 429, 500, 502, 503, 504, 521, 522, 524],
|
29
29
|
retry_methods: %i[get put], environment: 'production',
|
30
30
|
custom_url: 'https://connect.squareup.com',
|
31
|
-
square_version: '2021-
|
31
|
+
square_version: '2021-07-21', access_token: 'TODO: Replace',
|
32
32
|
additional_headers: {})
|
33
33
|
# The value to use for connection timeout
|
34
34
|
@timeout = timeout
|
@@ -0,0 +1,151 @@
|
|
1
|
+
require 'date'
|
2
|
+
module Square
|
3
|
+
# A utility that supports dateTime conversion to different formats
|
4
|
+
class DateTimeHelper
|
5
|
+
# Safely converts a DateTime object into a rfc1123 format string
|
6
|
+
# @param [DateTime] The DateTime object
|
7
|
+
# @return [String] The rfc1123 formatted datetime string
|
8
|
+
def self.to_rfc1123(date_time)
|
9
|
+
date_time.httpdate unless date_time.nil?
|
10
|
+
end
|
11
|
+
|
12
|
+
# Safely converts a map of DateTime objects into a map of rfc1123 format string
|
13
|
+
# @param [hash] a map of DateTime objects
|
14
|
+
# @return [hash] a map of rfc1123 formatted datetime string
|
15
|
+
def self.to_rfc1123_map(date_time, hash, key)
|
16
|
+
return if date_time.nil?
|
17
|
+
|
18
|
+
hash[key] = {}
|
19
|
+
date_time.each do |k, v|
|
20
|
+
hash[key][k] =
|
21
|
+
if v.is_a?(BaseModel)
|
22
|
+
v.to_hash
|
23
|
+
else
|
24
|
+
v.is_a?(DateTime) ? DateTimeHelper.to_rfc1123(v) : v
|
25
|
+
end
|
26
|
+
end
|
27
|
+
hash[key]
|
28
|
+
end
|
29
|
+
|
30
|
+
# Safely converts an array of DateTime objects into an array of rfc1123 format string
|
31
|
+
# @param [Array] an array of DateTime objects
|
32
|
+
# @return [Array] an array of rfc1123 formatted datetime string
|
33
|
+
def self.to_rfc1123_array(date_time, hash, key)
|
34
|
+
return if date_time.nil?
|
35
|
+
|
36
|
+
hash[key] = date_time.map do |v|
|
37
|
+
if v.is_a?(BaseModel)
|
38
|
+
v.to_hash
|
39
|
+
else
|
40
|
+
v.is_a?(DateTime) ? DateTimeHelper.to_rfc1123(v) : v
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
# Safely converts a DateTime object into a unix format string
|
46
|
+
# @param [DateTime] The DateTime object
|
47
|
+
# @return [String] The unix formatted datetime string
|
48
|
+
def self.to_unix(date_time)
|
49
|
+
date_time.to_time.utc.to_i unless date_time.nil?
|
50
|
+
end
|
51
|
+
|
52
|
+
# Safely converts a map of DateTime objects into a map of unix format string
|
53
|
+
# @param [hash] a map of DateTime objects
|
54
|
+
# @return [hash] a map of unix formatted datetime string
|
55
|
+
def self.to_unix_map(date_time, hash, key)
|
56
|
+
return if date_time.nil?
|
57
|
+
|
58
|
+
hash[key] = {}
|
59
|
+
date_time.each do |k, v|
|
60
|
+
hash[key][k] =
|
61
|
+
if v.is_a?(BaseModel)
|
62
|
+
v.to_hash
|
63
|
+
else
|
64
|
+
v.is_a?(DateTime) ? DateTimeHelper.to_unix(v) : v
|
65
|
+
end
|
66
|
+
end
|
67
|
+
hash[key]
|
68
|
+
end
|
69
|
+
|
70
|
+
# Safely converts an array of DateTime objects into a map of unix format string
|
71
|
+
# @param [hash] an array of DateTime objects
|
72
|
+
# @return [hash] an array of unix formatted datetime string
|
73
|
+
def self.to_unix_array(date_time, hash, key)
|
74
|
+
return if date_time.nil?
|
75
|
+
|
76
|
+
hash[key] = date_time.map do |v|
|
77
|
+
if v.is_a?(BaseModel)
|
78
|
+
v.to_hash
|
79
|
+
else
|
80
|
+
v.is_a?(DateTime) ? DateTimeHelper.to_unix(v) : v
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
# Safely converts a DateTime object into a rfc3339 format string
|
86
|
+
# @param [DateTime] The DateTime object
|
87
|
+
# @return [String] The rfc3339 formatted datetime string
|
88
|
+
def self.to_rfc3339(date_time)
|
89
|
+
date_time.rfc3339 unless date_time.nil?
|
90
|
+
end
|
91
|
+
|
92
|
+
# Safely converts a map of DateTime objects into a map of rfc1123 format string
|
93
|
+
# @param [hash] a map of DateTime objects
|
94
|
+
# @return [hash] a map of rfc1123 formatted datetime string
|
95
|
+
def self.to_rfc3339_map(date_time, hash, key)
|
96
|
+
return if date_time.nil?
|
97
|
+
|
98
|
+
hash[key] = {}
|
99
|
+
date_time.each do |k, v|
|
100
|
+
hash[key][k] =
|
101
|
+
if v.is_a?(BaseModel)
|
102
|
+
v.to_hash
|
103
|
+
else
|
104
|
+
v.is_a?(DateTime) ? DateTimeHelper.to_rfc3339(v) : v
|
105
|
+
end
|
106
|
+
end
|
107
|
+
hash[key]
|
108
|
+
end
|
109
|
+
|
110
|
+
# Safely converts an array of DateTime objects into an array of rfc1123 format string
|
111
|
+
# @param [Array] an array of DateTime objects
|
112
|
+
# @return [Array] an array of rfc1123 formatted datetime string
|
113
|
+
def self.to_rfc3339_array(date_time, hash, key)
|
114
|
+
return if date_time.nil?
|
115
|
+
|
116
|
+
hash[key] = date_time.map do |v|
|
117
|
+
if v.is_a?(BaseModel)
|
118
|
+
v.to_hash
|
119
|
+
else
|
120
|
+
v.is_a?(DateTime) ? DateTimeHelper.to_rfc3339(v) : v
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
# Safely converts a rfc1123 format string into a DateTime object
|
126
|
+
# @param [String] The rfc1123 formatted datetime string
|
127
|
+
# @return [DateTime] A DateTime object
|
128
|
+
def self.from_rfc1123(date_time)
|
129
|
+
DateTime.httpdate(date_time)
|
130
|
+
end
|
131
|
+
|
132
|
+
# Safely converts a unix format string into a DateTime object
|
133
|
+
# @param [String] The unix formatted datetime string
|
134
|
+
# @return [DateTime] A DateTime object
|
135
|
+
def self.from_unix(date_time)
|
136
|
+
Time.at(date_time.to_i).utc.to_datetime
|
137
|
+
end
|
138
|
+
|
139
|
+
# Safely converts a rfc3339 format string into a DateTime object
|
140
|
+
# @param [String] The rfc3339 formatted datetime string
|
141
|
+
# @return [DateTime] A DateTime object
|
142
|
+
def self.from_rfc3339(date_time)
|
143
|
+
# missing timezone information
|
144
|
+
if date_time.end_with?('Z') || date_time.index('+')
|
145
|
+
DateTime.rfc3339(date_time)
|
146
|
+
else
|
147
|
+
DateTime.rfc3339("#{date_time}Z")
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: square.rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 13.0.0.20210721
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Square Developer Platform
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-07-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: logging
|
@@ -183,6 +183,7 @@ files:
|
|
183
183
|
- lib/square/http/http_method_enum.rb
|
184
184
|
- lib/square/http/http_request.rb
|
185
185
|
- lib/square/http/http_response.rb
|
186
|
+
- lib/square/utilities/date_time_helper.rb
|
186
187
|
- lib/square/utilities/file_wrapper.rb
|
187
188
|
- spec/user_journey_spec.rb
|
188
189
|
- test/api/api_test_base.rb
|