square.rb 8.1.0.20210121 → 18.1.0.20220316

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.
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
@@ -13,17 +13,26 @@ module Square
13
13
  # profiles can take closer to one minute or longer, especially during
14
14
  # network incidents and outages.
15
15
  # @param [String] cursor Optional parameter: A pagination cursor returned by
16
- # a previous call to this endpoint. Provide this to retrieve the next set of
17
- # results for your original query. See the [Pagination
18
- # guide](https://developer.squareup.com/docs/working-with-apis/pagination)
19
- # for more information.
16
+ # a previous call to this endpoint. Provide this cursor to retrieve the next
17
+ # set of results for your original query. For more information, see
18
+ # [Pagination](https://developer.squareup.com/docs/build-basics/common-api-p
19
+ # atterns/pagination).
20
+ # @param [Integer] limit Optional parameter: The maximum number of results
21
+ # to return in a single page. This limit is advisory. The response might
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).
20
28
  # @param [CustomerSortField] sort_field Optional parameter: Indicates how
21
- # Customers should be sorted. Default: `DEFAULT`.
29
+ # customers should be sorted. The default value is `DEFAULT`.
22
30
  # @param [SortOrder] sort_order Optional parameter: Indicates whether
23
- # Customers should be sorted in ascending (`ASC`) or descending (`DESC`)
24
- # order. Default: `ASC`.
31
+ # customers should be sorted in ascending (`ASC`) or descending (`DESC`)
32
+ # order. The default value is `ASC`.
25
33
  # @return [ListCustomersResponse Hash] response from the API call
26
34
  def list_customers(cursor: nil,
35
+ limit: nil,
27
36
  sort_field: nil,
28
37
  sort_order: nil)
29
38
  # Prepare query url.
@@ -32,6 +41,7 @@ module Square
32
41
  _query_builder = APIHelper.append_url_with_query_parameters(
33
42
  _query_builder,
34
43
  'cursor' => cursor,
44
+ 'limit' => limit,
35
45
  'sort_field' => sort_field,
36
46
  'sort_order' => sort_order
37
47
  )
@@ -58,10 +68,9 @@ module Square
58
68
  )
59
69
  end
60
70
 
61
- # Creates a new customer for a business, which can have associated cards on
62
- # file.
63
- # You must provide __at least one__ of the following values in your request
64
- # to this
71
+ # Creates a new customer for a business.
72
+ # You must provide at least one of the following values in your request to
73
+ # this
65
74
  # endpoint:
66
75
  # - `given_name`
67
76
  # - `family_name`
@@ -81,7 +90,7 @@ module Square
81
90
  # Prepare headers.
82
91
  _headers = {
83
92
  'accept' => 'application/json',
84
- 'content-type' => 'application/json; charset=utf-8'
93
+ 'Content-Type' => 'application/json'
85
94
  }
86
95
 
87
96
  # Prepare and execute HttpRequest.
@@ -125,7 +134,7 @@ module Square
125
134
  # Prepare headers.
126
135
  _headers = {
127
136
  'accept' => 'application/json',
128
- 'content-type' => 'application/json; charset=utf-8'
137
+ 'Content-Type' => 'application/json'
129
138
  }
130
139
 
131
140
  # Prepare and execute HttpRequest.
@@ -145,15 +154,28 @@ module Square
145
154
  )
146
155
  end
147
156
 
148
- # Deletes a customer from a business, along with any linked cards on file.
149
- # When two profiles
150
- # are merged into a single profile, that profile is assigned a new
151
- # `customer_id`. You must use the
152
- # new `customer_id` to delete merged profiles.
157
+ # Deletes a customer profile from a business. This operation also unlinks
158
+ # any associated cards on file.
159
+ # As a best practice, you should include the `version` field in the request
160
+ # to enable [optimistic
161
+ # concurrency](https://developer.squareup.com/docs/working-with-apis/optimis
162
+ # tic-concurrency) control. The value must be set to the current version of
163
+ # the customer profile.
164
+ # To delete a customer profile that was created by merging existing
165
+ # profiles, you must use the ID of the newly created profile.
153
166
  # @param [String] customer_id Required parameter: The ID of the customer to
154
167
  # delete.
168
+ # @param [Long] version Optional parameter: The current version of the
169
+ # customer profile. As a best practice, you should include this parameter
170
+ # to enable [optimistic
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
174
+ # profile](https://developer.squareup.com/docs/customers-api/use-the-api/kee
175
+ # p-records#delete-customer-profile).
155
176
  # @return [DeleteCustomerResponse Hash] response from the API call
156
- def delete_customer(customer_id:)
177
+ def delete_customer(customer_id:,
178
+ version: nil)
157
179
  # Prepare query url.
158
180
  _query_builder = config.get_base_uri
159
181
  _query_builder << '/v2/customers/{customer_id}'
@@ -161,6 +183,10 @@ module Square
161
183
  _query_builder,
162
184
  'customer_id' => { 'value' => customer_id, 'encode' => true }
163
185
  )
186
+ _query_builder = APIHelper.append_url_with_query_parameters(
187
+ _query_builder,
188
+ 'version' => version
189
+ )
164
190
  _query_url = APIHelper.clean_url _query_builder
165
191
 
166
192
  # Prepare headers.
@@ -219,16 +245,18 @@ module Square
219
245
  )
220
246
  end
221
247
 
222
- # Updates the details of an existing customer. When two profiles are merged
223
- # into a single profile, that profile is assigned a new `customer_id`. You
224
- # must use
225
- # the new `customer_id` to update merged profiles.
226
- # You cannot edit a customer's cards on file with this endpoint. To make
227
- # changes
228
- # to a card on file, you must delete the existing card on file with the
229
- # [DeleteCustomerCard](#endpoint-Customers-deletecustomercard) endpoint,
230
- # then create a new one with the
231
- # [CreateCustomerCard](#endpoint-Customers-createcustomercard) endpoint.
248
+ # Updates a customer profile. To change an attribute, specify the new value.
249
+ # To remove an attribute, specify the value as an empty string or empty
250
+ # object.
251
+ # As a best practice, you should include the `version` field in the request
252
+ # to enable [optimistic
253
+ # concurrency](https://developer.squareup.com/docs/working-with-apis/optimis
254
+ # tic-concurrency) control. The value must be set to the current version of
255
+ # the customer profile.
256
+ # To update a customer profile that was created by merging existing
257
+ # profiles, you must use the ID of the newly created profile.
258
+ # You cannot use this endpoint to change cards on file. To make changes, use
259
+ # the [Cards API]($e/Cards) or [Gift Cards API]($e/GiftCards).
232
260
  # @param [String] customer_id Required parameter: The ID of the customer to
233
261
  # update.
234
262
  # @param [UpdateCustomerRequest] body Required parameter: An object
@@ -249,7 +277,7 @@ module Square
249
277
  # Prepare headers.
250
278
  _headers = {
251
279
  'accept' => 'application/json',
252
- 'content-type' => 'application/json; charset=utf-8'
280
+ 'Content-Type' => 'application/json'
253
281
  }
254
282
 
255
283
  # Prepare and execute HttpRequest.
@@ -282,6 +310,7 @@ module Square
282
310
  # @return [CreateCustomerCardResponse Hash] response from the API call
283
311
  def create_customer_card(customer_id:,
284
312
  body:)
313
+ warn 'Endpoint create_customer_card in CustomersApi is deprecated'
285
314
  # Prepare query url.
286
315
  _query_builder = config.get_base_uri
287
316
  _query_builder << '/v2/customers/{customer_id}/cards'
@@ -294,7 +323,7 @@ module Square
294
323
  # Prepare headers.
295
324
  _headers = {
296
325
  'accept' => 'application/json',
297
- 'content-type' => 'application/json; charset=utf-8'
326
+ 'Content-Type' => 'application/json'
298
327
  }
299
328
 
300
329
  # Prepare and execute HttpRequest.
@@ -322,6 +351,7 @@ module Square
322
351
  # @return [DeleteCustomerCardResponse Hash] response from the API call
323
352
  def delete_customer_card(customer_id:,
324
353
  card_id:)
354
+ warn 'Endpoint delete_customer_card in CustomersApi is deprecated'
325
355
  # Prepare query url.
326
356
  _query_builder = config.get_base_uri
327
357
  _query_builder << '/v2/customers/{customer_id}/cards/{card_id}'
@@ -9,7 +9,8 @@ module Square
9
9
  # @param [String] cursor Optional parameter: A pagination cursor returned by
10
10
  # a previous call to this endpoint. Provide this to retrieve the next set of
11
11
  # results for your original query. See [Paginating
12
- # results](#paginatingresults) for more information.
12
+ # results](https://developer.squareup.com/docs/working-with-apis/pagination)
13
+ # for more information.
13
14
  # @param [String] location_id Optional parameter: If specified, only returns
14
15
  # DeviceCodes of the specified location. Returns DeviceCodes of all
15
16
  # locations if empty.
@@ -73,7 +74,7 @@ module Square
73
74
  # Prepare headers.
74
75
  _headers = {
75
76
  'accept' => 'application/json',
76
- 'content-type' => 'application/json; charset=utf-8'
77
+ 'Content-Type' => 'application/json'
77
78
  }
78
79
 
79
80
  # Prepare and execute HttpRequest.
@@ -131,8 +131,14 @@ module Square
131
131
 
132
132
  # Returns a list of evidence associated with a dispute.
133
133
  # @param [String] dispute_id Required parameter: The ID of the dispute.
134
+ # @param [String] cursor Optional parameter: A pagination cursor returned by
135
+ # a previous call to this endpoint. Provide this cursor to retrieve the next
136
+ # set of results for the original query. For more information, see
137
+ # [Pagination](https://developer.squareup.com/docs/basics/api101/pagination)
138
+ # .
134
139
  # @return [ListDisputeEvidenceResponse Hash] response from the API call
135
- def list_dispute_evidence(dispute_id:)
140
+ def list_dispute_evidence(dispute_id:,
141
+ cursor: nil)
136
142
  # Prepare query url.
137
143
  _query_builder = config.get_base_uri
138
144
  _query_builder << '/v2/disputes/{dispute_id}/evidence'
@@ -140,91 +146,9 @@ module Square
140
146
  _query_builder,
141
147
  'dispute_id' => { 'value' => dispute_id, 'encode' => true }
142
148
  )
143
- _query_url = APIHelper.clean_url _query_builder
144
-
145
- # Prepare headers.
146
- _headers = {
147
- 'accept' => 'application/json'
148
- }
149
-
150
- # Prepare and execute HttpRequest.
151
- _request = config.http_client.get(
152
- _query_url,
153
- headers: _headers
154
- )
155
- OAuth2.apply(config, _request)
156
- _response = execute_request(_request)
157
-
158
- # Return appropriate response type.
159
- decoded = APIHelper.json_deserialize(_response.raw_body)
160
- _errors = APIHelper.map_response(decoded, ['errors'])
161
- ApiResponse.new(
162
- _response, data: decoded, errors: _errors
163
- )
164
- end
165
-
166
- # Removes specified evidence from a dispute.
167
- # Square does not send the bank any evidence that is removed. Also, you
168
- # cannot remove evidence after
169
- # submitting it to the bank using
170
- # [SubmitEvidence](https://developer.squareup.com/docs/reference/square/disp
171
- # utes-api/submit-evidence).
172
- # @param [String] dispute_id Required parameter: The ID of the dispute you
173
- # want to remove evidence from.
174
- # @param [String] evidence_id Required parameter: The ID of the evidence you
175
- # want to remove.
176
- # @return [RemoveDisputeEvidenceResponse Hash] response from the API call
177
- def remove_dispute_evidence(dispute_id:,
178
- evidence_id:)
179
- # Prepare query url.
180
- _query_builder = config.get_base_uri
181
- _query_builder << '/v2/disputes/{dispute_id}/evidence/{evidence_id}'
182
- _query_builder = APIHelper.append_url_with_template_parameters(
183
- _query_builder,
184
- 'dispute_id' => { 'value' => dispute_id, 'encode' => true },
185
- 'evidence_id' => { 'value' => evidence_id, 'encode' => true }
186
- )
187
- _query_url = APIHelper.clean_url _query_builder
188
-
189
- # Prepare headers.
190
- _headers = {
191
- 'accept' => 'application/json'
192
- }
193
-
194
- # Prepare and execute HttpRequest.
195
- _request = config.http_client.delete(
196
- _query_url,
197
- headers: _headers
198
- )
199
- OAuth2.apply(config, _request)
200
- _response = execute_request(_request)
201
-
202
- # Return appropriate response type.
203
- decoded = APIHelper.json_deserialize(_response.raw_body)
204
- _errors = APIHelper.map_response(decoded, ['errors'])
205
- ApiResponse.new(
206
- _response, data: decoded, errors: _errors
207
- )
208
- end
209
-
210
- # Returns the specific evidence metadata associated with a specific dispute.
211
- # You must maintain a copy of the evidence you upload if you want to
212
- # reference it later. You cannot
213
- # download the evidence after you upload it.
214
- # @param [String] dispute_id Required parameter: The ID of the dispute that
215
- # you want to retrieve evidence from.
216
- # @param [String] evidence_id Required parameter: The ID of the evidence to
217
- # retrieve.
218
- # @return [RetrieveDisputeEvidenceResponse Hash] response from the API call
219
- def retrieve_dispute_evidence(dispute_id:,
220
- evidence_id:)
221
- # Prepare query url.
222
- _query_builder = config.get_base_uri
223
- _query_builder << '/v2/disputes/{dispute_id}/evidence/{evidence_id}'
224
- _query_builder = APIHelper.append_url_with_template_parameters(
149
+ _query_builder = APIHelper.append_url_with_query_parameters(
225
150
  _query_builder,
226
- 'dispute_id' => { 'value' => dispute_id, 'encode' => true },
227
- 'evidence_id' => { 'value' => evidence_id, 'encode' => true }
151
+ 'cursor' => cursor
228
152
  )
229
153
  _query_url = APIHelper.clean_url _query_builder
230
154
 
@@ -264,7 +188,7 @@ module Square
264
188
  image_file: nil)
265
189
  # Prepare query url.
266
190
  _query_builder = config.get_base_uri
267
- _query_builder << '/v2/disputes/{dispute_id}/evidence_file'
191
+ _query_builder << '/v2/disputes/{dispute_id}/evidence-files'
268
192
  _query_builder = APIHelper.append_url_with_template_parameters(
269
193
  _query_builder,
270
194
  'dispute_id' => { 'value' => dispute_id, 'encode' => true }
@@ -325,7 +249,7 @@ module Square
325
249
  body:)
326
250
  # Prepare query url.
327
251
  _query_builder = config.get_base_uri
328
- _query_builder << '/v2/disputes/{dispute_id}/evidence_text'
252
+ _query_builder << '/v2/disputes/{dispute_id}/evidence-text'
329
253
  _query_builder = APIHelper.append_url_with_template_parameters(
330
254
  _query_builder,
331
255
  'dispute_id' => { 'value' => dispute_id, 'encode' => true }
@@ -335,7 +259,7 @@ module Square
335
259
  # Prepare headers.
336
260
  _headers = {
337
261
  'accept' => 'application/json',
338
- 'content-type' => 'application/json; charset=utf-8'
262
+ 'Content-Type' => 'application/json'
339
263
  }
340
264
 
341
265
  # Prepare and execute HttpRequest.
@@ -355,14 +279,99 @@ module Square
355
279
  )
356
280
  end
357
281
 
282
+ # Removes specified evidence from a dispute.
283
+ # Square does not send the bank any evidence that is removed. Also, you
284
+ # cannot remove evidence after
285
+ # submitting it to the bank using
286
+ # [SubmitEvidence]($e/Disputes/SubmitEvidence).
287
+ # @param [String] dispute_id Required parameter: The ID of the dispute you
288
+ # want to remove evidence from.
289
+ # @param [String] evidence_id Required parameter: The ID of the evidence you
290
+ # want to remove.
291
+ # @return [DeleteDisputeEvidenceResponse Hash] response from the API call
292
+ def delete_dispute_evidence(dispute_id:,
293
+ evidence_id:)
294
+ # Prepare query url.
295
+ _query_builder = config.get_base_uri
296
+ _query_builder << '/v2/disputes/{dispute_id}/evidence/{evidence_id}'
297
+ _query_builder = APIHelper.append_url_with_template_parameters(
298
+ _query_builder,
299
+ 'dispute_id' => { 'value' => dispute_id, 'encode' => true },
300
+ 'evidence_id' => { 'value' => evidence_id, 'encode' => true }
301
+ )
302
+ _query_url = APIHelper.clean_url _query_builder
303
+
304
+ # Prepare headers.
305
+ _headers = {
306
+ 'accept' => 'application/json'
307
+ }
308
+
309
+ # Prepare and execute HttpRequest.
310
+ _request = config.http_client.delete(
311
+ _query_url,
312
+ headers: _headers
313
+ )
314
+ OAuth2.apply(config, _request)
315
+ _response = execute_request(_request)
316
+
317
+ # Return appropriate response type.
318
+ decoded = APIHelper.json_deserialize(_response.raw_body)
319
+ _errors = APIHelper.map_response(decoded, ['errors'])
320
+ ApiResponse.new(
321
+ _response, data: decoded, errors: _errors
322
+ )
323
+ end
324
+
325
+ # Returns the evidence metadata specified by the evidence ID in the request
326
+ # URL path
327
+ # You must maintain a copy of the evidence you upload if you want to
328
+ # reference it later. You cannot
329
+ # download the evidence after you upload it.
330
+ # @param [String] dispute_id Required parameter: The ID of the dispute that
331
+ # you want to retrieve evidence from.
332
+ # @param [String] evidence_id Required parameter: The ID of the evidence to
333
+ # retrieve.
334
+ # @return [RetrieveDisputeEvidenceResponse Hash] response from the API call
335
+ def retrieve_dispute_evidence(dispute_id:,
336
+ evidence_id:)
337
+ # Prepare query url.
338
+ _query_builder = config.get_base_uri
339
+ _query_builder << '/v2/disputes/{dispute_id}/evidence/{evidence_id}'
340
+ _query_builder = APIHelper.append_url_with_template_parameters(
341
+ _query_builder,
342
+ 'dispute_id' => { 'value' => dispute_id, 'encode' => true },
343
+ 'evidence_id' => { 'value' => evidence_id, 'encode' => true }
344
+ )
345
+ _query_url = APIHelper.clean_url _query_builder
346
+
347
+ # Prepare headers.
348
+ _headers = {
349
+ 'accept' => 'application/json'
350
+ }
351
+
352
+ # Prepare and execute HttpRequest.
353
+ _request = config.http_client.get(
354
+ _query_url,
355
+ headers: _headers
356
+ )
357
+ OAuth2.apply(config, _request)
358
+ _response = execute_request(_request)
359
+
360
+ # Return appropriate response type.
361
+ decoded = APIHelper.json_deserialize(_response.raw_body)
362
+ _errors = APIHelper.map_response(decoded, ['errors'])
363
+ ApiResponse.new(
364
+ _response, data: decoded, errors: _errors
365
+ )
366
+ end
367
+
358
368
  # Submits evidence to the cardholder's bank.
359
369
  # Before submitting evidence, Square compiles all available evidence. This
360
370
  # includes evidence uploaded
361
371
  # using the
362
- # [CreateDisputeEvidenceFile](https://developer.squareup.com/docs/reference/
363
- # square/disputes-api/create-dispute-evidence-file) and
364
- # [CreateDisputeEvidenceText](https://developer.squareup.com/docs/reference/
365
- # square/disputes-api/create-dispute-evidence-text) endpoints and
372
+ # [CreateDisputeEvidenceFile]($e/Disputes/CreateDisputeEvidenceFile) and
373
+ # [CreateDisputeEvidenceText]($e/Disputes/CreateDisputeEvidenceText)
374
+ # endpoints and
366
375
  # evidence automatically provided by Square, when available.
367
376
  # @param [String] dispute_id Required parameter: The ID of the dispute that
368
377
  # you want to submit evidence for.
@@ -0,0 +1,133 @@
1
+ module Square
2
+ # GiftCardActivitiesApi
3
+ class GiftCardActivitiesApi < BaseApi
4
+ def initialize(config, http_call_back: nil)
5
+ super(config, http_call_back: http_call_back)
6
+ end
7
+
8
+ # Lists gift card activities. By default, you get gift card activities for
9
+ # all
10
+ # gift cards in the seller's account. You can optionally specify query
11
+ # parameters to
12
+ # filter the list. For example, you can get a list of gift card activities
13
+ # for a gift card,
14
+ # for all gift cards in a specific region, or for activities within a time
15
+ # window.
16
+ # @param [String] gift_card_id Optional parameter: If a gift card ID is
17
+ # provided, the endpoint returns activities related to the specified gift
18
+ # card. Otherwise, the endpoint returns all gift card activities for the
19
+ # seller.
20
+ # @param [String] type Optional parameter: If a
21
+ # [type]($m/GiftCardActivityType) is provided, the endpoint returns gift
22
+ # card activities of the specified type. Otherwise, the endpoint returns
23
+ # all types of gift card activities.
24
+ # @param [String] location_id Optional parameter: If a location ID is
25
+ # provided, the endpoint returns gift card activities for the specified
26
+ # location. Otherwise, the endpoint returns gift card activities for all
27
+ # locations.
28
+ # @param [String] begin_time Optional parameter: The timestamp for the
29
+ # beginning of the reporting period, in RFC 3339 format. This start time is
30
+ # inclusive. The default value is the current time minus one year.
31
+ # @param [String] end_time Optional parameter: The timestamp for the end of
32
+ # the reporting period, in RFC 3339 format. This end time is inclusive. The
33
+ # default value is the current time.
34
+ # @param [Integer] limit Optional parameter: If a limit is provided, the
35
+ # endpoint returns the specified number of results (or fewer) per page. The
36
+ # maximum value is 100. The default value is 50. For more information, see
37
+ # [Pagination](https://developer.squareup.com/docs/working-with-apis/paginat
38
+ # ion).
39
+ # @param [String] cursor Optional parameter: A pagination cursor returned by
40
+ # a previous call to this endpoint. Provide this cursor to retrieve the next
41
+ # set of results for the original query. If a cursor is not provided, the
42
+ # endpoint returns the first page of the results. For more information, see
43
+ # [Pagination](https://developer.squareup.com/docs/working-with-apis/paginat
44
+ # ion).
45
+ # @param [String] sort_order Optional parameter: The order in which the
46
+ # endpoint returns the activities, based on `created_at`. - `ASC` - Oldest
47
+ # to newest. - `DESC` - Newest to oldest (default).
48
+ # @return [ListGiftCardActivitiesResponse Hash] response from the API call
49
+ def list_gift_card_activities(gift_card_id: nil,
50
+ type: nil,
51
+ location_id: nil,
52
+ begin_time: nil,
53
+ end_time: nil,
54
+ limit: nil,
55
+ cursor: nil,
56
+ sort_order: nil)
57
+ # Prepare query url.
58
+ _query_builder = config.get_base_uri
59
+ _query_builder << '/v2/gift-cards/activities'
60
+ _query_builder = APIHelper.append_url_with_query_parameters(
61
+ _query_builder,
62
+ 'gift_card_id' => gift_card_id,
63
+ 'type' => type,
64
+ 'location_id' => location_id,
65
+ 'begin_time' => begin_time,
66
+ 'end_time' => end_time,
67
+ 'limit' => limit,
68
+ 'cursor' => cursor,
69
+ 'sort_order' => sort_order
70
+ )
71
+ _query_url = APIHelper.clean_url _query_builder
72
+
73
+ # Prepare headers.
74
+ _headers = {
75
+ 'accept' => 'application/json'
76
+ }
77
+
78
+ # Prepare and execute HttpRequest.
79
+ _request = config.http_client.get(
80
+ _query_url,
81
+ headers: _headers
82
+ )
83
+ OAuth2.apply(config, _request)
84
+ _response = execute_request(_request)
85
+
86
+ # Return appropriate response type.
87
+ decoded = APIHelper.json_deserialize(_response.raw_body)
88
+ _errors = APIHelper.map_response(decoded, ['errors'])
89
+ ApiResponse.new(
90
+ _response, data: decoded, errors: _errors
91
+ )
92
+ end
93
+
94
+ # Creates a gift card activity. For more information, see
95
+ # [GiftCardActivity](https://developer.squareup.com/docs/gift-cards/using-gi
96
+ # ft-cards-api#giftcardactivity) and
97
+ # [Using activated gift
98
+ # cards](https://developer.squareup.com/docs/gift-cards/using-gift-cards-api
99
+ # #using-activated-gift-cards).
100
+ # @param [CreateGiftCardActivityRequest] body Required parameter: An object
101
+ # containing the fields to POST for the request. See the corresponding
102
+ # object definition for field details.
103
+ # @return [CreateGiftCardActivityResponse Hash] response from the API call
104
+ def create_gift_card_activity(body:)
105
+ # Prepare query url.
106
+ _query_builder = config.get_base_uri
107
+ _query_builder << '/v2/gift-cards/activities'
108
+ _query_url = APIHelper.clean_url _query_builder
109
+
110
+ # Prepare headers.
111
+ _headers = {
112
+ 'accept' => 'application/json',
113
+ 'Content-Type' => 'application/json'
114
+ }
115
+
116
+ # Prepare and execute HttpRequest.
117
+ _request = config.http_client.post(
118
+ _query_url,
119
+ headers: _headers,
120
+ parameters: body.to_json
121
+ )
122
+ OAuth2.apply(config, _request)
123
+ _response = execute_request(_request)
124
+
125
+ # Return appropriate response type.
126
+ decoded = APIHelper.json_deserialize(_response.raw_body)
127
+ _errors = APIHelper.map_response(decoded, ['errors'])
128
+ ApiResponse.new(
129
+ _response, data: decoded, errors: _errors
130
+ )
131
+ end
132
+ end
133
+ end