square.rb 26.1.0.20230119 → 26.2.0.20230315

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 (70) hide show
  1. checksums.yaml +4 -4
  2. data/lib/square/api/apple_pay_api.rb +14 -30
  3. data/lib/square/api/bank_accounts_api.rb +40 -90
  4. data/lib/square/api/base_api.rb +42 -42
  5. data/lib/square/api/booking_custom_attributes_api.rb +164 -329
  6. data/lib/square/api/bookings_api.rb +135 -260
  7. data/lib/square/api/cards_api.rb +56 -118
  8. data/lib/square/api/cash_drawers_api.rb +47 -103
  9. data/lib/square/api/catalog_api.rb +197 -423
  10. data/lib/square/api/checkout_api.rb +85 -175
  11. data/lib/square/api/customer_custom_attributes_api.rb +150 -303
  12. data/lib/square/api/customer_groups_api.rb +69 -145
  13. data/lib/square/api/customer_segments_api.rb +26 -61
  14. data/lib/square/api/customers_api.rb +147 -294
  15. data/lib/square/api/devices_api.rb +42 -89
  16. data/lib/square/api/disputes_api.rb +130 -288
  17. data/lib/square/api/employees_api.rb +28 -63
  18. data/lib/square/api/gift_card_activities_api.rb +33 -65
  19. data/lib/square/api/gift_cards_api.rb +103 -202
  20. data/lib/square/api/inventory_api.rb +179 -366
  21. data/lib/square/api/invoices_api.rb +118 -237
  22. data/lib/square/api/labor_api.rb +223 -459
  23. data/lib/square/api/location_custom_attributes_api.rb +166 -331
  24. data/lib/square/api/locations_api.rb +54 -112
  25. data/lib/square/api/loyalty_api.rb +259 -512
  26. data/lib/square/api/merchants_api.rb +25 -60
  27. data/lib/square/api/mobile_authorization_api.rb +14 -30
  28. data/lib/square/api/o_auth_api.rb +54 -109
  29. data/lib/square/api/order_custom_attributes_api.rb +168 -333
  30. data/lib/square/api/orders_api.rb +115 -222
  31. data/lib/square/api/payments_api.rb +106 -208
  32. data/lib/square/api/payouts_api.rb +47 -100
  33. data/lib/square/api/refunds_api.rb +46 -93
  34. data/lib/square/api/sites_api.rb +11 -28
  35. data/lib/square/api/snippets_api.rb +42 -90
  36. data/lib/square/api/subscriptions_api.rb +150 -299
  37. data/lib/square/api/team_api.rb +114 -224
  38. data/lib/square/api/terminal_api.rb +162 -328
  39. data/lib/square/api/transactions_api.rb +62 -126
  40. data/lib/square/api/v1_transactions_api.rb +155 -296
  41. data/lib/square/api/vendors_api.rb +99 -192
  42. data/lib/square/api/webhook_subscriptions_api.rb +115 -235
  43. data/lib/square/api_helper.rb +1 -437
  44. data/lib/square/client.rb +77 -47
  45. data/lib/square/configuration.rb +28 -53
  46. data/lib/square/exceptions/api_exception.rb +1 -11
  47. data/lib/square/http/api_response.rb +13 -19
  48. data/lib/square/http/auth/o_auth2.rb +14 -7
  49. data/lib/square/http/http_call_back.rb +1 -15
  50. data/lib/square/http/http_method_enum.rb +1 -4
  51. data/lib/square/http/http_request.rb +1 -45
  52. data/lib/square/http/http_response.rb +1 -20
  53. data/lib/square/utilities/date_time_helper.rb +1 -146
  54. data/lib/square/utilities/file_wrapper.rb +5 -5
  55. data/lib/square.rb +6 -6
  56. data/spec/user_journey_spec.rb +2 -2
  57. data/test/api/api_test_base.rb +13 -5
  58. data/test/api/test_catalog_api.rb +5 -4
  59. data/test/api/test_customers_api.rb +3 -2
  60. data/test/api/test_employees_api.rb +4 -3
  61. data/test/api/test_labor_api.rb +6 -5
  62. data/test/api/test_locations_api.rb +3 -2
  63. data/test/api/test_merchants_api.rb +4 -3
  64. data/test/api/test_payments_api.rb +4 -3
  65. data/test/api/test_refunds_api.rb +4 -3
  66. metadata +11 -111
  67. data/lib/square/exceptions/validation_exception.rb +0 -13
  68. data/lib/square/http/faraday_client.rb +0 -93
  69. data/lib/square/http/http_client.rb +0 -118
  70. data/test/test_helper.rb +0 -89
@@ -1,39 +1,22 @@
1
1
  module Square
2
2
  # LocationsApi
3
3
  class LocationsApi < BaseApi
4
- def initialize(config, http_call_back: nil)
5
- super(config, http_call_back: http_call_back)
6
- end
7
-
8
4
  # Provides details about all of the seller's
9
5
  # [locations](https://developer.squareup.com/docs/locations-api),
10
6
  # including those with an inactive status.
11
7
  # @return [ListLocationsResponse Hash] response from the API call
12
8
  def list_locations
13
- # Prepare query url.
14
- _query_builder = config.get_base_uri
15
- _query_builder << '/v2/locations'
16
- _query_url = APIHelper.clean_url _query_builder
17
-
18
- # Prepare headers.
19
- _headers = {
20
- 'accept' => 'application/json'
21
- }
22
-
23
- # Prepare and execute HttpRequest.
24
- _request = config.http_client.get(
25
- _query_url,
26
- headers: _headers
27
- )
28
- OAuth2.apply(config, _request)
29
- _response = execute_request(_request)
30
-
31
- # Return appropriate response type.
32
- decoded = APIHelper.json_deserialize(_response.raw_body)
33
- _errors = APIHelper.map_response(decoded, ['errors'])
34
- ApiResponse.new(
35
- _response, data: decoded, errors: _errors
36
- )
9
+ new_api_call_builder
10
+ .request(new_request_builder(HttpMethodEnum::GET,
11
+ '/v2/locations',
12
+ 'default')
13
+ .header_param(new_parameter('application/json', key: 'accept'))
14
+ .auth(Single.new('global')))
15
+ .response(new_response_handler
16
+ .deserializer(APIHelper.method(:json_deserialize))
17
+ .is_api_response(true)
18
+ .convertor(ApiResponse.method(:create)))
19
+ .execute
37
20
  end
38
21
 
39
22
  # Creates a [location](https://developer.squareup.com/docs/locations-api).
@@ -51,32 +34,20 @@ module Square
51
34
  # object definition for field details.
52
35
  # @return [CreateLocationResponse Hash] response from the API call
53
36
  def create_location(body:)
54
- # Prepare query url.
55
- _query_builder = config.get_base_uri
56
- _query_builder << '/v2/locations'
57
- _query_url = APIHelper.clean_url _query_builder
58
-
59
- # Prepare headers.
60
- _headers = {
61
- 'accept' => 'application/json',
62
- 'Content-Type' => 'application/json'
63
- }
64
-
65
- # Prepare and execute HttpRequest.
66
- _request = config.http_client.post(
67
- _query_url,
68
- headers: _headers,
69
- parameters: body.to_json
70
- )
71
- OAuth2.apply(config, _request)
72
- _response = execute_request(_request)
73
-
74
- # Return appropriate response type.
75
- decoded = APIHelper.json_deserialize(_response.raw_body)
76
- _errors = APIHelper.map_response(decoded, ['errors'])
77
- ApiResponse.new(
78
- _response, data: decoded, errors: _errors
79
- )
37
+ new_api_call_builder
38
+ .request(new_request_builder(HttpMethodEnum::POST,
39
+ '/v2/locations',
40
+ 'default')
41
+ .header_param(new_parameter('application/json', key: 'Content-Type'))
42
+ .body_param(new_parameter(body))
43
+ .header_param(new_parameter('application/json', key: 'accept'))
44
+ .body_serializer(proc do |param| param.to_json unless param.nil? end)
45
+ .auth(Single.new('global')))
46
+ .response(new_response_handler
47
+ .deserializer(APIHelper.method(:json_deserialize))
48
+ .is_api_response(true)
49
+ .convertor(ApiResponse.method(:create)))
50
+ .execute
80
51
  end
81
52
 
82
53
  # Retrieves details of a single location. Specify "main"
@@ -87,34 +58,19 @@ module Square
87
58
  # retrieve. Specify the string "main" to return the main location.
88
59
  # @return [RetrieveLocationResponse Hash] response from the API call
89
60
  def retrieve_location(location_id:)
90
- # Prepare query url.
91
- _query_builder = config.get_base_uri
92
- _query_builder << '/v2/locations/{location_id}'
93
- _query_builder = APIHelper.append_url_with_template_parameters(
94
- _query_builder,
95
- 'location_id' => { 'value' => location_id, 'encode' => true }
96
- )
97
- _query_url = APIHelper.clean_url _query_builder
98
-
99
- # Prepare headers.
100
- _headers = {
101
- 'accept' => 'application/json'
102
- }
103
-
104
- # Prepare and execute HttpRequest.
105
- _request = config.http_client.get(
106
- _query_url,
107
- headers: _headers
108
- )
109
- OAuth2.apply(config, _request)
110
- _response = execute_request(_request)
111
-
112
- # Return appropriate response type.
113
- decoded = APIHelper.json_deserialize(_response.raw_body)
114
- _errors = APIHelper.map_response(decoded, ['errors'])
115
- ApiResponse.new(
116
- _response, data: decoded, errors: _errors
117
- )
61
+ new_api_call_builder
62
+ .request(new_request_builder(HttpMethodEnum::GET,
63
+ '/v2/locations/{location_id}',
64
+ 'default')
65
+ .template_param(new_parameter(location_id, key: 'location_id')
66
+ .should_encode(true))
67
+ .header_param(new_parameter('application/json', key: 'accept'))
68
+ .auth(Single.new('global')))
69
+ .response(new_response_handler
70
+ .deserializer(APIHelper.method(:json_deserialize))
71
+ .is_api_response(true)
72
+ .convertor(ApiResponse.method(:create)))
73
+ .execute
118
74
  end
119
75
 
120
76
  # Updates a [location](https://developer.squareup.com/docs/locations-api).
@@ -126,36 +82,22 @@ module Square
126
82
  # @return [UpdateLocationResponse Hash] response from the API call
127
83
  def update_location(location_id:,
128
84
  body:)
129
- # Prepare query url.
130
- _query_builder = config.get_base_uri
131
- _query_builder << '/v2/locations/{location_id}'
132
- _query_builder = APIHelper.append_url_with_template_parameters(
133
- _query_builder,
134
- 'location_id' => { 'value' => location_id, 'encode' => true }
135
- )
136
- _query_url = APIHelper.clean_url _query_builder
137
-
138
- # Prepare headers.
139
- _headers = {
140
- 'accept' => 'application/json',
141
- 'Content-Type' => 'application/json'
142
- }
143
-
144
- # Prepare and execute HttpRequest.
145
- _request = config.http_client.put(
146
- _query_url,
147
- headers: _headers,
148
- parameters: body.to_json
149
- )
150
- OAuth2.apply(config, _request)
151
- _response = execute_request(_request)
152
-
153
- # Return appropriate response type.
154
- decoded = APIHelper.json_deserialize(_response.raw_body)
155
- _errors = APIHelper.map_response(decoded, ['errors'])
156
- ApiResponse.new(
157
- _response, data: decoded, errors: _errors
158
- )
85
+ new_api_call_builder
86
+ .request(new_request_builder(HttpMethodEnum::PUT,
87
+ '/v2/locations/{location_id}',
88
+ 'default')
89
+ .template_param(new_parameter(location_id, key: 'location_id')
90
+ .should_encode(true))
91
+ .header_param(new_parameter('application/json', key: 'Content-Type'))
92
+ .body_param(new_parameter(body))
93
+ .header_param(new_parameter('application/json', key: 'accept'))
94
+ .body_serializer(proc do |param| param.to_json unless param.nil? end)
95
+ .auth(Single.new('global')))
96
+ .response(new_response_handler
97
+ .deserializer(APIHelper.method(:json_deserialize))
98
+ .is_api_response(true)
99
+ .convertor(ApiResponse.method(:create)))
100
+ .execute
159
101
  end
160
102
  end
161
103
  end