square.rb 16.0.0.20211117 → 18.0.0.20220216

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 25ab6d01177792b1eb326af1a782a12ab26eff2678b44666aac14954907740e2
4
- data.tar.gz: 1ba81bfd71af7fd3124015de59166e33401f0e230301d4ea45e6c70438380741
3
+ metadata.gz: d63ad56661f521ead949670191ddb004cf944daedf7836047c9281e8e6600ecf
4
+ data.tar.gz: 548171c3a90103f2a2492166e6b69f9c0dd7855f1c20d656e4c7c1f922053e86
5
5
  SHA512:
6
- metadata.gz: c0fa97ef6d70db8247d6a14cb946a942f9327faa37e881ce8628cd8f68e38bb6c91238cf10419dc915597701b69c73ecb0f1813d45be4d6f37eaa837c1646364
7
- data.tar.gz: a9337cd596b733099e84765048134f4edc183f548ac6638da50257bfb0d3b0529271d17c509a1f9b34342abe9e7184d56ec4fe1f292ea1fa2ad36036228384d1
6
+ metadata.gz: 4d5f5cdb0c4992a16eca7327a67642d9fcb807ae040b7c3426d5635ac3ef9f40ab9d144fe011b60c5ad996b81b098e49a3e4cf8a3e6aa3dd4742fab08fd6e1b3
7
+ data.tar.gz: 56b7b2f269877ec3b2f867d608e0a803a066e74bc958d2e0f60e156a034360e872d0c7eccefa5d552a35b700f2c9cb83b364a942e96968a713ab33013069dea5
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2021 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
@@ -10,7 +10,7 @@ Use this gem to integrate Square payments into your app and grow your business w
10
10
 
11
11
  ## Requirements
12
12
 
13
- We support Ruby 2.5.x, 2.6.x, and 2.7.x.
13
+ We support Ruby 2.6 through 3.1.
14
14
 
15
15
  ## Installation
16
16
 
@@ -1,3 +1,4 @@
1
+ require 'erb'
1
2
  module Square
2
3
  # BaseApi.
3
4
  class BaseApi
@@ -8,7 +9,7 @@ module Square
8
9
  @http_call_back = http_call_back
9
10
 
10
11
  @global_headers = {
11
- 'user-agent' => 'Square-Ruby-SDK/16.0.0.20211117',
12
+ 'user-agent' => get_user_agent,
12
13
  'Square-Version' => config.square_version
13
14
  }
14
15
  end
@@ -35,5 +36,19 @@ module Square
35
36
 
36
37
  response
37
38
  end
39
+
40
+ def get_user_agent
41
+ user_agent = 'Square-Ruby-SDK/18.0.0.20220216 ({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
38
53
  end
39
54
  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 for paginating
172
- # 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.
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
@@ -136,10 +136,10 @@ module Square
136
136
  end
137
137
 
138
138
  # Uploads an image file to be represented by a
139
- # [CatalogImage]($m/CatalogImage) object linked to an existing
140
- # [CatalogObject]($m/CatalogObject) instance. A call to this endpoint can
141
- # upload an image, link an image to
142
- # a catalog object, or do both.
139
+ # [CatalogImage]($m/CatalogImage) object that can be linked to an existing
140
+ # [CatalogObject]($m/CatalogObject) instance. The resulting `CatalogImage`
141
+ # is unattached to any `CatalogObject` if the `object_id`
142
+ # is not specified.
143
143
  # This `CreateCatalogImage` endpoint accepts HTTP multipart/form-data
144
144
  # requests with a JSON part and an image file part in
145
145
  # JPEG, PJPEG, PNG, or GIF format. The maximum file size is 15MB.
@@ -196,6 +196,71 @@ module Square
196
196
  )
197
197
  end
198
198
 
199
+ # Uploads a new image file to replace the existing one in the specified
200
+ # [CatalogImage]($m/CatalogImage) object.
201
+ # This `UpdateCatalogImage` endpoint accepts HTTP multipart/form-data
202
+ # requests with a JSON part and an image file part in
203
+ # JPEG, PJPEG, PNG, or GIF format. The maximum file size is 15MB.
204
+ # @param [String] image_id Required parameter: The ID of the `CatalogImage`
205
+ # object to update the encapsulated image file.
206
+ # @param [UpdateCatalogImageRequest] request Optional parameter: Example:
207
+ # @param [File | UploadIO] image_file Optional parameter: Example:
208
+ # @return [UpdateCatalogImageResponse Hash] response from the API call
209
+ def update_catalog_image(image_id:,
210
+ request: nil,
211
+ image_file: nil)
212
+ # Prepare query url.
213
+ _query_builder = config.get_base_uri
214
+ _query_builder << '/v2/catalog/images/{image_id}'
215
+ _query_builder = APIHelper.append_url_with_template_parameters(
216
+ _query_builder,
217
+ 'image_id' => { 'value' => image_id, 'encode' => true }
218
+ )
219
+ _query_url = APIHelper.clean_url _query_builder
220
+
221
+ if image_file.is_a? FileWrapper
222
+ image_file_wrapper = image_file.file
223
+ image_file_content_type = image_file.content_type
224
+ else
225
+ image_file_wrapper = image_file
226
+ image_file_content_type = 'image/jpeg'
227
+ end
228
+
229
+ # Prepare headers.
230
+ _headers = {
231
+ 'accept' => 'application/json'
232
+ }
233
+
234
+ # Prepare form parameters.
235
+ _parameters = {
236
+ 'request' => Faraday::UploadIO.new(
237
+ StringIO.new(request.to_json),
238
+ 'application/json'
239
+ ),
240
+ 'image_file' => Faraday::UploadIO.new(
241
+ image_file_wrapper,
242
+ image_file_content_type
243
+ )
244
+ }
245
+ _parameters = APIHelper.form_encode_parameters(_parameters)
246
+
247
+ # Prepare and execute HttpRequest.
248
+ _request = config.http_client.put(
249
+ _query_url,
250
+ headers: _headers,
251
+ parameters: _parameters
252
+ )
253
+ OAuth2.apply(config, _request)
254
+ _response = execute_request(_request)
255
+
256
+ # Return appropriate response type.
257
+ decoded = APIHelper.json_deserialize(_response.raw_body)
258
+ _errors = APIHelper.map_response(decoded, ['errors'])
259
+ ApiResponse.new(
260
+ _response, data: decoded, errors: _errors
261
+ )
262
+ end
263
+
199
264
  # Retrieves information about the Square Catalog API, such as batch size
200
265
  # limits that can be used by the `BatchUpsertCatalogObjects` endpoint.
201
266
  # @return [CatalogInfoResponse Hash] response from the API call
@@ -226,15 +291,12 @@ module Square
226
291
  )
227
292
  end
228
293
 
229
- # Returns a list of [CatalogObject]($m/CatalogObject)s that includes
230
- # all objects of a set of desired types (for example, all
231
- # [CatalogItem]($m/CatalogItem)
232
- # and [CatalogTax]($m/CatalogTax) objects) in the catalog. The `types`
233
- # parameter
234
- # is specified as a comma-separated list of valid
235
- # [CatalogObject]($m/CatalogObject) types:
236
- # `ITEM`, `ITEM_VARIATION`, `MODIFIER`, `MODIFIER_LIST`, `CATEGORY`,
237
- # `DISCOUNT`, `TAX`, `IMAGE`.
294
+ # Returns a list of all [CatalogObject]($m/CatalogObject)s of the specified
295
+ # types in the catalog.
296
+ # The `types` parameter is specified as a comma-separated list of the
297
+ # [CatalogObjectType]($m/CatalogObjectType) values,
298
+ # for example, "`ITEM`, `ITEM_VARIATION`, `MODIFIER`, `MODIFIER_LIST`,
299
+ # `CATEGORY`, `DISCOUNT`, `TAX`, `IMAGE`".
238
300
  # __Important:__ ListCatalog does not return deleted catalog items. To
239
301
  # retrieve
240
302
  # deleted catalog items, use
@@ -247,16 +309,22 @@ module Square
247
309
  # for more information.
248
310
  # @param [String] types Optional parameter: An optional case-insensitive,
249
311
  # comma-separated list of object types to retrieve. The valid values are
250
- # defined in the [CatalogObjectType]($m/CatalogObjectType) enum, including
251
- # `ITEM`, `ITEM_VARIATION`, `CATEGORY`, `DISCOUNT`, `TAX`, `MODIFIER`,
252
- # `MODIFIER_LIST`, or `IMAGE`. If this is unspecified, the operation
253
- # returns objects of all the types at the version of the Square API used to
254
- # make the request.
312
+ # defined in the [CatalogObjectType]($m/CatalogObjectType) enum, for
313
+ # example, `ITEM`, `ITEM_VARIATION`, `CATEGORY`, `DISCOUNT`, `TAX`,
314
+ # `MODIFIER`, `MODIFIER_LIST`, `IMAGE`, etc. If this is unspecified, the
315
+ # operation returns objects of all the top level types at the version of the
316
+ # Square API used to make the request. Object types that are nested onto
317
+ # other object types are not included in the defaults. At the current API
318
+ # version the default object types are: ITEM, CATEGORY, TAX, DISCOUNT,
319
+ # MODIFIER_LIST, DINING_OPTION, TAX_EXEMPTION, SERVICE_CHARGE, PRICING_RULE,
320
+ # PRODUCT_SET, TIME_PERIOD, MEASUREMENT_UNIT, SUBSCRIPTION_PLAN,
321
+ # ITEM_OPTION, CUSTOM_ATTRIBUTE_DEFINITION, QUICK_AMOUNT_SETTINGS.
255
322
  # @param [Long] catalog_version Optional parameter: The specific version of
256
323
  # the catalog objects to be included in the response. This allows you to
257
324
  # retrieve historical versions of objects. The specified version value is
258
325
  # matched against the [CatalogObject]($m/CatalogObject)s' `version`
259
- # attribute.
326
+ # attribute. If not included, results will be from the current version of
327
+ # the catalog.
260
328
  # @return [ListCatalogResponse Hash] response from the API call
261
329
  def list_catalog(cursor: nil,
262
330
  types: nil,
@@ -382,17 +450,24 @@ module Square
382
450
  # catalog objects to be retrieved.
383
451
  # @param [Boolean] include_related_objects Optional parameter: If `true`,
384
452
  # the response will include additional objects that are related to the
385
- # requested object, as follows: If the `object` field of the response
386
- # contains a `CatalogItem`, its associated `CatalogCategory`, `CatalogTax`,
387
- # `CatalogImage` and `CatalogModifierList` objects will be returned in the
388
- # `related_objects` field of the response. If the `object` field of the
389
- # response contains a `CatalogItemVariation`, its parent `CatalogItem` will
390
- # be returned in the `related_objects` field of the response. Default
391
- # value: `false`
453
+ # requested objects. Related objects are defined as any objects referenced
454
+ # by ID by the results in the `objects` field of the response. These objects
455
+ # are put in the `related_objects` field. Setting this to `true` is helpful
456
+ # when the objects are needed for immediate display to a user. This process
457
+ # only goes one level deep. Objects referenced by the related objects will
458
+ # not be included. For example, if the `objects` field of the response
459
+ # contains a CatalogItem, its associated CatalogCategory objects, CatalogTax
460
+ # objects, CatalogImage objects and CatalogModifierLists will be returned in
461
+ # the `related_objects` field of the response. If the `objects` field of the
462
+ # response contains a CatalogItemVariation, its parent CatalogItem will be
463
+ # returned in the `related_objects` field of the response. Default value:
464
+ # `false`
392
465
  # @param [Long] catalog_version Optional parameter: Requests objects as of a
393
466
  # specific version of the catalog. This allows you to retrieve historical
394
467
  # versions of objects. The value to retrieve a specific version of an object
395
468
  # can be found in the version field of [CatalogObject]($m/CatalogObject)s.
469
+ # If not included, results will be from the current version of the
470
+ # catalog.
396
471
  # @return [RetrieveCatalogObjectResponse Hash] response from the API call
397
472
  def retrieve_catalog_object(object_id:,
398
473
  include_related_objects: false,
@@ -5,10 +5,9 @@ module Square
5
5
  super(config, http_call_back: http_call_back)
6
6
  end
7
7
 
8
- # Provides information of all locations of a business.
9
- # Many Square API endpoints require a `location_id` parameter.
10
- # The `id` field of the [`Location`]($m/Location) objects returned by this
11
- # endpoint correspond to that `location_id` parameter.
8
+ # Provides details about all of the seller's
9
+ # [locations](https://developer.squareup.com/docs/locations-api),
10
+ # including those with an inactive status.
12
11
  # @return [ListLocationsResponse Hash] response from the API call
13
12
  def list_locations
14
13
  # Prepare query url.
@@ -37,7 +36,17 @@ module Square
37
36
  )
38
37
  end
39
38
 
40
- # Creates a location.
39
+ # Creates a [location](https://developer.squareup.com/docs/locations-api).
40
+ # Creating new locations allows for separate configuration of receipt
41
+ # layouts, item prices,
42
+ # and sales reports. Developers can use locations to separate sales activity
43
+ # via applications
44
+ # that integrate with Square from sales activity elsewhere in a seller's
45
+ # account.
46
+ # Locations created programmatically with the Locations API will last
47
+ # forever and
48
+ # are visible to the seller for their own management, so ensure that
49
+ # each location has a sensible and unique name.
41
50
  # @param [CreateLocationRequest] body Required parameter: An object
42
51
  # containing the fields to POST for the request. See the corresponding
43
52
  # object definition for field details.
@@ -71,12 +80,12 @@ module Square
71
80
  )
72
81
  end
73
82
 
74
- # Retrieves details of a location. You can specify "main"
75
- # as the location ID to retrieve details of the
76
- # main location.
83
+ # Retrieves details of a single location. Specify "main"
84
+ # as the location ID to retrieve details of the [main
85
+ # location](https://developer.squareup.com/docs/locations-api#about-the-main
86
+ # -location).
77
87
  # @param [String] location_id Required parameter: The ID of the location to
78
- # retrieve. If you specify the string "main", then the endpoint returns the
79
- # main location.
88
+ # retrieve. Specify the string "main" to return the main location.
80
89
  # @return [RetrieveLocationResponse Hash] response from the API call
81
90
  def retrieve_location(location_id:)
82
91
  # Prepare query url.
@@ -109,7 +118,7 @@ module Square
109
118
  )
110
119
  end
111
120
 
112
- # Updates a location.
121
+ # Updates a [location](https://developer.squareup.com/docs/locations-api).
113
122
  # @param [String] location_id Required parameter: The ID of the location to
114
123
  # update.
115
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 `order_id`
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
- # __Note:__ The country of the seller's Square account determines whether
349
- # tax is included in the purchase amount when accruing points for
350
- # spend-based and visit-based programs.
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.
@@ -5,15 +5,17 @@ module Square
5
5
  super(config, http_call_back: http_call_back)
6
6
  end
7
7
 
8
- # Returns `Merchant` information for a given access token.
9
- # If you don't know a `Merchant` ID, you can use this endpoint to retrieve
10
- # the merchant ID for an access token.
11
- # You can specify your personal access token to get your own merchant
12
- # information or specify an OAuth token
13
- # to get the information for the merchant that granted you access.
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 get the merchant information.
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
- # Retrieve a `Merchant` object for the given `merchant_id`.
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.
@@ -6,9 +6,9 @@ module Square
6
6
  end
7
7
 
8
8
  # Generates code to authorize a mobile application to connect to a Square
9
- # card reader
10
- # Authorization codes are one-time-use and expire __60 minutes__ after being
11
- # issued.
9
+ # card reader.
10
+ # Authorization codes are one-time-use codes and expire 60 minutes after
11
+ # being issued.
12
12
  # __Important:__ The `Authorization` header you provide to this endpoint
13
13
  # must have the following format:
14
14
  # ```
@@ -12,11 +12,11 @@ module Square
12
12
  # okens).
13
13
  # Renews an OAuth access token before it expires.
14
14
  # OAuth access tokens besides your application's personal access token
15
- # expire after __30 days__.
16
- # You can also renew expired tokens within __15 days__ of their expiration.
15
+ # expire after 30 days.
16
+ # You can also renew expired tokens within 15 days of their expiration.
17
17
  # You cannot renew an access token that has been expired for more than 15
18
18
  # days.
19
- # Instead, the associated user must re-complete the OAuth flow from the
19
+ # Instead, the associated user must recomplete the OAuth flow from the
20
20
  # beginning.
21
21
  # __Important:__ The `Authorization` header for this endpoint must have the
22
22
  # following format:
@@ -25,10 +25,10 @@ module Square
25
25
  # ```
26
26
  # Replace `APPLICATION_SECRET` with the application secret on the
27
27
  # Credentials
28
- # page in the [developer dashboard](https://developer.squareup.com/apps).
29
- # @param [String] client_id Required parameter: Your application ID,
30
- # available from the OAuth page for your application on the Developer
31
- # Dashboard.
28
+ # page in the [Developer Dashboard](https://developer.squareup.com/apps).
29
+ # @param [String] client_id Required parameter: Your application ID, which
30
+ # is available in the OAuth page in the [Developer
31
+ # Dashboard](https://developer.squareup.com/apps).
32
32
  # @param [RenewTokenRequest] body Required parameter: An object containing
33
33
  # the fields to POST for the request. See the corresponding object
34
34
  # definition for field details.
@@ -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 refunds
35
- # with the given source type are returned. - `CARD` - List refunds only for
36
- # payments where `CARD` was specified as the payment source. Default: If
37
- # omitted, refunds are returned regardless of the source type.
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
@@ -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
- when 'unindexed'
13
- tuples += array.map { |element| ["#{key}[]", element] }
14
- when 'indexed'
15
- tuples += array.map.with_index do |element, index|
16
- ["#{key}[#{index}]", element]
17
- end
18
- when 'plain'
19
- tuples += array.map { |element| [key, element] }
20
- else
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
- query_builder += case array_serialization
85
- when 'csv'
86
- "#{seperator}#{key}=#{value.map do |element|
87
- CGI.escape(element.to_s)
88
- end.join(',')}"
89
- when 'psv'
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,13 +4,17 @@ module Square
4
4
  attr_reader :config
5
5
 
6
6
  def sdk_version
7
- '16.0.0.20211117'
7
+ '18.0.0.20220216'
8
8
  end
9
9
 
10
10
  def square_version
11
11
  config.square_version
12
12
  end
13
13
 
14
+ def user_agent_detail
15
+ config.user_agent_detail
16
+ end
17
+
14
18
  # Access to mobile_authorization controller.
15
19
  # @return [MobileAuthorizationApi] Returns the controller instance.
16
20
  def mobile_authorization
@@ -209,16 +213,16 @@ module Square
209
213
  @terminal ||= TerminalApi.new config
210
214
  end
211
215
 
212
- def initialize(http_client_instance: nil, timeout: 60, max_retries: 0,
216
+ def initialize(connection: nil, timeout: 60, max_retries: 0,
213
217
  retry_interval: 1, backoff_factor: 2,
214
218
  retry_statuses: [408, 413, 429, 500, 502, 503, 504, 521, 522, 524],
215
219
  retry_methods: %i[get put], environment: 'production',
216
220
  custom_url: 'https://connect.squareup.com',
217
- square_version: '2021-11-17', access_token: '',
218
- additional_headers: {}, config: nil)
221
+ square_version: '2022-02-16', access_token: '',
222
+ user_agent_detail: '', additional_headers: {}, config: nil)
219
223
  @config = if config.nil?
220
- Configuration.new(http_client_instance: http_client_instance,
221
- timeout: timeout, max_retries: max_retries,
224
+ Configuration.new(connection: connection, timeout: timeout,
225
+ max_retries: max_retries,
222
226
  retry_interval: retry_interval,
223
227
  backoff_factor: backoff_factor,
224
228
  retry_statuses: retry_statuses,
@@ -227,6 +231,7 @@ module Square
227
231
  custom_url: custom_url,
228
232
  square_version: square_version,
229
233
  access_token: access_token,
234
+ user_agent_detail: user_agent_detail,
230
235
  additional_headers: additional_headers)
231
236
  else
232
237
  config
@@ -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, :http_client_instance, :timeout, :max_retries, :retry_interval,
7
- :backoff_factor, :retry_statuses, :retry_methods, :environment, :custom_url,
8
- :square_version, :access_token
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(http_client_instance: nil, timeout: 60, max_retries: 0,
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: '2021-11-17', access_token: '',
24
- additional_headers: {})
25
- # The Http Client passed from the sdk user for making requests
26
- @http_client_instance = http_client_instance
23
+ square_version: '2022-02-16', access_token: '',
24
+ user_agent_detail: '', additional_headers: {})
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(http_client_instance: nil, timeout: nil, max_retries: nil,
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
- additional_headers: nil)
71
- http_client_instance ||= self.http_client_instance
73
+ user_agent_detail: nil, additional_headers: nil)
74
+ connection ||= self.connection
72
75
  timeout ||= self.timeout
73
76
  max_retries ||= self.max_retries
74
77
  retry_interval ||= self.retry_interval
@@ -79,16 +82,18 @@ module Square
79
82
  custom_url ||= self.custom_url
80
83
  square_version ||= self.square_version
81
84
  access_token ||= self.access_token
85
+ user_agent_detail ||= self.user_agent_detail
82
86
  additional_headers ||= self.additional_headers
83
87
 
84
- Configuration.new(http_client_instance: http_client_instance,
85
- timeout: timeout, max_retries: max_retries,
88
+ Configuration.new(connection: connection, timeout: timeout,
89
+ max_retries: max_retries,
86
90
  retry_interval: retry_interval,
87
91
  backoff_factor: backoff_factor,
88
92
  retry_statuses: retry_statuses,
89
93
  retry_methods: retry_methods, environment: environment,
90
94
  custom_url: custom_url, square_version: square_version,
91
95
  access_token: access_token,
96
+ user_agent_detail: user_agent_detail,
92
97
  additional_headers: additional_headers)
93
98
  end
94
99
 
@@ -97,8 +102,13 @@ module Square
97
102
  retry_interval: retry_interval,
98
103
  backoff_factor: backoff_factor,
99
104
  retry_statuses: retry_statuses,
100
- retry_methods: retry_methods,
101
- http_client_instance: http_client_instance)
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
102
112
  end
103
113
 
104
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
- http_client_instance: nil, cache: false, verify: true)
11
- if http_client_instance.nil?
12
- create_connection(timeout: timeout, max_retries: max_retries,
13
- retry_interval: retry_interval, backoff_factor: backoff_factor,
14
- retry_statuses: retry_statuses, retry_methods: retry_methods,
15
- cache: cache, verify: verify)
16
- else
17
- if http_client_instance.instance_variable_get('@connection').nil?
18
- raise ArgumentError,
19
- "`connection` cannot be nil in `#{self.class}`. Please specify a valid value."
20
- end
21
- @connection = http_client_instance.instance_variable_get('@connection')
22
- end
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
- @connection = Faraday.new do |faraday|
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.
@@ -7,11 +7,8 @@ class LocationsApiTests < ApiTestBase
7
7
  @controller = LocationsApi.new CONFIG, http_call_back: @response_catcher
8
8
  end
9
9
 
10
- # Provides information of all locations of a business.
11
- #
12
- #Many Square API endpoints require a `location_id` parameter.
13
- #The `id` field of the [`Location`]($m/Location) objects returned by this
14
- #endpoint correspond to that `location_id` parameter.
10
+ # Provides details about all of the seller's [locations](https://developer.squareup.com/docs/locations-api),
11
+ #including those with an inactive status.
15
12
  def test_list_locations()
16
13
 
17
14
  # Perform the API call through the SDK function
data/test/test_helper.rb CHANGED
@@ -82,7 +82,7 @@ class TestHelper
82
82
  unless @cache.keys.include? url
83
83
  @cache[url] = Tempfile.new('APIMatic')
84
84
  @cache[url].binmode
85
- @cache[url].write(open(url, {ssl_ca_cert: Certifi.where}).read)
85
+ @cache[url].write(URI.open(url, {ssl_ca_cert: Certifi.where}).read)
86
86
  end
87
87
  return @cache[url].path
88
88
  end
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: 16.0.0.20211117
4
+ version: 18.0.0.20220216
5
5
  platform: ruby
6
6
  authors:
7
7
  - Square Developer Platform
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-11-17 00:00:00.000000000 Z
11
+ date: 2022-02-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: logging
@@ -209,9 +209,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
209
209
  - - ">="
210
210
  - !ruby/object:Gem::Version
211
211
  version: '2.5'
212
- - - "<"
213
- - !ruby/object:Gem::Version
214
- version: '3.0'
215
212
  required_rubygems_version: !ruby/object:Gem::Requirement
216
213
  requirements:
217
214
  - - ">="