square.rb 6.4.0.20200923 → 6.5.0.20201028

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +31 -30
  3. data/lib/square.rb +61 -61
  4. data/lib/square/api/apple_pay_api.rb +3 -1
  5. data/lib/square/api/bank_accounts_api.rb +12 -15
  6. data/lib/square/api/base_api.rb +1 -1
  7. data/lib/square/api/cash_drawers_api.rb +11 -5
  8. data/lib/square/api/catalog_api.rb +47 -25
  9. data/lib/square/api/checkout_api.rb +4 -2
  10. data/lib/square/api/customer_groups_api.rb +18 -8
  11. data/lib/square/api/customer_segments_api.rb +7 -3
  12. data/lib/square/api/customers_api.rb +47 -27
  13. data/lib/square/api/devices_api.rb +17 -6
  14. data/lib/square/api/disputes_api.rb +37 -19
  15. data/lib/square/api/employees_api.rb +7 -3
  16. data/lib/square/api/inventory_api.rb +25 -11
  17. data/lib/square/api/invoices_api.rb +29 -13
  18. data/lib/square/api/labor_api.rb +57 -25
  19. data/lib/square/api/locations_api.rb +16 -13
  20. data/lib/square/api/loyalty_api.rb +59 -65
  21. data/lib/square/api/merchants_api.rb +7 -3
  22. data/lib/square/api/mobile_authorization_api.rb +3 -1
  23. data/lib/square/api/o_auth_api.rb +10 -4
  24. data/lib/square/api/orders_api.rb +55 -8
  25. data/lib/square/api/payments_api.rb +68 -55
  26. data/lib/square/api/refunds_api.rb +12 -6
  27. data/lib/square/api/subscriptions_api.rb +22 -10
  28. data/lib/square/api/team_api.rb +32 -16
  29. data/lib/square/api/terminal_api.rb +156 -7
  30. data/lib/square/api/transactions_api.rb +32 -18
  31. data/lib/square/api/v1_employees_api.rb +59 -27
  32. data/lib/square/api/v1_items_api.rb +195 -115
  33. data/lib/square/api/v1_locations_api.rb +6 -2
  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 +2 -2
  37. data/lib/square/configuration.rb +1 -1
  38. data/lib/square/http/api_response.rb +2 -0
  39. data/lib/square/http/faraday_client.rb +1 -0
  40. data/spec/user_journey_spec.rb +2 -5
  41. data/test/api/test_locations_api.rb +1 -1
  42. metadata +3 -3
@@ -30,7 +30,9 @@ module Square
30
30
  # Return appropriate response type.
31
31
  decoded = APIHelper.json_deserialize(_response.raw_body)
32
32
  _errors = APIHelper.map_response(decoded, ['errors'])
33
- ApiResponse.new(_response, data: decoded, errors: _errors)
33
+ ApiResponse.new(
34
+ _response, data: decoded, errors: _errors
35
+ )
34
36
  end
35
37
 
36
38
  # Provides details for all business locations associated with a Square
@@ -59,7 +61,9 @@ module Square
59
61
  # Return appropriate response type.
60
62
  decoded = APIHelper.json_deserialize(_response.raw_body)
61
63
  _errors = APIHelper.map_response(decoded, ['errors'])
62
- ApiResponse.new(_response, data: decoded, errors: _errors)
64
+ ApiResponse.new(
65
+ _response, data: decoded, errors: _errors
66
+ )
63
67
  end
64
68
  end
65
69
  end
@@ -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.4.0.20200923'
7
+ '6.5.0.20201028'
8
8
  end
9
9
 
10
10
  def square_version
@@ -193,7 +193,7 @@ module Square
193
193
 
194
194
  def initialize(timeout: 60, max_retries: 0, retry_interval: 1,
195
195
  backoff_factor: 1, environment: 'production',
196
- square_version: '2020-09-23', access_token: 'TODO: Replace',
196
+ square_version: '2020-10-28', access_token: 'TODO: Replace',
197
197
  additional_headers: {}, config: nil)
198
198
  @config = if config.nil?
199
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-09-23', access_token: 'TODO: Replace',
25
+ square_version: '2020-10-28', access_token: 'TODO: Replace',
26
26
  additional_headers: {})
27
27
  # The value to use for connection timeout
28
28
  @timeout = timeout
@@ -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
@@ -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)
@@ -9,7 +9,7 @@ class LocationsApiTests < ApiTestBase
9
9
 
10
10
  # Provides information of all locations of a business.
11
11
  #
12
- #Most other Connect API endpoints have a required `location_id` path parameter.
12
+ #Many Square API endpoints require a `location_id` parameter.
13
13
  #The `id` field of the [`Location`](#type-location) objects returned by this
14
14
  #endpoint correspond to that `location_id` parameter.
15
15
  def test_list_locations()
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: 6.4.0.20200923
4
+ version: 6.5.0.20201028
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: 2020-09-23 00:00:00.000000000 Z
11
+ date: 2020-10-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: logging
@@ -211,7 +211,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
211
211
  - !ruby/object:Gem::Version
212
212
  version: '0'
213
213
  requirements: []
214
- rubygems_version: 3.0.8
214
+ rubygems_version: 3.1.4
215
215
  signing_key:
216
216
  specification_version: 4
217
217
  summary: square