square.rb 19.0.0.20220420 → 21.0.0.20220720
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/README.md +6 -0
- data/lib/square/api/base_api.rb +8 -1
- data/lib/square/api/bookings_api.rb +12 -3
- data/lib/square/api/cards_api.rb +3 -2
- data/lib/square/api/catalog_api.rb +25 -25
- data/lib/square/api/checkout_api.rb +202 -0
- data/lib/square/api/customer_custom_attributes_api.rb +540 -0
- data/lib/square/api/customers_api.rb +1 -1
- data/lib/square/api/gift_card_activities_api.rb +5 -6
- data/lib/square/api/gift_cards_api.rb +8 -7
- 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 +141 -0
- data/lib/square/api/v1_transactions_api.rb +4 -4
- data/lib/square/api_helper.rb +176 -4
- data/lib/square/client.rb +12 -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 +2 -0
- data/test/test_helper.rb +1 -1
- metadata +24 -2
@@ -5,6 +5,147 @@ 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
|
+
# @param [CreateTerminalActionRequest] body Required parameter: An object
|
10
|
+
# containing the fields to POST for the request. See the corresponding
|
11
|
+
# object definition for field details.
|
12
|
+
# @return [CreateTerminalActionResponse Hash] response from the API call
|
13
|
+
def create_terminal_action(body:)
|
14
|
+
# Prepare query url.
|
15
|
+
_query_builder = config.get_base_uri
|
16
|
+
_query_builder << '/v2/terminals/actions'
|
17
|
+
_query_url = APIHelper.clean_url _query_builder
|
18
|
+
|
19
|
+
# Prepare headers.
|
20
|
+
_headers = {
|
21
|
+
'accept' => 'application/json',
|
22
|
+
'Content-Type' => 'application/json'
|
23
|
+
}
|
24
|
+
|
25
|
+
# Prepare and execute HttpRequest.
|
26
|
+
_request = config.http_client.post(
|
27
|
+
_query_url,
|
28
|
+
headers: _headers,
|
29
|
+
parameters: body.to_json
|
30
|
+
)
|
31
|
+
OAuth2.apply(config, _request)
|
32
|
+
_response = execute_request(_request)
|
33
|
+
|
34
|
+
# Return appropriate response type.
|
35
|
+
decoded = APIHelper.json_deserialize(_response.raw_body)
|
36
|
+
_errors = APIHelper.map_response(decoded, ['errors'])
|
37
|
+
ApiResponse.new(
|
38
|
+
_response, data: decoded, errors: _errors
|
39
|
+
)
|
40
|
+
end
|
41
|
+
|
42
|
+
# Retrieves a filtered list of Terminal action requests created by the
|
43
|
+
# account making the request. Terminal action requests are available for 30
|
44
|
+
# days.
|
45
|
+
# @param [SearchTerminalActionsRequest] body Required parameter: An object
|
46
|
+
# containing the fields to POST for the request. See the corresponding
|
47
|
+
# object definition for field details.
|
48
|
+
# @return [SearchTerminalActionsResponse Hash] response from the API call
|
49
|
+
def search_terminal_actions(body:)
|
50
|
+
# Prepare query url.
|
51
|
+
_query_builder = config.get_base_uri
|
52
|
+
_query_builder << '/v2/terminals/actions/search'
|
53
|
+
_query_url = APIHelper.clean_url _query_builder
|
54
|
+
|
55
|
+
# Prepare headers.
|
56
|
+
_headers = {
|
57
|
+
'accept' => 'application/json',
|
58
|
+
'Content-Type' => 'application/json'
|
59
|
+
}
|
60
|
+
|
61
|
+
# Prepare and execute HttpRequest.
|
62
|
+
_request = config.http_client.post(
|
63
|
+
_query_url,
|
64
|
+
headers: _headers,
|
65
|
+
parameters: body.to_json
|
66
|
+
)
|
67
|
+
OAuth2.apply(config, _request)
|
68
|
+
_response = execute_request(_request)
|
69
|
+
|
70
|
+
# Return appropriate response type.
|
71
|
+
decoded = APIHelper.json_deserialize(_response.raw_body)
|
72
|
+
_errors = APIHelper.map_response(decoded, ['errors'])
|
73
|
+
ApiResponse.new(
|
74
|
+
_response, data: decoded, errors: _errors
|
75
|
+
)
|
76
|
+
end
|
77
|
+
|
78
|
+
# Retrieves a Terminal action request by `action_id`. Terminal action
|
79
|
+
# requests are available for 30 days.
|
80
|
+
# @param [String] action_id Required parameter: Unique ID for the desired
|
81
|
+
# `TerminalAction`
|
82
|
+
# @return [GetTerminalActionResponse Hash] response from the API call
|
83
|
+
def get_terminal_action(action_id:)
|
84
|
+
# Prepare query url.
|
85
|
+
_query_builder = config.get_base_uri
|
86
|
+
_query_builder << '/v2/terminals/actions/{action_id}'
|
87
|
+
_query_builder = APIHelper.append_url_with_template_parameters(
|
88
|
+
_query_builder,
|
89
|
+
'action_id' => { 'value' => action_id, 'encode' => true }
|
90
|
+
)
|
91
|
+
_query_url = APIHelper.clean_url _query_builder
|
92
|
+
|
93
|
+
# Prepare headers.
|
94
|
+
_headers = {
|
95
|
+
'accept' => 'application/json'
|
96
|
+
}
|
97
|
+
|
98
|
+
# Prepare and execute HttpRequest.
|
99
|
+
_request = config.http_client.get(
|
100
|
+
_query_url,
|
101
|
+
headers: _headers
|
102
|
+
)
|
103
|
+
OAuth2.apply(config, _request)
|
104
|
+
_response = execute_request(_request)
|
105
|
+
|
106
|
+
# Return appropriate response type.
|
107
|
+
decoded = APIHelper.json_deserialize(_response.raw_body)
|
108
|
+
_errors = APIHelper.map_response(decoded, ['errors'])
|
109
|
+
ApiResponse.new(
|
110
|
+
_response, data: decoded, errors: _errors
|
111
|
+
)
|
112
|
+
end
|
113
|
+
|
114
|
+
# Cancels a Terminal action request if the status of the request permits it.
|
115
|
+
# @param [String] action_id Required parameter: Unique ID for the desired
|
116
|
+
# `TerminalAction`
|
117
|
+
# @return [CancelTerminalActionResponse Hash] response from the API call
|
118
|
+
def cancel_terminal_action(action_id:)
|
119
|
+
# Prepare query url.
|
120
|
+
_query_builder = config.get_base_uri
|
121
|
+
_query_builder << '/v2/terminals/actions/{action_id}/cancel'
|
122
|
+
_query_builder = APIHelper.append_url_with_template_parameters(
|
123
|
+
_query_builder,
|
124
|
+
'action_id' => { 'value' => action_id, 'encode' => true }
|
125
|
+
)
|
126
|
+
_query_url = APIHelper.clean_url _query_builder
|
127
|
+
|
128
|
+
# Prepare headers.
|
129
|
+
_headers = {
|
130
|
+
'accept' => 'application/json'
|
131
|
+
}
|
132
|
+
|
133
|
+
# Prepare and execute HttpRequest.
|
134
|
+
_request = config.http_client.post(
|
135
|
+
_query_url,
|
136
|
+
headers: _headers
|
137
|
+
)
|
138
|
+
OAuth2.apply(config, _request)
|
139
|
+
_response = execute_request(_request)
|
140
|
+
|
141
|
+
# Return appropriate response type.
|
142
|
+
decoded = APIHelper.json_deserialize(_response.raw_body)
|
143
|
+
_errors = APIHelper.map_response(decoded, ['errors'])
|
144
|
+
ApiResponse.new(
|
145
|
+
_response, data: decoded, errors: _errors
|
146
|
+
)
|
147
|
+
end
|
148
|
+
|
8
149
|
# Creates a Terminal checkout request and sends it to the specified device
|
9
150
|
# to take a payment
|
10
151
|
# for the requested amount.
|
@@ -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.0.0.20220720'
|
8
8
|
end
|
9
9
|
|
10
10
|
def square_version
|
@@ -75,6 +75,12 @@ module Square
|
|
75
75
|
@customers ||= CustomersApi.new config
|
76
76
|
end
|
77
77
|
|
78
|
+
# Access to customer_custom_attributes controller.
|
79
|
+
# @return [CustomerCustomAttributesApi] Returns the controller instance.
|
80
|
+
def customer_custom_attributes
|
81
|
+
@customer_custom_attributes ||= CustomerCustomAttributesApi.new config
|
82
|
+
end
|
83
|
+
|
78
84
|
# Access to customer_groups controller.
|
79
85
|
# @return [CustomerGroupsApi] Returns the controller instance.
|
80
86
|
def customer_groups
|
@@ -225,16 +231,16 @@ module Square
|
|
225
231
|
@vendors ||= VendorsApi.new config
|
226
232
|
end
|
227
233
|
|
228
|
-
def initialize(connection: nil,
|
229
|
-
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,
|
230
236
|
retry_statuses: [408, 413, 429, 500, 502, 503, 504, 521, 522, 524],
|
231
237
|
retry_methods: %i[get put], environment: 'production',
|
232
238
|
custom_url: 'https://connect.squareup.com',
|
233
|
-
square_version: '2022-
|
239
|
+
square_version: '2022-07-20', access_token: '',
|
234
240
|
user_agent_detail: '', additional_headers: {}, config: nil)
|
235
241
|
@config = if config.nil?
|
236
|
-
Configuration.new(connection: connection,
|
237
|
-
max_retries: max_retries,
|
242
|
+
Configuration.new(connection: connection, adapter: adapter,
|
243
|
+
timeout: timeout, max_retries: max_retries,
|
238
244
|
retry_interval: retry_interval,
|
239
245
|
backoff_factor: backoff_factor,
|
240
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
@@ -25,6 +25,7 @@ require_relative 'square/http/auth/o_auth2'
|
|
25
25
|
|
26
26
|
# Exceptions
|
27
27
|
require_relative 'square/exceptions/api_exception'
|
28
|
+
require_relative 'square/exceptions/validation_exception'
|
28
29
|
|
29
30
|
require_relative 'square/configuration'
|
30
31
|
|
@@ -40,6 +41,7 @@ require_relative 'square/api/cards_api'
|
|
40
41
|
require_relative 'square/api/cash_drawers_api'
|
41
42
|
require_relative 'square/api/catalog_api'
|
42
43
|
require_relative 'square/api/customers_api'
|
44
|
+
require_relative 'square/api/customer_custom_attributes_api'
|
43
45
|
require_relative 'square/api/customer_groups_api'
|
44
46
|
require_relative 'square/api/customer_segments_api'
|
45
47
|
require_relative 'square/api/devices_api'
|
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.0.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-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: logging
|
@@ -31,6 +31,9 @@ dependencies:
|
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '2.0'
|
34
|
+
- - ">="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: 2.0.1
|
34
37
|
type: :runtime
|
35
38
|
prerelease: false
|
36
39
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -38,6 +41,9 @@ dependencies:
|
|
38
41
|
- - "~>"
|
39
42
|
- !ruby/object:Gem::Version
|
40
43
|
version: '2.0'
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 2.0.1
|
41
47
|
- !ruby/object:Gem::Dependency
|
42
48
|
name: faraday-follow_redirects
|
43
49
|
requirement: !ruby/object:Gem::Requirement
|
@@ -94,6 +100,20 @@ dependencies:
|
|
94
100
|
- - "~>"
|
95
101
|
- !ruby/object:Gem::Version
|
96
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'
|
97
117
|
- !ruby/object:Gem::Dependency
|
98
118
|
name: certifi
|
99
119
|
requirement: !ruby/object:Gem::Requirement
|
@@ -180,6 +200,7 @@ files:
|
|
180
200
|
- lib/square/api/cash_drawers_api.rb
|
181
201
|
- lib/square/api/catalog_api.rb
|
182
202
|
- lib/square/api/checkout_api.rb
|
203
|
+
- lib/square/api/customer_custom_attributes_api.rb
|
183
204
|
- lib/square/api/customer_groups_api.rb
|
184
205
|
- lib/square/api/customer_segments_api.rb
|
185
206
|
- lib/square/api/customers_api.rb
|
@@ -212,6 +233,7 @@ files:
|
|
212
233
|
- lib/square/client.rb
|
213
234
|
- lib/square/configuration.rb
|
214
235
|
- lib/square/exceptions/api_exception.rb
|
236
|
+
- lib/square/exceptions/validation_exception.rb
|
215
237
|
- lib/square/http/api_response.rb
|
216
238
|
- lib/square/http/auth/o_auth2.rb
|
217
239
|
- lib/square/http/faraday_client.rb
|