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,44 +1,24 @@
1
1
  module Square
2
2
  # WebhookSubscriptionsApi
3
3
  class WebhookSubscriptionsApi < BaseApi
4
- def initialize(config, http_call_back: nil)
5
- super(config, http_call_back: http_call_back)
6
- end
7
-
8
4
  # Lists all webhook event types that can be subscribed to.
9
5
  # @param [String] api_version Optional parameter: The API version for which
10
6
  # to list event types. Setting this field overrides the default version used
11
7
  # by the application.
12
8
  # @return [ListWebhookEventTypesResponse Hash] response from the API call
13
9
  def list_webhook_event_types(api_version: nil)
14
- # Prepare query url.
15
- _query_builder = config.get_base_uri
16
- _query_builder << '/v2/webhooks/event-types'
17
- _query_builder = APIHelper.append_url_with_query_parameters(
18
- _query_builder,
19
- 'api_version' => api_version
20
- )
21
- _query_url = APIHelper.clean_url _query_builder
22
-
23
- # Prepare headers.
24
- _headers = {
25
- 'accept' => 'application/json'
26
- }
27
-
28
- # Prepare and execute HttpRequest.
29
- _request = config.http_client.get(
30
- _query_url,
31
- headers: _headers
32
- )
33
- OAuth2.apply(config, _request)
34
- _response = execute_request(_request)
35
-
36
- # Return appropriate response type.
37
- decoded = APIHelper.json_deserialize(_response.raw_body)
38
- _errors = APIHelper.map_response(decoded, ['errors'])
39
- ApiResponse.new(
40
- _response, data: decoded, errors: _errors
41
- )
10
+ new_api_call_builder
11
+ .request(new_request_builder(HttpMethodEnum::GET,
12
+ '/v2/webhooks/event-types',
13
+ 'default')
14
+ .query_param(new_parameter(api_version, key: 'api_version'))
15
+ .header_param(new_parameter('application/json', key: 'accept'))
16
+ .auth(Single.new('global')))
17
+ .response(new_response_handler
18
+ .deserializer(APIHelper.method(:json_deserialize))
19
+ .is_api_response(true)
20
+ .convertor(ApiResponse.method(:create)))
21
+ .execute
42
22
  end
43
23
 
44
24
  # Lists all webhook subscriptions owned by your application.
@@ -62,37 +42,21 @@ module Square
62
42
  include_disabled: false,
63
43
  sort_order: nil,
64
44
  limit: nil)
65
- # Prepare query url.
66
- _query_builder = config.get_base_uri
67
- _query_builder << '/v2/webhooks/subscriptions'
68
- _query_builder = APIHelper.append_url_with_query_parameters(
69
- _query_builder,
70
- 'cursor' => cursor,
71
- 'include_disabled' => include_disabled,
72
- 'sort_order' => sort_order,
73
- 'limit' => limit
74
- )
75
- _query_url = APIHelper.clean_url _query_builder
76
-
77
- # Prepare headers.
78
- _headers = {
79
- 'accept' => 'application/json'
80
- }
81
-
82
- # Prepare and execute HttpRequest.
83
- _request = config.http_client.get(
84
- _query_url,
85
- headers: _headers
86
- )
87
- OAuth2.apply(config, _request)
88
- _response = execute_request(_request)
89
-
90
- # Return appropriate response type.
91
- decoded = APIHelper.json_deserialize(_response.raw_body)
92
- _errors = APIHelper.map_response(decoded, ['errors'])
93
- ApiResponse.new(
94
- _response, data: decoded, errors: _errors
95
- )
45
+ new_api_call_builder
46
+ .request(new_request_builder(HttpMethodEnum::GET,
47
+ '/v2/webhooks/subscriptions',
48
+ 'default')
49
+ .query_param(new_parameter(cursor, key: 'cursor'))
50
+ .query_param(new_parameter(include_disabled, key: 'include_disabled'))
51
+ .query_param(new_parameter(sort_order, key: 'sort_order'))
52
+ .query_param(new_parameter(limit, key: 'limit'))
53
+ .header_param(new_parameter('application/json', key: 'accept'))
54
+ .auth(Single.new('global')))
55
+ .response(new_response_handler
56
+ .deserializer(APIHelper.method(:json_deserialize))
57
+ .is_api_response(true)
58
+ .convertor(ApiResponse.method(:create)))
59
+ .execute
96
60
  end
97
61
 
98
62
  # Creates a webhook subscription.
@@ -101,32 +65,20 @@ module Square
101
65
  # corresponding object definition for field details.
102
66
  # @return [CreateWebhookSubscriptionResponse Hash] response from the API call
103
67
  def create_webhook_subscription(body:)
104
- # Prepare query url.
105
- _query_builder = config.get_base_uri
106
- _query_builder << '/v2/webhooks/subscriptions'
107
- _query_url = APIHelper.clean_url _query_builder
108
-
109
- # Prepare headers.
110
- _headers = {
111
- 'accept' => 'application/json',
112
- 'Content-Type' => 'application/json'
113
- }
114
-
115
- # Prepare and execute HttpRequest.
116
- _request = config.http_client.post(
117
- _query_url,
118
- headers: _headers,
119
- parameters: body.to_json
120
- )
121
- OAuth2.apply(config, _request)
122
- _response = execute_request(_request)
123
-
124
- # Return appropriate response type.
125
- decoded = APIHelper.json_deserialize(_response.raw_body)
126
- _errors = APIHelper.map_response(decoded, ['errors'])
127
- ApiResponse.new(
128
- _response, data: decoded, errors: _errors
129
- )
68
+ new_api_call_builder
69
+ .request(new_request_builder(HttpMethodEnum::POST,
70
+ '/v2/webhooks/subscriptions',
71
+ 'default')
72
+ .header_param(new_parameter('application/json', key: 'Content-Type'))
73
+ .body_param(new_parameter(body))
74
+ .header_param(new_parameter('application/json', key: 'accept'))
75
+ .body_serializer(proc do |param| param.to_json unless param.nil? end)
76
+ .auth(Single.new('global')))
77
+ .response(new_response_handler
78
+ .deserializer(APIHelper.method(:json_deserialize))
79
+ .is_api_response(true)
80
+ .convertor(ApiResponse.method(:create)))
81
+ .execute
130
82
  end
131
83
 
132
84
  # Deletes a webhook subscription.
@@ -134,34 +86,19 @@ module Square
134
86
  # the [Subscription]($m/WebhookSubscription) to delete.
135
87
  # @return [DeleteWebhookSubscriptionResponse Hash] response from the API call
136
88
  def delete_webhook_subscription(subscription_id:)
137
- # Prepare query url.
138
- _query_builder = config.get_base_uri
139
- _query_builder << '/v2/webhooks/subscriptions/{subscription_id}'
140
- _query_builder = APIHelper.append_url_with_template_parameters(
141
- _query_builder,
142
- 'subscription_id' => { 'value' => subscription_id, 'encode' => true }
143
- )
144
- _query_url = APIHelper.clean_url _query_builder
145
-
146
- # Prepare headers.
147
- _headers = {
148
- 'accept' => 'application/json'
149
- }
150
-
151
- # Prepare and execute HttpRequest.
152
- _request = config.http_client.delete(
153
- _query_url,
154
- headers: _headers
155
- )
156
- OAuth2.apply(config, _request)
157
- _response = execute_request(_request)
158
-
159
- # Return appropriate response type.
160
- decoded = APIHelper.json_deserialize(_response.raw_body)
161
- _errors = APIHelper.map_response(decoded, ['errors'])
162
- ApiResponse.new(
163
- _response, data: decoded, errors: _errors
164
- )
89
+ new_api_call_builder
90
+ .request(new_request_builder(HttpMethodEnum::DELETE,
91
+ '/v2/webhooks/subscriptions/{subscription_id}',
92
+ 'default')
93
+ .template_param(new_parameter(subscription_id, key: 'subscription_id')
94
+ .should_encode(true))
95
+ .header_param(new_parameter('application/json', key: 'accept'))
96
+ .auth(Single.new('global')))
97
+ .response(new_response_handler
98
+ .deserializer(APIHelper.method(:json_deserialize))
99
+ .is_api_response(true)
100
+ .convertor(ApiResponse.method(:create)))
101
+ .execute
165
102
  end
166
103
 
167
104
  # Retrieves a webhook subscription identified by its ID.
@@ -169,34 +106,19 @@ module Square
169
106
  # the [Subscription]($m/WebhookSubscription) to retrieve.
170
107
  # @return [RetrieveWebhookSubscriptionResponse Hash] response from the API call
171
108
  def retrieve_webhook_subscription(subscription_id:)
172
- # Prepare query url.
173
- _query_builder = config.get_base_uri
174
- _query_builder << '/v2/webhooks/subscriptions/{subscription_id}'
175
- _query_builder = APIHelper.append_url_with_template_parameters(
176
- _query_builder,
177
- 'subscription_id' => { 'value' => subscription_id, 'encode' => true }
178
- )
179
- _query_url = APIHelper.clean_url _query_builder
180
-
181
- # Prepare headers.
182
- _headers = {
183
- 'accept' => 'application/json'
184
- }
185
-
186
- # Prepare and execute HttpRequest.
187
- _request = config.http_client.get(
188
- _query_url,
189
- headers: _headers
190
- )
191
- OAuth2.apply(config, _request)
192
- _response = execute_request(_request)
193
-
194
- # Return appropriate response type.
195
- decoded = APIHelper.json_deserialize(_response.raw_body)
196
- _errors = APIHelper.map_response(decoded, ['errors'])
197
- ApiResponse.new(
198
- _response, data: decoded, errors: _errors
199
- )
109
+ new_api_call_builder
110
+ .request(new_request_builder(HttpMethodEnum::GET,
111
+ '/v2/webhooks/subscriptions/{subscription_id}',
112
+ 'default')
113
+ .template_param(new_parameter(subscription_id, key: 'subscription_id')
114
+ .should_encode(true))
115
+ .header_param(new_parameter('application/json', key: 'accept'))
116
+ .auth(Single.new('global')))
117
+ .response(new_response_handler
118
+ .deserializer(APIHelper.method(:json_deserialize))
119
+ .is_api_response(true)
120
+ .convertor(ApiResponse.method(:create)))
121
+ .execute
200
122
  end
201
123
 
202
124
  # Updates a webhook subscription.
@@ -208,36 +130,22 @@ module Square
208
130
  # @return [UpdateWebhookSubscriptionResponse Hash] response from the API call
209
131
  def update_webhook_subscription(subscription_id:,
210
132
  body:)
211
- # Prepare query url.
212
- _query_builder = config.get_base_uri
213
- _query_builder << '/v2/webhooks/subscriptions/{subscription_id}'
214
- _query_builder = APIHelper.append_url_with_template_parameters(
215
- _query_builder,
216
- 'subscription_id' => { 'value' => subscription_id, 'encode' => true }
217
- )
218
- _query_url = APIHelper.clean_url _query_builder
219
-
220
- # Prepare headers.
221
- _headers = {
222
- 'accept' => 'application/json',
223
- 'Content-Type' => 'application/json'
224
- }
225
-
226
- # Prepare and execute HttpRequest.
227
- _request = config.http_client.put(
228
- _query_url,
229
- headers: _headers,
230
- parameters: body.to_json
231
- )
232
- OAuth2.apply(config, _request)
233
- _response = execute_request(_request)
234
-
235
- # Return appropriate response type.
236
- decoded = APIHelper.json_deserialize(_response.raw_body)
237
- _errors = APIHelper.map_response(decoded, ['errors'])
238
- ApiResponse.new(
239
- _response, data: decoded, errors: _errors
240
- )
133
+ new_api_call_builder
134
+ .request(new_request_builder(HttpMethodEnum::PUT,
135
+ '/v2/webhooks/subscriptions/{subscription_id}',
136
+ 'default')
137
+ .template_param(new_parameter(subscription_id, key: 'subscription_id')
138
+ .should_encode(true))
139
+ .header_param(new_parameter('application/json', key: 'Content-Type'))
140
+ .body_param(new_parameter(body))
141
+ .header_param(new_parameter('application/json', key: 'accept'))
142
+ .body_serializer(proc do |param| param.to_json unless param.nil? end)
143
+ .auth(Single.new('global')))
144
+ .response(new_response_handler
145
+ .deserializer(APIHelper.method(:json_deserialize))
146
+ .is_api_response(true)
147
+ .convertor(ApiResponse.method(:create)))
148
+ .execute
241
149
  end
242
150
 
243
151
  # Updates a webhook subscription by replacing the existing signature key
@@ -250,36 +158,22 @@ module Square
250
158
  # @return [UpdateWebhookSubscriptionSignatureKeyResponse Hash] response from the API call
251
159
  def update_webhook_subscription_signature_key(subscription_id:,
252
160
  body:)
253
- # Prepare query url.
254
- _query_builder = config.get_base_uri
255
- _query_builder << '/v2/webhooks/subscriptions/{subscription_id}/signature-key'
256
- _query_builder = APIHelper.append_url_with_template_parameters(
257
- _query_builder,
258
- 'subscription_id' => { 'value' => subscription_id, 'encode' => true }
259
- )
260
- _query_url = APIHelper.clean_url _query_builder
261
-
262
- # Prepare headers.
263
- _headers = {
264
- 'accept' => 'application/json',
265
- 'Content-Type' => 'application/json'
266
- }
267
-
268
- # Prepare and execute HttpRequest.
269
- _request = config.http_client.post(
270
- _query_url,
271
- headers: _headers,
272
- parameters: body.to_json
273
- )
274
- OAuth2.apply(config, _request)
275
- _response = execute_request(_request)
276
-
277
- # Return appropriate response type.
278
- decoded = APIHelper.json_deserialize(_response.raw_body)
279
- _errors = APIHelper.map_response(decoded, ['errors'])
280
- ApiResponse.new(
281
- _response, data: decoded, errors: _errors
282
- )
161
+ new_api_call_builder
162
+ .request(new_request_builder(HttpMethodEnum::POST,
163
+ '/v2/webhooks/subscriptions/{subscription_id}/signature-key',
164
+ 'default')
165
+ .template_param(new_parameter(subscription_id, key: 'subscription_id')
166
+ .should_encode(true))
167
+ .header_param(new_parameter('application/json', key: 'Content-Type'))
168
+ .body_param(new_parameter(body))
169
+ .header_param(new_parameter('application/json', key: 'accept'))
170
+ .body_serializer(proc do |param| param.to_json unless param.nil? end)
171
+ .auth(Single.new('global')))
172
+ .response(new_response_handler
173
+ .deserializer(APIHelper.method(:json_deserialize))
174
+ .is_api_response(true)
175
+ .convertor(ApiResponse.method(:create)))
176
+ .execute
283
177
  end
284
178
 
285
179
  # Tests a webhook subscription by sending a test event to the notification
@@ -292,36 +186,22 @@ module Square
292
186
  # @return [TestWebhookSubscriptionResponse Hash] response from the API call
293
187
  def test_webhook_subscription(subscription_id:,
294
188
  body:)
295
- # Prepare query url.
296
- _query_builder = config.get_base_uri
297
- _query_builder << '/v2/webhooks/subscriptions/{subscription_id}/test'
298
- _query_builder = APIHelper.append_url_with_template_parameters(
299
- _query_builder,
300
- 'subscription_id' => { 'value' => subscription_id, 'encode' => true }
301
- )
302
- _query_url = APIHelper.clean_url _query_builder
303
-
304
- # Prepare headers.
305
- _headers = {
306
- 'accept' => 'application/json',
307
- 'Content-Type' => 'application/json'
308
- }
309
-
310
- # Prepare and execute HttpRequest.
311
- _request = config.http_client.post(
312
- _query_url,
313
- headers: _headers,
314
- parameters: body.to_json
315
- )
316
- OAuth2.apply(config, _request)
317
- _response = execute_request(_request)
318
-
319
- # Return appropriate response type.
320
- decoded = APIHelper.json_deserialize(_response.raw_body)
321
- _errors = APIHelper.map_response(decoded, ['errors'])
322
- ApiResponse.new(
323
- _response, data: decoded, errors: _errors
324
- )
189
+ new_api_call_builder
190
+ .request(new_request_builder(HttpMethodEnum::POST,
191
+ '/v2/webhooks/subscriptions/{subscription_id}/test',
192
+ 'default')
193
+ .template_param(new_parameter(subscription_id, key: 'subscription_id')
194
+ .should_encode(true))
195
+ .header_param(new_parameter('application/json', key: 'Content-Type'))
196
+ .body_param(new_parameter(body))
197
+ .header_param(new_parameter('application/json', key: 'accept'))
198
+ .body_serializer(proc do |param| param.to_json unless param.nil? end)
199
+ .auth(Single.new('global')))
200
+ .response(new_response_handler
201
+ .deserializer(APIHelper.method(:json_deserialize))
202
+ .is_api_response(true)
203
+ .convertor(ApiResponse.method(:create)))
204
+ .execute
325
205
  end
326
206
  end
327
207
  end