square.rb 6.3.0.20200826 → 17.1.0.20220120
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/LICENSE +1 -1
- data/README.md +86 -51
- data/lib/square/api/apple_pay_api.rb +12 -9
- data/lib/square/api/bank_accounts_api.rb +21 -24
- data/lib/square/api/base_api.rb +20 -9
- data/lib/square/api/bookings_api.rb +391 -0
- data/lib/square/api/cards_api.rb +170 -0
- data/lib/square/api/cash_drawers_api.rb +13 -6
- data/lib/square/api/catalog_api.rb +195 -85
- data/lib/square/api/checkout_api.rb +7 -5
- data/lib/square/api/customer_groups_api.rb +34 -16
- data/lib/square/api/customer_segments_api.rb +21 -9
- data/lib/square/api/customers_api.rb +102 -55
- data/lib/square/api/devices_api.rb +20 -8
- data/lib/square/api/disputes_api.rb +156 -144
- data/lib/square/api/employees_api.rb +7 -3
- data/lib/square/api/gift_card_activities_api.rb +133 -0
- data/lib/square/api/gift_cards_api.rb +297 -0
- data/lib/square/api/inventory_api.rb +290 -37
- data/lib/square/api/invoices_api.rb +61 -57
- data/lib/square/api/labor_api.rb +127 -93
- data/lib/square/api/locations_api.rb +36 -25
- data/lib/square/api/loyalty_api.rb +134 -87
- data/lib/square/api/merchants_api.rb +8 -4
- data/lib/square/api/mobile_authorization_api.rb +9 -7
- data/lib/square/api/o_auth_api.rb +41 -32
- data/lib/square/api/orders_api.rb +132 -54
- data/lib/square/api/payments_api.rb +133 -75
- data/lib/square/api/refunds_api.rb +51 -30
- data/lib/square/api/sites_api.rb +43 -0
- data/lib/square/api/snippets_api.rb +146 -0
- data/lib/square/api/subscriptions_api.rb +216 -26
- data/lib/square/api/team_api.rb +81 -65
- data/lib/square/api/terminal_api.rb +166 -16
- data/lib/square/api/transactions_api.rb +32 -194
- data/lib/square/api/v1_transactions_api.rb +53 -103
- data/lib/square/api_helper.rb +38 -43
- data/lib/square/client.rb +54 -24
- data/lib/square/configuration.rb +61 -21
- data/lib/square/http/api_response.rb +3 -1
- data/lib/square/http/faraday_client.rb +34 -5
- data/lib/square/utilities/date_time_helper.rb +151 -0
- data/lib/square/utilities/file_wrapper.rb +1 -2
- data/lib/square.rb +65 -61
- data/spec/user_journey_spec.rb +2 -5
- data/test/api/api_test_base.rb +1 -6
- data/test/api/test_catalog_api.rb +1 -4
- data/test/api/test_customers_api.rb +1 -4
- data/test/api/test_employees_api.rb +1 -4
- data/test/api/test_labor_api.rb +2 -6
- data/test/api/test_locations_api.rb +21 -35
- data/test/api/test_merchants_api.rb +1 -4
- data/test/api/test_payments_api.rb +3 -6
- data/test/api/test_refunds_api.rb +3 -6
- data/test/http_response_catcher.rb +0 -5
- data/test/test_helper.rb +1 -6
- metadata +40 -18
- data/lib/square/api/v1_employees_api.rb +0 -723
- data/lib/square/api/v1_items_api.rb +0 -1686
- data/lib/square/api/v1_locations_api.rb +0 -65
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 407147246777f8a4eda2d4848cad5edb62be5801c25b6361f0dfb21d58663fd9
|
4
|
+
data.tar.gz: 735c7e92297b1d4a79ebd856dbe39cc304051536622f0277ddd9489811652cb6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 90ccb1516f8ff8998787d63a168c8c8688b9a12691d85cac3a2b6af35ce52af93bbc013e11336d5319cc252ec75ce7f790165ea5c38c69367f092e5ef62b365d
|
7
|
+
data.tar.gz: 05a3eb69caf678ad7f071b66a27c3ed4375ac96470ba09e51df9db6eba1401b80bd461c7fd6cb7bde91f30bb7ee5d11b9f7f293a59d40c70ab5ed52b25b9d180
|
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -2,12 +2,16 @@
|
|
2
2
|
|
3
3
|
# Square Ruby SDK
|
4
4
|
|
5
|
-
[](https://github.com/square/square-ruby-sdk/actions/workflows/ruby.yml)
|
6
6
|
[](https://badge.fury.io/rb/square.rb)
|
7
7
|
[](https://www.apache.org/licenses/LICENSE-2.0)
|
8
8
|
|
9
9
|
Use this gem to integrate Square payments into your app and grow your business with Square APIs including Catalog, Customers, Employees, Inventory, Labor, Locations, and Orders.
|
10
10
|
|
11
|
+
## Requirements
|
12
|
+
|
13
|
+
We support Ruby 2.5.x, 2.6.x, 2.7.x, and 3.0.x.
|
14
|
+
|
11
15
|
## Installation
|
12
16
|
|
13
17
|
Install the gem from the command line:
|
@@ -33,6 +37,9 @@ gem 'square.rb'
|
|
33
37
|
* [Disputes]
|
34
38
|
* [Checkout]
|
35
39
|
* [Apple Pay]
|
40
|
+
* [Cards]
|
41
|
+
|
42
|
+
### Terminal
|
36
43
|
* [Terminal]
|
37
44
|
|
38
45
|
### Orders
|
@@ -56,26 +63,36 @@ gem 'square.rb'
|
|
56
63
|
### Loyalty
|
57
64
|
* [Loyalty]
|
58
65
|
|
66
|
+
### Gift Cards
|
67
|
+
* [Gift Cards]
|
68
|
+
* [Gift Card Activities]
|
69
|
+
|
70
|
+
### Bookings
|
71
|
+
* [Bookings]
|
72
|
+
|
59
73
|
### Business
|
60
74
|
* [Merchants]
|
61
75
|
* [Locations]
|
62
76
|
* [Devices]
|
77
|
+
* [Cash Drawers]
|
63
78
|
|
64
79
|
### Team
|
65
80
|
* [Team]
|
66
|
-
* [Employees]
|
67
81
|
* [Labor]
|
68
|
-
* [Cash Drawers]
|
69
82
|
|
70
83
|
### Financials
|
71
84
|
* [Bank Accounts]
|
72
85
|
|
86
|
+
### Online
|
87
|
+
* [Sites]
|
88
|
+
* [Snippets]
|
89
|
+
|
73
90
|
### Authorization APIs
|
74
91
|
* [Mobile Authorization]
|
75
|
-
* [
|
92
|
+
* [OAuth]
|
76
93
|
|
77
94
|
### Deprecated APIs
|
78
|
-
* [
|
95
|
+
* [Employees]
|
79
96
|
* [V1 Employees]
|
80
97
|
* [V1 Transactions]
|
81
98
|
* [V1 Items]
|
@@ -98,8 +115,8 @@ require 'square'
|
|
98
115
|
# for the Square account whose assets you want to manage.
|
99
116
|
|
100
117
|
client = Square::Client.new(
|
101
|
-
|
102
|
-
|
118
|
+
access_token: 'YOUR SANDBOX ACCESS TOKEN HERE',
|
119
|
+
environment: 'sandbox'
|
103
120
|
)
|
104
121
|
|
105
122
|
# Call list_locations method to get all locations in this Square account
|
@@ -107,10 +124,10 @@ result = client.locations.list_locations
|
|
107
124
|
|
108
125
|
# Call the #success? method to see if the call succeeded
|
109
126
|
if result.success?
|
110
|
-
|
127
|
+
# The #data Struct contains a list of locations
|
111
128
|
locations = result.data.locations
|
112
129
|
|
113
|
-
|
130
|
+
# Iterate over the list
|
114
131
|
locations.each do |location|
|
115
132
|
# Each location is represented as a Hash
|
116
133
|
location.each do |key, value|
|
@@ -159,6 +176,7 @@ This error was returned when an invalid token was used to call the API.
|
|
159
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.
|
160
177
|
|
161
178
|
## SDK patterns
|
179
|
+
|
162
180
|
If you know a few patterns, you’ll be able to call any API in the SDK. Here are some important ones:
|
163
181
|
|
164
182
|
### Get an access token
|
@@ -179,21 +197,31 @@ To use the Square API, you import the Client class, instantiate a Client object,
|
|
179
197
|
|
180
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:
|
181
199
|
|
182
|
-
```ruby
|
183
|
-
client = Square::Client.new(
|
200
|
+
```ruby
|
201
|
+
client = Square::Client.new(
|
184
202
|
access_token: 'SANDBOX ACCESS TOKEN HERE',
|
185
203
|
environment: 'sandbox'
|
186
|
-
)
|
187
|
-
```
|
204
|
+
)
|
205
|
+
```
|
188
206
|
|
189
207
|
- To access production resources, set environment to production:
|
190
208
|
|
191
|
-
```ruby
|
192
|
-
client = Square::Client.new(
|
209
|
+
```ruby
|
210
|
+
client = Square::Client.new(
|
193
211
|
access_token: 'ACCESS TOKEN HERE',
|
194
212
|
environment: 'production'
|
195
|
-
)
|
196
|
-
```
|
213
|
+
)
|
214
|
+
```
|
215
|
+
|
216
|
+
- To set a custom environment provide a `custom_url`, and set environment to `custom`:
|
217
|
+
|
218
|
+
```ruby
|
219
|
+
client = Square::Client.new(
|
220
|
+
access_token:'ACCESS TOKEN HERE',
|
221
|
+
environment: 'custom',
|
222
|
+
custom_url: 'https://your.customdomain.com'
|
223
|
+
)
|
224
|
+
```
|
197
225
|
|
198
226
|
### Get an Instance of an API object and call its methods
|
199
227
|
|
@@ -201,9 +229,9 @@ Each API is implemented as a class. The Client object instantiates every API cla
|
|
201
229
|
|
202
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:
|
203
231
|
|
204
|
-
```ruby
|
205
|
-
result = client.customers.list_customers
|
206
|
-
```
|
232
|
+
```ruby
|
233
|
+
result = client.customers.list_customers
|
234
|
+
```
|
207
235
|
|
208
236
|
See the SDK documentation for the list of methods for each API class.
|
209
237
|
|
@@ -224,6 +252,7 @@ result = client.customers.create_customer(request_body)
|
|
224
252
|
```
|
225
253
|
|
226
254
|
If your call succeeds, you’ll see a response that looks like this:
|
255
|
+
|
227
256
|
```
|
228
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'}}
|
229
258
|
```
|
@@ -248,7 +277,7 @@ end
|
|
248
277
|
|
249
278
|
## Tests
|
250
279
|
|
251
|
-
First, clone the
|
280
|
+
First, clone the repo locally and `cd` into the directory.
|
252
281
|
|
253
282
|
```sh
|
254
283
|
git clone https://github.com/square/square-ruby-sdk.git
|
@@ -280,38 +309,44 @@ The Square Platform is built on the [Square API]. Square has a number of other S
|
|
280
309
|
|
281
310
|
You can also use the Square API to create applications or services that work with payments, orders, inventory, etc. that have been created and managed in Square’s in-person hardware products (Square Point of Sale and Square Register).
|
282
311
|
|
312
|
+
[//]: # "Link anchor definitions"
|
283
313
|
[Square Logo]: https://docs.connect.squareup.com/images/github/github-square-logo.svg
|
284
314
|
[Developer Dashboard]: https://developer.squareup.com/apps
|
285
315
|
[Square API]: https://squareup.com/developers
|
286
316
|
[sign up for a developer account]: https://squareup.com/signup?v=developers
|
287
317
|
[Client]: doc/client.md
|
288
|
-
[Devices]: doc/devices.md
|
289
|
-
[Disputes]: doc/disputes.md
|
290
|
-
[Terminal]: doc/terminal.md
|
291
|
-
[Team]: doc/team.md
|
292
|
-
[Cash Drawers]: doc/cash-drawers.md
|
293
|
-
[Customer Groups]: doc/customer-groups.md
|
294
|
-
[Customer Segments]: doc/customer-segments.md
|
295
|
-
[Bank Accounts]: doc/bank-accounts
|
296
|
-
[Payments]: doc/payments.md
|
297
|
-
[Checkout]: doc/checkout.md
|
298
|
-
[Catalog]: doc/catalog.md
|
299
|
-
[Customers]: doc/customers.md
|
300
|
-
[Employees]: doc/employees.md
|
301
|
-
[Inventory]: doc/inventory.md
|
302
|
-
[Labor]: doc/labor.md
|
303
|
-
[Loyalty]: doc/loyalty.md
|
304
|
-
[
|
305
|
-
[
|
306
|
-
[
|
307
|
-
[
|
308
|
-
[
|
309
|
-
[
|
310
|
-
[
|
311
|
-
[
|
312
|
-
[
|
313
|
-
[
|
314
|
-
[V1
|
315
|
-
[V1
|
316
|
-
[
|
317
|
-
[
|
318
|
+
[Devices]: doc/api/devices.md
|
319
|
+
[Disputes]: doc/api/disputes.md
|
320
|
+
[Terminal]: doc/api/terminal.md
|
321
|
+
[Team]: doc/api/team.md
|
322
|
+
[Cash Drawers]: doc/api/cash-drawers.md
|
323
|
+
[Customer Groups]: doc/api/customer-groups.md
|
324
|
+
[Customer Segments]: doc/api/customer-segments.md
|
325
|
+
[Bank Accounts]: doc/api/bank-accounts.md
|
326
|
+
[Payments]: doc/api/payments.md
|
327
|
+
[Checkout]: doc/api/checkout.md
|
328
|
+
[Catalog]: doc/api/catalog.md
|
329
|
+
[Customers]: doc/api/customers.md
|
330
|
+
[Employees]: doc/api/employees.md
|
331
|
+
[Inventory]: doc/api/inventory.md
|
332
|
+
[Labor]: doc/api/labor.md
|
333
|
+
[Loyalty]: doc/api/loyalty.md
|
334
|
+
[Bookings]: doc/api/bookings.md
|
335
|
+
[Locations]: doc/api/locations.md
|
336
|
+
[Merchants]: doc/api/merchants.md
|
337
|
+
[Orders]: doc/api/orders.md
|
338
|
+
[Invoices]: doc/api/invoices.md
|
339
|
+
[Apple Pay]: doc/api/apple-pay.md
|
340
|
+
[Refunds]: doc/api/refunds.md
|
341
|
+
[Subscriptions]: doc/api/subscriptions.md
|
342
|
+
[Mobile Authorization]: doc/api/mobile-authorization.md
|
343
|
+
[OAuth]: doc/api/o-auth.md
|
344
|
+
[V1 Employees]: doc/api/v1-employees.md
|
345
|
+
[V1 Transactions]: doc/api/v1-transactions.md
|
346
|
+
[V1 Items]: doc/api/v1-items.md
|
347
|
+
[Transactions]: doc/api/transactions.md
|
348
|
+
[Sites]: doc/api/sites.md
|
349
|
+
[Snippets]: doc/api/snippets.md
|
350
|
+
[Cards]: doc/api/cards.md
|
351
|
+
[Gift Cards]: doc/api/gift-cards.md
|
352
|
+
[Gift Card Activities]: doc/api/gift-card-activities.md
|
@@ -5,17 +5,18 @@ module Square
|
|
5
5
|
super(config, http_call_back: http_call_back)
|
6
6
|
end
|
7
7
|
|
8
|
-
# Activates a domain for use with
|
9
|
-
#
|
8
|
+
# Activates a domain for use with Apple Pay on the Web and Square. A
|
9
|
+
# validation
|
10
|
+
# is performed on this domain by Apple to ensure that it is properly set up
|
10
11
|
# as
|
11
12
|
# an Apple Pay enabled domain.
|
12
13
|
# This endpoint provides an easy way for platform developers to bulk
|
13
14
|
# activate
|
14
|
-
#
|
15
|
-
# To learn more about
|
16
|
-
# [
|
17
|
-
#
|
18
|
-
# -
|
15
|
+
# Apple Pay on the Web with Square for merchants using their platform.
|
16
|
+
# To learn more about Web Apple Pay, see
|
17
|
+
# [Add the Apple Pay on the Web
|
18
|
+
# Button](https://developer.squareup.com/docs/payment-form/add-digital-walle
|
19
|
+
# ts/apple-pay).
|
19
20
|
# @param [RegisterDomainRequest] body Required parameter: An object
|
20
21
|
# containing the fields to POST for the request. See the corresponding
|
21
22
|
# object definition for field details.
|
@@ -29,7 +30,7 @@ module Square
|
|
29
30
|
# Prepare headers.
|
30
31
|
_headers = {
|
31
32
|
'accept' => 'application/json',
|
32
|
-
'
|
33
|
+
'Content-Type' => 'application/json'
|
33
34
|
}
|
34
35
|
|
35
36
|
# Prepare and execute HttpRequest.
|
@@ -44,7 +45,9 @@ module Square
|
|
44
45
|
# Return appropriate response type.
|
45
46
|
decoded = APIHelper.json_deserialize(_response.raw_body)
|
46
47
|
_errors = APIHelper.map_response(decoded, ['errors'])
|
47
|
-
ApiResponse.new(
|
48
|
+
ApiResponse.new(
|
49
|
+
_response, data: decoded, errors: _errors
|
50
|
+
)
|
48
51
|
end
|
49
52
|
end
|
50
53
|
end
|
@@ -5,16 +5,13 @@ module Square
|
|
5
5
|
super(config, http_call_back: http_call_back)
|
6
6
|
end
|
7
7
|
|
8
|
-
# Returns a list of [BankAccount](
|
9
|
-
#
|
10
|
-
# For more information, see
|
11
|
-
# [Bank Accounts
|
12
|
-
# API](https://developer.squareup.com/docs/docs/bank-accounts-api).
|
8
|
+
# Returns a list of [BankAccount]($m/BankAccount) objects linked to a Square
|
9
|
+
# account.
|
13
10
|
# @param [String] cursor Optional parameter: The pagination cursor returned
|
14
11
|
# by a previous call to this endpoint. Use it in the next `ListBankAccounts`
|
15
12
|
# request to retrieve the next set of results. See the
|
16
|
-
# [Pagination](https://developer.squareup.com/docs/
|
17
|
-
#
|
13
|
+
# [Pagination](https://developer.squareup.com/docs/working-with-apis/paginat
|
14
|
+
# ion) guide for more information.
|
18
15
|
# @param [Integer] limit Optional parameter: Upper limit on the number of
|
19
16
|
# bank accounts to return in the response. Currently, 1000 is the largest
|
20
17
|
# supported limit. You can specify a limit of up to 1000 bank accounts.
|
@@ -53,20 +50,18 @@ module Square
|
|
53
50
|
# Return appropriate response type.
|
54
51
|
decoded = APIHelper.json_deserialize(_response.raw_body)
|
55
52
|
_errors = APIHelper.map_response(decoded, ['errors'])
|
56
|
-
ApiResponse.new(
|
53
|
+
ApiResponse.new(
|
54
|
+
_response, data: decoded, errors: _errors
|
55
|
+
)
|
57
56
|
end
|
58
57
|
|
59
|
-
# Returns details of a [BankAccount](
|
60
|
-
#
|
61
|
-
# For more information, see
|
62
|
-
# [Retrieve a bank account by using an ID issued by V1 Bank Accounts
|
63
|
-
# API](https://developer.squareup.com/docs/docs/bank-accounts-api#retrieve-a
|
64
|
-
# -bank-account-by-using-an-id-issued-by-the-v1-bank-accounts-api).
|
58
|
+
# Returns details of a [BankAccount]($m/BankAccount) identified by V1 bank
|
59
|
+
# account ID.
|
65
60
|
# @param [String] v1_bank_account_id Required parameter: Connect V1 ID of
|
66
61
|
# the desired `BankAccount`. For more information, see [Retrieve a bank
|
67
62
|
# account by using an ID issued by V1 Bank Accounts
|
68
|
-
# API](https://developer.squareup.com/docs/
|
69
|
-
# -
|
63
|
+
# API](https://developer.squareup.com/docs/bank-accounts-api#retrieve-a-bank
|
64
|
+
# -account-by-using-an-id-issued-by-v1-bank-accounts-api).
|
70
65
|
# @return [GetBankAccountByV1IdResponse Hash] response from the API call
|
71
66
|
def get_bank_account_by_v1_id(v1_bank_account_id:)
|
72
67
|
# Prepare query url.
|
@@ -74,7 +69,7 @@ module Square
|
|
74
69
|
_query_builder << '/v2/bank-accounts/by-v1-id/{v1_bank_account_id}'
|
75
70
|
_query_builder = APIHelper.append_url_with_template_parameters(
|
76
71
|
_query_builder,
|
77
|
-
'v1_bank_account_id' => v1_bank_account_id
|
72
|
+
'v1_bank_account_id' => { 'value' => v1_bank_account_id, 'encode' => true }
|
78
73
|
)
|
79
74
|
_query_url = APIHelper.clean_url _query_builder
|
80
75
|
|
@@ -94,13 +89,13 @@ module Square
|
|
94
89
|
# Return appropriate response type.
|
95
90
|
decoded = APIHelper.json_deserialize(_response.raw_body)
|
96
91
|
_errors = APIHelper.map_response(decoded, ['errors'])
|
97
|
-
ApiResponse.new(
|
92
|
+
ApiResponse.new(
|
93
|
+
_response, data: decoded, errors: _errors
|
94
|
+
)
|
98
95
|
end
|
99
96
|
|
100
|
-
# Returns details of a [BankAccount](
|
101
|
-
# linked to a Square account.
|
102
|
-
# [Bank Accounts
|
103
|
-
# API](https://developer.squareup.com/docs/docs/bank-accounts-api).
|
97
|
+
# Returns details of a [BankAccount]($m/BankAccount)
|
98
|
+
# linked to a Square account.
|
104
99
|
# @param [String] bank_account_id Required parameter: Square-issued ID of
|
105
100
|
# the desired `BankAccount`.
|
106
101
|
# @return [GetBankAccountResponse Hash] response from the API call
|
@@ -110,7 +105,7 @@ module Square
|
|
110
105
|
_query_builder << '/v2/bank-accounts/{bank_account_id}'
|
111
106
|
_query_builder = APIHelper.append_url_with_template_parameters(
|
112
107
|
_query_builder,
|
113
|
-
'bank_account_id' => bank_account_id
|
108
|
+
'bank_account_id' => { 'value' => bank_account_id, 'encode' => true }
|
114
109
|
)
|
115
110
|
_query_url = APIHelper.clean_url _query_builder
|
116
111
|
|
@@ -130,7 +125,9 @@ module Square
|
|
130
125
|
# Return appropriate response type.
|
131
126
|
decoded = APIHelper.json_deserialize(_response.raw_body)
|
132
127
|
_errors = APIHelper.map_response(decoded, ['errors'])
|
133
|
-
ApiResponse.new(
|
128
|
+
ApiResponse.new(
|
129
|
+
_response, data: decoded, errors: _errors
|
130
|
+
)
|
134
131
|
end
|
135
132
|
end
|
136
133
|
end
|
data/lib/square/api/base_api.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'erb'
|
1
2
|
module Square
|
2
3
|
# BaseApi.
|
3
4
|
class BaseApi
|
@@ -8,36 +9,46 @@ module Square
|
|
8
9
|
@http_call_back = http_call_back
|
9
10
|
|
10
11
|
@global_headers = {
|
11
|
-
'user-agent' =>
|
12
|
+
'user-agent' => get_user_agent,
|
12
13
|
'Square-Version' => config.square_version
|
13
14
|
}
|
14
15
|
end
|
15
16
|
|
16
17
|
def validate_parameters(args)
|
17
18
|
args.each do |_name, value|
|
18
|
-
if value.nil?
|
19
|
-
raise ArgumentError, "Required parameter #{_name} cannot be nil."
|
20
|
-
end
|
19
|
+
raise ArgumentError, "Required parameter #{_name} cannot be nil." if value.nil?
|
21
20
|
end
|
22
21
|
end
|
23
22
|
|
24
23
|
def execute_request(request, binary: false)
|
25
|
-
@http_call_back
|
24
|
+
@http_call_back&.on_before_request(request)
|
26
25
|
|
27
26
|
APIHelper.clean_hash(request.headers)
|
28
27
|
request.headers.merge!(@global_headers)
|
29
|
-
unless config.additional_headers.nil?
|
30
|
-
request.headers.merge!(config.additional_headers)
|
31
|
-
end
|
28
|
+
request.headers.merge!(config.additional_headers) unless config.additional_headers.nil?
|
32
29
|
|
33
30
|
response = if binary
|
34
31
|
config.http_client.execute_as_binary(request)
|
35
32
|
else
|
36
33
|
config.http_client.execute_as_string(request)
|
37
34
|
end
|
38
|
-
@http_call_back
|
35
|
+
@http_call_back&.on_after_response(response)
|
39
36
|
|
40
37
|
response
|
41
38
|
end
|
39
|
+
|
40
|
+
def get_user_agent
|
41
|
+
user_agent = 'Square-Ruby-SDK/17.1.0.20220120 ({api-version}) {engine}/{engine-version} ({os-info}) {detail}'
|
42
|
+
user_agent['{engine}'] = RUBY_ENGINE
|
43
|
+
user_agent['{engine-version}'] = RUBY_ENGINE_VERSION
|
44
|
+
user_agent['{os-info}'] = RUBY_PLATFORM
|
45
|
+
user_agent['{api-version}'] = config.square_version
|
46
|
+
if config.user_agent_detail.nil? || config.user_agent_detail.empty?
|
47
|
+
user_agent = user_agent.gsub('{detail}', '')
|
48
|
+
else
|
49
|
+
user_agent['{detail}'] = ERB::Util.url_encode(config.user_agent_detail.to_s)
|
50
|
+
end
|
51
|
+
user_agent
|
52
|
+
end
|
42
53
|
end
|
43
54
|
end
|