square.rb 8.0.0.20201216 → 26.1.0.20230119

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +1 -1
  3. data/README.md +79 -221
  4. data/lib/square/api/apple_pay_api.rb +15 -8
  5. data/lib/square/api/bank_accounts_api.rb +5 -5
  6. data/lib/square/api/base_api.rb +27 -9
  7. data/lib/square/api/booking_custom_attributes_api.rb +555 -0
  8. data/lib/square/api/bookings_api.rb +107 -15
  9. data/lib/square/api/cards_api.rb +171 -0
  10. data/lib/square/api/cash_drawers_api.rb +2 -2
  11. data/lib/square/api/catalog_api.rb +167 -73
  12. data/lib/square/api/checkout_api.rb +205 -3
  13. data/lib/square/api/customer_custom_attributes_api.rb +561 -0
  14. data/lib/square/api/customer_groups_api.rb +17 -8
  15. data/lib/square/api/customer_segments_api.rb +15 -6
  16. data/lib/square/api/customers_api.rb +67 -33
  17. data/lib/square/api/devices_api.rb +3 -2
  18. data/lib/square/api/disputes_api.rb +109 -105
  19. data/lib/square/api/gift_card_activities_api.rb +132 -0
  20. data/lib/square/api/gift_cards_api.rb +298 -0
  21. data/lib/square/api/inventory_api.rb +263 -24
  22. data/lib/square/api/invoices_api.rb +21 -21
  23. data/lib/square/api/labor_api.rb +70 -68
  24. data/lib/square/api/location_custom_attributes_api.rb +584 -0
  25. data/lib/square/api/locations_api.rb +21 -14
  26. data/lib/square/api/loyalty_api.rb +333 -50
  27. data/lib/square/api/merchants_api.rb +11 -9
  28. data/lib/square/api/mobile_authorization_api.rb +4 -4
  29. data/lib/square/api/o_auth_api.rb +78 -25
  30. data/lib/square/api/order_custom_attributes_api.rb +601 -0
  31. data/lib/square/api/orders_api.rb +84 -45
  32. data/lib/square/api/payments_api.rb +72 -24
  33. data/lib/square/api/payouts_api.rb +173 -0
  34. data/lib/square/api/refunds_api.rb +18 -7
  35. data/lib/square/api/sites_api.rb +43 -0
  36. data/lib/square/api/snippets_api.rb +146 -0
  37. data/lib/square/api/subscriptions_api.rb +190 -15
  38. data/lib/square/api/team_api.rb +46 -46
  39. data/lib/square/api/terminal_api.rb +172 -22
  40. data/lib/square/api/transactions_api.rb +15 -191
  41. data/lib/square/api/v1_transactions_api.rb +52 -124
  42. data/lib/square/api/vendors_api.rb +257 -0
  43. data/lib/square/api/webhook_subscriptions_api.rb +327 -0
  44. data/lib/square/api_helper.rb +217 -57
  45. data/lib/square/client.rb +90 -18
  46. data/lib/square/configuration.rb +64 -20
  47. data/lib/square/exceptions/validation_exception.rb +13 -0
  48. data/lib/square/http/api_response.rb +7 -9
  49. data/lib/square/http/faraday_client.rb +40 -9
  50. data/lib/square/http/http_client.rb +31 -12
  51. data/lib/square/http/http_request.rb +6 -2
  52. data/lib/square/utilities/date_time_helper.rb +151 -0
  53. data/lib/square/utilities/file_wrapper.rb +1 -2
  54. data/lib/square.rb +56 -44
  55. data/test/api/test_locations_api.rb +2 -5
  56. data/test/test_helper.rb +2 -2
  57. metadata +83 -15
  58. data/lib/square/api/v1_employees_api.rb +0 -751
  59. data/lib/square/api/v1_items_api.rb +0 -1766
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 50abb148c3dd6d03e86147fc8f95f3f58eeafeabb22d81c65a5c58b87b0b1060
4
- data.tar.gz: 26371d6cdfa25de275bfef471b8145e43eaeccc7dc661d0abac57f9b643645aa
3
+ metadata.gz: ac8d00e1d947c816019d207e36e19a85ef2f8d66e3b5c4295e3e19f6cfcd5af6
4
+ data.tar.gz: ba91ef39e6e11e16af9a859abe126cd8f25e0d0751a65a101e63dfb0bbbf4718
5
5
  SHA512:
6
- metadata.gz: a404bd6129da3f1ed2cdeaa8080d05c4ec75fe2ae93913c9c6e01de706f8dfc8487fb8696d431072a87511d9036fa6fa7cc797e6765f326c382d45ba0658d719
7
- data.tar.gz: 8000f93f083e58f8c6c820520f535cdf5015f1184ac0bd2febfb3a4448e0850a9ea168e997f7a42f54435255a3beba8a2c74615fd2a155e05fe8cb8bcd7c1652
6
+ metadata.gz: 23f2218d4d9757a648c69c5d6d21eb764f121695c6a11ac80607f24bb86301745f410b1103937ad49a157f150784ea1d396ea57393d0743c0742848b8beba0fa
7
+ data.tar.gz: fc4af83a8b04a151839c45f6f0c632f2b6b5b65abfcde66027d89714ac8566770b5f70407d021337d7cae3daa67957b06ca373eaf4b3b6791aef13ae1029ca87
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2020 Square, Inc.
1
+ Copyright 2023 Square, Inc.
2
2
  Licensed under the Apache License, Version 2.0 (the "License");
3
3
  you may not use this file except in compliance with the License.
4
4
  You may obtain a copy of the License at
data/README.md CHANGED
@@ -2,30 +2,66 @@
2
2
 
3
3
  # Square Ruby SDK
4
4
 
5
- [![Travis status](https://travis-ci.org/square/square-ruby-sdk.svg?branch=master)](https://travis-ci.org/square/square-ruby-sdk)
5
+ [![Build](https://github.com/square/square-ruby-sdk/actions/workflows/ruby.yml/badge.svg)](https://github.com/square/square-ruby-sdk/actions/workflows/ruby.yml)
6
6
  [![Gem version](https://badge.fury.io/rb/square.rb.svg?new)](https://badge.fury.io/rb/square.rb)
7
7
  [![Apache-2 license](https://img.shields.io/badge/license-Apache2-brightgreen.svg)](https://www.apache.org/licenses/LICENSE-2.0)
8
8
 
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.
9
+ Use this library to integrate Square payments into your app and grow your business with Square APIs including Catalog, Customers, Employees, Inventory, Labor, Locations, and Orders.
10
+
11
+ * [Requirements](#requirements)
12
+ * [Installation](#installation)
13
+ * [Quickstart](#quickstart)
14
+ * [Usage](#usage)
15
+ * [Tests](#tests)
16
+ * [SDK Reference](#sdk-reference)
17
+ * [Deprecated APIs](#deprecated-apis)
18
+
19
+ ## Requirements
20
+
21
+ Use of the Square Ruby SDK requires:
22
+
23
+ * Ruby 2.6 through 3.1
10
24
 
11
25
  ## Installation
12
26
 
13
- Install the gem from the command line:
27
+ For more information, see [Set Up Your Square SDK for a Ruby Project](https://developer.squareup.com/docs/sdks/ruby/setup-project).
28
+
29
+ ## Quickstart
30
+
31
+ For more information, see [Square Ruby SDK Quickstart](https://developer.squareup.com/docs/sdks/ruby/quick-start).
32
+
33
+ ## Usage
34
+ For more information, see [Using the Square Ruby SDK](https://developer.squareup.com/docs/sdks/ruby/using-ruby-sdk).
35
+
36
+ ## Tests
37
+
38
+ First, clone the repo locally and `cd` into the directory.
39
+
40
+ ```sh
41
+ git clone https://github.com/square/square-ruby-sdk.git
42
+ cd square-ruby-sdk
43
+ ```
44
+
45
+ Next, make sure Bundler is installed and install the development dependencies.
14
46
 
15
- ```ruby
16
- gem install square.rb
47
+ ```sh
48
+ gem install bundler
49
+ bundle
17
50
  ```
18
51
 
19
- Or add the gem to your Gemfile and `bundle`:
52
+ Before running the tests, find a sandbox token in your [Developer Dashboard] and set a `SQUARE_SANDBOX_TOKEN` environment variable.
20
53
 
21
- ```ruby
22
- gem 'square.rb'
54
+ ```sh
55
+ export SQUARE_SANDBOX_TOKEN="YOUR SANDBOX TOKEN HERE"
23
56
  ```
24
57
 
25
- ### API Client
26
- * [Client]
58
+ And run the tests.
27
59
 
28
- ## API documentation
60
+ ```sh
61
+ rake
62
+ ```
63
+
64
+ ## SDK Reference
29
65
 
30
66
  ### Payments
31
67
  * [Payments]
@@ -33,6 +69,10 @@ gem 'square.rb'
33
69
  * [Disputes]
34
70
  * [Checkout]
35
71
  * [Apple Pay]
72
+ * [Cards]
73
+ * [Payouts]
74
+
75
+ ### Terminal
36
76
  * [Terminal]
37
77
 
38
78
  ### Orders
@@ -50,12 +90,17 @@ gem 'square.rb'
50
90
 
51
91
  ### Customers
52
92
  * [Customers]
93
+ * [Customer Custom Attributes]
53
94
  * [Customer Groups]
54
95
  * [Customer Segments]
55
96
 
56
97
  ### Loyalty
57
98
  * [Loyalty]
58
99
 
100
+ ### Gift Cards
101
+ * [Gift Cards]
102
+ * [Gift Card Activities]
103
+
59
104
  ### Bookings
60
105
  * [Bookings]
61
106
 
@@ -63,225 +108,33 @@ gem 'square.rb'
63
108
  * [Merchants]
64
109
  * [Locations]
65
110
  * [Devices]
111
+ * [Cash Drawers]
112
+ * [Vendors]
66
113
 
67
114
  ### Team
68
115
  * [Team]
69
- * [Employees]
70
116
  * [Labor]
71
- * [Cash Drawers]
72
117
 
73
118
  ### Financials
74
119
  * [Bank Accounts]
75
120
 
76
- ### Authorization APIs
77
- * [Mobile Authorization]
78
- * [O Auth]
79
-
80
- ### Deprecated APIs
81
- * [V1 Employees]
82
- * [V1 Transactions]
83
- * [V1 Items]
84
- * [Transactions]
85
-
86
- ## Usage
87
-
88
- First time using Square? Here’s how to get started:
89
-
90
- 1. **Create a Square account.** If you don’t have one already, [sign up for a developer account].
91
- 1. **Create an application.** Go to your [Developer Dashboard] and create your first application. All you need to do is give it a name. When you’re doing this for your production application, enter the name as you would want a customer to see it.
92
- 1. **Make your first API call.** Almost all Square API calls require a location ID. You’ll make your first call to #list_locations, which happens to be one of the API calls that don’t require a location ID. For more information about locations, see the [Locations] API documentation.
93
-
94
- Now let’s call your first Square API. Open your favorite text editor, create a new file called `locations.rb`, and copy the following code into that file:
95
-
96
- ```ruby
97
- require 'square'
98
-
99
- # Create an instance of the API Client and initialize it with the credentials
100
- # for the Square account whose assets you want to manage.
101
-
102
- client = Square::Client.new(
103
- access_token: 'YOUR SANDBOX ACCESS TOKEN HERE',
104
- environment: 'sandbox'
105
- )
106
-
107
- # Call list_locations method to get all locations in this Square account
108
- result = client.locations.list_locations
109
-
110
- # Call the #success? method to see if the call succeeded
111
- if result.success?
112
- # The #data Struct contains a list of locations
113
- locations = result.data.locations
114
-
115
- # Iterate over the list
116
- locations.each do |location|
117
- # Each location is represented as a Hash
118
- location.each do |key, value|
119
- puts "#{key}: #{value}"
120
- end
121
- end
122
- else
123
- # Handle the case that the result is an error.
124
- warn 'Error calling LocationsApi.listlocations ...'
125
-
126
- # The #errors method returns an Array of error Hashes
127
- result.errors.each do |key, value|
128
- warn "#{key}: #{value}"
129
- end
130
- end
131
- ```
132
-
133
- Next, get an access token and reference it in your code. Go back to your application in the Developer Dashboard, in the Sandbox section click Show in the Sandbox Access Token box, copy that access token, and replace `'YOUR SANDBOX ACCESS TOKEN HERE'` with that token.
134
-
135
- **Important** When you eventually switch from trying things out on sandbox to actually working with your real production resources, you should not embed the access token in your code. Make sure you store and access your production access tokens securely.
136
-
137
- Now save `locations.rb` and run it:
138
-
139
- ```sh
140
- ruby locations.rb
141
- ```
142
-
143
- If your call is successful, you’ll get a response that looks like this:
144
-
145
- ```
146
- address : {'address_line_1': '1455 Market Street', 'administrative_district_level_1': 'CA', 'country': 'US', 'locality': 'San Francisco', 'postal_code': '94103'}
147
- # ...
148
- ```
149
-
150
- Yay! You successfully made your first call. If you didn’t, you would see an error message that looks something like this:
151
-
152
- ```
153
- Error calling LocationsApi.listlocations
154
- category : AUTHENTICATION_ERROR
155
- code : UNAUTHORIZED
156
- detail : This request could not be authorized.
157
- ```
158
-
159
- This error was returned when an invalid token was used to call the API.
160
-
161
- 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.
162
-
163
- ## SDK patterns
164
- If you know a few patterns, you’ll be able to call any API in the SDK. Here are some important ones:
165
-
166
- ### Get an access token
167
-
168
- To use the Square API to manage the resources (such as payments, orders, customers, etc.) of a Square account, you need to create an application (or use an existing one) in the Developer Dashboard and get an access token.
169
-
170
- When you call a Square API, you call it using an access key. An access key has specific permissions to resources in a specific Square account that can be accessed by a specific application in a specific developer account.
171
- Use an access token that is appropriate for your use case. There are two options:
121
+ ### Online
122
+ * [Sites]
123
+ * [Snippets]
172
124
 
173
- - To manage the resources for your own Square account, use the Personal Access Token for the application created in your Square account.
174
- - To manage resources for other Square accounts, use OAuth to ask owners of the accounts you want to manage so that you can work on their behalf. When you implement OAuth, you ask the Square account holder for permission to manage resources in their account (you can define the specific resources to access) and get an OAuth access token and refresh token for their account.
175
-
176
- **Important** For both use cases, make sure you store and access the tokens securely.
177
-
178
- ### Import and Instantiate the Client Class
179
-
180
- To use the Square API, you import the Client class, instantiate a Client object, and initialize it with the appropriate access token. Here’s how:
181
-
182
- - 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:
183
-
184
- ```ruby
185
- client = Square::Client.new(
186
- access_token: 'SANDBOX ACCESS TOKEN HERE',
187
- environment: 'sandbox'
188
- )
189
- ```
190
-
191
- - To access production resources, set environment to production:
192
-
193
- ```ruby
194
- client = Square::Client.new(
195
- access_token: 'ACCESS TOKEN HERE',
196
- environment: 'production'
197
- )
198
- ```
199
-
200
- ### Get an Instance of an API object and call its methods
201
-
202
- Each API is implemented as a class. The Client object instantiates every API class and exposes them as properties so you can easily start using any Square API. You work with an API by calling methods on an instance of an API class. Here’s how:
203
-
204
- - 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:
205
-
206
- ```ruby
207
- result = client.customers.list_customers
208
- ```
209
-
210
- See the SDK documentation for the list of methods for each API class.
211
-
212
- Pass complex parameters (such as create, update, search, etc.) as a Hash. For example, you would pass a Hash containing the values used to create a new customer using create_customer:
213
-
214
- ```ruby
215
- # Create a unique key for this creation operation so you don't accidentally
216
- # create the customer multiple times if you need to retry this operation.
217
- require 'securerandom'
218
-
219
- idempotency_key = SecureRandom.uuid
220
-
221
- # To create a customer, you'll need to specify at least a few required fields.
222
- request_body = {idempotency_key: idempotency_key, given_name: 'Amelia', family_name: 'Earhardt'}
223
-
224
- # Call create_customer method to create a new customer in this Square account
225
- result = client.customers.create_customer(request_body)
226
- ```
227
-
228
- If your call succeeds, you’ll see a response that looks like this:
229
- ```
230
- {'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'}}
231
- ```
232
-
233
- - Use idempotency for create, update, or other calls that you want to avoid calling twice. To make an idempotent API call, you add the idempotency_key with a unique value in the Hash for the API call’s request.
234
- - Specify a location ID for APIs such as Transactions, Orders, and Checkout that deal with payments. When a payment or order is created in Square, it is always associated with a location.
235
-
236
- ### Handle the response
237
-
238
- API calls return a response object that contains properties that describe both the request (headers and request) and the response (status_code, reason_phrase, text, errors, body, and cursor). The response also has #success? and #error? helper methods so you can easily determine the success or failure of a call:
239
-
240
- ```ruby
241
- if result.success?
242
- p result.data
243
- elsif result.error?
244
- warn result.errors.inspect
245
- end
246
- ```
247
-
248
- - Read the response payload. The response payload is returned as a Struct from the #data method. For retrieve calls, a Struct containing a single item is returned with a key name that is the name of the object (for example, customer). For list calls, a Struct containing a Array of objects is returned with a key name that is the plural of the object name (for example, customers).
249
- - Make sure you get all items returned in a list call by checking the cursor value returned in the API response. When you call a list API the first time, set the cursor to an empty String or omit it from the API request. If the API response contains a cursor with a value, you call the API again to get the next page of items and continue to call that API again until the cursor is an empty String.
250
-
251
- ## Tests
252
-
253
- First, clone the gem locally and `cd` into the directory.
254
-
255
- ```sh
256
- git clone https://github.com/square/square-ruby-sdk.git
257
- cd square-ruby-sdk
258
- ```
259
-
260
- Next, make sure Bundler is installed and install the development dependencies.
261
-
262
- ```sh
263
- gem install bundler
264
- bundle
265
- ```
266
-
267
- Before running the tests, find a sandbox token in your [Developer Dashboard] and set a `SQUARE_SANDBOX_TOKEN` environment variable.
268
-
269
- ```sh
270
- export SQUARE_SANDBOX_TOKEN="YOUR SANDBOX TOKEN HERE"
271
- ```
272
-
273
- And run the tests.
125
+ ### Authorization
126
+ * [Mobile Authorization]
127
+ * [OAuth]
274
128
 
275
- ```sh
276
- rake
277
- ```
129
+ ## Deprecated APIs
278
130
 
279
- ## Learn more
131
+ The following Square APIs are [deprecated](https://developer.squareup.com/docs/build-basics/api-lifecycle):
280
132
 
281
- The Square Platform is built on the [Square API]. Square has a number of other SDKs that enable you to securely handle credit card information on both mobile and web so that you can process payments via the Square API.
133
+ * [Employees] - replaced by the [Team] API. For more information, see [Migrate from the Employees API](https://developer.squareup.com/docs/team/migrate-from-v2-employees).
282
134
 
283
- 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).
135
+ * [Transactions] - replaced by the [Orders] and [Payments] APIs. For more information, see [Migrate from the Transactions API](https://developer.squareup.com/docs/payments-api/migrate-from-transactions-api).
284
136
 
137
+
285
138
  [//]: # "Link anchor definitions"
286
139
  [Square Logo]: https://docs.connect.squareup.com/images/github/github-square-logo.svg
287
140
  [Developer Dashboard]: https://developer.squareup.com/apps
@@ -293,6 +146,7 @@ You can also use the Square API to create applications or services that work wit
293
146
  [Terminal]: doc/api/terminal.md
294
147
  [Team]: doc/api/team.md
295
148
  [Cash Drawers]: doc/api/cash-drawers.md
149
+ [Vendors]: doc/api/vendors.md
296
150
  [Customer Groups]: doc/api/customer-groups.md
297
151
  [Customer Segments]: doc/api/customer-segments.md
298
152
  [Bank Accounts]: doc/api/bank-accounts.md
@@ -300,7 +154,7 @@ You can also use the Square API to create applications or services that work wit
300
154
  [Checkout]: doc/api/checkout.md
301
155
  [Catalog]: doc/api/catalog.md
302
156
  [Customers]: doc/api/customers.md
303
- [Employees]: doc/api/employees.md
157
+ [Customer Custom Attributes]: doc/api/customer-custom-attributes.md
304
158
  [Inventory]: doc/api/inventory.md
305
159
  [Labor]: doc/api/labor.md
306
160
  [Loyalty]: doc/api/loyalty.md
@@ -313,8 +167,12 @@ You can also use the Square API to create applications or services that work wit
313
167
  [Refunds]: doc/api/refunds.md
314
168
  [Subscriptions]: doc/api/subscriptions.md
315
169
  [Mobile Authorization]: doc/api/mobile-authorization.md
316
- [O Auth]: doc/api/o-auth.md
317
- [V1 Employees]: doc/api/v1-employees.md
318
- [V1 Transactions]: doc/api/v1-transactions.md
319
- [V1 Items]: doc/api/v1-items.md
170
+ [OAuth]: doc/api/o-auth.md
171
+ [Sites]: doc/api/sites.md
172
+ [Snippets]: doc/api/snippets.md
173
+ [Cards]: doc/api/cards.md
174
+ [Payouts]: doc/api/payouts.md
175
+ [Gift Cards]: doc/api/gift-cards.md
176
+ [Gift Card Activities]: doc/api/gift-card-activities.md
177
+ [Employees]: doc/api/employees.md
320
178
  [Transactions]: doc/api/transactions.md
@@ -5,17 +5,24 @@ module Square
5
5
  super(config, http_call_back: http_call_back)
6
6
  end
7
7
 
8
- # Activates a domain for use with Web Apple Pay and Square. A validation
9
- # will be performed on this domain by Apple to ensure is it properly set up
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
- # Web Apple Pay with Square for merchants using their platform.
15
- # To learn more about Apple Pay on Web see the Apple Pay section in the
16
- # [Square Payment Form
17
- # Walkthrough](https://developer.squareup.com/docs/payment-form/payment-form
18
- # -walkthrough).
15
+ # Apple Pay on the Web with Square for merchants using their platform.
16
+ # Note: The SqPaymentForm library is deprecated as of May 13, 2021, and will
17
+ # only receive critical security updates until it is retired on October 31,
18
+ # 2022.
19
+ # You must migrate your payment form code to the Web Payments SDK to
20
+ # continue using your domain for Apple Pay. For more information on
21
+ # migrating to the Web Payments SDK, see [Migrate to the Web Payments
22
+ # SDK](https://developer.squareup.com/docs/web-payments/migrate).
23
+ # To learn more about the Web Payments SDK and how to add Apple Pay, see
24
+ # [Take an Apple Pay
25
+ # Payment](https://developer.squareup.com/docs/web-payments/apple-pay).
19
26
  # @param [RegisterDomainRequest] body Required parameter: An object
20
27
  # containing the fields to POST for the request. See the corresponding
21
28
  # object definition for field details.
@@ -29,7 +36,7 @@ module Square
29
36
  # Prepare headers.
30
37
  _headers = {
31
38
  'accept' => 'application/json',
32
- 'content-type' => 'application/json; charset=utf-8'
39
+ 'Content-Type' => 'application/json'
33
40
  }
34
41
 
35
42
  # Prepare and execute HttpRequest.
@@ -5,8 +5,8 @@ module Square
5
5
  super(config, http_call_back: http_call_back)
6
6
  end
7
7
 
8
- # Returns a list of [BankAccount](#type-bankaccount) objects linked to a
9
- # Square account.
8
+ # Returns a list of [BankAccount]($m/BankAccount) objects linked to a Square
9
+ # account.
10
10
  # @param [String] cursor Optional parameter: The pagination cursor returned
11
11
  # by a previous call to this endpoint. Use it in the next `ListBankAccounts`
12
12
  # request to retrieve the next set of results. See the
@@ -55,8 +55,8 @@ module Square
55
55
  )
56
56
  end
57
57
 
58
- # Returns details of a [BankAccount](#type-bankaccount) identified by V1
59
- # bank account ID.
58
+ # Returns details of a [BankAccount]($m/BankAccount) identified by V1 bank
59
+ # account ID.
60
60
  # @param [String] v1_bank_account_id Required parameter: Connect V1 ID of
61
61
  # the desired `BankAccount`. For more information, see [Retrieve a bank
62
62
  # account by using an ID issued by V1 Bank Accounts
@@ -94,7 +94,7 @@ module Square
94
94
  )
95
95
  end
96
96
 
97
- # Returns details of a [BankAccount](#type-bankaccount)
97
+ # Returns details of a [BankAccount]($m/BankAccount)
98
98
  # linked to a Square account.
99
99
  # @param [String] bank_account_id Required parameter: Square-issued ID of
100
100
  # the desired `BankAccount`.
@@ -1,3 +1,4 @@
1
+ require 'erb'
1
2
  module Square
2
3
  # BaseApi.
3
4
  class BaseApi
@@ -8,36 +9,53 @@ module Square
8
9
  @http_call_back = http_call_back
9
10
 
10
11
  @global_headers = {
11
- 'user-agent' => 'Square-Ruby-SDK/8.0.0.20201216',
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?
20
+ end
21
+ end
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?
21
27
  end
22
28
  end
23
29
 
24
30
  def execute_request(request, binary: false)
25
- @http_call_back.on_before_request(request) if @http_call_back
31
+ @http_call_back&.on_before_request(request)
26
32
 
27
33
  APIHelper.clean_hash(request.headers)
28
34
  request.headers.merge!(@global_headers)
29
- unless config.additional_headers.nil?
30
- request.headers.merge!(config.additional_headers)
31
- end
35
+ request.headers.merge!(config.additional_headers) unless config.additional_headers.nil?
32
36
 
33
37
  response = if binary
34
38
  config.http_client.execute_as_binary(request)
35
39
  else
36
40
  config.http_client.execute_as_string(request)
37
41
  end
38
- @http_call_back.on_after_response(response) if @http_call_back
42
+ @http_call_back&.on_after_response(response)
39
43
 
40
44
  response
41
45
  end
46
+
47
+ def get_user_agent
48
+ user_agent = 'Square-Ruby-SDK/26.1.0.20230119 ({api-version}) {engine}/{engine-version} ({os-info}) {detail}'
49
+ user_agent['{engine}'] = RUBY_ENGINE
50
+ user_agent['{engine-version}'] = RUBY_ENGINE_VERSION
51
+ user_agent['{os-info}'] = RUBY_PLATFORM
52
+ user_agent['{api-version}'] = config.square_version
53
+ if config.user_agent_detail.nil? || config.user_agent_detail.empty?
54
+ user_agent = user_agent.gsub('{detail}', '')
55
+ else
56
+ user_agent['{detail}'] = ERB::Util.url_encode(config.user_agent_detail.to_s)
57
+ end
58
+ user_agent
59
+ end
42
60
  end
43
61
  end