square.rb 8.1.0.20210121 → 18.1.0.20220316

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +1 -1
  3. data/README.md +59 -213
  4. data/lib/square/api/apple_pay_api.rb +9 -8
  5. data/lib/square/api/bank_accounts_api.rb +5 -5
  6. data/lib/square/api/base_api.rb +20 -9
  7. data/lib/square/api/bookings_api.rb +95 -12
  8. data/lib/square/api/cards_api.rb +170 -0
  9. data/lib/square/api/cash_drawers_api.rb +2 -2
  10. data/lib/square/api/catalog_api.rb +140 -66
  11. data/lib/square/api/checkout_api.rb +3 -3
  12. data/lib/square/api/customer_groups_api.rb +17 -8
  13. data/lib/square/api/customer_segments_api.rb +15 -6
  14. data/lib/square/api/customers_api.rb +61 -31
  15. data/lib/square/api/devices_api.rb +3 -2
  16. data/lib/square/api/disputes_api.rb +101 -92
  17. data/lib/square/api/gift_card_activities_api.rb +133 -0
  18. data/lib/square/api/gift_cards_api.rb +297 -0
  19. data/lib/square/api/inventory_api.rb +263 -24
  20. data/lib/square/api/invoices_api.rb +19 -19
  21. data/lib/square/api/labor_api.rb +70 -68
  22. data/lib/square/api/locations_api.rb +22 -14
  23. data/lib/square/api/loyalty_api.rb +86 -32
  24. data/lib/square/api/merchants_api.rb +11 -9
  25. data/lib/square/api/mobile_authorization_api.rb +4 -4
  26. data/lib/square/api/o_auth_api.rb +31 -25
  27. data/lib/square/api/orders_api.rb +78 -39
  28. data/lib/square/api/payments_api.rb +71 -23
  29. data/lib/square/api/refunds_api.rb +18 -7
  30. data/lib/square/api/sites_api.rb +43 -0
  31. data/lib/square/api/snippets_api.rb +146 -0
  32. data/lib/square/api/subscriptions_api.rb +190 -12
  33. data/lib/square/api/team_api.rb +46 -46
  34. data/lib/square/api/terminal_api.rb +19 -18
  35. data/lib/square/api/transactions_api.rb +15 -191
  36. data/lib/square/api/v1_transactions_api.rb +13 -85
  37. data/lib/square/api/vendors_api.rb +257 -0
  38. data/lib/square/api_helper.rb +45 -57
  39. data/lib/square/client.rb +54 -18
  40. data/lib/square/configuration.rb +59 -20
  41. data/lib/square/http/api_response.rb +1 -1
  42. data/lib/square/http/faraday_client.rb +24 -4
  43. data/lib/square/utilities/date_time_helper.rb +151 -0
  44. data/lib/square/utilities/file_wrapper.rb +1 -2
  45. data/lib/square.rb +49 -44
  46. data/test/api/test_locations_api.rb +2 -5
  47. data/test/test_helper.rb +1 -1
  48. metadata +11 -6
  49. data/lib/square/api/v1_employees_api.rb +0 -749
  50. 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: 65883291fee1f3779feb258fe5df4efdc171b581e34b9245be01e143ed8cd819
4
- data.tar.gz: 8665e1c3187d85b979970ace13887e6bf18688e47828af12671cd6e939994174
3
+ metadata.gz: bbb5aeea53c32ac7828ffb52501c522f8e4811bb81aa4f0deb453802dcc9147e
4
+ data.tar.gz: 2526651aefdbeb8e605d35ef011de1c21f241e860c9d3fde2853b3c9e8912932
5
5
  SHA512:
6
- metadata.gz: 7d7b11eded83cbbbfa7e1985e9b7456568f26353681380ab370446045d15c2d8882a048ef940ef9c34b36cd6ca541a421e3cea740b38db85a7048e08b0bbb08e
7
- data.tar.gz: 88a9b4f2a1bd0ec750b83ecc8ce582bd8e7f3a8cfe30c203feadb8e13851946780a2c2ef92be350448204fa76aadcb98552d7281a3b9dea1e33f01c13aa21ba3
6
+ metadata.gz: 500aa37342e9b95690d2541bc0f55d4b2ba2797290439a9da44bb1056b3aaf20d741a30b853afdaf9a81be4720b1b2284062974ac5c31908b17e0bc858725fa8
7
+ data.tar.gz: 83e45f18a23572b205a30ac3aad83529a6f94e0ae2a340ce28d3a06b243ace51e315114ca5e24cfa8676420d705dd7d80aec69053306eb63f799578c9a499f97
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2121 Square, Inc.
1
+ Copyright 2022 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,58 @@
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
12
+
13
+ Use of the Square Ruby SDK requires:
14
+
15
+ * Ruby 2.6 through 3.1
10
16
 
11
17
  ## Installation
12
18
 
13
- Install the gem from the command line:
19
+ For more information, see [Set Up Your Square SDK for a Ruby Project](https://developer.squareup.com/docs/sdks/ruby/setup-project).
20
+
21
+ ## Quickstart
22
+
23
+ For more information, see [Square Ruby SDK Quickstart](https://developer.squareup.com/docs/sdks/ruby/quick-start).
24
+
25
+ ## Usage
26
+ For more information, see [Using the Square Ruby SDK](https://developer.squareup.com/docs/sdks/ruby/using-ruby-sdk).
27
+
28
+ ## Tests
29
+
30
+ First, clone the repo locally and `cd` into the directory.
31
+
32
+ ```sh
33
+ git clone https://github.com/square/square-ruby-sdk.git
34
+ cd square-ruby-sdk
35
+ ```
36
+
37
+ Next, make sure Bundler is installed and install the development dependencies.
14
38
 
15
- ```ruby
16
- gem install square.rb
39
+ ```sh
40
+ gem install bundler
41
+ bundle
17
42
  ```
18
43
 
19
- Or add the gem to your Gemfile and `bundle`:
44
+ Before running the tests, find a sandbox token in your [Developer Dashboard] and set a `SQUARE_SANDBOX_TOKEN` environment variable.
20
45
 
21
- ```ruby
22
- gem 'square.rb'
46
+ ```sh
47
+ export SQUARE_SANDBOX_TOKEN="YOUR SANDBOX TOKEN HERE"
23
48
  ```
24
49
 
25
- ### API Client
26
- * [Client]
50
+ And run the tests.
27
51
 
28
- ## API documentation
52
+ ```sh
53
+ rake
54
+ ```
55
+
56
+ ## SDK Reference
29
57
 
30
58
  ### Payments
31
59
  * [Payments]
@@ -33,6 +61,9 @@ gem 'square.rb'
33
61
  * [Disputes]
34
62
  * [Checkout]
35
63
  * [Apple Pay]
64
+ * [Cards]
65
+
66
+ ### Terminal
36
67
  * [Terminal]
37
68
 
38
69
  ### Orders
@@ -56,6 +87,10 @@ gem 'square.rb'
56
87
  ### Loyalty
57
88
  * [Loyalty]
58
89
 
90
+ ### Gift Cards
91
+ * [Gift Cards]
92
+ * [Gift Card Activities]
93
+
59
94
  ### Bookings
60
95
  * [Bookings]
61
96
 
@@ -63,224 +98,30 @@ gem 'square.rb'
63
98
  * [Merchants]
64
99
  * [Locations]
65
100
  * [Devices]
101
+ * [Cash Drawers]
66
102
 
67
103
  ### Team
68
104
  * [Team]
69
- * [Employees]
70
105
  * [Labor]
71
- * [Cash Drawers]
72
106
 
73
107
  ### Financials
74
108
  * [Bank Accounts]
75
109
 
110
+ ### Online
111
+ * [Sites]
112
+ * [Snippets]
113
+
76
114
  ### Authorization APIs
77
115
  * [Mobile Authorization]
78
- * [O Auth]
116
+ * [OAuth]
79
117
 
80
118
  ### Deprecated APIs
119
+ * [Employees]
81
120
  * [V1 Employees]
82
121
  * [V1 Transactions]
83
122
  * [V1 Items]
84
123
  * [Transactions]
85
124
 
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:
172
-
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.
274
-
275
- ```sh
276
- rake
277
- ```
278
-
279
- ## Learn more
280
-
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.
282
-
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).
284
125
 
285
126
  [//]: # "Link anchor definitions"
286
127
  [Square Logo]: https://docs.connect.squareup.com/images/github/github-square-logo.svg
@@ -313,8 +154,13 @@ You can also use the Square API to create applications or services that work wit
313
154
  [Refunds]: doc/api/refunds.md
314
155
  [Subscriptions]: doc/api/subscriptions.md
315
156
  [Mobile Authorization]: doc/api/mobile-authorization.md
316
- [O Auth]: doc/api/o-auth.md
157
+ [OAuth]: doc/api/o-auth.md
317
158
  [V1 Employees]: doc/api/v1-employees.md
318
159
  [V1 Transactions]: doc/api/v1-transactions.md
319
160
  [V1 Items]: doc/api/v1-items.md
320
161
  [Transactions]: doc/api/transactions.md
162
+ [Sites]: doc/api/sites.md
163
+ [Snippets]: doc/api/snippets.md
164
+ [Cards]: doc/api/cards.md
165
+ [Gift Cards]: doc/api/gift-cards.md
166
+ [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 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
+ # 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
- 'content-type' => 'application/json; charset=utf-8'
33
+ 'Content-Type' => 'application/json'
33
34
  }
34
35
 
35
36
  # 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,46 @@ module Square
8
9
  @http_call_back = http_call_back
9
10
 
10
11
  @global_headers = {
11
- 'user-agent' => 'Square-Ruby-SDK/8.1.0.20210121',
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.on_before_request(request) if @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.on_after_response(response) if @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/18.1.0.20220316 ({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
@@ -5,7 +5,75 @@ module Square
5
5
  super(config, http_call_back: http_call_back)
6
6
  end
7
7
 
8
+ # Retrieve a collection of bookings.
9
+ # To call this endpoint with buyer-level permissions, set
10
+ # `APPOINTMENTS_READ` for the OAuth scope.
11
+ # To call this endpoint with seller-level permissions, set
12
+ # `APPOINTMENTS_ALL_READ` and `APPOINTMENTS_READ` for the OAuth scope.
13
+ # @param [Integer] limit Optional parameter: The maximum number of results
14
+ # per page to return in a paged response.
15
+ # @param [String] cursor Optional parameter: The pagination cursor from the
16
+ # preceding response to return the next page of the results. Do not set this
17
+ # when retrieving the first page of the results.
18
+ # @param [String] team_member_id Optional parameter: The team member for
19
+ # whom to retrieve bookings. If this is not set, bookings of all members are
20
+ # retrieved.
21
+ # @param [String] location_id Optional parameter: The location for which to
22
+ # retrieve bookings. If this is not set, all locations' bookings are
23
+ # retrieved.
24
+ # @param [String] start_at_min Optional parameter: The RFC 3339 timestamp
25
+ # specifying the earliest of the start time. If this is not set, the current
26
+ # time is used.
27
+ # @param [String] start_at_max Optional parameter: The RFC 3339 timestamp
28
+ # specifying the latest of the start time. If this is not set, the time of
29
+ # 31 days after `start_at_min` is used.
30
+ # @return [ListBookingsResponse Hash] response from the API call
31
+ def list_bookings(limit: nil,
32
+ cursor: nil,
33
+ team_member_id: nil,
34
+ location_id: nil,
35
+ start_at_min: nil,
36
+ start_at_max: nil)
37
+ # Prepare query url.
38
+ _query_builder = config.get_base_uri
39
+ _query_builder << '/v2/bookings'
40
+ _query_builder = APIHelper.append_url_with_query_parameters(
41
+ _query_builder,
42
+ 'limit' => limit,
43
+ 'cursor' => cursor,
44
+ 'team_member_id' => team_member_id,
45
+ 'location_id' => location_id,
46
+ 'start_at_min' => start_at_min,
47
+ 'start_at_max' => start_at_max
48
+ )
49
+ _query_url = APIHelper.clean_url _query_builder
50
+
51
+ # Prepare headers.
52
+ _headers = {
53
+ 'accept' => 'application/json'
54
+ }
55
+
56
+ # Prepare and execute HttpRequest.
57
+ _request = config.http_client.get(
58
+ _query_url,
59
+ headers: _headers
60
+ )
61
+ OAuth2.apply(config, _request)
62
+ _response = execute_request(_request)
63
+
64
+ # Return appropriate response type.
65
+ decoded = APIHelper.json_deserialize(_response.raw_body)
66
+ _errors = APIHelper.map_response(decoded, ['errors'])
67
+ ApiResponse.new(
68
+ _response, data: decoded, errors: _errors
69
+ )
70
+ end
71
+
8
72
  # Creates a booking.
73
+ # To call this endpoint with buyer-level permissions, set
74
+ # `APPOINTMENTS_WRITE` for the OAuth scope.
75
+ # To call this endpoint with seller-level permissions, set
76
+ # `APPOINTMENTS_ALL_WRITE` and `APPOINTMENTS_WRITE` for the OAuth scope.
9
77
  # @param [CreateBookingRequest] body Required parameter: An object
10
78
  # containing the fields to POST for the request. See the corresponding
11
79
  # object definition for field details.
@@ -19,7 +87,7 @@ module Square
19
87
  # Prepare headers.
20
88
  _headers = {
21
89
  'accept' => 'application/json',
22
- 'content-type' => 'application/json; charset=utf-8'
90
+ 'Content-Type' => 'application/json'
23
91
  }
24
92
 
25
93
  # Prepare and execute HttpRequest.
@@ -40,6 +108,10 @@ module Square
40
108
  end
41
109
 
42
110
  # Searches for availabilities for booking.
111
+ # To call this endpoint with buyer-level permissions, set
112
+ # `APPOINTMENTS_READ` for the OAuth scope.
113
+ # To call this endpoint with seller-level permissions, set
114
+ # `APPOINTMENTS_ALL_READ` and `APPOINTMENTS_READ` for the OAuth scope.
43
115
  # @param [SearchAvailabilityRequest] body Required parameter: An object
44
116
  # containing the fields to POST for the request. See the corresponding
45
117
  # object definition for field details.
@@ -53,7 +125,7 @@ module Square
53
125
  # Prepare headers.
54
126
  _headers = {
55
127
  'accept' => 'application/json',
56
- 'content-type' => 'application/json; charset=utf-8'
128
+ 'Content-Type' => 'application/json'
57
129
  }
58
130
 
59
131
  # Prepare and execute HttpRequest.
@@ -107,9 +179,10 @@ module Square
107
179
  # include only bookable team members in the returned result (`true`) or not
108
180
  # (`false`).
109
181
  # @param [Integer] limit Optional parameter: The maximum number of results
110
- # to return.
111
- # @param [String] cursor Optional parameter: The cursor for paginating
112
- # through the results.
182
+ # to return in a paged response.
183
+ # @param [String] cursor Optional parameter: The pagination cursor from the
184
+ # preceding response to return the next page of the results. Do not set this
185
+ # when retrieving the first page of the results.
113
186
  # @param [String] location_id Optional parameter: Indicates whether to
114
187
  # include only team members enabled at the given location in the returned
115
188
  # result.
@@ -187,9 +260,12 @@ module Square
187
260
  end
188
261
 
189
262
  # Retrieves a booking.
263
+ # To call this endpoint with buyer-level permissions, set
264
+ # `APPOINTMENTS_READ` for the OAuth scope.
265
+ # To call this endpoint with seller-level permissions, set
266
+ # `APPOINTMENTS_ALL_READ` and `APPOINTMENTS_READ` for the OAuth scope.
190
267
  # @param [String] booking_id Required parameter: The ID of the
191
- # [Booking](#type-booking) object representing the to-be-retrieved
192
- # booking.
268
+ # [Booking]($m/Booking) object representing the to-be-retrieved booking.
193
269
  # @return [RetrieveBookingResponse Hash] response from the API call
194
270
  def retrieve_booking(booking_id:)
195
271
  # Prepare query url.
@@ -223,8 +299,12 @@ module Square
223
299
  end
224
300
 
225
301
  # Updates a booking.
302
+ # To call this endpoint with buyer-level permissions, set
303
+ # `APPOINTMENTS_WRITE` for the OAuth scope.
304
+ # To call this endpoint with seller-level permissions, set
305
+ # `APPOINTMENTS_ALL_WRITE` and `APPOINTMENTS_WRITE` for the OAuth scope.
226
306
  # @param [String] booking_id Required parameter: The ID of the
227
- # [Booking](#type-booking) object representing the to-be-updated booking.
307
+ # [Booking]($m/Booking) object representing the to-be-updated booking.
228
308
  # @param [UpdateBookingRequest] body Required parameter: An object
229
309
  # containing the fields to POST for the request. See the corresponding
230
310
  # object definition for field details.
@@ -243,7 +323,7 @@ module Square
243
323
  # Prepare headers.
244
324
  _headers = {
245
325
  'accept' => 'application/json',
246
- 'content-type' => 'application/json; charset=utf-8'
326
+ 'Content-Type' => 'application/json'
247
327
  }
248
328
 
249
329
  # Prepare and execute HttpRequest.
@@ -264,9 +344,12 @@ module Square
264
344
  end
265
345
 
266
346
  # Cancels an existing booking.
347
+ # To call this endpoint with buyer-level permissions, set
348
+ # `APPOINTMENTS_WRITE` for the OAuth scope.
349
+ # To call this endpoint with seller-level permissions, set
350
+ # `APPOINTMENTS_ALL_WRITE` and `APPOINTMENTS_WRITE` for the OAuth scope.
267
351
  # @param [String] booking_id Required parameter: The ID of the
268
- # [Booking](#type-booking) object representing the to-be-cancelled
269
- # booking.
352
+ # [Booking]($m/Booking) object representing the to-be-cancelled booking.
270
353
  # @param [CancelBookingRequest] body Required parameter: An object
271
354
  # containing the fields to POST for the request. See the corresponding
272
355
  # object definition for field details.
@@ -285,7 +368,7 @@ module Square
285
368
  # Prepare headers.
286
369
  _headers = {
287
370
  'accept' => 'application/json',
288
- 'content-type' => 'application/json; charset=utf-8'
371
+ 'Content-Type' => 'application/json'
289
372
  }
290
373
 
291
374
  # Prepare and execute HttpRequest.