square.rb 17.0.0.20211215 → 18.1.0.20220316
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 +35 -221
- data/lib/square/api/base_api.rb +10 -1
- data/lib/square/api/bookings_api.rb +28 -3
- data/lib/square/api/customer_groups_api.rb +7 -6
- data/lib/square/api/customer_segments_api.rb +7 -6
- data/lib/square/api/customers_api.rb +11 -8
- data/lib/square/api/locations_api.rb +3 -2
- data/lib/square/api/loyalty_api.rb +9 -17
- data/lib/square/api/merchants_api.rb +10 -8
- data/lib/square/api/refunds_api.rb +7 -4
- data/lib/square/api/vendors_api.rb +257 -0
- data/lib/square/api_helper.rb +29 -31
- data/lib/square/client.rb +11 -5
- data/lib/square/configuration.rb +21 -13
- data/lib/square/http/faraday_client.rb +13 -15
- data/lib/square.rb +1 -0
- data/test/api/test_locations_api.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bbb5aeea53c32ac7828ffb52501c522f8e4811bb81aa4f0deb453802dcc9147e
|
4
|
+
data.tar.gz: 2526651aefdbeb8e605d35ef011de1c21f241e860c9d3fde2853b3c9e8912932
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 500aa37342e9b95690d2541bc0f55d4b2ba2797290439a9da44bb1056b3aaf20d741a30b853afdaf9a81be4720b1b2284062974ac5c31908b17e0bc858725fa8
|
7
|
+
data.tar.gz: 83e45f18a23572b205a30ac3aad83529a6f94e0ae2a340ce28d3a06b243ace51e315114ca5e24cfa8676420d705dd7d80aec69053306eb63f799578c9a499f97
|
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -6,30 +6,54 @@
|
|
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
|
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
10
|
|
11
11
|
## Requirements
|
12
12
|
|
13
|
-
|
13
|
+
Use of the Square Ruby SDK requires:
|
14
|
+
|
15
|
+
* Ruby 2.6 through 3.1
|
14
16
|
|
15
17
|
## Installation
|
16
18
|
|
17
|
-
|
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.
|
18
38
|
|
19
|
-
```
|
20
|
-
gem install
|
39
|
+
```sh
|
40
|
+
gem install bundler
|
41
|
+
bundle
|
21
42
|
```
|
22
43
|
|
23
|
-
|
44
|
+
Before running the tests, find a sandbox token in your [Developer Dashboard] and set a `SQUARE_SANDBOX_TOKEN` environment variable.
|
24
45
|
|
25
|
-
```
|
26
|
-
|
46
|
+
```sh
|
47
|
+
export SQUARE_SANDBOX_TOKEN="YOUR SANDBOX TOKEN HERE"
|
27
48
|
```
|
28
49
|
|
29
|
-
|
30
|
-
* [Client]
|
50
|
+
And run the tests.
|
31
51
|
|
32
|
-
|
52
|
+
```sh
|
53
|
+
rake
|
54
|
+
```
|
55
|
+
|
56
|
+
## SDK Reference
|
33
57
|
|
34
58
|
### Payments
|
35
59
|
* [Payments]
|
@@ -98,216 +122,6 @@ gem 'square.rb'
|
|
98
122
|
* [V1 Items]
|
99
123
|
* [Transactions]
|
100
124
|
|
101
|
-
## Usage
|
102
|
-
|
103
|
-
First time using Square? Here’s how to get started:
|
104
|
-
|
105
|
-
1. **Create a Square account.** If you don’t have one already, [sign up for a developer account].
|
106
|
-
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.
|
107
|
-
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.
|
108
|
-
|
109
|
-
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:
|
110
|
-
|
111
|
-
```ruby
|
112
|
-
require 'square'
|
113
|
-
|
114
|
-
# Create an instance of the API Client and initialize it with the credentials
|
115
|
-
# for the Square account whose assets you want to manage.
|
116
|
-
|
117
|
-
client = Square::Client.new(
|
118
|
-
access_token: 'YOUR SANDBOX ACCESS TOKEN HERE',
|
119
|
-
environment: 'sandbox'
|
120
|
-
)
|
121
|
-
|
122
|
-
# Call list_locations method to get all locations in this Square account
|
123
|
-
result = client.locations.list_locations
|
124
|
-
|
125
|
-
# Call the #success? method to see if the call succeeded
|
126
|
-
if result.success?
|
127
|
-
# The #data Struct contains a list of locations
|
128
|
-
locations = result.data.locations
|
129
|
-
|
130
|
-
# Iterate over the list
|
131
|
-
locations.each do |location|
|
132
|
-
# Each location is represented as a Hash
|
133
|
-
location.each do |key, value|
|
134
|
-
puts "#{key}: #{value}"
|
135
|
-
end
|
136
|
-
end
|
137
|
-
else
|
138
|
-
# Handle the case that the result is an error.
|
139
|
-
warn 'Error calling LocationsApi.listlocations ...'
|
140
|
-
|
141
|
-
# The #errors method returns an Array of error Hashes
|
142
|
-
result.errors.each do |key, value|
|
143
|
-
warn "#{key}: #{value}"
|
144
|
-
end
|
145
|
-
end
|
146
|
-
```
|
147
|
-
|
148
|
-
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.
|
149
|
-
|
150
|
-
**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.
|
151
|
-
|
152
|
-
Now save `locations.rb` and run it:
|
153
|
-
|
154
|
-
```sh
|
155
|
-
ruby locations.rb
|
156
|
-
```
|
157
|
-
|
158
|
-
If your call is successful, you’ll get a response that looks like this:
|
159
|
-
|
160
|
-
```
|
161
|
-
address : {'address_line_1': '1455 Market Street', 'administrative_district_level_1': 'CA', 'country': 'US', 'locality': 'San Francisco', 'postal_code': '94103'}
|
162
|
-
# ...
|
163
|
-
```
|
164
|
-
|
165
|
-
Yay! You successfully made your first call. If you didn’t, you would see an error message that looks something like this:
|
166
|
-
|
167
|
-
```
|
168
|
-
Error calling LocationsApi.listlocations
|
169
|
-
category : AUTHENTICATION_ERROR
|
170
|
-
code : UNAUTHORIZED
|
171
|
-
detail : This request could not be authorized.
|
172
|
-
```
|
173
|
-
|
174
|
-
This error was returned when an invalid token was used to call the API.
|
175
|
-
|
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
|
-
|
178
|
-
## SDK patterns
|
179
|
-
|
180
|
-
If you know a few patterns, you’ll be able to call any API in the SDK. Here are some important ones:
|
181
|
-
|
182
|
-
### Get an access token
|
183
|
-
|
184
|
-
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.
|
185
|
-
|
186
|
-
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.
|
187
|
-
Use an access token that is appropriate for your use case. There are two options:
|
188
|
-
|
189
|
-
- To manage the resources for your own Square account, use the Personal Access Token for the application created in your Square account.
|
190
|
-
- 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.
|
191
|
-
|
192
|
-
**Important** For both use cases, make sure you store and access the tokens securely.
|
193
|
-
|
194
|
-
### Import and Instantiate the Client Class
|
195
|
-
|
196
|
-
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:
|
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:
|
199
|
-
|
200
|
-
```ruby
|
201
|
-
client = Square::Client.new(
|
202
|
-
access_token: 'SANDBOX ACCESS TOKEN HERE',
|
203
|
-
environment: 'sandbox'
|
204
|
-
)
|
205
|
-
```
|
206
|
-
|
207
|
-
- To access production resources, set environment to production:
|
208
|
-
|
209
|
-
```ruby
|
210
|
-
client = Square::Client.new(
|
211
|
-
access_token: 'ACCESS TOKEN HERE',
|
212
|
-
environment: 'production'
|
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
|
-
```
|
225
|
-
|
226
|
-
### Get an Instance of an API object and call its methods
|
227
|
-
|
228
|
-
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:
|
229
|
-
|
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:
|
231
|
-
|
232
|
-
```ruby
|
233
|
-
result = client.customers.list_customers
|
234
|
-
```
|
235
|
-
|
236
|
-
See the SDK documentation for the list of methods for each API class.
|
237
|
-
|
238
|
-
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:
|
239
|
-
|
240
|
-
```ruby
|
241
|
-
# Create a unique key for this creation operation so you don't accidentally
|
242
|
-
# create the customer multiple times if you need to retry this operation.
|
243
|
-
require 'securerandom'
|
244
|
-
|
245
|
-
idempotency_key = SecureRandom.uuid
|
246
|
-
|
247
|
-
# To create a customer, you'll need to specify at least a few required fields.
|
248
|
-
request_body = {idempotency_key: idempotency_key, given_name: 'Amelia', family_name: 'Earhardt'}
|
249
|
-
|
250
|
-
# Call create_customer method to create a new customer in this Square account
|
251
|
-
result = client.customers.create_customer(request_body)
|
252
|
-
```
|
253
|
-
|
254
|
-
If your call succeeds, you’ll see a response that looks like this:
|
255
|
-
|
256
|
-
```
|
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'}}
|
258
|
-
```
|
259
|
-
|
260
|
-
- 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.
|
261
|
-
- 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.
|
262
|
-
|
263
|
-
### Handle the response
|
264
|
-
|
265
|
-
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:
|
266
|
-
|
267
|
-
```ruby
|
268
|
-
if result.success?
|
269
|
-
p result.data
|
270
|
-
elsif result.error?
|
271
|
-
warn result.errors.inspect
|
272
|
-
end
|
273
|
-
```
|
274
|
-
|
275
|
-
- 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).
|
276
|
-
- 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.
|
277
|
-
|
278
|
-
## Tests
|
279
|
-
|
280
|
-
First, clone the repo locally and `cd` into the directory.
|
281
|
-
|
282
|
-
```sh
|
283
|
-
git clone https://github.com/square/square-ruby-sdk.git
|
284
|
-
cd square-ruby-sdk
|
285
|
-
```
|
286
|
-
|
287
|
-
Next, make sure Bundler is installed and install the development dependencies.
|
288
|
-
|
289
|
-
```sh
|
290
|
-
gem install bundler
|
291
|
-
bundle
|
292
|
-
```
|
293
|
-
|
294
|
-
Before running the tests, find a sandbox token in your [Developer Dashboard] and set a `SQUARE_SANDBOX_TOKEN` environment variable.
|
295
|
-
|
296
|
-
```sh
|
297
|
-
export SQUARE_SANDBOX_TOKEN="YOUR SANDBOX TOKEN HERE"
|
298
|
-
```
|
299
|
-
|
300
|
-
And run the tests.
|
301
|
-
|
302
|
-
```sh
|
303
|
-
rake
|
304
|
-
```
|
305
|
-
|
306
|
-
## Learn more
|
307
|
-
|
308
|
-
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.
|
309
|
-
|
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).
|
311
125
|
|
312
126
|
[//]: # "Link anchor definitions"
|
313
127
|
[Square Logo]: https://docs.connect.squareup.com/images/github/github-square-logo.svg
|
data/lib/square/api/base_api.rb
CHANGED
@@ -38,7 +38,16 @@ module Square
|
|
38
38
|
end
|
39
39
|
|
40
40
|
def get_user_agent
|
41
|
-
user_agent = 'Square-Ruby-SDK/
|
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
|
42
51
|
user_agent
|
43
52
|
end
|
44
53
|
end
|
@@ -6,6 +6,10 @@ module Square
|
|
6
6
|
end
|
7
7
|
|
8
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.
|
9
13
|
# @param [Integer] limit Optional parameter: The maximum number of results
|
10
14
|
# per page to return in a paged response.
|
11
15
|
# @param [String] cursor Optional parameter: The pagination cursor from the
|
@@ -66,6 +70,10 @@ module Square
|
|
66
70
|
end
|
67
71
|
|
68
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.
|
69
77
|
# @param [CreateBookingRequest] body Required parameter: An object
|
70
78
|
# containing the fields to POST for the request. See the corresponding
|
71
79
|
# object definition for field details.
|
@@ -100,6 +108,10 @@ module Square
|
|
100
108
|
end
|
101
109
|
|
102
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.
|
103
115
|
# @param [SearchAvailabilityRequest] body Required parameter: An object
|
104
116
|
# containing the fields to POST for the request. See the corresponding
|
105
117
|
# object definition for field details.
|
@@ -167,9 +179,10 @@ module Square
|
|
167
179
|
# include only bookable team members in the returned result (`true`) or not
|
168
180
|
# (`false`).
|
169
181
|
# @param [Integer] limit Optional parameter: The maximum number of results
|
170
|
-
# to return.
|
171
|
-
# @param [String] cursor Optional parameter: The cursor
|
172
|
-
#
|
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.
|
173
186
|
# @param [String] location_id Optional parameter: Indicates whether to
|
174
187
|
# include only team members enabled at the given location in the returned
|
175
188
|
# result.
|
@@ -247,6 +260,10 @@ module Square
|
|
247
260
|
end
|
248
261
|
|
249
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.
|
250
267
|
# @param [String] booking_id Required parameter: The ID of the
|
251
268
|
# [Booking]($m/Booking) object representing the to-be-retrieved booking.
|
252
269
|
# @return [RetrieveBookingResponse Hash] response from the API call
|
@@ -282,6 +299,10 @@ module Square
|
|
282
299
|
end
|
283
300
|
|
284
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.
|
285
306
|
# @param [String] booking_id Required parameter: The ID of the
|
286
307
|
# [Booking]($m/Booking) object representing the to-be-updated booking.
|
287
308
|
# @param [UpdateBookingRequest] body Required parameter: An object
|
@@ -323,6 +344,10 @@ module Square
|
|
323
344
|
end
|
324
345
|
|
325
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.
|
326
351
|
# @param [String] booking_id Required parameter: The ID of the
|
327
352
|
# [Booking]($m/Booking) object representing the to-be-cancelled booking.
|
328
353
|
# @param [CancelBookingRequest] body Required parameter: An object
|
@@ -9,14 +9,15 @@ module Square
|
|
9
9
|
# @param [String] cursor Optional parameter: A pagination cursor returned by
|
10
10
|
# a previous call to this endpoint. Provide this cursor to retrieve the next
|
11
11
|
# set of results for your original query. For more information, see
|
12
|
-
# [Pagination](https://developer.squareup.com/docs/
|
13
|
-
#
|
12
|
+
# [Pagination](https://developer.squareup.com/docs/build-basics/common-api-p
|
13
|
+
# atterns/pagination).
|
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.
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
16
|
+
# contain more or fewer results. If the limit is less than 1 or greater than
|
17
|
+
# 50, Square returns a `400 VALUE_TOO_LOW` or `400 VALUE_TOO_HIGH` error.
|
18
|
+
# The default value is 50. For more information, see
|
19
|
+
# [Pagination](https://developer.squareup.com/docs/build-basics/common-api-p
|
20
|
+
# atterns/pagination).
|
20
21
|
# @return [ListCustomerGroupsResponse Hash] response from the API call
|
21
22
|
def list_customer_groups(cursor: nil,
|
22
23
|
limit: nil)
|
@@ -9,14 +9,15 @@ module Square
|
|
9
9
|
# @param [String] cursor Optional parameter: A pagination cursor returned by
|
10
10
|
# previous calls to `ListCustomerSegments`. This cursor is used to retrieve
|
11
11
|
# the next set of query results. For more information, see
|
12
|
-
# [Pagination](https://developer.squareup.com/docs/
|
13
|
-
#
|
12
|
+
# [Pagination](https://developer.squareup.com/docs/build-basics/common-api-p
|
13
|
+
# atterns/pagination).
|
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.
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
16
|
+
# contain more or fewer results. If the specified limit is less than 1 or
|
17
|
+
# greater than 50, Square returns a `400 VALUE_TOO_LOW` or `400
|
18
|
+
# VALUE_TOO_HIGH` error. The default value is 50. For more information, see
|
19
|
+
# [Pagination](https://developer.squareup.com/docs/build-basics/common-api-p
|
20
|
+
# atterns/pagination).
|
20
21
|
# @return [ListCustomerSegmentsResponse Hash] response from the API call
|
21
22
|
def list_customer_segments(cursor: nil,
|
22
23
|
limit: nil)
|
@@ -15,14 +15,16 @@ module Square
|
|
15
15
|
# @param [String] cursor Optional parameter: A pagination cursor returned by
|
16
16
|
# a previous call to this endpoint. Provide this cursor to retrieve the next
|
17
17
|
# set of results for your original query. For more information, see
|
18
|
-
# [Pagination](https://developer.squareup.com/docs/
|
19
|
-
#
|
18
|
+
# [Pagination](https://developer.squareup.com/docs/build-basics/common-api-p
|
19
|
+
# atterns/pagination).
|
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.
|
23
|
-
#
|
24
|
-
#
|
25
|
-
#
|
22
|
+
# contain more or fewer results. If the specified limit is less than 1 or
|
23
|
+
# greater than 100, Square returns a `400 VALUE_TOO_LOW` or `400
|
24
|
+
# VALUE_TOO_HIGH` error. The default value is 100. For more information,
|
25
|
+
# see
|
26
|
+
# [Pagination](https://developer.squareup.com/docs/build-basics/common-api-p
|
27
|
+
# atterns/pagination).
|
26
28
|
# @param [CustomerSortField] sort_field Optional parameter: Indicates how
|
27
29
|
# customers should be sorted. The default value is `DEFAULT`.
|
28
30
|
# @param [SortOrder] sort_order Optional parameter: Indicates whether
|
@@ -166,8 +168,9 @@ module Square
|
|
166
168
|
# @param [Long] version Optional parameter: The current version of the
|
167
169
|
# customer profile. As a best practice, you should include this parameter
|
168
170
|
# to enable [optimistic
|
169
|
-
# concurrency](https://developer.squareup.com/docs/
|
170
|
-
#
|
171
|
+
# concurrency](https://developer.squareup.com/docs/build-basics/common-api-p
|
172
|
+
# atterns/optimistic-concurrency) control. For more information, see
|
173
|
+
# [Delete a customer
|
171
174
|
# profile](https://developer.squareup.com/docs/customers-api/use-the-api/kee
|
172
175
|
# p-records#delete-customer-profile).
|
173
176
|
# @return [DeleteCustomerResponse Hash] response from the API call
|
@@ -5,7 +5,8 @@ module Square
|
|
5
5
|
super(config, http_call_back: http_call_back)
|
6
6
|
end
|
7
7
|
|
8
|
-
# Provides details about all of the seller's
|
8
|
+
# Provides details about all of the seller's
|
9
|
+
# [locations](https://developer.squareup.com/docs/locations-api),
|
9
10
|
# including those with an inactive status.
|
10
11
|
# @return [ListLocationsResponse Hash] response from the API call
|
11
12
|
def list_locations
|
@@ -117,7 +118,7 @@ module Square
|
|
117
118
|
)
|
118
119
|
end
|
119
120
|
|
120
|
-
# Updates a location.
|
121
|
+
# Updates a [location](https://developer.squareup.com/docs/locations-api).
|
121
122
|
# @param [String] location_id Required parameter: The ID of the location to
|
122
123
|
# update.
|
123
124
|
# @param [UpdateLocationRequest] body Required parameter: An object
|
@@ -124,12 +124,6 @@ module Square
|
|
124
124
|
# [CalculateLoyaltyPoints]($e/Loyalty/CalculateLoyaltyPoints) to compute the
|
125
125
|
# points
|
126
126
|
# that you provide to this endpoint.
|
127
|
-
# __Note:__ The country of the seller's Square account determines whether
|
128
|
-
# tax is included in the purchase amount when accruing points for
|
129
|
-
# spend-based and visit-based programs.
|
130
|
-
# For more information, see [Availability of Square
|
131
|
-
# Loyalty](https://developer.squareup.com/docs/loyalty-api/overview#loyalty-
|
132
|
-
# market-availability).
|
133
127
|
# @param [String] account_id Required parameter: The [loyalty
|
134
128
|
# account]($m/LoyaltyAccount) ID to which to add the points.
|
135
129
|
# @param [AccumulateLoyaltyPointsRequest] body Required parameter: An object
|
@@ -336,8 +330,8 @@ module Square
|
|
336
330
|
end
|
337
331
|
|
338
332
|
# Calculates the points a purchase earns.
|
339
|
-
# - If you are using the Orders API to manage orders, you provide
|
340
|
-
# in the request. The
|
333
|
+
# - If you are using the Orders API to manage orders, you provide the
|
334
|
+
# `order_id` in the request. The
|
341
335
|
# endpoint calculates the points by reading the order.
|
342
336
|
# - If you are not using the Orders API to manage orders, you provide the
|
343
337
|
# purchase amount in
|
@@ -345,12 +339,9 @@ module Square
|
|
345
339
|
# An application might call this endpoint to show the points that a buyer
|
346
340
|
# can earn with the
|
347
341
|
# specific purchase.
|
348
|
-
#
|
349
|
-
#
|
350
|
-
#
|
351
|
-
# For more information, see [Availability of Square
|
352
|
-
# Loyalty](https://developer.squareup.com/docs/loyalty-api/overview#loyalty-
|
353
|
-
# market-availability).
|
342
|
+
# For spend-based and visit-based programs, the `tax_mode` setting of the
|
343
|
+
# accrual rule indicates how taxes should be treated for loyalty points
|
344
|
+
# accrual.
|
354
345
|
# @param [String] program_id Required parameter: The [loyalty
|
355
346
|
# program]($m/LoyaltyProgram) ID, which defines the rules for accruing
|
356
347
|
# points.
|
@@ -433,9 +424,10 @@ module Square
|
|
433
424
|
)
|
434
425
|
end
|
435
426
|
|
436
|
-
# Searches for loyalty rewards
|
437
|
-
#
|
438
|
-
# `
|
427
|
+
# Searches for loyalty rewards. This endpoint accepts a request with no
|
428
|
+
# query filters and returns results for all loyalty accounts.
|
429
|
+
# If you include a `query` object, `loyalty_account_id` is required and
|
430
|
+
# `status` is optional.
|
439
431
|
# If you know a reward ID, use the
|
440
432
|
# [RetrieveLoyaltyReward]($e/Loyalty/RetrieveLoyaltyReward) endpoint.
|
441
433
|
# Search results are sorted by `updated_at` in descending order.
|
@@ -5,15 +5,17 @@ module Square
|
|
5
5
|
super(config, http_call_back: http_call_back)
|
6
6
|
end
|
7
7
|
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
8
|
+
# Provides details about the merchant associated with a given access token.
|
9
|
+
# The access token used to connect your application to a Square seller is
|
10
|
+
# associated
|
11
|
+
# with a single merchant. That means that `ListMerchants` returns a list
|
12
|
+
# with a single `Merchant` object. You can specify your personal access
|
13
|
+
# token
|
14
|
+
# to get your own merchant information or specify an OAuth token to get the
|
15
|
+
# information for the merchant that granted your application access.
|
14
16
|
# If you know the merchant ID, you can also use the
|
15
17
|
# [RetrieveMerchant]($e/Merchants/RetrieveMerchant)
|
16
|
-
# endpoint to
|
18
|
+
# endpoint to retrieve the merchant information.
|
17
19
|
# @param [Integer] cursor Optional parameter: The cursor generated by the
|
18
20
|
# previous response.
|
19
21
|
# @return [ListMerchantsResponse Hash] response from the API call
|
@@ -48,7 +50,7 @@ module Square
|
|
48
50
|
)
|
49
51
|
end
|
50
52
|
|
51
|
-
#
|
53
|
+
# Retrieves the `Merchant` object for the given `merchant_id`.
|
52
54
|
# @param [String] merchant_id Required parameter: The ID of the merchant to
|
53
55
|
# retrieve. If the string "me" is supplied as the ID, then retrieve the
|
54
56
|
# merchant that is currently accessible to this call.
|
@@ -31,10 +31,13 @@ module Square
|
|
31
31
|
# the given status are returned. For a list of refund status values, see
|
32
32
|
# [PaymentRefund]($m/PaymentRefund). Default: If omitted, refunds are
|
33
33
|
# returned regardless of their status.
|
34
|
-
# @param [String] source_type Optional parameter: If provided, only
|
35
|
-
#
|
36
|
-
#
|
37
|
-
#
|
34
|
+
# @param [String] source_type Optional parameter: If provided, only returns
|
35
|
+
# refunds whose payments have the indicated source type. Current values
|
36
|
+
# include `CARD`, `BANK_ACCOUNT`, `WALLET`, `CASH`, and `EXTERNAL`. For
|
37
|
+
# information about these payment source types, see [Take
|
38
|
+
# Payments](https://developer.squareup.com/docs/payments-api/take-payments).
|
39
|
+
# Default: If omitted, refunds are returned regardless of the source
|
40
|
+
# type.
|
38
41
|
# @param [Integer] limit Optional parameter: The maximum number of results
|
39
42
|
# to be returned in a single page. It is possible to receive fewer results
|
40
43
|
# than the specified limit on a given page. If the supplied value is
|
@@ -0,0 +1,257 @@
|
|
1
|
+
module Square
|
2
|
+
# VendorsApi
|
3
|
+
class VendorsApi < BaseApi
|
4
|
+
def initialize(config, http_call_back: nil)
|
5
|
+
super(config, http_call_back: http_call_back)
|
6
|
+
end
|
7
|
+
|
8
|
+
# Creates one or more [Vendor]($m/Vendor) objects to represent suppliers to
|
9
|
+
# a seller.
|
10
|
+
# @param [BulkCreateVendorsRequest] body Required parameter: An object
|
11
|
+
# containing the fields to POST for the request. See the corresponding
|
12
|
+
# object definition for field details.
|
13
|
+
# @return [BulkCreateVendorsResponse Hash] response from the API call
|
14
|
+
def bulk_create_vendors(body:)
|
15
|
+
# Prepare query url.
|
16
|
+
_query_builder = config.get_base_uri
|
17
|
+
_query_builder << '/v2/vendors/bulk-create'
|
18
|
+
_query_url = APIHelper.clean_url _query_builder
|
19
|
+
|
20
|
+
# Prepare headers.
|
21
|
+
_headers = {
|
22
|
+
'accept' => 'application/json',
|
23
|
+
'Content-Type' => 'application/json'
|
24
|
+
}
|
25
|
+
|
26
|
+
# Prepare and execute HttpRequest.
|
27
|
+
_request = config.http_client.post(
|
28
|
+
_query_url,
|
29
|
+
headers: _headers,
|
30
|
+
parameters: body.to_json
|
31
|
+
)
|
32
|
+
OAuth2.apply(config, _request)
|
33
|
+
_response = execute_request(_request)
|
34
|
+
|
35
|
+
# Return appropriate response type.
|
36
|
+
decoded = APIHelper.json_deserialize(_response.raw_body)
|
37
|
+
_errors = APIHelper.map_response(decoded, ['errors'])
|
38
|
+
ApiResponse.new(
|
39
|
+
_response, data: decoded, errors: _errors
|
40
|
+
)
|
41
|
+
end
|
42
|
+
|
43
|
+
# Retrieves one or more vendors of specified [Vendor]($m/Vendor) IDs.
|
44
|
+
# @param [BulkRetrieveVendorsRequest] body Required parameter: An object
|
45
|
+
# containing the fields to POST for the request. See the corresponding
|
46
|
+
# object definition for field details.
|
47
|
+
# @return [BulkRetrieveVendorsResponse Hash] response from the API call
|
48
|
+
def bulk_retrieve_vendors(body:)
|
49
|
+
# Prepare query url.
|
50
|
+
_query_builder = config.get_base_uri
|
51
|
+
_query_builder << '/v2/vendors/bulk-retrieve'
|
52
|
+
_query_url = APIHelper.clean_url _query_builder
|
53
|
+
|
54
|
+
# Prepare headers.
|
55
|
+
_headers = {
|
56
|
+
'accept' => 'application/json',
|
57
|
+
'Content-Type' => 'application/json'
|
58
|
+
}
|
59
|
+
|
60
|
+
# Prepare and execute HttpRequest.
|
61
|
+
_request = config.http_client.post(
|
62
|
+
_query_url,
|
63
|
+
headers: _headers,
|
64
|
+
parameters: body.to_json
|
65
|
+
)
|
66
|
+
OAuth2.apply(config, _request)
|
67
|
+
_response = execute_request(_request)
|
68
|
+
|
69
|
+
# Return appropriate response type.
|
70
|
+
decoded = APIHelper.json_deserialize(_response.raw_body)
|
71
|
+
_errors = APIHelper.map_response(decoded, ['errors'])
|
72
|
+
ApiResponse.new(
|
73
|
+
_response, data: decoded, errors: _errors
|
74
|
+
)
|
75
|
+
end
|
76
|
+
|
77
|
+
# Updates one or more of existing [Vendor]($m/Vendor) objects as suppliers
|
78
|
+
# to a seller.
|
79
|
+
# @param [BulkUpdateVendorsRequest] body Required parameter: An object
|
80
|
+
# containing the fields to POST for the request. See the corresponding
|
81
|
+
# object definition for field details.
|
82
|
+
# @return [BulkUpdateVendorsResponse Hash] response from the API call
|
83
|
+
def bulk_update_vendors(body:)
|
84
|
+
# Prepare query url.
|
85
|
+
_query_builder = config.get_base_uri
|
86
|
+
_query_builder << '/v2/vendors/bulk-update'
|
87
|
+
_query_url = APIHelper.clean_url _query_builder
|
88
|
+
|
89
|
+
# Prepare headers.
|
90
|
+
_headers = {
|
91
|
+
'accept' => 'application/json',
|
92
|
+
'Content-Type' => 'application/json'
|
93
|
+
}
|
94
|
+
|
95
|
+
# Prepare and execute HttpRequest.
|
96
|
+
_request = config.http_client.put(
|
97
|
+
_query_url,
|
98
|
+
headers: _headers,
|
99
|
+
parameters: body.to_json
|
100
|
+
)
|
101
|
+
OAuth2.apply(config, _request)
|
102
|
+
_response = execute_request(_request)
|
103
|
+
|
104
|
+
# Return appropriate response type.
|
105
|
+
decoded = APIHelper.json_deserialize(_response.raw_body)
|
106
|
+
_errors = APIHelper.map_response(decoded, ['errors'])
|
107
|
+
ApiResponse.new(
|
108
|
+
_response, data: decoded, errors: _errors
|
109
|
+
)
|
110
|
+
end
|
111
|
+
|
112
|
+
# Creates a single [Vendor]($m/Vendor) object to represent a supplier to a
|
113
|
+
# seller.
|
114
|
+
# @param [CreateVendorRequest] body Required parameter: An object containing
|
115
|
+
# the fields to POST for the request. See the corresponding object
|
116
|
+
# definition for field details.
|
117
|
+
# @return [CreateVendorResponse Hash] response from the API call
|
118
|
+
def create_vendor(body:)
|
119
|
+
# Prepare query url.
|
120
|
+
_query_builder = config.get_base_uri
|
121
|
+
_query_builder << '/v2/vendors/create'
|
122
|
+
_query_url = APIHelper.clean_url _query_builder
|
123
|
+
|
124
|
+
# Prepare headers.
|
125
|
+
_headers = {
|
126
|
+
'accept' => 'application/json',
|
127
|
+
'Content-Type' => 'application/json'
|
128
|
+
}
|
129
|
+
|
130
|
+
# Prepare and execute HttpRequest.
|
131
|
+
_request = config.http_client.post(
|
132
|
+
_query_url,
|
133
|
+
headers: _headers,
|
134
|
+
parameters: body.to_json
|
135
|
+
)
|
136
|
+
OAuth2.apply(config, _request)
|
137
|
+
_response = execute_request(_request)
|
138
|
+
|
139
|
+
# Return appropriate response type.
|
140
|
+
decoded = APIHelper.json_deserialize(_response.raw_body)
|
141
|
+
_errors = APIHelper.map_response(decoded, ['errors'])
|
142
|
+
ApiResponse.new(
|
143
|
+
_response, data: decoded, errors: _errors
|
144
|
+
)
|
145
|
+
end
|
146
|
+
|
147
|
+
# Searches for vendors using a filter against supported [Vendor]($m/Vendor)
|
148
|
+
# properties and a supported sorter.
|
149
|
+
# @param [SearchVendorsRequest] body Required parameter: An object
|
150
|
+
# containing the fields to POST for the request. See the corresponding
|
151
|
+
# object definition for field details.
|
152
|
+
# @return [SearchVendorsResponse Hash] response from the API call
|
153
|
+
def search_vendors(body:)
|
154
|
+
# Prepare query url.
|
155
|
+
_query_builder = config.get_base_uri
|
156
|
+
_query_builder << '/v2/vendors/search'
|
157
|
+
_query_url = APIHelper.clean_url _query_builder
|
158
|
+
|
159
|
+
# Prepare headers.
|
160
|
+
_headers = {
|
161
|
+
'accept' => 'application/json',
|
162
|
+
'Content-Type' => 'application/json'
|
163
|
+
}
|
164
|
+
|
165
|
+
# Prepare and execute HttpRequest.
|
166
|
+
_request = config.http_client.post(
|
167
|
+
_query_url,
|
168
|
+
headers: _headers,
|
169
|
+
parameters: body.to_json
|
170
|
+
)
|
171
|
+
OAuth2.apply(config, _request)
|
172
|
+
_response = execute_request(_request)
|
173
|
+
|
174
|
+
# Return appropriate response type.
|
175
|
+
decoded = APIHelper.json_deserialize(_response.raw_body)
|
176
|
+
_errors = APIHelper.map_response(decoded, ['errors'])
|
177
|
+
ApiResponse.new(
|
178
|
+
_response, data: decoded, errors: _errors
|
179
|
+
)
|
180
|
+
end
|
181
|
+
|
182
|
+
# Retrieves the vendor of a specified [Vendor]($m/Vendor) ID.
|
183
|
+
# @param [String] vendor_id Required parameter: ID of the
|
184
|
+
# [Vendor]($m/Vendor) to retrieve.
|
185
|
+
# @return [RetrieveVendorResponse Hash] response from the API call
|
186
|
+
def retrieve_vendor(vendor_id:)
|
187
|
+
# Prepare query url.
|
188
|
+
_query_builder = config.get_base_uri
|
189
|
+
_query_builder << '/v2/vendors/{vendor_id}'
|
190
|
+
_query_builder = APIHelper.append_url_with_template_parameters(
|
191
|
+
_query_builder,
|
192
|
+
'vendor_id' => { 'value' => vendor_id, 'encode' => true }
|
193
|
+
)
|
194
|
+
_query_url = APIHelper.clean_url _query_builder
|
195
|
+
|
196
|
+
# Prepare headers.
|
197
|
+
_headers = {
|
198
|
+
'accept' => 'application/json'
|
199
|
+
}
|
200
|
+
|
201
|
+
# Prepare and execute HttpRequest.
|
202
|
+
_request = config.http_client.get(
|
203
|
+
_query_url,
|
204
|
+
headers: _headers
|
205
|
+
)
|
206
|
+
OAuth2.apply(config, _request)
|
207
|
+
_response = execute_request(_request)
|
208
|
+
|
209
|
+
# Return appropriate response type.
|
210
|
+
decoded = APIHelper.json_deserialize(_response.raw_body)
|
211
|
+
_errors = APIHelper.map_response(decoded, ['errors'])
|
212
|
+
ApiResponse.new(
|
213
|
+
_response, data: decoded, errors: _errors
|
214
|
+
)
|
215
|
+
end
|
216
|
+
|
217
|
+
# Updates an existing [Vendor]($m/Vendor) object as a supplier to a seller.
|
218
|
+
# @param [UpdateVendorRequest] body Required parameter: An object containing
|
219
|
+
# the fields to POST for the request. See the corresponding object
|
220
|
+
# definition for field details.
|
221
|
+
# @param [String] vendor_id Required parameter: Example:
|
222
|
+
# @return [UpdateVendorResponse Hash] response from the API call
|
223
|
+
def update_vendor(body:,
|
224
|
+
vendor_id:)
|
225
|
+
# Prepare query url.
|
226
|
+
_query_builder = config.get_base_uri
|
227
|
+
_query_builder << '/v2/vendors/{vendor_id}'
|
228
|
+
_query_builder = APIHelper.append_url_with_template_parameters(
|
229
|
+
_query_builder,
|
230
|
+
'vendor_id' => { 'value' => vendor_id, 'encode' => true }
|
231
|
+
)
|
232
|
+
_query_url = APIHelper.clean_url _query_builder
|
233
|
+
|
234
|
+
# Prepare headers.
|
235
|
+
_headers = {
|
236
|
+
'accept' => 'application/json',
|
237
|
+
'Content-Type' => 'application/json'
|
238
|
+
}
|
239
|
+
|
240
|
+
# Prepare and execute HttpRequest.
|
241
|
+
_request = config.http_client.put(
|
242
|
+
_query_url,
|
243
|
+
headers: _headers,
|
244
|
+
parameters: body.to_json
|
245
|
+
)
|
246
|
+
OAuth2.apply(config, _request)
|
247
|
+
_response = execute_request(_request)
|
248
|
+
|
249
|
+
# Return appropriate response type.
|
250
|
+
decoded = APIHelper.json_deserialize(_response.raw_body)
|
251
|
+
_errors = APIHelper.map_response(decoded, ['errors'])
|
252
|
+
ApiResponse.new(
|
253
|
+
_response, data: decoded, errors: _errors
|
254
|
+
)
|
255
|
+
end
|
256
|
+
end
|
257
|
+
end
|
data/lib/square/api_helper.rb
CHANGED
@@ -8,18 +8,16 @@ module Square
|
|
8
8
|
def self.serialize_array(key, array, formatting: 'indexed')
|
9
9
|
tuples = []
|
10
10
|
|
11
|
-
case formatting
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
raise ArgumentError, 'Invalid format provided.'
|
22
|
-
end
|
11
|
+
tuples += case formatting
|
12
|
+
when 'csv'
|
13
|
+
[[key, array.map { |element| CGI.escape(element.to_s) }.join(',')]]
|
14
|
+
when 'psv'
|
15
|
+
[[key, array.map { |element| CGI.escape(element.to_s) }.join('|')]]
|
16
|
+
when 'tsv'
|
17
|
+
[[key, array.map { |element| CGI.escape(element.to_s) }.join("\t")]]
|
18
|
+
else
|
19
|
+
array.map { |element| [key, element] }
|
20
|
+
end
|
23
21
|
tuples
|
24
22
|
end
|
25
23
|
|
@@ -75,31 +73,19 @@ module Square
|
|
75
73
|
return query_builder if parameters.nil?
|
76
74
|
|
77
75
|
array_serialization = 'indexed'
|
76
|
+
parameters = process_complex_types_parameters(parameters, array_serialization)
|
78
77
|
|
79
78
|
parameters.each do |key, value|
|
80
79
|
seperator = query_builder.include?('?') ? '&' : '?'
|
81
80
|
unless value.nil?
|
82
81
|
if value.instance_of? Array
|
83
82
|
value.compact!
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
"#{seperator}#{key}=#{value.map do |element|
|
91
|
-
CGI.escape(element.to_s)
|
92
|
-
end.join('|')}"
|
93
|
-
when 'tsv'
|
94
|
-
"#{seperator}#{key}=#{value.map do |element|
|
95
|
-
CGI.escape(element.to_s)
|
96
|
-
end.join("\t")}"
|
97
|
-
else
|
98
|
-
"#{seperator}#{APIHelper.serialize_array(
|
99
|
-
key, value, formatting: array_serialization
|
100
|
-
).map { |k, v| "#{k}=#{CGI.escape(v.to_s)}" }
|
101
|
-
.join('&')}"
|
102
|
-
end
|
83
|
+
APIHelper.serialize_array(
|
84
|
+
key, value, formatting: array_serialization
|
85
|
+
).each do |element|
|
86
|
+
seperator = query_builder.include?('?') ? '&' : '?'
|
87
|
+
query_builder += "#{seperator}#{element[0]}=#{element[1]}"
|
88
|
+
end
|
103
89
|
else
|
104
90
|
query_builder += "#{seperator}#{key}=#{CGI.escape(value.to_s)}"
|
105
91
|
end
|
@@ -163,6 +149,18 @@ module Square
|
|
163
149
|
encoded
|
164
150
|
end
|
165
151
|
|
152
|
+
# Process complex types in query_params.
|
153
|
+
# @param [Hash] The hash of query parameters.
|
154
|
+
# @return [Hash] A hash with the processed query parameters.
|
155
|
+
def self.process_complex_types_parameters(query_parameters, array_serialization)
|
156
|
+
processed_params = {}
|
157
|
+
query_parameters.each do |key, value|
|
158
|
+
processed_params.merge!(APIHelper.form_encode(value, key, formatting:
|
159
|
+
array_serialization))
|
160
|
+
end
|
161
|
+
processed_params
|
162
|
+
end
|
163
|
+
|
166
164
|
def self.custom_merge(a, b)
|
167
165
|
x = {}
|
168
166
|
a.each do |key, value_a|
|
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
|
+
'18.1.0.20220316'
|
8
8
|
end
|
9
9
|
|
10
10
|
def square_version
|
@@ -213,16 +213,22 @@ module Square
|
|
213
213
|
@terminal ||= TerminalApi.new config
|
214
214
|
end
|
215
215
|
|
216
|
-
|
216
|
+
# Access to vendors controller.
|
217
|
+
# @return [VendorsApi] Returns the controller instance.
|
218
|
+
def vendors
|
219
|
+
@vendors ||= VendorsApi.new config
|
220
|
+
end
|
221
|
+
|
222
|
+
def initialize(connection: nil, timeout: 60, max_retries: 0,
|
217
223
|
retry_interval: 1, backoff_factor: 2,
|
218
224
|
retry_statuses: [408, 413, 429, 500, 502, 503, 504, 521, 522, 524],
|
219
225
|
retry_methods: %i[get put], environment: 'production',
|
220
226
|
custom_url: 'https://connect.squareup.com',
|
221
|
-
square_version: '
|
227
|
+
square_version: '2022-03-16', access_token: '',
|
222
228
|
user_agent_detail: '', additional_headers: {}, config: nil)
|
223
229
|
@config = if config.nil?
|
224
|
-
Configuration.new(
|
225
|
-
|
230
|
+
Configuration.new(connection: connection, timeout: timeout,
|
231
|
+
max_retries: max_retries,
|
226
232
|
retry_interval: retry_interval,
|
227
233
|
backoff_factor: backoff_factor,
|
228
234
|
retry_statuses: retry_statuses,
|
data/lib/square/configuration.rb
CHANGED
@@ -3,9 +3,9 @@ module Square
|
|
3
3
|
# are configured in this class.
|
4
4
|
class Configuration
|
5
5
|
# The attribute readers for properties.
|
6
|
-
attr_reader :http_client, :
|
7
|
-
:
|
8
|
-
:
|
6
|
+
attr_reader :http_client, :connection, :timeout, :max_retries, :retry_interval, :backoff_factor,
|
7
|
+
:retry_statuses, :retry_methods, :environment, :custom_url, :square_version,
|
8
|
+
:access_token, :user_agent_detail
|
9
9
|
|
10
10
|
def additional_headers
|
11
11
|
@additional_headers.clone
|
@@ -15,15 +15,15 @@ module Square
|
|
15
15
|
attr_reader :environments
|
16
16
|
end
|
17
17
|
|
18
|
-
def initialize(
|
18
|
+
def initialize(connection: nil, timeout: 60, max_retries: 0,
|
19
19
|
retry_interval: 1, backoff_factor: 2,
|
20
20
|
retry_statuses: [408, 413, 429, 500, 502, 503, 504, 521, 522, 524],
|
21
21
|
retry_methods: %i[get put], environment: 'production',
|
22
22
|
custom_url: 'https://connect.squareup.com',
|
23
|
-
square_version: '
|
23
|
+
square_version: '2022-03-16', access_token: '',
|
24
24
|
user_agent_detail: '', additional_headers: {})
|
25
|
-
# The
|
26
|
-
@
|
25
|
+
# The Faraday connection object passed by the SDK user for making requests
|
26
|
+
@connection = connection
|
27
27
|
|
28
28
|
# The value to use for connection timeout
|
29
29
|
@timeout = timeout
|
@@ -61,14 +61,17 @@ module Square
|
|
61
61
|
|
62
62
|
# The Http Client to use for making requests.
|
63
63
|
@http_client = create_http_client
|
64
|
+
|
65
|
+
# User agent detail, to be appended with user-agent header.
|
66
|
+
@user_agent_detail = get_user_agent(user_agent_detail)
|
64
67
|
end
|
65
68
|
|
66
|
-
def clone_with(
|
69
|
+
def clone_with(connection: nil, timeout: nil, max_retries: nil,
|
67
70
|
retry_interval: nil, backoff_factor: nil,
|
68
71
|
retry_statuses: nil, retry_methods: nil, environment: nil,
|
69
72
|
custom_url: nil, square_version: nil, access_token: nil,
|
70
73
|
user_agent_detail: nil, additional_headers: nil)
|
71
|
-
|
74
|
+
connection ||= self.connection
|
72
75
|
timeout ||= self.timeout
|
73
76
|
max_retries ||= self.max_retries
|
74
77
|
retry_interval ||= self.retry_interval
|
@@ -82,8 +85,8 @@ module Square
|
|
82
85
|
user_agent_detail ||= self.user_agent_detail
|
83
86
|
additional_headers ||= self.additional_headers
|
84
87
|
|
85
|
-
Configuration.new(
|
86
|
-
|
88
|
+
Configuration.new(connection: connection, timeout: timeout,
|
89
|
+
max_retries: max_retries,
|
87
90
|
retry_interval: retry_interval,
|
88
91
|
backoff_factor: backoff_factor,
|
89
92
|
retry_statuses: retry_statuses,
|
@@ -99,8 +102,13 @@ module Square
|
|
99
102
|
retry_interval: retry_interval,
|
100
103
|
backoff_factor: backoff_factor,
|
101
104
|
retry_statuses: retry_statuses,
|
102
|
-
retry_methods: retry_methods,
|
103
|
-
|
105
|
+
retry_methods: retry_methods, connection: connection)
|
106
|
+
end
|
107
|
+
|
108
|
+
def get_user_agent(user_agent_detail)
|
109
|
+
raise ArgumentError, 'The length of user-agent detail should not exceed 128 characters.' unless user_agent_detail.length < 128
|
110
|
+
|
111
|
+
user_agent_detail
|
104
112
|
end
|
105
113
|
|
106
114
|
# All the environments the SDK can run in.
|
@@ -4,29 +4,28 @@ require 'faraday_middleware'
|
|
4
4
|
module Square
|
5
5
|
# An implementation of HttpClient.
|
6
6
|
class FaradayClient < HttpClient
|
7
|
+
# The attribute readers for properties.
|
8
|
+
attr_reader :connection
|
9
|
+
|
7
10
|
# The constructor.
|
8
11
|
def initialize(timeout:, max_retries:, retry_interval:,
|
9
12
|
backoff_factor:, retry_statuses:, retry_methods:,
|
10
|
-
|
11
|
-
if
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
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
|
13
|
+
connection: nil, cache: false, verify: true)
|
14
|
+
@connection = if connection.nil?
|
15
|
+
create_connection(timeout: timeout, max_retries: max_retries,
|
16
|
+
retry_interval: retry_interval, backoff_factor: backoff_factor,
|
17
|
+
retry_statuses: retry_statuses, retry_methods: retry_methods,
|
18
|
+
cache: cache, verify: verify)
|
19
|
+
else
|
20
|
+
connection
|
21
|
+
end
|
23
22
|
end
|
24
23
|
|
25
24
|
# Method to initialize connection.
|
26
25
|
def create_connection(timeout:, max_retries:, retry_interval:,
|
27
26
|
backoff_factor:, retry_statuses:, retry_methods:,
|
28
27
|
cache: false, verify: true)
|
29
|
-
|
28
|
+
Faraday.new do |faraday|
|
30
29
|
faraday.use Faraday::HttpCache, serializer: Marshal if cache
|
31
30
|
faraday.use FaradayMiddleware::FollowRedirects
|
32
31
|
faraday.use :gzip
|
@@ -42,7 +41,6 @@ module Square
|
|
42
41
|
faraday.options[:params_encoder] = Faraday::FlatParamsEncoder
|
43
42
|
faraday.options[:timeout] = timeout if timeout.positive?
|
44
43
|
end
|
45
|
-
@connection
|
46
44
|
end
|
47
45
|
|
48
46
|
# Method overridden from HttpClient.
|
data/lib/square.rb
CHANGED
@@ -7,7 +7,7 @@ class LocationsApiTests < ApiTestBase
|
|
7
7
|
@controller = LocationsApi.new CONFIG, http_call_back: @response_catcher
|
8
8
|
end
|
9
9
|
|
10
|
-
# Provides details about all of the seller's locations,
|
10
|
+
# Provides details about all of the seller's [locations](https://developer.squareup.com/docs/locations-api),
|
11
11
|
#including those with an inactive status.
|
12
12
|
def test_list_locations()
|
13
13
|
|
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: 18.1.0.20220316
|
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:
|
11
|
+
date: 2022-03-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: logging
|
@@ -170,6 +170,7 @@ files:
|
|
170
170
|
- lib/square/api/terminal_api.rb
|
171
171
|
- lib/square/api/transactions_api.rb
|
172
172
|
- lib/square/api/v1_transactions_api.rb
|
173
|
+
- lib/square/api/vendors_api.rb
|
173
174
|
- lib/square/api_helper.rb
|
174
175
|
- lib/square/client.rb
|
175
176
|
- lib/square/configuration.rb
|