square.rb 20.0.0.20220512 → 21.1.0.20220720
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/square/api/base_api.rb +8 -1
- data/lib/square/api/bookings_api.rb +3 -3
- data/lib/square/api/cards_api.rb +3 -2
- data/lib/square/api/catalog_api.rb +25 -25
- data/lib/square/api/customer_custom_attributes_api.rb +12 -12
- data/lib/square/api/customers_api.rb +1 -1
- data/lib/square/api/gift_cards_api.rb +2 -1
- data/lib/square/api/loyalty_api.rb +3 -2
- data/lib/square/api/orders_api.rb +2 -2
- data/lib/square/api/payments_api.rb +1 -1
- data/lib/square/api/terminal_api.rb +1 -3
- data/lib/square/api/v1_transactions_api.rb +4 -4
- data/lib/square/api_helper.rb +176 -4
- data/lib/square/client.rb +6 -6
- data/lib/square/configuration.rb +16 -11
- data/lib/square/exceptions/validation_exception.rb +13 -0
- data/lib/square/http/api_response.rb +7 -9
- data/lib/square/http/faraday_client.rb +5 -4
- data/lib/square.rb +1 -0
- data/test/test_helper.rb +1 -1
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6b796ded54a09909000ce7bec6e21f330eff83acd4f858e69d7117c111c559ab
|
4
|
+
data.tar.gz: b84c503fac9be2866d23b77d9c2db26b4ccc67f3bb869a116c8072baae6177ef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5aca939812e70ddf5e3613aad5864a7d8840113800cdf75a2b683a211df65d235b88be2426f8ae88d6de1c25f3126197bc37a2b14dc6611321bb890862b2408b
|
7
|
+
data.tar.gz: 5a0807787411142d1bee04db39e0e6d835611620d6f7bb00e8ea65e60d7e26e1dad34bb4ff3bf9ee4ce36fff09232d983c1ae124e16d91651ee24e5ca247273a
|
data/lib/square/api/base_api.rb
CHANGED
@@ -20,6 +20,13 @@ module Square
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
+
def validate_parameters_types(args)
|
24
|
+
args.each do |_name, type|
|
25
|
+
key, val = type.first
|
26
|
+
APIHelper.validate_types(key, val) unless key.nil?
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
23
30
|
def execute_request(request, binary: false)
|
24
31
|
@http_call_back&.on_before_request(request)
|
25
32
|
|
@@ -38,7 +45,7 @@ module Square
|
|
38
45
|
end
|
39
46
|
|
40
47
|
def get_user_agent
|
41
|
-
user_agent = 'Square-Ruby-SDK/
|
48
|
+
user_agent = 'Square-Ruby-SDK/21.1.0.20220720 ({api-version}) {engine}/{engine-version} ({os-info}) {detail}'
|
42
49
|
user_agent['{engine}'] = RUBY_ENGINE
|
43
50
|
user_agent['{engine-version}'] = RUBY_ENGINE_VERSION
|
44
51
|
user_agent['{os-info}'] = RUBY_PLATFORM
|
@@ -178,9 +178,9 @@ module Square
|
|
178
178
|
end
|
179
179
|
|
180
180
|
# Lists booking profiles for team members.
|
181
|
-
# @param [
|
182
|
-
# include only bookable team members in the returned result
|
183
|
-
# (`false`).
|
181
|
+
# @param [TrueClass|FalseClass] bookable_only Optional parameter: Indicates
|
182
|
+
# whether to include only bookable team members in the returned result
|
183
|
+
# (`true`) or not (`false`).
|
184
184
|
# @param [Integer] limit Optional parameter: The maximum number of results
|
185
185
|
# to return in a paged response.
|
186
186
|
# @param [String] cursor Optional parameter: The pagination cursor from the
|
data/lib/square/api/cards_api.rb
CHANGED
@@ -15,8 +15,9 @@ module Square
|
|
15
15
|
# @param [String] customer_id Optional parameter: Limit results to cards
|
16
16
|
# associated with the customer supplied. By default, all cards owned by the
|
17
17
|
# merchant are returned.
|
18
|
-
# @param [
|
19
|
-
# cards. By default, all enabled cards owned by the
|
18
|
+
# @param [TrueClass|FalseClass] include_disabled Optional parameter:
|
19
|
+
# Includes disabled cards. By default, all enabled cards owned by the
|
20
|
+
# merchant are returned.
|
20
21
|
# @param [String] reference_id Optional parameter: Limit results to cards
|
21
22
|
# associated with the reference_id supplied.
|
22
23
|
# @param [SortOrder] sort_order Optional parameter: Sorts the returned list
|
@@ -316,11 +316,11 @@ module Square
|
|
316
316
|
# Square API used to make the request. Object types that are nested onto
|
317
317
|
# other object types are not included in the defaults. At the current API
|
318
318
|
# version the default object types are: ITEM, CATEGORY, TAX, DISCOUNT,
|
319
|
-
# MODIFIER_LIST,
|
320
|
-
#
|
321
|
-
#
|
322
|
-
# @param [
|
323
|
-
# the catalog objects to be included in the response. This allows you to
|
319
|
+
# MODIFIER_LIST, PRICING_RULE, PRODUCT_SET, TIME_PERIOD, MEASUREMENT_UNIT,
|
320
|
+
# SUBSCRIPTION_PLAN, ITEM_OPTION, CUSTOM_ATTRIBUTE_DEFINITION,
|
321
|
+
# QUICK_AMOUNT_SETTINGS.
|
322
|
+
# @param [Integer] catalog_version Optional parameter: The specific version
|
323
|
+
# of the catalog objects to be included in the response. This allows you to
|
324
324
|
# retrieve historical versions of objects. The specified version value is
|
325
325
|
# matched against the [CatalogObject]($m/CatalogObject)s' `version`
|
326
326
|
# attribute. If not included, results will be from the current version of
|
@@ -448,26 +448,26 @@ module Square
|
|
448
448
|
# any [CatalogTax]($m/CatalogTax) objects that apply to it.
|
449
449
|
# @param [String] object_id Required parameter: The object ID of any type of
|
450
450
|
# catalog objects to be retrieved.
|
451
|
-
# @param [
|
452
|
-
# the response will include additional objects that are related
|
453
|
-
# requested objects. Related objects are defined as any objects
|
454
|
-
# by ID by the results in the `objects` field of the response.
|
455
|
-
# are put in the `related_objects` field. Setting this to
|
456
|
-
# when the objects are needed for immediate display to a
|
457
|
-
# only goes one level deep. Objects referenced by the
|
458
|
-
# not be included. For example, if the `objects` field
|
459
|
-
# contains a CatalogItem, its associated CatalogCategory
|
460
|
-
# objects, CatalogImage objects and CatalogModifierLists
|
461
|
-
# the `related_objects` field of the response. If the
|
462
|
-
# response contains a CatalogItemVariation, its
|
463
|
-
# returned in the `related_objects` field of the
|
464
|
-
# `false`
|
465
|
-
# @param [
|
466
|
-
# specific version of the catalog. This allows you to retrieve
|
467
|
-
# versions of objects. The value to retrieve a specific version
|
468
|
-
# can be found in the version field of
|
469
|
-
# If not included, results will be from
|
470
|
-
# catalog.
|
451
|
+
# @param [TrueClass|FalseClass] include_related_objects Optional parameter:
|
452
|
+
# If `true`, the response will include additional objects that are related
|
453
|
+
# to the requested objects. Related objects are defined as any objects
|
454
|
+
# referenced by ID by the results in the `objects` field of the response.
|
455
|
+
# These objects are put in the `related_objects` field. Setting this to
|
456
|
+
# `true` is helpful when the objects are needed for immediate display to a
|
457
|
+
# user. This process only goes one level deep. Objects referenced by the
|
458
|
+
# related objects will not be included. For example, if the `objects` field
|
459
|
+
# of the response contains a CatalogItem, its associated CatalogCategory
|
460
|
+
# objects, CatalogTax objects, CatalogImage objects and CatalogModifierLists
|
461
|
+
# will be returned in the `related_objects` field of the response. If the
|
462
|
+
# `objects` field of the response contains a CatalogItemVariation, its
|
463
|
+
# parent CatalogItem will be returned in the `related_objects` field of the
|
464
|
+
# response. Default value: `false`
|
465
|
+
# @param [Integer] catalog_version Optional parameter: Requests objects as
|
466
|
+
# of a specific version of the catalog. This allows you to retrieve
|
467
|
+
# historical versions of objects. The value to retrieve a specific version
|
468
|
+
# of an object can be found in the version field of
|
469
|
+
# [CatalogObject]($m/CatalogObject)s. If not included, results will be from
|
470
|
+
# the current version of the catalog.
|
471
471
|
# @return [RetrieveCatalogObjectResponse Hash] response from the API call
|
472
472
|
def retrieve_catalog_object(object_id:,
|
473
473
|
include_related_objects: false,
|
@@ -323,12 +323,12 @@ module Square
|
|
323
323
|
# more information, see
|
324
324
|
# [Pagination](https://developer.squareup.com/docs/build-basics/common-api-p
|
325
325
|
# atterns/pagination).
|
326
|
-
# @param [
|
327
|
-
# return the [custom attribute
|
328
|
-
# the `definition` field of
|
329
|
-
# `true` to get the name and
|
330
|
-
# information about the data type, or
|
331
|
-
# value is `false`.
|
326
|
+
# @param [TrueClass|FalseClass] with_definitions Optional parameter:
|
327
|
+
# Indicates whether to return the [custom attribute
|
328
|
+
# definition]($m/CustomAttributeDefinition) in the `definition` field of
|
329
|
+
# each custom attribute. Set this parameter to `true` to get the name and
|
330
|
+
# description of each custom attribute, information about the data type, or
|
331
|
+
# other definition details. The default value is `false`.
|
332
332
|
# @return [ListCustomerCustomAttributesResponse Hash] response from the API call
|
333
333
|
def list_customer_custom_attributes(customer_id:,
|
334
334
|
limit: nil,
|
@@ -427,12 +427,12 @@ module Square
|
|
427
427
|
# retrieve. This key must match the `key` of a custom attribute definition
|
428
428
|
# in the Square seller account. If the requesting application is not the
|
429
429
|
# definition owner, you must use the qualified key.
|
430
|
-
# @param [
|
431
|
-
# return the [custom attribute
|
432
|
-
# the `definition` field of the
|
433
|
-
# `true` to get the name and
|
434
|
-
# information about the data type, or
|
435
|
-
# value is `false`.
|
430
|
+
# @param [TrueClass|FalseClass] with_definition Optional parameter:
|
431
|
+
# Indicates whether to return the [custom attribute
|
432
|
+
# definition]($m/CustomAttributeDefinition) in the `definition` field of the
|
433
|
+
# custom attribute. Set this parameter to `true` to get the name and
|
434
|
+
# description of the custom attribute, information about the data type, or
|
435
|
+
# other definition details. The default value is `false`.
|
436
436
|
# @param [Integer] version Optional parameter: The current version of the
|
437
437
|
# custom attribute, which is used for strongly consistent reads to guarantee
|
438
438
|
# that you receive the most up-to-date data. When included in the request,
|
@@ -165,7 +165,7 @@ module Square
|
|
165
165
|
# profiles, you must use the ID of the newly created profile.
|
166
166
|
# @param [String] customer_id Required parameter: The ID of the customer to
|
167
167
|
# delete.
|
168
|
-
# @param [
|
168
|
+
# @param [Integer] version Optional parameter: The current version of the
|
169
169
|
# customer profile. As a best practice, you should include this parameter
|
170
170
|
# to enable [optimistic
|
171
171
|
# concurrency](https://developer.squareup.com/docs/build-basics/common-api-p
|
@@ -6,7 +6,8 @@ module Square
|
|
6
6
|
end
|
7
7
|
|
8
8
|
# Lists all gift cards. You can specify optional filters to retrieve
|
9
|
-
# a subset of the gift cards.
|
9
|
+
# a subset of the gift cards. Results are sorted by `created_at` in
|
10
|
+
# ascending order.
|
10
11
|
# @param [String] type Optional parameter: If a [type]($m/GiftCardType) is
|
11
12
|
# provided, the endpoint returns gift cards of the specified type.
|
12
13
|
# Otherwise, the endpoint returns gift cards of all types.
|
@@ -113,7 +113,7 @@ module Square
|
|
113
113
|
)
|
114
114
|
end
|
115
115
|
|
116
|
-
# Adds points to a loyalty account.
|
116
|
+
# Adds points earned from the base loyalty program to a loyalty account.
|
117
117
|
# - If you are using the Orders API to manage orders, you only provide the
|
118
118
|
# `order_id`.
|
119
119
|
# The endpoint reads the order to compute points to add to the buyer's
|
@@ -124,6 +124,7 @@ module Square
|
|
124
124
|
# [CalculateLoyaltyPoints]($e/Loyalty/CalculateLoyaltyPoints) to compute the
|
125
125
|
# points
|
126
126
|
# that you provide to this endpoint.
|
127
|
+
# This endpoint excludes additional points earned from loyalty promotions.
|
127
128
|
# @param [String] account_id Required parameter: The [loyalty
|
128
129
|
# account]($m/LoyaltyAccount) ID to which to add the points.
|
129
130
|
# @param [AccumulateLoyaltyPointsRequest] body Required parameter: An object
|
@@ -329,7 +330,7 @@ module Square
|
|
329
330
|
)
|
330
331
|
end
|
331
332
|
|
332
|
-
# Calculates the points a purchase earns.
|
333
|
+
# Calculates the points a purchase earns from the base loyalty program.
|
333
334
|
# - If you are using the Orders API to manage orders, you provide the
|
334
335
|
# `order_id` in the request. The
|
335
336
|
# endpoint calculates the points by reading the order.
|
@@ -244,8 +244,8 @@ module Square
|
|
244
244
|
# - The `order_id` in the endpoint path, identifying the order to update.
|
245
245
|
# - The latest `version` of the order to update.
|
246
246
|
# - The [sparse
|
247
|
-
# order](https://developer.squareup.com/docs/orders-api/manage-orders
|
248
|
-
# -order-objects)
|
247
|
+
# order](https://developer.squareup.com/docs/orders-api/manage-orders/update
|
248
|
+
# -orders#sparse-order-objects)
|
249
249
|
# containing only the fields to update and the version to which the update
|
250
250
|
# is
|
251
251
|
# being applied.
|
@@ -26,7 +26,7 @@ module Square
|
|
26
26
|
# @param [String] location_id Optional parameter: Limit results to the
|
27
27
|
# location supplied. By default, results are returned for the default (main)
|
28
28
|
# location associated with the seller.
|
29
|
-
# @param [
|
29
|
+
# @param [Integer] total Optional parameter: The exact amount in the
|
30
30
|
# `total_money` for a payment.
|
31
31
|
# @param [String] last_4 Optional parameter: The last four digits of a
|
32
32
|
# payment card.
|
@@ -5,9 +5,7 @@ module Square
|
|
5
5
|
super(config, http_call_back: http_call_back)
|
6
6
|
end
|
7
7
|
|
8
|
-
# Creates a Terminal action request and sends it to the specified device
|
9
|
-
# take a payment
|
10
|
-
# for the requested amount.
|
8
|
+
# Creates a Terminal action request and sends it to the specified device.
|
11
9
|
# @param [CreateTerminalActionRequest] body Required parameter: An object
|
12
10
|
# containing the fields to POST for the request. See the corresponding
|
13
11
|
# object definition for field details.
|
@@ -175,10 +175,10 @@ module Square
|
|
175
175
|
# @param [String] batch_token Optional parameter: A pagination cursor to
|
176
176
|
# retrieve the next set of results for your original query to the
|
177
177
|
# endpoint.
|
178
|
-
# @param [
|
179
|
-
# not to include partial payments in the response.
|
180
|
-
# have the tenders collected so far, but the
|
181
|
-
# until the payment is completed.
|
178
|
+
# @param [TrueClass|FalseClass] include_partial Optional parameter:
|
179
|
+
# Indicates whether or not to include partial payments in the response.
|
180
|
+
# Partial payments will have the tenders collected so far, but the
|
181
|
+
# itemizations will be empty until the payment is completed.
|
182
182
|
# @return [List of V1Payment Hash] response from the API call
|
183
183
|
def list_payments(location_id:,
|
184
184
|
order: nil,
|
data/lib/square/api_helper.rb
CHANGED
@@ -130,6 +130,12 @@ module Square
|
|
130
130
|
raise TypeError, 'Server responded with invalid JSON.'
|
131
131
|
end
|
132
132
|
|
133
|
+
# Parses JSON string.
|
134
|
+
# @param [object] The object to serialize.
|
135
|
+
def self.json_serialize(obj)
|
136
|
+
serializable_types.map { |x| obj.is_a? x }.any? ? obj.to_s : obj.to_json
|
137
|
+
end
|
138
|
+
|
133
139
|
# Removes elements with empty values from a hash.
|
134
140
|
# @param [Hash] The hash to clean.
|
135
141
|
def self.clean_hash(hash)
|
@@ -199,9 +205,6 @@ module Square
|
|
199
205
|
def self.form_encode(obj, instance_name, formatting: 'indexed')
|
200
206
|
retval = {}
|
201
207
|
|
202
|
-
serializable_types = [String, Numeric, TrueClass,
|
203
|
-
FalseClass, Date, DateTime]
|
204
|
-
|
205
208
|
# Create a form encoded hash for this object.
|
206
209
|
if obj.nil?
|
207
210
|
nil
|
@@ -210,7 +213,7 @@ module Square
|
|
210
213
|
obj.each_with_index do |value, index|
|
211
214
|
retval.merge!(APIHelper.form_encode(value, "#{instance_name}[#{index}]"))
|
212
215
|
end
|
213
|
-
elsif serializable_types.map { |x| obj[0].is_a? x }.any?
|
216
|
+
elsif APIHelper.serializable_types.map { |x| obj[0].is_a? x }.any?
|
214
217
|
obj.each do |value|
|
215
218
|
abc = if formatting == 'unindexed'
|
216
219
|
APIHelper.form_encode(value, "#{instance_name}[]",
|
@@ -265,5 +268,174 @@ module Square
|
|
265
268
|
end
|
266
269
|
val
|
267
270
|
end
|
271
|
+
|
272
|
+
# Deserialize the value against the template (group of types).
|
273
|
+
# @param [String] The value to be deserialized.
|
274
|
+
# @param [String] The parameter indicates the type-combination
|
275
|
+
# against which the value will be mapped (oneOf(Integer, String)).
|
276
|
+
def self.deserialize(template, value)
|
277
|
+
decoded = APIHelper.json_deserialize(value)
|
278
|
+
map_types(decoded, template)
|
279
|
+
end
|
280
|
+
|
281
|
+
# Validates and processes the value against the template(group of types).
|
282
|
+
# @param [String] The value to be mapped against the template.
|
283
|
+
# @param [String] The parameter indicates the group of types (oneOf(Integer, String)).
|
284
|
+
# @param [String] The parameter indicates the group (oneOf|anyOf).
|
285
|
+
def self.map_types(value, template, group_name: nil)
|
286
|
+
result_value = nil
|
287
|
+
matches = 0
|
288
|
+
types = []
|
289
|
+
group_name = template.partition('(').first if group_name.nil? && template.match?(/anyOf|oneOf/)
|
290
|
+
|
291
|
+
return if value.nil?
|
292
|
+
|
293
|
+
if template.end_with?('{}') || template.end_with?('[]')
|
294
|
+
types = template.split(group_name, 2).last.gsub(/\s+/, '').split
|
295
|
+
else
|
296
|
+
template = template.split(group_name, 2).last.delete_prefix('(').delete_suffix(')')
|
297
|
+
types = template.scan(/(anyOf|oneOf)[(]([^[)]]*)[)]/).flatten.combination(2).map { |a, b| "#{a}(#{b})" }
|
298
|
+
types.each { |t| template = template.gsub(", #{t}", '') }
|
299
|
+
types = template.gsub(/\s+/, '').split(',').push(*types)
|
300
|
+
end
|
301
|
+
types.each do |element|
|
302
|
+
if element.match?(/^(oneOf|anyOf)[(].*$/)
|
303
|
+
begin
|
304
|
+
result_value = map_types(value, element, matches)
|
305
|
+
matches += 1
|
306
|
+
rescue ValidationException
|
307
|
+
next
|
308
|
+
end
|
309
|
+
elsif element.end_with?('{}')
|
310
|
+
result_value, matches = map_hash_type(value, element, group_name, matches)
|
311
|
+
elsif element.end_with?('[]')
|
312
|
+
result_value, matches = map_array_type(value, element, group_name, matches)
|
313
|
+
else
|
314
|
+
begin
|
315
|
+
result_value, matches = map_type(value, element, group_name, matches)
|
316
|
+
rescue StandardError
|
317
|
+
next
|
318
|
+
end
|
319
|
+
end
|
320
|
+
break if group_name == 'anyOf' && matches == 1
|
321
|
+
end
|
322
|
+
raise ValidationException.new(value, template) unless matches == 1
|
323
|
+
|
324
|
+
value = result_value unless result_value.nil?
|
325
|
+
value
|
326
|
+
end
|
327
|
+
|
328
|
+
# Validates and processes the value against the [Hash] type.
|
329
|
+
# @param [String] The value to be mapped against the type.
|
330
|
+
# @param [String] The possible type of the value.
|
331
|
+
# @param [String] The parameter indicates the group (oneOf|anyOf).
|
332
|
+
# @param [Integer] The parameter indicates the number of matches of value against types.
|
333
|
+
def self.map_hash_type(value, type, group_name, matches)
|
334
|
+
if value.instance_of? Hash
|
335
|
+
decoded = {}
|
336
|
+
value.each do |key, val|
|
337
|
+
type = type.chomp('{}').to_s
|
338
|
+
val = map_types(val, type, group_name: group_name)
|
339
|
+
decoded[key] = val unless type.empty?
|
340
|
+
rescue ValidationException
|
341
|
+
next
|
342
|
+
end
|
343
|
+
matches += 1 if decoded.length == value.length
|
344
|
+
value = decoded unless decoded.empty?
|
345
|
+
end
|
346
|
+
[value, matches]
|
347
|
+
end
|
348
|
+
|
349
|
+
# Validates and processes the value against the [Array] type.
|
350
|
+
# @param [String] The value to be mapped against the type.
|
351
|
+
# @param [String] The possible type of the value.
|
352
|
+
# @param [String] The parameter indicates the group (oneOf|anyOf).
|
353
|
+
# @param [Integer] The parameter indicates the number of matches of value against types.
|
354
|
+
def self.map_array_type(value, type, group_name, matches)
|
355
|
+
if value.instance_of? Array
|
356
|
+
decoded = []
|
357
|
+
value.each do |val|
|
358
|
+
type = type.chomp('[]').to_s
|
359
|
+
val = map_types(val, type, group_name: group_name)
|
360
|
+
decoded.append(val) unless type.empty?
|
361
|
+
rescue ValidationException
|
362
|
+
next
|
363
|
+
end
|
364
|
+
matches += 1 if decoded.length == value.length
|
365
|
+
value = decoded unless decoded.empty?
|
366
|
+
end
|
367
|
+
[value, matches]
|
368
|
+
end
|
369
|
+
|
370
|
+
# Validates and processes the value against the type.
|
371
|
+
# @param [String] The value to be mapped against the type.
|
372
|
+
# @param [String] The possible type of the value.
|
373
|
+
# @param [String] The parameter indicates the group (oneOf|anyOf).
|
374
|
+
# @param [Integer] The parameter indicates the number of matches of value against types.
|
375
|
+
def self.map_type(value, type, _group_name, matches)
|
376
|
+
if Square.constants.select do |c|
|
377
|
+
Square.const_get(c).to_s == "Square::#{type}"
|
378
|
+
end.empty?
|
379
|
+
value, matches = map_data_type(value, type, matches)
|
380
|
+
else
|
381
|
+
value, matches = map_complex_type(value, type, matches)
|
382
|
+
end
|
383
|
+
[value, matches]
|
384
|
+
end
|
385
|
+
|
386
|
+
# Validates and processes the value against the complex types.
|
387
|
+
# @param [String] The value to be mapped against the type.
|
388
|
+
# @param [String] The possible type of the value.
|
389
|
+
# @param [Integer] The parameter indicates the number of matches of value against types.
|
390
|
+
def self.map_complex_type(value, type, matches)
|
391
|
+
obj = Square.const_get(type)
|
392
|
+
value = if obj.respond_to? 'from_hash'
|
393
|
+
obj.send('from_hash', value)
|
394
|
+
else
|
395
|
+
obj.constants.find { |k| obj.const_get(k) == value }
|
396
|
+
end
|
397
|
+
matches += 1 unless value.nil?
|
398
|
+
[value, matches]
|
399
|
+
end
|
400
|
+
|
401
|
+
# Validates and processes the value against the data types.
|
402
|
+
# @param [String] The value to be mapped against the type.
|
403
|
+
# @param [String] The possible type of the value.
|
404
|
+
# @param [Integer] The parameter indicates the number of matches of value against types.
|
405
|
+
def self.map_data_type(value, element, matches)
|
406
|
+
element = element.split('|').map { |x| Object.const_get x }
|
407
|
+
matches += 1 if element.all? { |x| APIHelper.data_types.include?(x) } &&
|
408
|
+
element.any? { |x| (value.instance_of? x) || (value.class.ancestors.include? x) }
|
409
|
+
[value, matches]
|
410
|
+
end
|
411
|
+
|
412
|
+
# Validates the value against the template(group of types).
|
413
|
+
# @param [String] The value to be mapped against the type.
|
414
|
+
# @param [String] The parameter indicates the group of types (oneOf(Integer, String)).
|
415
|
+
def self.validate_types(value, template)
|
416
|
+
map_types(APIHelper.json_deserialize(value.to_json), template)
|
417
|
+
end
|
418
|
+
|
419
|
+
# Get content-type depending on the value
|
420
|
+
def self.get_content_type(value)
|
421
|
+
if serializable_types.map { |x| value.is_a? x }.any?
|
422
|
+
'text/plain; charset=utf-8'
|
423
|
+
else
|
424
|
+
'application/json; charset=utf-8'
|
425
|
+
end
|
426
|
+
end
|
427
|
+
|
428
|
+
# Array of serializable types
|
429
|
+
def self.serializable_types
|
430
|
+
[String, Numeric, TrueClass,
|
431
|
+
FalseClass, Date, DateTime]
|
432
|
+
end
|
433
|
+
|
434
|
+
# Array of supported data types
|
435
|
+
def self.data_types
|
436
|
+
[String, Float, Integer,
|
437
|
+
TrueClass, FalseClass, Date,
|
438
|
+
DateTime, Array, Hash, Object]
|
439
|
+
end
|
268
440
|
end
|
269
441
|
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
|
+
'21.1.0.20220720'
|
8
8
|
end
|
9
9
|
|
10
10
|
def square_version
|
@@ -231,16 +231,16 @@ module Square
|
|
231
231
|
@vendors ||= VendorsApi.new config
|
232
232
|
end
|
233
233
|
|
234
|
-
def initialize(connection: nil,
|
235
|
-
retry_interval: 1, backoff_factor: 2,
|
234
|
+
def initialize(connection: nil, adapter: :net_http_persistent, timeout: 60,
|
235
|
+
max_retries: 0, retry_interval: 1, backoff_factor: 2,
|
236
236
|
retry_statuses: [408, 413, 429, 500, 502, 503, 504, 521, 522, 524],
|
237
237
|
retry_methods: %i[get put], environment: 'production',
|
238
238
|
custom_url: 'https://connect.squareup.com',
|
239
|
-
square_version: '2022-
|
239
|
+
square_version: '2022-07-20', access_token: '',
|
240
240
|
user_agent_detail: '', additional_headers: {}, config: nil)
|
241
241
|
@config = if config.nil?
|
242
|
-
Configuration.new(connection: connection,
|
243
|
-
max_retries: max_retries,
|
242
|
+
Configuration.new(connection: connection, adapter: adapter,
|
243
|
+
timeout: timeout, max_retries: max_retries,
|
244
244
|
retry_interval: retry_interval,
|
245
245
|
backoff_factor: backoff_factor,
|
246
246
|
retry_statuses: retry_statuses,
|
data/lib/square/configuration.rb
CHANGED
@@ -3,9 +3,9 @@ module Square
|
|
3
3
|
# are configured in this class.
|
4
4
|
class Configuration
|
5
5
|
# The attribute readers for properties.
|
6
|
-
attr_reader :http_client, :connection, :timeout, :max_retries, :retry_interval,
|
7
|
-
:retry_statuses, :retry_methods, :environment, :custom_url,
|
8
|
-
:access_token, :user_agent_detail
|
6
|
+
attr_reader :http_client, :connection, :adapter, :timeout, :max_retries, :retry_interval,
|
7
|
+
:backoff_factor, :retry_statuses, :retry_methods, :environment, :custom_url,
|
8
|
+
:square_version, :access_token, :user_agent_detail
|
9
9
|
|
10
10
|
def additional_headers
|
11
11
|
@additional_headers.clone
|
@@ -15,16 +15,19 @@ module Square
|
|
15
15
|
attr_reader :environments
|
16
16
|
end
|
17
17
|
|
18
|
-
def initialize(connection: nil,
|
19
|
-
retry_interval: 1, backoff_factor: 2,
|
18
|
+
def initialize(connection: nil, adapter: :net_http_persistent, timeout: 60,
|
19
|
+
max_retries: 0, retry_interval: 1, backoff_factor: 2,
|
20
20
|
retry_statuses: [408, 413, 429, 500, 502, 503, 504, 521, 522, 524],
|
21
21
|
retry_methods: %i[get put], environment: 'production',
|
22
22
|
custom_url: 'https://connect.squareup.com',
|
23
|
-
square_version: '2022-
|
23
|
+
square_version: '2022-07-20', access_token: '',
|
24
24
|
user_agent_detail: '', additional_headers: {})
|
25
25
|
# The Faraday connection object passed by the SDK user for making requests
|
26
26
|
@connection = connection
|
27
27
|
|
28
|
+
# The Faraday adapter object passed by the SDK user for performing http requests
|
29
|
+
@adapter = adapter
|
30
|
+
|
28
31
|
# The value to use for connection timeout
|
29
32
|
@timeout = timeout
|
30
33
|
|
@@ -66,12 +69,13 @@ module Square
|
|
66
69
|
@user_agent_detail = get_user_agent(user_agent_detail)
|
67
70
|
end
|
68
71
|
|
69
|
-
def clone_with(connection: nil,
|
70
|
-
retry_interval: nil, backoff_factor: nil,
|
72
|
+
def clone_with(connection: nil, adapter: nil, timeout: nil,
|
73
|
+
max_retries: nil, retry_interval: nil, backoff_factor: nil,
|
71
74
|
retry_statuses: nil, retry_methods: nil, environment: nil,
|
72
75
|
custom_url: nil, square_version: nil, access_token: nil,
|
73
76
|
user_agent_detail: nil, additional_headers: nil)
|
74
77
|
connection ||= self.connection
|
78
|
+
adapter ||= self.adapter
|
75
79
|
timeout ||= self.timeout
|
76
80
|
max_retries ||= self.max_retries
|
77
81
|
retry_interval ||= self.retry_interval
|
@@ -85,8 +89,8 @@ module Square
|
|
85
89
|
user_agent_detail ||= self.user_agent_detail
|
86
90
|
additional_headers ||= self.additional_headers
|
87
91
|
|
88
|
-
Configuration.new(connection: connection,
|
89
|
-
max_retries: max_retries,
|
92
|
+
Configuration.new(connection: connection, adapter: adapter,
|
93
|
+
timeout: timeout, max_retries: max_retries,
|
90
94
|
retry_interval: retry_interval,
|
91
95
|
backoff_factor: backoff_factor,
|
92
96
|
retry_statuses: retry_statuses,
|
@@ -102,7 +106,8 @@ module Square
|
|
102
106
|
retry_interval: retry_interval,
|
103
107
|
backoff_factor: backoff_factor,
|
104
108
|
retry_statuses: retry_statuses,
|
105
|
-
retry_methods: retry_methods, connection: connection
|
109
|
+
retry_methods: retry_methods, connection: connection,
|
110
|
+
adapter: adapter)
|
106
111
|
end
|
107
112
|
|
108
113
|
def get_user_agent(user_agent_detail)
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Square
|
2
|
+
# Class for exceptions when there is a schema validation error.
|
3
|
+
class ValidationException < StandardError
|
4
|
+
attr_reader :reason
|
5
|
+
|
6
|
+
# The constructor.
|
7
|
+
# @param [String] The reason for raising an exception.
|
8
|
+
def initialize(value, template)
|
9
|
+
@reason = "The value #{value} provided doesn't validate against the schema #{template}"
|
10
|
+
super(reason)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -18,16 +18,14 @@ module Square
|
|
18
18
|
@request = http_response.request
|
19
19
|
@errors = errors
|
20
20
|
|
21
|
-
if data.is_a? Hash
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
end.new(*data.values)
|
21
|
+
if (data.is_a? Hash) && data.keys.any?
|
22
|
+
@body = Struct.new(*data.keys) do
|
23
|
+
define_method(:to_s) { http_response.raw_body }
|
24
|
+
end.new(*data.values)
|
26
25
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
end
|
26
|
+
@cursor = data.fetch(:cursor, nil)
|
27
|
+
data.reject! { |k| %i[cursor errors].include?(k) }
|
28
|
+
@data = Struct.new(*data.keys).new(*data.values) if data.keys.any?
|
31
29
|
else
|
32
30
|
@data = data
|
33
31
|
@body = data
|
@@ -3,6 +3,7 @@ require 'faraday/retry'
|
|
3
3
|
require 'faraday/multipart'
|
4
4
|
require 'faraday/follow_redirects'
|
5
5
|
require 'faraday/gzip'
|
6
|
+
require 'faraday/net_http_persistent'
|
6
7
|
|
7
8
|
module Square
|
8
9
|
# An implementation of HttpClient.
|
@@ -13,12 +14,12 @@ module Square
|
|
13
14
|
# The constructor.
|
14
15
|
def initialize(timeout:, max_retries:, retry_interval:,
|
15
16
|
backoff_factor:, retry_statuses:, retry_methods:,
|
16
|
-
connection
|
17
|
+
connection:, adapter:, cache: false, verify: true)
|
17
18
|
@connection = if connection.nil?
|
18
19
|
create_connection(timeout: timeout, max_retries: max_retries,
|
19
20
|
retry_interval: retry_interval, backoff_factor: backoff_factor,
|
20
21
|
retry_statuses: retry_statuses, retry_methods: retry_methods,
|
21
|
-
cache: cache, verify: verify)
|
22
|
+
adapter: adapter, cache: cache, verify: verify)
|
22
23
|
else
|
23
24
|
connection
|
24
25
|
end
|
@@ -27,7 +28,7 @@ module Square
|
|
27
28
|
# Method to initialize connection.
|
28
29
|
def create_connection(timeout:, max_retries:, retry_interval:,
|
29
30
|
backoff_factor:, retry_statuses:, retry_methods:,
|
30
|
-
cache: false, verify: true)
|
31
|
+
adapter:, cache: false, verify: true)
|
31
32
|
Faraday.new do |faraday|
|
32
33
|
faraday.use Faraday::HttpCache, serializer: Marshal if cache
|
33
34
|
faraday.use Faraday::FollowRedirects::Middleware
|
@@ -43,7 +44,7 @@ module Square
|
|
43
44
|
retry_if: proc { |env, _exc|
|
44
45
|
env.request.context['forced_retry'] ||= false
|
45
46
|
}
|
46
|
-
faraday.adapter
|
47
|
+
faraday.adapter adapter
|
47
48
|
faraday.options[:params_encoder] = Faraday::FlatParamsEncoder
|
48
49
|
faraday.options[:timeout] = timeout if timeout.positive?
|
49
50
|
end
|
data/lib/square.rb
CHANGED
data/test/test_helper.rb
CHANGED
@@ -49,7 +49,7 @@ class TestHelper
|
|
49
49
|
end
|
50
50
|
end
|
51
51
|
elsif expected_body.instance_of? Array
|
52
|
-
return
|
52
|
+
return false unless received_body.instance_of? Array
|
53
53
|
if check_count == true && (expected_body.length != received_body.length)
|
54
54
|
return false
|
55
55
|
else
|
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: 21.1.0.20220720
|
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: 2022-
|
11
|
+
date: 2022-07-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: logging
|
@@ -100,6 +100,20 @@ dependencies:
|
|
100
100
|
- - "~>"
|
101
101
|
- !ruby/object:Gem::Version
|
102
102
|
version: '1.0'
|
103
|
+
- !ruby/object:Gem::Dependency
|
104
|
+
name: faraday-net_http_persistent
|
105
|
+
requirement: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - "~>"
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '2.0'
|
110
|
+
type: :runtime
|
111
|
+
prerelease: false
|
112
|
+
version_requirements: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - "~>"
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '2.0'
|
103
117
|
- !ruby/object:Gem::Dependency
|
104
118
|
name: certifi
|
105
119
|
requirement: !ruby/object:Gem::Requirement
|
@@ -219,6 +233,7 @@ files:
|
|
219
233
|
- lib/square/client.rb
|
220
234
|
- lib/square/configuration.rb
|
221
235
|
- lib/square/exceptions/api_exception.rb
|
236
|
+
- lib/square/exceptions/validation_exception.rb
|
222
237
|
- lib/square/http/api_response.rb
|
223
238
|
- lib/square/http/auth/o_auth2.rb
|
224
239
|
- lib/square/http/faraday_client.rb
|