square.rb 6.2.0.20200812 → 8.0.0.20201216

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +34 -33
  3. data/lib/square.rb +61 -62
  4. data/lib/square/api/apple_pay_api.rb +5 -3
  5. data/lib/square/api/bank_accounts_api.rb +16 -19
  6. data/lib/square/api/base_api.rb +1 -1
  7. data/lib/square/api/bookings_api.rb +308 -0
  8. data/lib/square/api/cash_drawers_api.rb +13 -6
  9. data/lib/square/api/catalog_api.rb +68 -32
  10. data/lib/square/api/checkout_api.rb +4 -2
  11. data/lib/square/api/customer_groups_api.rb +18 -8
  12. data/lib/square/api/customer_segments_api.rb +9 -5
  13. data/lib/square/api/customers_api.rb +47 -27
  14. data/lib/square/api/devices_api.rb +17 -6
  15. data/lib/square/api/disputes_api.rb +71 -68
  16. data/lib/square/api/employees_api.rb +10 -5
  17. data/lib/square/api/inventory_api.rb +30 -15
  18. data/lib/square/api/invoices_api.rb +42 -38
  19. data/lib/square/api/labor_api.rb +131 -22
  20. data/lib/square/api/locations_api.rb +16 -13
  21. data/lib/square/api/loyalty_api.rb +60 -66
  22. data/lib/square/api/merchants_api.rb +7 -3
  23. data/lib/square/api/mobile_authorization_api.rb +5 -3
  24. data/lib/square/api/o_auth_api.rb +11 -8
  25. data/lib/square/api/orders_api.rb +111 -90
  26. data/lib/square/api/payments_api.rb +75 -65
  27. data/lib/square/api/refunds_api.rb +37 -27
  28. data/lib/square/api/subscriptions_api.rb +29 -28
  29. data/lib/square/api/team_api.rb +46 -30
  30. data/lib/square/api/terminal_api.rb +156 -7
  31. data/lib/square/api/transactions_api.rb +32 -18
  32. data/lib/square/api/v1_employees_api.rb +59 -31
  33. data/lib/square/api/v1_items_api.rb +195 -115
  34. data/lib/square/api/v1_transactions_api.rb +49 -27
  35. data/lib/square/api_helper.rb +14 -9
  36. data/lib/square/client.rb +14 -20
  37. data/lib/square/configuration.rb +2 -2
  38. data/lib/square/http/api_response.rb +2 -0
  39. data/lib/square/http/faraday_client.rb +9 -2
  40. data/spec/user_journey_spec.rb +2 -5
  41. data/test/api/api_test_base.rb +1 -6
  42. data/test/api/test_catalog_api.rb +1 -4
  43. data/test/api/test_customers_api.rb +1 -4
  44. data/test/api/test_employees_api.rb +1 -4
  45. data/test/api/test_labor_api.rb +2 -6
  46. data/test/api/test_locations_api.rb +22 -33
  47. data/test/api/test_merchants_api.rb +1 -4
  48. data/test/api/test_payments_api.rb +3 -6
  49. data/test/api/test_refunds_api.rb +3 -6
  50. data/test/http_response_catcher.rb +0 -5
  51. data/test/test_helper.rb +0 -5
  52. metadata +33 -16
  53. data/lib/square/api/reporting_api.rb +0 -138
  54. data/lib/square/api/v1_locations_api.rb +0 -65
@@ -18,7 +18,7 @@ module Square
18
18
  _query_builder << '/v1/{location_id}/bank-accounts'
19
19
  _query_builder = APIHelper.append_url_with_template_parameters(
20
20
  _query_builder,
21
- 'location_id' => location_id
21
+ 'location_id' => { 'value' => location_id, 'encode' => true }
22
22
  )
23
23
  _query_url = APIHelper.clean_url _query_builder
24
24
 
@@ -38,7 +38,9 @@ module Square
38
38
  # Return appropriate response type.
39
39
  decoded = APIHelper.json_deserialize(_response.raw_body)
40
40
  _errors = APIHelper.map_response(decoded, ['errors'])
41
- ApiResponse.new(_response, data: decoded, errors: _errors)
41
+ ApiResponse.new(
42
+ _response, data: decoded, errors: _errors
43
+ )
42
44
  end
43
45
 
44
46
  # Provides non-confidential details for a merchant's associated bank
@@ -58,8 +60,8 @@ module Square
58
60
  _query_builder << '/v1/{location_id}/bank-accounts/{bank_account_id}'
59
61
  _query_builder = APIHelper.append_url_with_template_parameters(
60
62
  _query_builder,
61
- 'location_id' => location_id,
62
- 'bank_account_id' => bank_account_id
63
+ 'location_id' => { 'value' => location_id, 'encode' => true },
64
+ 'bank_account_id' => { 'value' => bank_account_id, 'encode' => true }
63
65
  )
64
66
  _query_url = APIHelper.clean_url _query_builder
65
67
 
@@ -79,7 +81,9 @@ module Square
79
81
  # Return appropriate response type.
80
82
  decoded = APIHelper.json_deserialize(_response.raw_body)
81
83
  _errors = APIHelper.map_response(decoded, ['errors'])
82
- ApiResponse.new(_response, data: decoded, errors: _errors)
84
+ ApiResponse.new(
85
+ _response, data: decoded, errors: _errors
86
+ )
83
87
  end
84
88
 
85
89
  # Provides summary information for a merchant's online store orders.
@@ -102,7 +106,7 @@ module Square
102
106
  _query_builder << '/v1/{location_id}/orders'
103
107
  _query_builder = APIHelper.append_url_with_template_parameters(
104
108
  _query_builder,
105
- 'location_id' => location_id
109
+ 'location_id' => { 'value' => location_id, 'encode' => true }
106
110
  )
107
111
  _query_builder = APIHelper.append_url_with_query_parameters(
108
112
  _query_builder,
@@ -128,7 +132,9 @@ module Square
128
132
  # Return appropriate response type.
129
133
  decoded = APIHelper.json_deserialize(_response.raw_body)
130
134
  _errors = APIHelper.map_response(decoded, ['errors'])
131
- ApiResponse.new(_response, data: decoded, errors: _errors)
135
+ ApiResponse.new(
136
+ _response, data: decoded, errors: _errors
137
+ )
132
138
  end
133
139
 
134
140
  # Provides comprehensive information for a single online store order,
@@ -146,8 +152,8 @@ module Square
146
152
  _query_builder << '/v1/{location_id}/orders/{order_id}'
147
153
  _query_builder = APIHelper.append_url_with_template_parameters(
148
154
  _query_builder,
149
- 'location_id' => location_id,
150
- 'order_id' => order_id
155
+ 'location_id' => { 'value' => location_id, 'encode' => true },
156
+ 'order_id' => { 'value' => order_id, 'encode' => true }
151
157
  )
152
158
  _query_url = APIHelper.clean_url _query_builder
153
159
 
@@ -167,7 +173,9 @@ module Square
167
173
  # Return appropriate response type.
168
174
  decoded = APIHelper.json_deserialize(_response.raw_body)
169
175
  _errors = APIHelper.map_response(decoded, ['errors'])
170
- ApiResponse.new(_response, data: decoded, errors: _errors)
176
+ ApiResponse.new(
177
+ _response, data: decoded, errors: _errors
178
+ )
171
179
  end
172
180
 
173
181
  # Updates the details of an online store order. Every update you perform on
@@ -189,8 +197,8 @@ module Square
189
197
  _query_builder << '/v1/{location_id}/orders/{order_id}'
190
198
  _query_builder = APIHelper.append_url_with_template_parameters(
191
199
  _query_builder,
192
- 'location_id' => location_id,
193
- 'order_id' => order_id
200
+ 'location_id' => { 'value' => location_id, 'encode' => true },
201
+ 'order_id' => { 'value' => order_id, 'encode' => true }
194
202
  )
195
203
  _query_url = APIHelper.clean_url _query_builder
196
204
 
@@ -212,7 +220,9 @@ module Square
212
220
  # Return appropriate response type.
213
221
  decoded = APIHelper.json_deserialize(_response.raw_body)
214
222
  _errors = APIHelper.map_response(decoded, ['errors'])
215
- ApiResponse.new(_response, data: decoded, errors: _errors)
223
+ ApiResponse.new(
224
+ _response, data: decoded, errors: _errors
225
+ )
216
226
  end
217
227
 
218
228
  # Provides summary information for all payments taken for a given
@@ -260,7 +270,7 @@ module Square
260
270
  _query_builder << '/v1/{location_id}/payments'
261
271
  _query_builder = APIHelper.append_url_with_template_parameters(
262
272
  _query_builder,
263
- 'location_id' => location_id
273
+ 'location_id' => { 'value' => location_id, 'encode' => true }
264
274
  )
265
275
  _query_builder = APIHelper.append_url_with_query_parameters(
266
276
  _query_builder,
@@ -289,7 +299,9 @@ module Square
289
299
  # Return appropriate response type.
290
300
  decoded = APIHelper.json_deserialize(_response.raw_body)
291
301
  _errors = APIHelper.map_response(decoded, ['errors'])
292
- ApiResponse.new(_response, data: decoded, errors: _errors)
302
+ ApiResponse.new(
303
+ _response, data: decoded, errors: _errors
304
+ )
293
305
  end
294
306
 
295
307
  # Provides comprehensive information for a single payment.
@@ -307,8 +319,8 @@ module Square
307
319
  _query_builder << '/v1/{location_id}/payments/{payment_id}'
308
320
  _query_builder = APIHelper.append_url_with_template_parameters(
309
321
  _query_builder,
310
- 'location_id' => location_id,
311
- 'payment_id' => payment_id
322
+ 'location_id' => { 'value' => location_id, 'encode' => true },
323
+ 'payment_id' => { 'value' => payment_id, 'encode' => true }
312
324
  )
313
325
  _query_url = APIHelper.clean_url _query_builder
314
326
 
@@ -328,7 +340,9 @@ module Square
328
340
  # Return appropriate response type.
329
341
  decoded = APIHelper.json_deserialize(_response.raw_body)
330
342
  _errors = APIHelper.map_response(decoded, ['errors'])
331
- ApiResponse.new(_response, data: decoded, errors: _errors)
343
+ ApiResponse.new(
344
+ _response, data: decoded, errors: _errors
345
+ )
332
346
  end
333
347
 
334
348
  # Provides the details for all refunds initiated by a merchant or any of the
@@ -366,7 +380,7 @@ module Square
366
380
  _query_builder << '/v1/{location_id}/refunds'
367
381
  _query_builder = APIHelper.append_url_with_template_parameters(
368
382
  _query_builder,
369
- 'location_id' => location_id
383
+ 'location_id' => { 'value' => location_id, 'encode' => true }
370
384
  )
371
385
  _query_builder = APIHelper.append_url_with_query_parameters(
372
386
  _query_builder,
@@ -394,7 +408,9 @@ module Square
394
408
  # Return appropriate response type.
395
409
  decoded = APIHelper.json_deserialize(_response.raw_body)
396
410
  _errors = APIHelper.map_response(decoded, ['errors'])
397
- ApiResponse.new(_response, data: decoded, errors: _errors)
411
+ ApiResponse.new(
412
+ _response, data: decoded, errors: _errors
413
+ )
398
414
  end
399
415
 
400
416
  # Issues a refund for a previously processed payment. You must issue
@@ -420,7 +436,7 @@ module Square
420
436
  _query_builder << '/v1/{location_id}/refunds'
421
437
  _query_builder = APIHelper.append_url_with_template_parameters(
422
438
  _query_builder,
423
- 'location_id' => location_id
439
+ 'location_id' => { 'value' => location_id, 'encode' => true }
424
440
  )
425
441
  _query_url = APIHelper.clean_url _query_builder
426
442
 
@@ -442,7 +458,9 @@ module Square
442
458
  # Return appropriate response type.
443
459
  decoded = APIHelper.json_deserialize(_response.raw_body)
444
460
  _errors = APIHelper.map_response(decoded, ['errors'])
445
- ApiResponse.new(_response, data: decoded, errors: _errors)
461
+ ApiResponse.new(
462
+ _response, data: decoded, errors: _errors
463
+ )
446
464
  end
447
465
 
448
466
  # Provides summary information for all deposits and withdrawals
@@ -485,7 +503,7 @@ module Square
485
503
  _query_builder << '/v1/{location_id}/settlements'
486
504
  _query_builder = APIHelper.append_url_with_template_parameters(
487
505
  _query_builder,
488
- 'location_id' => location_id
506
+ 'location_id' => { 'value' => location_id, 'encode' => true }
489
507
  )
490
508
  _query_builder = APIHelper.append_url_with_query_parameters(
491
509
  _query_builder,
@@ -514,7 +532,9 @@ module Square
514
532
  # Return appropriate response type.
515
533
  decoded = APIHelper.json_deserialize(_response.raw_body)
516
534
  _errors = APIHelper.map_response(decoded, ['errors'])
517
- ApiResponse.new(_response, data: decoded, errors: _errors)
535
+ ApiResponse.new(
536
+ _response, data: decoded, errors: _errors
537
+ )
518
538
  end
519
539
 
520
540
  # Provides comprehensive information for a single settlement.
@@ -545,8 +565,8 @@ module Square
545
565
  _query_builder << '/v1/{location_id}/settlements/{settlement_id}'
546
566
  _query_builder = APIHelper.append_url_with_template_parameters(
547
567
  _query_builder,
548
- 'location_id' => location_id,
549
- 'settlement_id' => settlement_id
568
+ 'location_id' => { 'value' => location_id, 'encode' => true },
569
+ 'settlement_id' => { 'value' => settlement_id, 'encode' => true }
550
570
  )
551
571
  _query_url = APIHelper.clean_url _query_builder
552
572
 
@@ -566,7 +586,9 @@ module Square
566
586
  # Return appropriate response type.
567
587
  decoded = APIHelper.json_deserialize(_response.raw_body)
568
588
  _errors = APIHelper.map_response(decoded, ['errors'])
569
- ApiResponse.new(_response, data: decoded, errors: _errors)
589
+ ApiResponse.new(
590
+ _response, data: decoded, errors: _errors
591
+ )
570
592
  end
571
593
  end
572
594
  end
@@ -36,17 +36,22 @@ module Square
36
36
  # Return if there are no parameters to replace.
37
37
  return query_builder if parameters.nil?
38
38
 
39
- # Iterate and append parameters.
40
- parameters.each do |key, value|
41
- replace_value = ''
42
-
43
- if value.nil?
39
+ parameters.each do |key, val|
40
+ if val.nil?
44
41
  replace_value = ''
45
- elsif value.instance_of? Array
46
- value.map! { |element| CGI.escape(element.to_s) }
47
- replace_value = value.join('/')
42
+ elsif val['value'].instance_of? Array
43
+ if val['encode'] == true
44
+ val['value'].map! { |element| CGI.escape(element.to_s) }
45
+ else
46
+ val['value'].map!(&:to_s)
47
+ end
48
+ replace_value = val['value'].join('/')
48
49
  else
49
- replace_value = CGI.escape(value.to_s)
50
+ replace_value = if val['encode'] == true
51
+ CGI.escape(val['value'].to_s)
52
+ else
53
+ val['value'].to_s
54
+ end
50
55
  end
51
56
 
52
57
  # Find the template parameter and replace it with its value.
@@ -4,7 +4,7 @@ module Square
4
4
  attr_reader :config
5
5
 
6
6
  def sdk_version
7
- '6.2.0.20200812'
7
+ '8.0.0.20201216'
8
8
  end
9
9
 
10
10
  def square_version
@@ -23,12 +23,6 @@ module Square
23
23
  @o_auth ||= OAuthApi.new config
24
24
  end
25
25
 
26
- # Access to v1_locations controller.
27
- # @return [V1LocationsApi] Returns the controller instance.
28
- def v1_locations
29
- @v1_locations ||= V1LocationsApi.new config
30
- end
31
-
32
26
  # Access to v1_employees controller.
33
27
  # @return [V1EmployeesApi] Returns the controller instance.
34
28
  def v1_employees
@@ -59,6 +53,12 @@ module Square
59
53
  @bank_accounts ||= BankAccountsApi.new config
60
54
  end
61
55
 
56
+ # Access to bookings controller.
57
+ # @return [BookingsApi] Returns the controller instance.
58
+ def bookings
59
+ @bookings ||= BookingsApi.new config
60
+ end
61
+
62
62
  # Access to cash_drawers controller.
63
63
  # @return [CashDrawersApi] Returns the controller instance.
64
64
  def cash_drawers
@@ -131,24 +131,12 @@ module Square
131
131
  @locations ||= LocationsApi.new config
132
132
  end
133
133
 
134
- # Access to reporting controller.
135
- # @return [ReportingApi] Returns the controller instance.
136
- def reporting
137
- @reporting ||= ReportingApi.new config
138
- end
139
-
140
134
  # Access to checkout controller.
141
135
  # @return [CheckoutApi] Returns the controller instance.
142
136
  def checkout
143
137
  @checkout ||= CheckoutApi.new config
144
138
  end
145
139
 
146
- # Access to orders controller.
147
- # @return [OrdersApi] Returns the controller instance.
148
- def orders
149
- @orders ||= OrdersApi.new config
150
- end
151
-
152
140
  # Access to transactions controller.
153
141
  # @return [TransactionsApi] Returns the controller instance.
154
142
  def transactions
@@ -167,6 +155,12 @@ module Square
167
155
  @merchants ||= MerchantsApi.new config
168
156
  end
169
157
 
158
+ # Access to orders controller.
159
+ # @return [OrdersApi] Returns the controller instance.
160
+ def orders
161
+ @orders ||= OrdersApi.new config
162
+ end
163
+
170
164
  # Access to payments controller.
171
165
  # @return [PaymentsApi] Returns the controller instance.
172
166
  def payments
@@ -199,7 +193,7 @@ module Square
199
193
 
200
194
  def initialize(timeout: 60, max_retries: 0, retry_interval: 1,
201
195
  backoff_factor: 1, environment: 'production',
202
- square_version: '2020-08-12', access_token: 'TODO: Replace',
196
+ square_version: '2020-12-16', access_token: 'TODO: Replace',
203
197
  additional_headers: {}, config: nil)
204
198
  @config = if config.nil?
205
199
  Configuration.new(timeout: timeout, max_retries: max_retries,
@@ -22,7 +22,7 @@ module Square
22
22
 
23
23
  def initialize(timeout: 60, max_retries: 0, retry_interval: 1,
24
24
  backoff_factor: 1, environment: 'production',
25
- square_version: '2020-08-12', access_token: 'TODO: Replace',
25
+ square_version: '2020-12-16', access_token: 'TODO: Replace',
26
26
  additional_headers: {})
27
27
  # The value to use for connection timeout
28
28
  @timeout = timeout
@@ -43,7 +43,7 @@ module Square
43
43
  # Square Connect API versions
44
44
  @square_version = square_version
45
45
 
46
- # OAuth 2.0 Access Token
46
+ # The OAuth 2.0 Access Token to use for API requests.
47
47
  @access_token = access_token
48
48
 
49
49
  # Additional headers to add to each API request
@@ -34,10 +34,12 @@ module Square
34
34
  end
35
35
  end
36
36
 
37
+ # returns true if status_code is between 200-300
37
38
  def success?
38
39
  status_code >= 200 && status_code < 300
39
40
  end
40
41
 
42
+ # returns true if status_code is between 400-600
41
43
  def error?
42
44
  status_code >= 400 && status_code < 600
43
45
  end
@@ -10,6 +10,7 @@ module Square
10
10
  @connection = Faraday.new do |faraday|
11
11
  faraday.use Faraday::HttpCache, serializer: Marshal if cache
12
12
  faraday.use FaradayMiddleware::FollowRedirects
13
+ faraday.use :gzip
13
14
  faraday.request :multipart
14
15
  faraday.request :url_encoded
15
16
  faraday.ssl[:ca_file] = Certifi.where
@@ -29,7 +30,10 @@ module Square
29
30
  http_request.query_url
30
31
  ) do |request|
31
32
  request.headers = http_request.headers
32
- request.body = http_request.parameters
33
+ unless http_request.http_method == HttpMethodEnum::GET &&
34
+ http_request.parameters.empty?
35
+ request.body = http_request.parameters
36
+ end
33
37
  end
34
38
  convert_response(response, http_request)
35
39
  end
@@ -41,7 +45,10 @@ module Square
41
45
  http_request.query_url
42
46
  ) do |request|
43
47
  request.headers = http_request.headers
44
- request.body = http_request.parameters
48
+ unless http_request.http_method == HttpMethodEnum::GET &&
49
+ http_request.parameters.empty?
50
+ request.body = http_request.parameters
51
+ end
45
52
  end
46
53
  convert_response(response, http_request)
47
54
  end
@@ -121,11 +121,8 @@ describe "UserJourney" do
121
121
 
122
122
  # list
123
123
  response = sq.customers.list_customers
124
- if response.data != nil
125
- assert_equal response.data.to_h.keys, %i[customers]
126
- assert_equal response.status_code, 200
127
- end
128
-
124
+ assert_equal response.data.to_h.keys, %i[customers]
125
+ assert_equal response.status_code, 200
129
126
 
130
127
  # update
131
128
  response = sq.customers.update_customer(customer_id: created_customer[:id], body: customer2)
@@ -1,8 +1,3 @@
1
- # square
2
- #
3
- # This file was automatically generated by APIMATIC v2.0
4
- # ( https://apimatic.io ).
5
-
6
1
  require 'json'
7
2
  require 'minitest/autorun'
8
3
  require 'minitest/hell'
@@ -19,6 +14,6 @@ class ApiTestBase < Minitest::Test
19
14
  # Create configuration and set any test parameters
20
15
  CONFIG = Configuration.new(
21
16
  access_token: ENV.fetch('SQUARE_SANDBOX_TOKEN', 'AccessToken'),
22
- environment: "sandbox"
17
+ environment: 'sandbox'
23
18
  )
24
19
  end
@@ -1,7 +1,4 @@
1
- # square
2
- #
3
- # This file was automatically generated by APIMATIC v2.0
4
- # ( https://apimatic.io ).
1
+
5
2
 
6
3
  require_relative 'api_test_base'
7
4
 
@@ -1,7 +1,4 @@
1
- # square
2
- #
3
- # This file was automatically generated by APIMATIC v2.0
4
- # ( https://apimatic.io ).
1
+
5
2
 
6
3
  require_relative 'api_test_base'
7
4
 
@@ -1,7 +1,4 @@
1
- # square
2
- #
3
- # This file was automatically generated by APIMATIC v2.0
4
- # ( https://apimatic.io ).
1
+
5
2
 
6
3
  require_relative 'api_test_base'
7
4