square.rb 14.1.0.20210915 → 15.0.0.20211020
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +1 -1
- data/README.md +23 -20
- data/lib/square/api/base_api.rb +2 -4
- data/lib/square/api/customer_groups_api.rb +1 -1
- data/lib/square/api/customer_segments_api.rb +1 -1
- data/lib/square/api/customers_api.rb +1 -1
- data/lib/square/api/payments_api.rb +9 -3
- data/lib/square/api/transactions_api.rb +0 -188
- data/lib/square/client.rb +6 -5
- data/lib/square/configuration.rb +20 -14
- data/lib/square/http/api_response.rb +1 -1
- data/lib/square/http/faraday_client.rb +20 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 25322287d3387bc053e23f58c5a3b74476789df2145f9648f46b330517aa7574
|
4
|
+
data.tar.gz: a5476f517732ce5df169b402fded9909cefa155e02c90d9af5996e4dc087a887
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2d30c67ff2493a1dded81c4078d3549c0c195f092f9826735cd1f98bb6749153bd45d6614419f95f6d6fb32ed505459abc11ab0508b3fa51f0ad089f8a0cce51
|
7
|
+
data.tar.gz: 2b4a9e0bdb771a3658ec3a46b9838421c154ff1b280da9d27e589111dbb010c2d3c5672ae38d5b22e52ae26f864ae6d8cd76e53effc65e65fdefafcf0b949aa4
|
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -115,8 +115,8 @@ require 'square'
|
|
115
115
|
# for the Square account whose assets you want to manage.
|
116
116
|
|
117
117
|
client = Square::Client.new(
|
118
|
-
|
119
|
-
|
118
|
+
access_token: 'YOUR SANDBOX ACCESS TOKEN HERE',
|
119
|
+
environment: 'sandbox'
|
120
120
|
)
|
121
121
|
|
122
122
|
# Call list_locations method to get all locations in this Square account
|
@@ -124,10 +124,10 @@ result = client.locations.list_locations
|
|
124
124
|
|
125
125
|
# Call the #success? method to see if the call succeeded
|
126
126
|
if result.success?
|
127
|
-
|
127
|
+
# The #data Struct contains a list of locations
|
128
128
|
locations = result.data.locations
|
129
129
|
|
130
|
-
|
130
|
+
# Iterate over the list
|
131
131
|
locations.each do |location|
|
132
132
|
# Each location is represented as a Hash
|
133
133
|
location.each do |key, value|
|
@@ -176,6 +176,7 @@ This error was returned when an invalid token was used to call the API.
|
|
176
176
|
After you’ve tried out the Square APIs and tested your application using sandbox, you will want to switch to your production credentials so that you can manage real Square resources. Don't forget to switch your access token from sandbox to production for real data.
|
177
177
|
|
178
178
|
## SDK patterns
|
179
|
+
|
179
180
|
If you know a few patterns, you’ll be able to call any API in the SDK. Here are some important ones:
|
180
181
|
|
181
182
|
### Get an access token
|
@@ -196,30 +197,31 @@ To use the Square API, you import the Client class, instantiate a Client object,
|
|
196
197
|
|
197
198
|
- Instantiate a `Square::Client` object with the access token for the Square account whose resources you want to manage. To access sandbox resources, initialize the `Square::Client` with environment set to sandbox:
|
198
199
|
|
199
|
-
```ruby
|
200
|
-
client = Square::Client.new(
|
200
|
+
```ruby
|
201
|
+
client = Square::Client.new(
|
201
202
|
access_token: 'SANDBOX ACCESS TOKEN HERE',
|
202
203
|
environment: 'sandbox'
|
203
|
-
)
|
204
|
-
```
|
204
|
+
)
|
205
|
+
```
|
205
206
|
|
206
207
|
- To access production resources, set environment to production:
|
207
208
|
|
208
|
-
```ruby
|
209
|
-
client = Square::Client.new(
|
209
|
+
```ruby
|
210
|
+
client = Square::Client.new(
|
210
211
|
access_token: 'ACCESS TOKEN HERE',
|
211
212
|
environment: 'production'
|
212
|
-
)
|
213
|
-
```
|
213
|
+
)
|
214
|
+
```
|
214
215
|
|
215
216
|
- To set a custom environment provide a `custom_url`, and set environment to `custom`:
|
216
217
|
|
217
|
-
```ruby
|
218
|
-
client = Square::Client.new(
|
218
|
+
```ruby
|
219
|
+
client = Square::Client.new(
|
219
220
|
access_token:'ACCESS TOKEN HERE',
|
220
221
|
environment: 'custom',
|
221
222
|
custom_url: 'https://your.customdomain.com'
|
222
|
-
)
|
223
|
+
)
|
224
|
+
```
|
223
225
|
|
224
226
|
### Get an Instance of an API object and call its methods
|
225
227
|
|
@@ -227,9 +229,9 @@ Each API is implemented as a class. The Client object instantiates every API cla
|
|
227
229
|
|
228
230
|
- Work with an API by calling the methods on the API object. For example, you would call list_customers to get a list of all customers in the Square account:
|
229
231
|
|
230
|
-
```ruby
|
231
|
-
result = client.customers.list_customers
|
232
|
-
```
|
232
|
+
```ruby
|
233
|
+
result = client.customers.list_customers
|
234
|
+
```
|
233
235
|
|
234
236
|
See the SDK documentation for the list of methods for each API class.
|
235
237
|
|
@@ -250,6 +252,7 @@ result = client.customers.create_customer(request_body)
|
|
250
252
|
```
|
251
253
|
|
252
254
|
If your call succeeds, you’ll see a response that looks like this:
|
255
|
+
|
253
256
|
```
|
254
257
|
{'customer': {'created_at': '2019-06-28T21:23:05.126Z', 'creation_source': 'THIRD_PARTY', 'family_name': 'Earhardt', 'given_name': 'Amelia', 'id': 'CBASEDwl3El91nohQ2FLEk4aBfcgAQ', 'preferences': {'email_unsubscribed': False}, 'updated_at': '2019-06-28T21:23:05.126Z'}}
|
255
258
|
```
|
@@ -274,7 +277,7 @@ end
|
|
274
277
|
|
275
278
|
## Tests
|
276
279
|
|
277
|
-
First, clone the
|
280
|
+
First, clone the repo locally and `cd` into the directory.
|
278
281
|
|
279
282
|
```sh
|
280
283
|
git clone https://github.com/square/square-ruby-sdk.git
|
@@ -346,4 +349,4 @@ You can also use the Square API to create applications or services that work wit
|
|
346
349
|
[Snippets]: doc/api/snippets.md
|
347
350
|
[Cards]: doc/api/cards.md
|
348
351
|
[Gift Cards]: doc/api/gift-cards.md
|
349
|
-
[Gift Card Activities]: doc/api/gift-card-activities.md
|
352
|
+
[Gift Card Activities]: doc/api/gift-card-activities.md
|
data/lib/square/api/base_api.rb
CHANGED
@@ -8,7 +8,7 @@ module Square
|
|
8
8
|
@http_call_back = http_call_back
|
9
9
|
|
10
10
|
@global_headers = {
|
11
|
-
'user-agent' => 'Square-Ruby-SDK/
|
11
|
+
'user-agent' => 'Square-Ruby-SDK/15.0.0.20211020',
|
12
12
|
'Square-Version' => config.square_version
|
13
13
|
}
|
14
14
|
end
|
@@ -24,9 +24,7 @@ module Square
|
|
24
24
|
|
25
25
|
APIHelper.clean_hash(request.headers)
|
26
26
|
request.headers.merge!(@global_headers)
|
27
|
-
unless config.additional_headers.nil?
|
28
|
-
request.headers.merge!(config.additional_headers)
|
29
|
-
end
|
27
|
+
request.headers.merge!(config.additional_headers) unless config.additional_headers.nil?
|
30
28
|
|
31
29
|
response = if binary
|
32
30
|
config.http_client.execute_as_binary(request)
|
@@ -13,7 +13,7 @@ module Square
|
|
13
13
|
# ion).
|
14
14
|
# @param [Integer] limit Optional parameter: The maximum number of results
|
15
15
|
# to return in a single page. This limit is advisory. The response might
|
16
|
-
# contain more or fewer results.
|
16
|
+
# contain more or fewer results. The limit is ignored if it is less than 1
|
17
17
|
# or greater than 50. The default value is 50. For more information, see
|
18
18
|
# [Pagination](https://developer.squareup.com/docs/working-with-apis/paginat
|
19
19
|
# ion).
|
@@ -13,7 +13,7 @@ module Square
|
|
13
13
|
# ion).
|
14
14
|
# @param [Integer] limit Optional parameter: The maximum number of results
|
15
15
|
# to return in a single page. This limit is advisory. The response might
|
16
|
-
# contain more or fewer results.
|
16
|
+
# contain more or fewer results. The limit is ignored if it is less than 1
|
17
17
|
# or greater than 50. The default value is 50. For more information, see
|
18
18
|
# [Pagination](https://developer.squareup.com/docs/working-with-apis/paginat
|
19
19
|
# ion).
|
@@ -19,7 +19,7 @@ module Square
|
|
19
19
|
# ion).
|
20
20
|
# @param [Integer] limit Optional parameter: The maximum number of results
|
21
21
|
# to return in a single page. This limit is advisory. The response might
|
22
|
-
# contain more or fewer results.
|
22
|
+
# contain more or fewer results. The limit is ignored if it is less than 1
|
23
23
|
# or greater than 100. The default value is 100. For more information, see
|
24
24
|
# [Pagination](https://developer.squareup.com/docs/working-with-apis/paginat
|
25
25
|
# ion).
|
@@ -296,8 +296,12 @@ module Square
|
|
296
296
|
# `status`.
|
297
297
|
# @param [String] payment_id Required parameter: The unique ID identifying
|
298
298
|
# the payment to be completed.
|
299
|
+
# @param [CompletePaymentRequest] body Required parameter: An object
|
300
|
+
# containing the fields to POST for the request. See the corresponding
|
301
|
+
# object definition for field details.
|
299
302
|
# @return [CompletePaymentResponse Hash] response from the API call
|
300
|
-
def complete_payment(payment_id
|
303
|
+
def complete_payment(payment_id:,
|
304
|
+
body:)
|
301
305
|
# Prepare query url.
|
302
306
|
_query_builder = config.get_base_uri
|
303
307
|
_query_builder << '/v2/payments/{payment_id}/complete'
|
@@ -309,13 +313,15 @@ module Square
|
|
309
313
|
|
310
314
|
# Prepare headers.
|
311
315
|
_headers = {
|
312
|
-
'accept' => 'application/json'
|
316
|
+
'accept' => 'application/json',
|
317
|
+
'content-type' => 'application/json; charset=utf-8'
|
313
318
|
}
|
314
319
|
|
315
320
|
# Prepare and execute HttpRequest.
|
316
321
|
_request = config.http_client.post(
|
317
322
|
_query_url,
|
318
|
-
headers: _headers
|
323
|
+
headers: _headers,
|
324
|
+
parameters: body.to_json
|
319
325
|
)
|
320
326
|
OAuth2.apply(config, _request)
|
321
327
|
_response = execute_request(_request)
|
@@ -5,80 +5,6 @@ module Square
|
|
5
5
|
super(config, http_call_back: http_call_back)
|
6
6
|
end
|
7
7
|
|
8
|
-
# Lists refunds for one of a business's locations.
|
9
|
-
# In addition to full or partial tender refunds processed through Square
|
10
|
-
# APIs,
|
11
|
-
# refunds may result from itemized returns or exchanges through Square's
|
12
|
-
# Point of Sale applications.
|
13
|
-
# Refunds with a `status` of `PENDING` are not currently included in this
|
14
|
-
# endpoint's response.
|
15
|
-
# Max results per
|
16
|
-
# [page](https://developer.squareup.com/docs/working-with-apis/pagination):
|
17
|
-
# 50
|
18
|
-
# @param [String] location_id Required parameter: The ID of the location to
|
19
|
-
# list refunds for.
|
20
|
-
# @param [String] begin_time Optional parameter: The beginning of the
|
21
|
-
# requested reporting period, in RFC 3339 format. See [Date
|
22
|
-
# ranges](https://developer.squareup.com/docs/build-basics/working-with-date
|
23
|
-
# s) for details on date inclusivity/exclusivity. Default value: The
|
24
|
-
# current time minus one year.
|
25
|
-
# @param [String] end_time Optional parameter: The end of the requested
|
26
|
-
# reporting period, in RFC 3339 format. See [Date
|
27
|
-
# ranges](https://developer.squareup.com/docs/build-basics/working-with-date
|
28
|
-
# s) for details on date inclusivity/exclusivity. Default value: The
|
29
|
-
# current time.
|
30
|
-
# @param [SortOrder] sort_order Optional parameter: The order in which
|
31
|
-
# results are listed in the response (`ASC` for oldest first, `DESC` for
|
32
|
-
# newest first). Default value: `DESC`
|
33
|
-
# @param [String] cursor Optional parameter: A pagination cursor returned by
|
34
|
-
# a previous call to this endpoint. Provide this to retrieve the next set of
|
35
|
-
# results for your original query. See [Paginating
|
36
|
-
# results](https://developer.squareup.com/docs/working-with-apis/pagination)
|
37
|
-
# for more information.
|
38
|
-
# @return [ListRefundsResponse Hash] response from the API call
|
39
|
-
def list_refunds(location_id:,
|
40
|
-
begin_time: nil,
|
41
|
-
end_time: nil,
|
42
|
-
sort_order: nil,
|
43
|
-
cursor: nil)
|
44
|
-
warn 'Endpoint list_refunds in TransactionsApi is deprecated'
|
45
|
-
# Prepare query url.
|
46
|
-
_query_builder = config.get_base_uri
|
47
|
-
_query_builder << '/v2/locations/{location_id}/refunds'
|
48
|
-
_query_builder = APIHelper.append_url_with_template_parameters(
|
49
|
-
_query_builder,
|
50
|
-
'location_id' => { 'value' => location_id, 'encode' => true }
|
51
|
-
)
|
52
|
-
_query_builder = APIHelper.append_url_with_query_parameters(
|
53
|
-
_query_builder,
|
54
|
-
'begin_time' => begin_time,
|
55
|
-
'end_time' => end_time,
|
56
|
-
'sort_order' => sort_order,
|
57
|
-
'cursor' => cursor
|
58
|
-
)
|
59
|
-
_query_url = APIHelper.clean_url _query_builder
|
60
|
-
|
61
|
-
# Prepare headers.
|
62
|
-
_headers = {
|
63
|
-
'accept' => 'application/json'
|
64
|
-
}
|
65
|
-
|
66
|
-
# Prepare and execute HttpRequest.
|
67
|
-
_request = config.http_client.get(
|
68
|
-
_query_url,
|
69
|
-
headers: _headers
|
70
|
-
)
|
71
|
-
OAuth2.apply(config, _request)
|
72
|
-
_response = execute_request(_request)
|
73
|
-
|
74
|
-
# Return appropriate response type.
|
75
|
-
decoded = APIHelper.json_deserialize(_response.raw_body)
|
76
|
-
_errors = APIHelper.map_response(decoded, ['errors'])
|
77
|
-
ApiResponse.new(
|
78
|
-
_response, data: decoded, errors: _errors
|
79
|
-
)
|
80
|
-
end
|
81
|
-
|
82
8
|
# Lists transactions for a particular location.
|
83
9
|
# Transactions include payment information from sales and exchanges and
|
84
10
|
# refund
|
@@ -150,67 +76,6 @@ module Square
|
|
150
76
|
)
|
151
77
|
end
|
152
78
|
|
153
|
-
# Charges a card represented by a card nonce or a customer's card on file.
|
154
|
-
# Your request to this endpoint must include _either_:
|
155
|
-
# - A value for the `card_nonce` parameter (to charge a card payment token
|
156
|
-
# generated
|
157
|
-
# with the Web Payments SDK)
|
158
|
-
# - Values for the `customer_card_id` and `customer_id` parameters (to
|
159
|
-
# charge
|
160
|
-
# a customer's card on file)
|
161
|
-
# In order for an eCommerce payment to potentially qualify for
|
162
|
-
# [Square chargeback protection](https://squareup.com/help/article/5394),
|
163
|
-
# you
|
164
|
-
# _must_ provide values for the following parameters in your request:
|
165
|
-
# - `buyer_email_address`
|
166
|
-
# - At least one of `billing_address` or `shipping_address`
|
167
|
-
# When this response is returned, the amount of Square's processing fee
|
168
|
-
# might not yet be
|
169
|
-
# calculated. To obtain the processing fee, wait about ten seconds and call
|
170
|
-
# [RetrieveTransaction]($e/Transactions/RetrieveTransaction). See the
|
171
|
-
# `processing_fee_money`
|
172
|
-
# field of each [Tender included]($m/Tender) in the transaction.
|
173
|
-
# @param [String] location_id Required parameter: The ID of the location to
|
174
|
-
# associate the created transaction with.
|
175
|
-
# @param [ChargeRequest] body Required parameter: An object containing the
|
176
|
-
# fields to POST for the request. See the corresponding object definition
|
177
|
-
# for field details.
|
178
|
-
# @return [ChargeResponse Hash] response from the API call
|
179
|
-
def charge(location_id:,
|
180
|
-
body:)
|
181
|
-
warn 'Endpoint charge in TransactionsApi is deprecated'
|
182
|
-
# Prepare query url.
|
183
|
-
_query_builder = config.get_base_uri
|
184
|
-
_query_builder << '/v2/locations/{location_id}/transactions'
|
185
|
-
_query_builder = APIHelper.append_url_with_template_parameters(
|
186
|
-
_query_builder,
|
187
|
-
'location_id' => { 'value' => location_id, 'encode' => true }
|
188
|
-
)
|
189
|
-
_query_url = APIHelper.clean_url _query_builder
|
190
|
-
|
191
|
-
# Prepare headers.
|
192
|
-
_headers = {
|
193
|
-
'accept' => 'application/json',
|
194
|
-
'content-type' => 'application/json; charset=utf-8'
|
195
|
-
}
|
196
|
-
|
197
|
-
# Prepare and execute HttpRequest.
|
198
|
-
_request = config.http_client.post(
|
199
|
-
_query_url,
|
200
|
-
headers: _headers,
|
201
|
-
parameters: body.to_json
|
202
|
-
)
|
203
|
-
OAuth2.apply(config, _request)
|
204
|
-
_response = execute_request(_request)
|
205
|
-
|
206
|
-
# Return appropriate response type.
|
207
|
-
decoded = APIHelper.json_deserialize(_response.raw_body)
|
208
|
-
_errors = APIHelper.map_response(decoded, ['errors'])
|
209
|
-
ApiResponse.new(
|
210
|
-
_response, data: decoded, errors: _errors
|
211
|
-
)
|
212
|
-
end
|
213
|
-
|
214
79
|
# Retrieves details for a single transaction.
|
215
80
|
# @param [String] location_id Required parameter: The ID of the
|
216
81
|
# transaction's associated location.
|
@@ -295,59 +160,6 @@ module Square
|
|
295
160
|
)
|
296
161
|
end
|
297
162
|
|
298
|
-
# Initiates a refund for a previously charged tender.
|
299
|
-
# You must issue a refund within 120 days of the associated payment. See
|
300
|
-
# [this article](https://squareup.com/help/us/en/article/5060) for more
|
301
|
-
# information
|
302
|
-
# on refund behavior.
|
303
|
-
# NOTE: Card-present transactions with Interac credit cards **cannot be
|
304
|
-
# refunded using the Connect API**. Interac transactions must refunded
|
305
|
-
# in-person (e.g., dipping the card using POS app).
|
306
|
-
# @param [String] location_id Required parameter: The ID of the original
|
307
|
-
# transaction's associated location.
|
308
|
-
# @param [String] transaction_id Required parameter: The ID of the original
|
309
|
-
# transaction that includes the tender to refund.
|
310
|
-
# @param [CreateRefundRequest] body Required parameter: An object containing
|
311
|
-
# the fields to POST for the request. See the corresponding object
|
312
|
-
# definition for field details.
|
313
|
-
# @return [CreateRefundResponse Hash] response from the API call
|
314
|
-
def create_refund(location_id:,
|
315
|
-
transaction_id:,
|
316
|
-
body:)
|
317
|
-
warn 'Endpoint create_refund in TransactionsApi is deprecated'
|
318
|
-
# Prepare query url.
|
319
|
-
_query_builder = config.get_base_uri
|
320
|
-
_query_builder << '/v2/locations/{location_id}/transactions/{transaction_id}/refund'
|
321
|
-
_query_builder = APIHelper.append_url_with_template_parameters(
|
322
|
-
_query_builder,
|
323
|
-
'location_id' => { 'value' => location_id, 'encode' => true },
|
324
|
-
'transaction_id' => { 'value' => transaction_id, 'encode' => true }
|
325
|
-
)
|
326
|
-
_query_url = APIHelper.clean_url _query_builder
|
327
|
-
|
328
|
-
# Prepare headers.
|
329
|
-
_headers = {
|
330
|
-
'accept' => 'application/json',
|
331
|
-
'content-type' => 'application/json; charset=utf-8'
|
332
|
-
}
|
333
|
-
|
334
|
-
# Prepare and execute HttpRequest.
|
335
|
-
_request = config.http_client.post(
|
336
|
-
_query_url,
|
337
|
-
headers: _headers,
|
338
|
-
parameters: body.to_json
|
339
|
-
)
|
340
|
-
OAuth2.apply(config, _request)
|
341
|
-
_response = execute_request(_request)
|
342
|
-
|
343
|
-
# Return appropriate response type.
|
344
|
-
decoded = APIHelper.json_deserialize(_response.raw_body)
|
345
|
-
_errors = APIHelper.map_response(decoded, ['errors'])
|
346
|
-
ApiResponse.new(
|
347
|
-
_response, data: decoded, errors: _errors
|
348
|
-
)
|
349
|
-
end
|
350
|
-
|
351
163
|
# Cancels a transaction that was created with the
|
352
164
|
# [Charge]($e/Transactions/Charge)
|
353
165
|
# endpoint with a `delay_capture` value of `true`.
|
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
|
+
'15.0.0.20211020'
|
8
8
|
end
|
9
9
|
|
10
10
|
def square_version
|
@@ -209,15 +209,16 @@ module Square
|
|
209
209
|
@terminal ||= TerminalApi.new config
|
210
210
|
end
|
211
211
|
|
212
|
-
def initialize(timeout: 60, max_retries: 0,
|
213
|
-
backoff_factor: 2,
|
212
|
+
def initialize(http_client_instance: nil, timeout: 60, max_retries: 0,
|
213
|
+
retry_interval: 1, backoff_factor: 2,
|
214
214
|
retry_statuses: [408, 413, 429, 500, 502, 503, 504, 521, 522, 524],
|
215
215
|
retry_methods: %i[get put], environment: 'production',
|
216
216
|
custom_url: 'https://connect.squareup.com',
|
217
|
-
square_version: '2021-
|
217
|
+
square_version: '2021-10-20', access_token: '',
|
218
218
|
additional_headers: {}, config: nil)
|
219
219
|
@config = if config.nil?
|
220
|
-
Configuration.new(
|
220
|
+
Configuration.new(http_client_instance: http_client_instance,
|
221
|
+
timeout: timeout, max_retries: max_retries,
|
221
222
|
retry_interval: retry_interval,
|
222
223
|
backoff_factor: backoff_factor,
|
223
224
|
retry_statuses: retry_statuses,
|
data/lib/square/configuration.rb
CHANGED
@@ -3,26 +3,28 @@ 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, :timeout, :max_retries, :retry_interval,
|
7
|
-
:retry_statuses, :retry_methods, :environment, :custom_url,
|
8
|
-
:access_token
|
9
|
-
|
6
|
+
attr_reader :http_client, :http_client_instance, :timeout, :max_retries, :retry_interval,
|
7
|
+
:backoff_factor, :retry_statuses, :retry_methods, :environment, :custom_url,
|
8
|
+
:square_version, :access_token
|
9
|
+
|
10
10
|
def additional_headers
|
11
11
|
@additional_headers.clone
|
12
12
|
end
|
13
13
|
|
14
|
-
|
15
14
|
class << self
|
16
15
|
attr_reader :environments
|
17
16
|
end
|
18
17
|
|
19
|
-
def initialize(timeout: 60, max_retries: 0,
|
20
|
-
backoff_factor: 2,
|
18
|
+
def initialize(http_client_instance: nil, timeout: 60, max_retries: 0,
|
19
|
+
retry_interval: 1, backoff_factor: 2,
|
21
20
|
retry_statuses: [408, 413, 429, 500, 502, 503, 504, 521, 522, 524],
|
22
21
|
retry_methods: %i[get put], environment: 'production',
|
23
22
|
custom_url: 'https://connect.squareup.com',
|
24
|
-
square_version: '2021-
|
23
|
+
square_version: '2021-10-20', access_token: '',
|
25
24
|
additional_headers: {})
|
25
|
+
# The Http Client passed from the sdk user for making requests
|
26
|
+
@http_client_instance = http_client_instance
|
27
|
+
|
26
28
|
# The value to use for connection timeout
|
27
29
|
@timeout = timeout
|
28
30
|
|
@@ -61,10 +63,12 @@ module Square
|
|
61
63
|
@http_client = create_http_client
|
62
64
|
end
|
63
65
|
|
64
|
-
def clone_with(
|
65
|
-
|
66
|
-
|
67
|
-
|
66
|
+
def clone_with(http_client_instance: nil, timeout: nil, max_retries: nil,
|
67
|
+
retry_interval: nil, backoff_factor: nil,
|
68
|
+
retry_statuses: nil, retry_methods: nil, environment: nil,
|
69
|
+
custom_url: nil, square_version: nil, access_token: nil,
|
70
|
+
additional_headers: nil)
|
71
|
+
http_client_instance ||= self.http_client_instance
|
68
72
|
timeout ||= self.timeout
|
69
73
|
max_retries ||= self.max_retries
|
70
74
|
retry_interval ||= self.retry_interval
|
@@ -77,7 +81,8 @@ module Square
|
|
77
81
|
access_token ||= self.access_token
|
78
82
|
additional_headers ||= self.additional_headers
|
79
83
|
|
80
|
-
Configuration.new(
|
84
|
+
Configuration.new(http_client_instance: http_client_instance,
|
85
|
+
timeout: timeout, max_retries: max_retries,
|
81
86
|
retry_interval: retry_interval,
|
82
87
|
backoff_factor: backoff_factor,
|
83
88
|
retry_statuses: retry_statuses,
|
@@ -92,7 +97,8 @@ module Square
|
|
92
97
|
retry_interval: retry_interval,
|
93
98
|
backoff_factor: backoff_factor,
|
94
99
|
retry_statuses: retry_statuses,
|
95
|
-
retry_methods: retry_methods
|
100
|
+
retry_methods: retry_methods,
|
101
|
+
http_client_instance: http_client_instance)
|
96
102
|
end
|
97
103
|
|
98
104
|
# All the environments the SDK can run in.
|
@@ -25,7 +25,7 @@ module Square
|
|
25
25
|
end.new(*data.values)
|
26
26
|
|
27
27
|
@cursor = data.fetch(:cursor, nil)
|
28
|
-
data.reject! { |k|
|
28
|
+
data.reject! { |k| %i[cursor errors].include?(k) }
|
29
29
|
@data = Struct.new(*data.keys).new(*data.values) if data.keys.any?
|
30
30
|
end
|
31
31
|
else
|
@@ -7,7 +7,25 @@ module Square
|
|
7
7
|
# The constructor.
|
8
8
|
def initialize(timeout:, max_retries:, retry_interval:,
|
9
9
|
backoff_factor:, retry_statuses:, retry_methods:,
|
10
|
-
cache: false, verify: true)
|
10
|
+
http_client_instance: nil, cache: false, verify: true)
|
11
|
+
if http_client_instance.nil?
|
12
|
+
create_connection(timeout: timeout, max_retries: max_retries,
|
13
|
+
retry_interval: retry_interval, backoff_factor: backoff_factor,
|
14
|
+
retry_statuses: retry_statuses, retry_methods: retry_methods,
|
15
|
+
cache: cache, verify: verify)
|
16
|
+
else
|
17
|
+
if http_client_instance.instance_variable_get('@connection').nil?
|
18
|
+
raise ArgumentError,
|
19
|
+
"`connection` cannot be nil in `#{self.class}`. Please specify a valid value."
|
20
|
+
end
|
21
|
+
@connection = http_client_instance.instance_variable_get('@connection')
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# Method to initialize connection.
|
26
|
+
def create_connection(timeout:, max_retries:, retry_interval:,
|
27
|
+
backoff_factor:, retry_statuses:, retry_methods:,
|
28
|
+
cache: false, verify: true)
|
11
29
|
@connection = Faraday.new do |faraday|
|
12
30
|
faraday.use Faraday::HttpCache, serializer: Marshal if cache
|
13
31
|
faraday.use FaradayMiddleware::FollowRedirects
|
@@ -24,6 +42,7 @@ module Square
|
|
24
42
|
faraday.options[:params_encoder] = Faraday::FlatParamsEncoder
|
25
43
|
faraday.options[:timeout] = timeout if timeout.positive?
|
26
44
|
end
|
45
|
+
@connection
|
27
46
|
end
|
28
47
|
|
29
48
|
# Method overridden from HttpClient.
|
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: 15.0.0.20211020
|
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-10-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: logging
|