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
  # SubscriptionsApi
3
3
  class SubscriptionsApi < BaseApi
4
- def initialize(config, http_call_back: nil)
5
- super(config, http_call_back: http_call_back)
6
- end
7
-
8
4
  # Creates a subscription to a subscription plan by a customer.
9
5
  # If you provide a card on file in the request, Square charges the card for
10
6
  # the subscription. Otherwise, Square bills an invoice to the customer's
@@ -17,32 +13,20 @@ module Square
17
13
  # object definition for field details.
18
14
  # @return [CreateSubscriptionResponse Hash] response from the API call
19
15
  def create_subscription(body:)
20
- # Prepare query url.
21
- _query_builder = config.get_base_uri
22
- _query_builder << '/v2/subscriptions'
23
- _query_url = APIHelper.clean_url _query_builder
24
-
25
- # Prepare headers.
26
- _headers = {
27
- 'accept' => 'application/json',
28
- 'Content-Type' => 'application/json'
29
- }
30
-
31
- # Prepare and execute HttpRequest.
32
- _request = config.http_client.post(
33
- _query_url,
34
- headers: _headers,
35
- parameters: body.to_json
36
- )
37
- OAuth2.apply(config, _request)
38
- _response = execute_request(_request)
39
-
40
- # Return appropriate response type.
41
- decoded = APIHelper.json_deserialize(_response.raw_body)
42
- _errors = APIHelper.map_response(decoded, ['errors'])
43
- ApiResponse.new(
44
- _response, data: decoded, errors: _errors
45
- )
16
+ new_api_call_builder
17
+ .request(new_request_builder(HttpMethodEnum::POST,
18
+ '/v2/subscriptions',
19
+ 'default')
20
+ .header_param(new_parameter('application/json', key: 'Content-Type'))
21
+ .body_param(new_parameter(body))
22
+ .header_param(new_parameter('application/json', key: 'accept'))
23
+ .body_serializer(proc do |param| param.to_json unless param.nil? end)
24
+ .auth(Single.new('global')))
25
+ .response(new_response_handler
26
+ .deserializer(APIHelper.method(:json_deserialize))
27
+ .is_api_response(true)
28
+ .convertor(ApiResponse.method(:create)))
29
+ .execute
46
30
  end
47
31
 
48
32
  # Searches for subscriptions.
@@ -67,32 +51,20 @@ module Square
67
51
  # object definition for field details.
68
52
  # @return [SearchSubscriptionsResponse Hash] response from the API call
69
53
  def search_subscriptions(body:)
70
- # Prepare query url.
71
- _query_builder = config.get_base_uri
72
- _query_builder << '/v2/subscriptions/search'
73
- _query_url = APIHelper.clean_url _query_builder
74
-
75
- # Prepare headers.
76
- _headers = {
77
- 'accept' => 'application/json',
78
- 'Content-Type' => 'application/json'
79
- }
80
-
81
- # Prepare and execute HttpRequest.
82
- _request = config.http_client.post(
83
- _query_url,
84
- headers: _headers,
85
- parameters: body.to_json
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
- )
54
+ new_api_call_builder
55
+ .request(new_request_builder(HttpMethodEnum::POST,
56
+ '/v2/subscriptions/search',
57
+ 'default')
58
+ .header_param(new_parameter('application/json', key: 'Content-Type'))
59
+ .body_param(new_parameter(body))
60
+ .header_param(new_parameter('application/json', key: 'accept'))
61
+ .body_serializer(proc do |param| param.to_json unless param.nil? end)
62
+ .auth(Single.new('global')))
63
+ .response(new_response_handler
64
+ .deserializer(APIHelper.method(:json_deserialize))
65
+ .is_api_response(true)
66
+ .convertor(ApiResponse.method(:create)))
67
+ .execute
96
68
  end
97
69
 
98
70
  # Retrieves a subscription.
@@ -105,38 +77,20 @@ module Square
105
77
  # @return [RetrieveSubscriptionResponse Hash] response from the API call
106
78
  def retrieve_subscription(subscription_id:,
107
79
  include: nil)
108
- # Prepare query url.
109
- _query_builder = config.get_base_uri
110
- _query_builder << '/v2/subscriptions/{subscription_id}'
111
- _query_builder = APIHelper.append_url_with_template_parameters(
112
- _query_builder,
113
- 'subscription_id' => { 'value' => subscription_id, 'encode' => true }
114
- )
115
- _query_builder = APIHelper.append_url_with_query_parameters(
116
- _query_builder,
117
- 'include' => include
118
- )
119
- _query_url = APIHelper.clean_url _query_builder
120
-
121
- # Prepare headers.
122
- _headers = {
123
- 'accept' => 'application/json'
124
- }
125
-
126
- # Prepare and execute HttpRequest.
127
- _request = config.http_client.get(
128
- _query_url,
129
- headers: _headers
130
- )
131
- OAuth2.apply(config, _request)
132
- _response = execute_request(_request)
133
-
134
- # Return appropriate response type.
135
- decoded = APIHelper.json_deserialize(_response.raw_body)
136
- _errors = APIHelper.map_response(decoded, ['errors'])
137
- ApiResponse.new(
138
- _response, data: decoded, errors: _errors
139
- )
80
+ new_api_call_builder
81
+ .request(new_request_builder(HttpMethodEnum::GET,
82
+ '/v2/subscriptions/{subscription_id}',
83
+ 'default')
84
+ .template_param(new_parameter(subscription_id, key: 'subscription_id')
85
+ .should_encode(true))
86
+ .query_param(new_parameter(include, key: 'include'))
87
+ .header_param(new_parameter('application/json', key: 'accept'))
88
+ .auth(Single.new('global')))
89
+ .response(new_response_handler
90
+ .deserializer(APIHelper.method(:json_deserialize))
91
+ .is_api_response(true)
92
+ .convertor(ApiResponse.method(:create)))
93
+ .execute
140
94
  end
141
95
 
142
96
  # Updates a subscription. You can set, modify, and clear the
@@ -149,36 +103,22 @@ module Square
149
103
  # @return [UpdateSubscriptionResponse Hash] response from the API call
150
104
  def update_subscription(subscription_id:,
151
105
  body:)
152
- # Prepare query url.
153
- _query_builder = config.get_base_uri
154
- _query_builder << '/v2/subscriptions/{subscription_id}'
155
- _query_builder = APIHelper.append_url_with_template_parameters(
156
- _query_builder,
157
- 'subscription_id' => { 'value' => subscription_id, 'encode' => true }
158
- )
159
- _query_url = APIHelper.clean_url _query_builder
160
-
161
- # Prepare headers.
162
- _headers = {
163
- 'accept' => 'application/json',
164
- 'Content-Type' => 'application/json'
165
- }
166
-
167
- # Prepare and execute HttpRequest.
168
- _request = config.http_client.put(
169
- _query_url,
170
- headers: _headers,
171
- parameters: body.to_json
172
- )
173
- OAuth2.apply(config, _request)
174
- _response = execute_request(_request)
175
-
176
- # Return appropriate response type.
177
- decoded = APIHelper.json_deserialize(_response.raw_body)
178
- _errors = APIHelper.map_response(decoded, ['errors'])
179
- ApiResponse.new(
180
- _response, data: decoded, errors: _errors
181
- )
106
+ new_api_call_builder
107
+ .request(new_request_builder(HttpMethodEnum::PUT,
108
+ '/v2/subscriptions/{subscription_id}',
109
+ 'default')
110
+ .template_param(new_parameter(subscription_id, key: 'subscription_id')
111
+ .should_encode(true))
112
+ .header_param(new_parameter('application/json', key: 'Content-Type'))
113
+ .body_param(new_parameter(body))
114
+ .header_param(new_parameter('application/json', key: 'accept'))
115
+ .body_serializer(proc do |param| param.to_json unless param.nil? end)
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
182
122
  end
183
123
 
184
124
  # Deletes a scheduled action for a subscription.
@@ -189,35 +129,21 @@ module Square
189
129
  # @return [DeleteSubscriptionActionResponse Hash] response from the API call
190
130
  def delete_subscription_action(subscription_id:,
191
131
  action_id:)
192
- # Prepare query url.
193
- _query_builder = config.get_base_uri
194
- _query_builder << '/v2/subscriptions/{subscription_id}/actions/{action_id}'
195
- _query_builder = APIHelper.append_url_with_template_parameters(
196
- _query_builder,
197
- 'subscription_id' => { 'value' => subscription_id, 'encode' => true },
198
- 'action_id' => { 'value' => action_id, 'encode' => true }
199
- )
200
- _query_url = APIHelper.clean_url _query_builder
201
-
202
- # Prepare headers.
203
- _headers = {
204
- 'accept' => 'application/json'
205
- }
206
-
207
- # Prepare and execute HttpRequest.
208
- _request = config.http_client.delete(
209
- _query_url,
210
- headers: _headers
211
- )
212
- OAuth2.apply(config, _request)
213
- _response = execute_request(_request)
214
-
215
- # Return appropriate response type.
216
- decoded = APIHelper.json_deserialize(_response.raw_body)
217
- _errors = APIHelper.map_response(decoded, ['errors'])
218
- ApiResponse.new(
219
- _response, data: decoded, errors: _errors
220
- )
132
+ new_api_call_builder
133
+ .request(new_request_builder(HttpMethodEnum::DELETE,
134
+ '/v2/subscriptions/{subscription_id}/actions/{action_id}',
135
+ 'default')
136
+ .template_param(new_parameter(subscription_id, key: 'subscription_id')
137
+ .should_encode(true))
138
+ .template_param(new_parameter(action_id, key: 'action_id')
139
+ .should_encode(true))
140
+ .header_param(new_parameter('application/json', key: 'accept'))
141
+ .auth(Single.new('global')))
142
+ .response(new_response_handler
143
+ .deserializer(APIHelper.method(:json_deserialize))
144
+ .is_api_response(true)
145
+ .convertor(ApiResponse.method(:create)))
146
+ .execute
221
147
  end
222
148
 
223
149
  # Schedules a `CANCEL` action to cancel an active subscription
@@ -229,41 +155,26 @@ module Square
229
155
  # subscription to cancel.
230
156
  # @return [CancelSubscriptionResponse Hash] response from the API call
231
157
  def cancel_subscription(subscription_id:)
232
- # Prepare query url.
233
- _query_builder = config.get_base_uri
234
- _query_builder << '/v2/subscriptions/{subscription_id}/cancel'
235
- _query_builder = APIHelper.append_url_with_template_parameters(
236
- _query_builder,
237
- 'subscription_id' => { 'value' => subscription_id, 'encode' => true }
238
- )
239
- _query_url = APIHelper.clean_url _query_builder
240
-
241
- # Prepare headers.
242
- _headers = {
243
- 'accept' => 'application/json'
244
- }
245
-
246
- # Prepare and execute HttpRequest.
247
- _request = config.http_client.post(
248
- _query_url,
249
- headers: _headers
250
- )
251
- OAuth2.apply(config, _request)
252
- _response = execute_request(_request)
253
-
254
- # Return appropriate response type.
255
- decoded = APIHelper.json_deserialize(_response.raw_body)
256
- _errors = APIHelper.map_response(decoded, ['errors'])
257
- ApiResponse.new(
258
- _response, data: decoded, errors: _errors
259
- )
158
+ new_api_call_builder
159
+ .request(new_request_builder(HttpMethodEnum::POST,
160
+ '/v2/subscriptions/{subscription_id}/cancel',
161
+ 'default')
162
+ .template_param(new_parameter(subscription_id, key: 'subscription_id')
163
+ .should_encode(true))
164
+ .header_param(new_parameter('application/json', key: 'accept'))
165
+ .auth(Single.new('global')))
166
+ .response(new_response_handler
167
+ .deserializer(APIHelper.method(:json_deserialize))
168
+ .is_api_response(true)
169
+ .convertor(ApiResponse.method(:create)))
170
+ .execute
260
171
  end
261
172
 
262
173
  # Lists all events for a specific subscription.
263
174
  # @param [String] subscription_id Required parameter: The ID of the
264
175
  # subscription to retrieve the events for.
265
176
  # @param [String] cursor Optional parameter: When the total number of
266
- # resulting subscription events exceeds the limit of a paged response,
177
+ # resulting subscription events exceeds the limit of a paged response,
267
178
  # specify the cursor returned from a preceding response here to fetch the
268
179
  # next set of results. If the cursor is unset, the response contains the
269
180
  # last page of the results. For more information, see
@@ -275,39 +186,21 @@ module Square
275
186
  def list_subscription_events(subscription_id:,
276
187
  cursor: nil,
277
188
  limit: nil)
278
- # Prepare query url.
279
- _query_builder = config.get_base_uri
280
- _query_builder << '/v2/subscriptions/{subscription_id}/events'
281
- _query_builder = APIHelper.append_url_with_template_parameters(
282
- _query_builder,
283
- 'subscription_id' => { 'value' => subscription_id, 'encode' => true }
284
- )
285
- _query_builder = APIHelper.append_url_with_query_parameters(
286
- _query_builder,
287
- 'cursor' => cursor,
288
- 'limit' => limit
289
- )
290
- _query_url = APIHelper.clean_url _query_builder
291
-
292
- # Prepare headers.
293
- _headers = {
294
- 'accept' => 'application/json'
295
- }
296
-
297
- # Prepare and execute HttpRequest.
298
- _request = config.http_client.get(
299
- _query_url,
300
- headers: _headers
301
- )
302
- OAuth2.apply(config, _request)
303
- _response = execute_request(_request)
304
-
305
- # Return appropriate response type.
306
- decoded = APIHelper.json_deserialize(_response.raw_body)
307
- _errors = APIHelper.map_response(decoded, ['errors'])
308
- ApiResponse.new(
309
- _response, data: decoded, errors: _errors
310
- )
189
+ new_api_call_builder
190
+ .request(new_request_builder(HttpMethodEnum::GET,
191
+ '/v2/subscriptions/{subscription_id}/events',
192
+ 'default')
193
+ .template_param(new_parameter(subscription_id, key: 'subscription_id')
194
+ .should_encode(true))
195
+ .query_param(new_parameter(cursor, key: 'cursor'))
196
+ .query_param(new_parameter(limit, key: 'limit'))
197
+ .header_param(new_parameter('application/json', key: 'accept'))
198
+ .auth(Single.new('global')))
199
+ .response(new_response_handler
200
+ .deserializer(APIHelper.method(:json_deserialize))
201
+ .is_api_response(true)
202
+ .convertor(ApiResponse.method(:create)))
203
+ .execute
311
204
  end
312
205
 
313
206
  # Schedules a `PAUSE` action to pause an active subscription.
@@ -319,36 +212,22 @@ module Square
319
212
  # @return [PauseSubscriptionResponse Hash] response from the API call
320
213
  def pause_subscription(subscription_id:,
321
214
  body:)
322
- # Prepare query url.
323
- _query_builder = config.get_base_uri
324
- _query_builder << '/v2/subscriptions/{subscription_id}/pause'
325
- _query_builder = APIHelper.append_url_with_template_parameters(
326
- _query_builder,
327
- 'subscription_id' => { 'value' => subscription_id, 'encode' => true }
328
- )
329
- _query_url = APIHelper.clean_url _query_builder
330
-
331
- # Prepare headers.
332
- _headers = {
333
- 'accept' => 'application/json',
334
- 'Content-Type' => 'application/json'
335
- }
336
-
337
- # Prepare and execute HttpRequest.
338
- _request = config.http_client.post(
339
- _query_url,
340
- headers: _headers,
341
- parameters: body.to_json
342
- )
343
- OAuth2.apply(config, _request)
344
- _response = execute_request(_request)
345
-
346
- # Return appropriate response type.
347
- decoded = APIHelper.json_deserialize(_response.raw_body)
348
- _errors = APIHelper.map_response(decoded, ['errors'])
349
- ApiResponse.new(
350
- _response, data: decoded, errors: _errors
351
- )
215
+ new_api_call_builder
216
+ .request(new_request_builder(HttpMethodEnum::POST,
217
+ '/v2/subscriptions/{subscription_id}/pause',
218
+ 'default')
219
+ .template_param(new_parameter(subscription_id, key: 'subscription_id')
220
+ .should_encode(true))
221
+ .header_param(new_parameter('application/json', key: 'Content-Type'))
222
+ .body_param(new_parameter(body))
223
+ .header_param(new_parameter('application/json', key: 'accept'))
224
+ .body_serializer(proc do |param| param.to_json unless param.nil? end)
225
+ .auth(Single.new('global')))
226
+ .response(new_response_handler
227
+ .deserializer(APIHelper.method(:json_deserialize))
228
+ .is_api_response(true)
229
+ .convertor(ApiResponse.method(:create)))
230
+ .execute
352
231
  end
353
232
 
354
233
  # Schedules a `RESUME` action to resume a paused or a deactivated
@@ -361,36 +240,22 @@ module Square
361
240
  # @return [ResumeSubscriptionResponse Hash] response from the API call
362
241
  def resume_subscription(subscription_id:,
363
242
  body:)
364
- # Prepare query url.
365
- _query_builder = config.get_base_uri
366
- _query_builder << '/v2/subscriptions/{subscription_id}/resume'
367
- _query_builder = APIHelper.append_url_with_template_parameters(
368
- _query_builder,
369
- 'subscription_id' => { 'value' => subscription_id, 'encode' => true }
370
- )
371
- _query_url = APIHelper.clean_url _query_builder
372
-
373
- # Prepare headers.
374
- _headers = {
375
- 'accept' => 'application/json',
376
- 'Content-Type' => 'application/json'
377
- }
378
-
379
- # Prepare and execute HttpRequest.
380
- _request = config.http_client.post(
381
- _query_url,
382
- headers: _headers,
383
- parameters: body.to_json
384
- )
385
- OAuth2.apply(config, _request)
386
- _response = execute_request(_request)
387
-
388
- # Return appropriate response type.
389
- decoded = APIHelper.json_deserialize(_response.raw_body)
390
- _errors = APIHelper.map_response(decoded, ['errors'])
391
- ApiResponse.new(
392
- _response, data: decoded, errors: _errors
393
- )
243
+ new_api_call_builder
244
+ .request(new_request_builder(HttpMethodEnum::POST,
245
+ '/v2/subscriptions/{subscription_id}/resume',
246
+ 'default')
247
+ .template_param(new_parameter(subscription_id, key: 'subscription_id')
248
+ .should_encode(true))
249
+ .header_param(new_parameter('application/json', key: 'Content-Type'))
250
+ .body_param(new_parameter(body))
251
+ .header_param(new_parameter('application/json', key: 'accept'))
252
+ .body_serializer(proc do |param| param.to_json unless param.nil? end)
253
+ .auth(Single.new('global')))
254
+ .response(new_response_handler
255
+ .deserializer(APIHelper.method(:json_deserialize))
256
+ .is_api_response(true)
257
+ .convertor(ApiResponse.method(:create)))
258
+ .execute
394
259
  end
395
260
 
396
261
  # Schedules a `SWAP_PLAN` action to swap a subscription plan in an existing
@@ -403,36 +268,22 @@ module Square
403
268
  # @return [SwapPlanResponse Hash] response from the API call
404
269
  def swap_plan(subscription_id:,
405
270
  body:)
406
- # Prepare query url.
407
- _query_builder = config.get_base_uri
408
- _query_builder << '/v2/subscriptions/{subscription_id}/swap-plan'
409
- _query_builder = APIHelper.append_url_with_template_parameters(
410
- _query_builder,
411
- 'subscription_id' => { 'value' => subscription_id, 'encode' => true }
412
- )
413
- _query_url = APIHelper.clean_url _query_builder
414
-
415
- # Prepare headers.
416
- _headers = {
417
- 'accept' => 'application/json',
418
- 'Content-Type' => 'application/json'
419
- }
420
-
421
- # Prepare and execute HttpRequest.
422
- _request = config.http_client.post(
423
- _query_url,
424
- headers: _headers,
425
- parameters: body.to_json
426
- )
427
- OAuth2.apply(config, _request)
428
- _response = execute_request(_request)
429
-
430
- # Return appropriate response type.
431
- decoded = APIHelper.json_deserialize(_response.raw_body)
432
- _errors = APIHelper.map_response(decoded, ['errors'])
433
- ApiResponse.new(
434
- _response, data: decoded, errors: _errors
435
- )
271
+ new_api_call_builder
272
+ .request(new_request_builder(HttpMethodEnum::POST,
273
+ '/v2/subscriptions/{subscription_id}/swap-plan',
274
+ 'default')
275
+ .template_param(new_parameter(subscription_id, key: 'subscription_id')
276
+ .should_encode(true))
277
+ .header_param(new_parameter('application/json', key: 'Content-Type'))
278
+ .body_param(new_parameter(body))
279
+ .header_param(new_parameter('application/json', key: 'accept'))
280
+ .body_serializer(proc do |param| param.to_json unless param.nil? end)
281
+ .auth(Single.new('global')))
282
+ .response(new_response_handler
283
+ .deserializer(APIHelper.method(:json_deserialize))
284
+ .is_api_response(true)
285
+ .convertor(ApiResponse.method(:create)))
286
+ .execute
436
287
  end
437
288
  end
438
289
  end