square.rb 26.0.0.20221214 → 26.2.0.20230315

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +1 -1
  3. data/lib/square/api/apple_pay_api.rb +14 -30
  4. data/lib/square/api/bank_accounts_api.rb +40 -90
  5. data/lib/square/api/base_api.rb +42 -42
  6. data/lib/square/api/booking_custom_attributes_api.rb +164 -329
  7. data/lib/square/api/bookings_api.rb +135 -260
  8. data/lib/square/api/cards_api.rb +56 -118
  9. data/lib/square/api/cash_drawers_api.rb +47 -103
  10. data/lib/square/api/catalog_api.rb +197 -423
  11. data/lib/square/api/checkout_api.rb +85 -175
  12. data/lib/square/api/customer_custom_attributes_api.rb +150 -303
  13. data/lib/square/api/customer_groups_api.rb +69 -145
  14. data/lib/square/api/customer_segments_api.rb +26 -61
  15. data/lib/square/api/customers_api.rb +147 -294
  16. data/lib/square/api/devices_api.rb +42 -89
  17. data/lib/square/api/disputes_api.rb +130 -288
  18. data/lib/square/api/employees_api.rb +28 -63
  19. data/lib/square/api/gift_card_activities_api.rb +33 -65
  20. data/lib/square/api/gift_cards_api.rb +103 -202
  21. data/lib/square/api/inventory_api.rb +179 -366
  22. data/lib/square/api/invoices_api.rb +118 -237
  23. data/lib/square/api/labor_api.rb +223 -459
  24. data/lib/square/api/location_custom_attributes_api.rb +419 -0
  25. data/lib/square/api/locations_api.rb +54 -112
  26. data/lib/square/api/loyalty_api.rb +259 -512
  27. data/lib/square/api/merchants_api.rb +25 -60
  28. data/lib/square/api/mobile_authorization_api.rb +14 -30
  29. data/lib/square/api/o_auth_api.rb +54 -109
  30. data/lib/square/api/order_custom_attributes_api.rb +168 -333
  31. data/lib/square/api/orders_api.rb +115 -222
  32. data/lib/square/api/payments_api.rb +106 -208
  33. data/lib/square/api/payouts_api.rb +47 -100
  34. data/lib/square/api/refunds_api.rb +46 -93
  35. data/lib/square/api/sites_api.rb +11 -28
  36. data/lib/square/api/snippets_api.rb +42 -90
  37. data/lib/square/api/subscriptions_api.rb +150 -299
  38. data/lib/square/api/team_api.rb +114 -224
  39. data/lib/square/api/terminal_api.rb +162 -328
  40. data/lib/square/api/transactions_api.rb +62 -126
  41. data/lib/square/api/v1_transactions_api.rb +155 -296
  42. data/lib/square/api/vendors_api.rb +99 -192
  43. data/lib/square/api/webhook_subscriptions_api.rb +115 -235
  44. data/lib/square/api_helper.rb +1 -437
  45. data/lib/square/client.rb +82 -46
  46. data/lib/square/configuration.rb +28 -53
  47. data/lib/square/exceptions/api_exception.rb +1 -11
  48. data/lib/square/http/api_response.rb +13 -19
  49. data/lib/square/http/auth/o_auth2.rb +14 -7
  50. data/lib/square/http/http_call_back.rb +1 -15
  51. data/lib/square/http/http_method_enum.rb +1 -4
  52. data/lib/square/http/http_request.rb +1 -45
  53. data/lib/square/http/http_response.rb +1 -20
  54. data/lib/square/utilities/date_time_helper.rb +1 -146
  55. data/lib/square/utilities/file_wrapper.rb +5 -5
  56. data/lib/square.rb +7 -6
  57. data/spec/user_journey_spec.rb +2 -2
  58. data/test/api/api_test_base.rb +13 -5
  59. data/test/api/test_catalog_api.rb +5 -4
  60. data/test/api/test_customers_api.rb +3 -2
  61. data/test/api/test_employees_api.rb +4 -3
  62. data/test/api/test_labor_api.rb +6 -5
  63. data/test/api/test_locations_api.rb +3 -2
  64. data/test/api/test_merchants_api.rb +4 -3
  65. data/test/api/test_payments_api.rb +4 -3
  66. data/test/api/test_refunds_api.rb +4 -3
  67. metadata +12 -111
  68. data/lib/square/exceptions/validation_exception.rb +0 -13
  69. data/lib/square/http/faraday_client.rb +0 -93
  70. data/lib/square/http/http_client.rb +0 -118
  71. data/test/test_helper.rb +0 -89
@@ -1,10 +1,6 @@
1
1
  module Square
2
2
  # VendorsApi
3
3
  class VendorsApi < BaseApi
4
- def initialize(config, http_call_back: nil)
5
- super(config, http_call_back: http_call_back)
6
- end
7
-
8
4
  # Creates one or more [Vendor]($m/Vendor) objects to represent suppliers to
9
5
  # a seller.
10
6
  # @param [BulkCreateVendorsRequest] body Required parameter: An object
@@ -12,32 +8,20 @@ module Square
12
8
  # object definition for field details.
13
9
  # @return [BulkCreateVendorsResponse Hash] response from the API call
14
10
  def bulk_create_vendors(body:)
15
- # Prepare query url.
16
- _query_builder = config.get_base_uri
17
- _query_builder << '/v2/vendors/bulk-create'
18
- _query_url = APIHelper.clean_url _query_builder
19
-
20
- # Prepare headers.
21
- _headers = {
22
- 'accept' => 'application/json',
23
- 'Content-Type' => 'application/json'
24
- }
25
-
26
- # Prepare and execute HttpRequest.
27
- _request = config.http_client.post(
28
- _query_url,
29
- headers: _headers,
30
- parameters: body.to_json
31
- )
32
- OAuth2.apply(config, _request)
33
- _response = execute_request(_request)
34
-
35
- # Return appropriate response type.
36
- decoded = APIHelper.json_deserialize(_response.raw_body)
37
- _errors = APIHelper.map_response(decoded, ['errors'])
38
- ApiResponse.new(
39
- _response, data: decoded, errors: _errors
40
- )
11
+ new_api_call_builder
12
+ .request(new_request_builder(HttpMethodEnum::POST,
13
+ '/v2/vendors/bulk-create',
14
+ 'default')
15
+ .header_param(new_parameter('application/json', key: 'Content-Type'))
16
+ .body_param(new_parameter(body))
17
+ .header_param(new_parameter('application/json', key: 'accept'))
18
+ .body_serializer(proc do |param| param.to_json unless param.nil? end)
19
+ .auth(Single.new('global')))
20
+ .response(new_response_handler
21
+ .deserializer(APIHelper.method(:json_deserialize))
22
+ .is_api_response(true)
23
+ .convertor(ApiResponse.method(:create)))
24
+ .execute
41
25
  end
42
26
 
43
27
  # Retrieves one or more vendors of specified [Vendor]($m/Vendor) IDs.
@@ -46,32 +30,20 @@ module Square
46
30
  # object definition for field details.
47
31
  # @return [BulkRetrieveVendorsResponse Hash] response from the API call
48
32
  def bulk_retrieve_vendors(body:)
49
- # Prepare query url.
50
- _query_builder = config.get_base_uri
51
- _query_builder << '/v2/vendors/bulk-retrieve'
52
- _query_url = APIHelper.clean_url _query_builder
53
-
54
- # Prepare headers.
55
- _headers = {
56
- 'accept' => 'application/json',
57
- 'Content-Type' => 'application/json'
58
- }
59
-
60
- # Prepare and execute HttpRequest.
61
- _request = config.http_client.post(
62
- _query_url,
63
- headers: _headers,
64
- parameters: body.to_json
65
- )
66
- OAuth2.apply(config, _request)
67
- _response = execute_request(_request)
68
-
69
- # Return appropriate response type.
70
- decoded = APIHelper.json_deserialize(_response.raw_body)
71
- _errors = APIHelper.map_response(decoded, ['errors'])
72
- ApiResponse.new(
73
- _response, data: decoded, errors: _errors
74
- )
33
+ new_api_call_builder
34
+ .request(new_request_builder(HttpMethodEnum::POST,
35
+ '/v2/vendors/bulk-retrieve',
36
+ 'default')
37
+ .header_param(new_parameter('application/json', key: 'Content-Type'))
38
+ .body_param(new_parameter(body))
39
+ .header_param(new_parameter('application/json', key: 'accept'))
40
+ .body_serializer(proc do |param| param.to_json unless param.nil? end)
41
+ .auth(Single.new('global')))
42
+ .response(new_response_handler
43
+ .deserializer(APIHelper.method(:json_deserialize))
44
+ .is_api_response(true)
45
+ .convertor(ApiResponse.method(:create)))
46
+ .execute
75
47
  end
76
48
 
77
49
  # Updates one or more of existing [Vendor]($m/Vendor) objects as suppliers
@@ -81,32 +53,20 @@ module Square
81
53
  # object definition for field details.
82
54
  # @return [BulkUpdateVendorsResponse Hash] response from the API call
83
55
  def bulk_update_vendors(body:)
84
- # Prepare query url.
85
- _query_builder = config.get_base_uri
86
- _query_builder << '/v2/vendors/bulk-update'
87
- _query_url = APIHelper.clean_url _query_builder
88
-
89
- # Prepare headers.
90
- _headers = {
91
- 'accept' => 'application/json',
92
- 'Content-Type' => 'application/json'
93
- }
94
-
95
- # Prepare and execute HttpRequest.
96
- _request = config.http_client.put(
97
- _query_url,
98
- headers: _headers,
99
- parameters: body.to_json
100
- )
101
- OAuth2.apply(config, _request)
102
- _response = execute_request(_request)
103
-
104
- # Return appropriate response type.
105
- decoded = APIHelper.json_deserialize(_response.raw_body)
106
- _errors = APIHelper.map_response(decoded, ['errors'])
107
- ApiResponse.new(
108
- _response, data: decoded, errors: _errors
109
- )
56
+ new_api_call_builder
57
+ .request(new_request_builder(HttpMethodEnum::PUT,
58
+ '/v2/vendors/bulk-update',
59
+ 'default')
60
+ .header_param(new_parameter('application/json', key: 'Content-Type'))
61
+ .body_param(new_parameter(body))
62
+ .header_param(new_parameter('application/json', key: 'accept'))
63
+ .body_serializer(proc do |param| param.to_json unless param.nil? end)
64
+ .auth(Single.new('global')))
65
+ .response(new_response_handler
66
+ .deserializer(APIHelper.method(:json_deserialize))
67
+ .is_api_response(true)
68
+ .convertor(ApiResponse.method(:create)))
69
+ .execute
110
70
  end
111
71
 
112
72
  # Creates a single [Vendor]($m/Vendor) object to represent a supplier to a
@@ -116,32 +76,20 @@ module Square
116
76
  # definition for field details.
117
77
  # @return [CreateVendorResponse Hash] response from the API call
118
78
  def create_vendor(body:)
119
- # Prepare query url.
120
- _query_builder = config.get_base_uri
121
- _query_builder << '/v2/vendors/create'
122
- _query_url = APIHelper.clean_url _query_builder
123
-
124
- # Prepare headers.
125
- _headers = {
126
- 'accept' => 'application/json',
127
- 'Content-Type' => 'application/json'
128
- }
129
-
130
- # Prepare and execute HttpRequest.
131
- _request = config.http_client.post(
132
- _query_url,
133
- headers: _headers,
134
- parameters: body.to_json
135
- )
136
- OAuth2.apply(config, _request)
137
- _response = execute_request(_request)
138
-
139
- # Return appropriate response type.
140
- decoded = APIHelper.json_deserialize(_response.raw_body)
141
- _errors = APIHelper.map_response(decoded, ['errors'])
142
- ApiResponse.new(
143
- _response, data: decoded, errors: _errors
144
- )
79
+ new_api_call_builder
80
+ .request(new_request_builder(HttpMethodEnum::POST,
81
+ '/v2/vendors/create',
82
+ 'default')
83
+ .header_param(new_parameter('application/json', key: 'Content-Type'))
84
+ .body_param(new_parameter(body))
85
+ .header_param(new_parameter('application/json', key: 'accept'))
86
+ .body_serializer(proc do |param| param.to_json unless param.nil? end)
87
+ .auth(Single.new('global')))
88
+ .response(new_response_handler
89
+ .deserializer(APIHelper.method(:json_deserialize))
90
+ .is_api_response(true)
91
+ .convertor(ApiResponse.method(:create)))
92
+ .execute
145
93
  end
146
94
 
147
95
  # Searches for vendors using a filter against supported [Vendor]($m/Vendor)
@@ -151,32 +99,20 @@ module Square
151
99
  # object definition for field details.
152
100
  # @return [SearchVendorsResponse Hash] response from the API call
153
101
  def search_vendors(body:)
154
- # Prepare query url.
155
- _query_builder = config.get_base_uri
156
- _query_builder << '/v2/vendors/search'
157
- _query_url = APIHelper.clean_url _query_builder
158
-
159
- # Prepare headers.
160
- _headers = {
161
- 'accept' => 'application/json',
162
- 'Content-Type' => 'application/json'
163
- }
164
-
165
- # Prepare and execute HttpRequest.
166
- _request = config.http_client.post(
167
- _query_url,
168
- headers: _headers,
169
- parameters: body.to_json
170
- )
171
- OAuth2.apply(config, _request)
172
- _response = execute_request(_request)
173
-
174
- # Return appropriate response type.
175
- decoded = APIHelper.json_deserialize(_response.raw_body)
176
- _errors = APIHelper.map_response(decoded, ['errors'])
177
- ApiResponse.new(
178
- _response, data: decoded, errors: _errors
179
- )
102
+ new_api_call_builder
103
+ .request(new_request_builder(HttpMethodEnum::POST,
104
+ '/v2/vendors/search',
105
+ 'default')
106
+ .header_param(new_parameter('application/json', key: 'Content-Type'))
107
+ .body_param(new_parameter(body))
108
+ .header_param(new_parameter('application/json', key: 'accept'))
109
+ .body_serializer(proc do |param| param.to_json unless param.nil? end)
110
+ .auth(Single.new('global')))
111
+ .response(new_response_handler
112
+ .deserializer(APIHelper.method(:json_deserialize))
113
+ .is_api_response(true)
114
+ .convertor(ApiResponse.method(:create)))
115
+ .execute
180
116
  end
181
117
 
182
118
  # Retrieves the vendor of a specified [Vendor]($m/Vendor) ID.
@@ -184,34 +120,19 @@ module Square
184
120
  # [Vendor]($m/Vendor) to retrieve.
185
121
  # @return [RetrieveVendorResponse Hash] response from the API call
186
122
  def retrieve_vendor(vendor_id:)
187
- # Prepare query url.
188
- _query_builder = config.get_base_uri
189
- _query_builder << '/v2/vendors/{vendor_id}'
190
- _query_builder = APIHelper.append_url_with_template_parameters(
191
- _query_builder,
192
- 'vendor_id' => { 'value' => vendor_id, 'encode' => true }
193
- )
194
- _query_url = APIHelper.clean_url _query_builder
195
-
196
- # Prepare headers.
197
- _headers = {
198
- 'accept' => 'application/json'
199
- }
200
-
201
- # Prepare and execute HttpRequest.
202
- _request = config.http_client.get(
203
- _query_url,
204
- headers: _headers
205
- )
206
- OAuth2.apply(config, _request)
207
- _response = execute_request(_request)
208
-
209
- # Return appropriate response type.
210
- decoded = APIHelper.json_deserialize(_response.raw_body)
211
- _errors = APIHelper.map_response(decoded, ['errors'])
212
- ApiResponse.new(
213
- _response, data: decoded, errors: _errors
214
- )
123
+ new_api_call_builder
124
+ .request(new_request_builder(HttpMethodEnum::GET,
125
+ '/v2/vendors/{vendor_id}',
126
+ 'default')
127
+ .template_param(new_parameter(vendor_id, key: 'vendor_id')
128
+ .should_encode(true))
129
+ .header_param(new_parameter('application/json', key: 'accept'))
130
+ .auth(Single.new('global')))
131
+ .response(new_response_handler
132
+ .deserializer(APIHelper.method(:json_deserialize))
133
+ .is_api_response(true)
134
+ .convertor(ApiResponse.method(:create)))
135
+ .execute
215
136
  end
216
137
 
217
138
  # Updates an existing [Vendor]($m/Vendor) object as a supplier to a seller.
@@ -222,36 +143,22 @@ module Square
222
143
  # @return [UpdateVendorResponse Hash] response from the API call
223
144
  def update_vendor(body:,
224
145
  vendor_id:)
225
- # Prepare query url.
226
- _query_builder = config.get_base_uri
227
- _query_builder << '/v2/vendors/{vendor_id}'
228
- _query_builder = APIHelper.append_url_with_template_parameters(
229
- _query_builder,
230
- 'vendor_id' => { 'value' => vendor_id, 'encode' => true }
231
- )
232
- _query_url = APIHelper.clean_url _query_builder
233
-
234
- # Prepare headers.
235
- _headers = {
236
- 'accept' => 'application/json',
237
- 'Content-Type' => 'application/json'
238
- }
239
-
240
- # Prepare and execute HttpRequest.
241
- _request = config.http_client.put(
242
- _query_url,
243
- headers: _headers,
244
- parameters: body.to_json
245
- )
246
- OAuth2.apply(config, _request)
247
- _response = execute_request(_request)
248
-
249
- # Return appropriate response type.
250
- decoded = APIHelper.json_deserialize(_response.raw_body)
251
- _errors = APIHelper.map_response(decoded, ['errors'])
252
- ApiResponse.new(
253
- _response, data: decoded, errors: _errors
254
- )
146
+ new_api_call_builder
147
+ .request(new_request_builder(HttpMethodEnum::PUT,
148
+ '/v2/vendors/{vendor_id}',
149
+ 'default')
150
+ .header_param(new_parameter('application/json', key: 'Content-Type'))
151
+ .body_param(new_parameter(body))
152
+ .template_param(new_parameter(vendor_id, key: 'vendor_id')
153
+ .should_encode(true))
154
+ .header_param(new_parameter('application/json', key: 'accept'))
155
+ .body_serializer(proc do |param| param.to_json unless param.nil? end)
156
+ .auth(Single.new('global')))
157
+ .response(new_response_handler
158
+ .deserializer(APIHelper.method(:json_deserialize))
159
+ .is_api_response(true)
160
+ .convertor(ApiResponse.method(:create)))
161
+ .execute
255
162
  end
256
163
  end
257
164
  end