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
  # DevicesApi
3
3
  class DevicesApi < 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 DeviceCodes associated with the merchant.
9
5
  # @param [String] cursor Optional parameter: A pagination cursor returned by
10
6
  # a previous call to this endpoint. Provide this to retrieve the next set of
@@ -25,37 +21,21 @@ module Square
25
21
  location_id: nil,
26
22
  product_type: nil,
27
23
  status: nil)
28
- # Prepare query url.
29
- _query_builder = config.get_base_uri
30
- _query_builder << '/v2/devices/codes'
31
- _query_builder = APIHelper.append_url_with_query_parameters(
32
- _query_builder,
33
- 'cursor' => cursor,
34
- 'location_id' => location_id,
35
- 'product_type' => product_type,
36
- 'status' => status
37
- )
38
- _query_url = APIHelper.clean_url _query_builder
39
-
40
- # Prepare headers.
41
- _headers = {
42
- 'accept' => 'application/json'
43
- }
44
-
45
- # Prepare and execute HttpRequest.
46
- _request = config.http_client.get(
47
- _query_url,
48
- headers: _headers
49
- )
50
- OAuth2.apply(config, _request)
51
- _response = execute_request(_request)
52
-
53
- # Return appropriate response type.
54
- decoded = APIHelper.json_deserialize(_response.raw_body)
55
- _errors = APIHelper.map_response(decoded, ['errors'])
56
- ApiResponse.new(
57
- _response, data: decoded, errors: _errors
58
- )
24
+ new_api_call_builder
25
+ .request(new_request_builder(HttpMethodEnum::GET,
26
+ '/v2/devices/codes',
27
+ 'default')
28
+ .query_param(new_parameter(cursor, key: 'cursor'))
29
+ .query_param(new_parameter(location_id, key: 'location_id'))
30
+ .query_param(new_parameter(product_type, key: 'product_type'))
31
+ .query_param(new_parameter(status, key: 'status'))
32
+ .header_param(new_parameter('application/json', key: 'accept'))
33
+ .auth(Single.new('global')))
34
+ .response(new_response_handler
35
+ .deserializer(APIHelper.method(:json_deserialize))
36
+ .is_api_response(true)
37
+ .convertor(ApiResponse.method(:create)))
38
+ .execute
59
39
  end
60
40
 
61
41
  # Creates a DeviceCode that can be used to login to a Square Terminal device
@@ -66,32 +46,20 @@ module Square
66
46
  # object definition for field details.
67
47
  # @return [CreateDeviceCodeResponse Hash] response from the API call
68
48
  def create_device_code(body:)
69
- # Prepare query url.
70
- _query_builder = config.get_base_uri
71
- _query_builder << '/v2/devices/codes'
72
- _query_url = APIHelper.clean_url _query_builder
73
-
74
- # Prepare headers.
75
- _headers = {
76
- 'accept' => 'application/json',
77
- 'Content-Type' => 'application/json'
78
- }
79
-
80
- # Prepare and execute HttpRequest.
81
- _request = config.http_client.post(
82
- _query_url,
83
- headers: _headers,
84
- parameters: body.to_json
85
- )
86
- OAuth2.apply(config, _request)
87
- _response = execute_request(_request)
88
-
89
- # Return appropriate response type.
90
- decoded = APIHelper.json_deserialize(_response.raw_body)
91
- _errors = APIHelper.map_response(decoded, ['errors'])
92
- ApiResponse.new(
93
- _response, data: decoded, errors: _errors
94
- )
49
+ new_api_call_builder
50
+ .request(new_request_builder(HttpMethodEnum::POST,
51
+ '/v2/devices/codes',
52
+ 'default')
53
+ .header_param(new_parameter('application/json', key: 'Content-Type'))
54
+ .body_param(new_parameter(body))
55
+ .header_param(new_parameter('application/json', key: 'accept'))
56
+ .body_serializer(proc do |param| param.to_json unless param.nil? end)
57
+ .auth(Single.new('global')))
58
+ .response(new_response_handler
59
+ .deserializer(APIHelper.method(:json_deserialize))
60
+ .is_api_response(true)
61
+ .convertor(ApiResponse.method(:create)))
62
+ .execute
95
63
  end
96
64
 
97
65
  # Retrieves DeviceCode with the associated ID.
@@ -99,34 +67,19 @@ module Square
99
67
  # device code.
100
68
  # @return [GetDeviceCodeResponse Hash] response from the API call
101
69
  def get_device_code(id:)
102
- # Prepare query url.
103
- _query_builder = config.get_base_uri
104
- _query_builder << '/v2/devices/codes/{id}'
105
- _query_builder = APIHelper.append_url_with_template_parameters(
106
- _query_builder,
107
- 'id' => { 'value' => id, 'encode' => true }
108
- )
109
- _query_url = APIHelper.clean_url _query_builder
110
-
111
- # Prepare headers.
112
- _headers = {
113
- 'accept' => 'application/json'
114
- }
115
-
116
- # Prepare and execute HttpRequest.
117
- _request = config.http_client.get(
118
- _query_url,
119
- headers: _headers
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
- )
70
+ new_api_call_builder
71
+ .request(new_request_builder(HttpMethodEnum::GET,
72
+ '/v2/devices/codes/{id}',
73
+ 'default')
74
+ .template_param(new_parameter(id, key: 'id')
75
+ .should_encode(true))
76
+ .header_param(new_parameter('application/json', key: 'accept'))
77
+ .auth(Single.new('global')))
78
+ .response(new_response_handler
79
+ .deserializer(APIHelper.method(:json_deserialize))
80
+ .is_api_response(true)
81
+ .convertor(ApiResponse.method(:create)))
82
+ .execute
130
83
  end
131
84
  end
132
85
  end
@@ -1,10 +1,6 @@
1
1
  module Square
2
2
  # DisputesApi
3
3
  class DisputesApi < BaseApi
4
- def initialize(config, http_call_back: nil)
5
- super(config, http_call_back: http_call_back)
6
- end
7
-
8
4
  # Returns a list of disputes associated with a particular account.
9
5
  # @param [String] cursor Optional parameter: A pagination cursor returned by
10
6
  # a previous call to this endpoint. Provide this cursor to retrieve the next
@@ -21,36 +17,20 @@ module Square
21
17
  def list_disputes(cursor: nil,
22
18
  states: nil,
23
19
  location_id: nil)
24
- # Prepare query url.
25
- _query_builder = config.get_base_uri
26
- _query_builder << '/v2/disputes'
27
- _query_builder = APIHelper.append_url_with_query_parameters(
28
- _query_builder,
29
- 'cursor' => cursor,
30
- 'states' => states,
31
- 'location_id' => location_id
32
- )
33
- _query_url = APIHelper.clean_url _query_builder
34
-
35
- # Prepare headers.
36
- _headers = {
37
- 'accept' => 'application/json'
38
- }
39
-
40
- # Prepare and execute HttpRequest.
41
- _request = config.http_client.get(
42
- _query_url,
43
- headers: _headers
44
- )
45
- OAuth2.apply(config, _request)
46
- _response = execute_request(_request)
47
-
48
- # Return appropriate response type.
49
- decoded = APIHelper.json_deserialize(_response.raw_body)
50
- _errors = APIHelper.map_response(decoded, ['errors'])
51
- ApiResponse.new(
52
- _response, data: decoded, errors: _errors
53
- )
20
+ new_api_call_builder
21
+ .request(new_request_builder(HttpMethodEnum::GET,
22
+ '/v2/disputes',
23
+ 'default')
24
+ .query_param(new_parameter(cursor, key: 'cursor'))
25
+ .query_param(new_parameter(states, key: 'states'))
26
+ .query_param(new_parameter(location_id, key: 'location_id'))
27
+ .header_param(new_parameter('application/json', key: 'accept'))
28
+ .auth(Single.new('global')))
29
+ .response(new_response_handler
30
+ .deserializer(APIHelper.method(:json_deserialize))
31
+ .is_api_response(true)
32
+ .convertor(ApiResponse.method(:create)))
33
+ .execute
54
34
  end
55
35
 
56
36
  # Returns details about a specific dispute.
@@ -58,34 +38,19 @@ module Square
58
38
  # want more details about.
59
39
  # @return [RetrieveDisputeResponse Hash] response from the API call
60
40
  def retrieve_dispute(dispute_id:)
61
- # Prepare query url.
62
- _query_builder = config.get_base_uri
63
- _query_builder << '/v2/disputes/{dispute_id}'
64
- _query_builder = APIHelper.append_url_with_template_parameters(
65
- _query_builder,
66
- 'dispute_id' => { 'value' => dispute_id, 'encode' => true }
67
- )
68
- _query_url = APIHelper.clean_url _query_builder
69
-
70
- # Prepare headers.
71
- _headers = {
72
- 'accept' => 'application/json'
73
- }
74
-
75
- # Prepare and execute HttpRequest.
76
- _request = config.http_client.get(
77
- _query_url,
78
- headers: _headers
79
- )
80
- OAuth2.apply(config, _request)
81
- _response = execute_request(_request)
82
-
83
- # Return appropriate response type.
84
- decoded = APIHelper.json_deserialize(_response.raw_body)
85
- _errors = APIHelper.map_response(decoded, ['errors'])
86
- ApiResponse.new(
87
- _response, data: decoded, errors: _errors
88
- )
41
+ new_api_call_builder
42
+ .request(new_request_builder(HttpMethodEnum::GET,
43
+ '/v2/disputes/{dispute_id}',
44
+ 'default')
45
+ .template_param(new_parameter(dispute_id, key: 'dispute_id')
46
+ .should_encode(true))
47
+ .header_param(new_parameter('application/json', key: 'accept'))
48
+ .auth(Single.new('global')))
49
+ .response(new_response_handler
50
+ .deserializer(APIHelper.method(:json_deserialize))
51
+ .is_api_response(true)
52
+ .convertor(ApiResponse.method(:create)))
53
+ .execute
89
54
  end
90
55
 
91
56
  # Accepts the loss on a dispute. Square returns the disputed amount to the
@@ -98,34 +63,19 @@ module Square
98
63
  # want to accept.
99
64
  # @return [AcceptDisputeResponse Hash] response from the API call
100
65
  def accept_dispute(dispute_id:)
101
- # Prepare query url.
102
- _query_builder = config.get_base_uri
103
- _query_builder << '/v2/disputes/{dispute_id}/accept'
104
- _query_builder = APIHelper.append_url_with_template_parameters(
105
- _query_builder,
106
- 'dispute_id' => { 'value' => dispute_id, 'encode' => true }
107
- )
108
- _query_url = APIHelper.clean_url _query_builder
109
-
110
- # Prepare headers.
111
- _headers = {
112
- 'accept' => 'application/json'
113
- }
114
-
115
- # Prepare and execute HttpRequest.
116
- _request = config.http_client.post(
117
- _query_url,
118
- headers: _headers
119
- )
120
- OAuth2.apply(config, _request)
121
- _response = execute_request(_request)
122
-
123
- # Return appropriate response type.
124
- decoded = APIHelper.json_deserialize(_response.raw_body)
125
- _errors = APIHelper.map_response(decoded, ['errors'])
126
- ApiResponse.new(
127
- _response, data: decoded, errors: _errors
128
- )
66
+ new_api_call_builder
67
+ .request(new_request_builder(HttpMethodEnum::POST,
68
+ '/v2/disputes/{dispute_id}/accept',
69
+ 'default')
70
+ .template_param(new_parameter(dispute_id, key: 'dispute_id')
71
+ .should_encode(true))
72
+ .header_param(new_parameter('application/json', key: 'accept'))
73
+ .auth(Single.new('global')))
74
+ .response(new_response_handler
75
+ .deserializer(APIHelper.method(:json_deserialize))
76
+ .is_api_response(true)
77
+ .convertor(ApiResponse.method(:create)))
78
+ .execute
129
79
  end
130
80
 
131
81
  # Returns a list of evidence associated with a dispute.
@@ -138,38 +88,20 @@ module Square
138
88
  # @return [ListDisputeEvidenceResponse Hash] response from the API call
139
89
  def list_dispute_evidence(dispute_id:,
140
90
  cursor: nil)
141
- # Prepare query url.
142
- _query_builder = config.get_base_uri
143
- _query_builder << '/v2/disputes/{dispute_id}/evidence'
144
- _query_builder = APIHelper.append_url_with_template_parameters(
145
- _query_builder,
146
- 'dispute_id' => { 'value' => dispute_id, 'encode' => true }
147
- )
148
- _query_builder = APIHelper.append_url_with_query_parameters(
149
- _query_builder,
150
- 'cursor' => cursor
151
- )
152
- _query_url = APIHelper.clean_url _query_builder
153
-
154
- # Prepare headers.
155
- _headers = {
156
- 'accept' => 'application/json'
157
- }
158
-
159
- # Prepare and execute HttpRequest.
160
- _request = config.http_client.get(
161
- _query_url,
162
- headers: _headers
163
- )
164
- OAuth2.apply(config, _request)
165
- _response = execute_request(_request)
166
-
167
- # Return appropriate response type.
168
- decoded = APIHelper.json_deserialize(_response.raw_body)
169
- _errors = APIHelper.map_response(decoded, ['errors'])
170
- ApiResponse.new(
171
- _response, data: decoded, errors: _errors
172
- )
91
+ new_api_call_builder
92
+ .request(new_request_builder(HttpMethodEnum::GET,
93
+ '/v2/disputes/{dispute_id}/evidence',
94
+ 'default')
95
+ .template_param(new_parameter(dispute_id, key: 'dispute_id')
96
+ .should_encode(true))
97
+ .query_param(new_parameter(cursor, key: 'cursor'))
98
+ .header_param(new_parameter('application/json', key: 'accept'))
99
+ .auth(Single.new('global')))
100
+ .response(new_response_handler
101
+ .deserializer(APIHelper.method(:json_deserialize))
102
+ .is_api_response(true)
103
+ .convertor(ApiResponse.method(:create)))
104
+ .execute
173
105
  end
174
106
 
175
107
  # Uploads a file to use as evidence in a dispute challenge. The endpoint
@@ -185,56 +117,23 @@ module Square
185
117
  def create_dispute_evidence_file(dispute_id:,
186
118
  request: nil,
187
119
  image_file: nil)
188
- # Prepare query url.
189
- _query_builder = config.get_base_uri
190
- _query_builder << '/v2/disputes/{dispute_id}/evidence-files'
191
- _query_builder = APIHelper.append_url_with_template_parameters(
192
- _query_builder,
193
- 'dispute_id' => { 'value' => dispute_id, 'encode' => true }
194
- )
195
- _query_url = APIHelper.clean_url _query_builder
196
-
197
- if image_file.is_a? FileWrapper
198
- image_file_wrapper = image_file.file
199
- image_file_content_type = image_file.content_type
200
- else
201
- image_file_wrapper = image_file
202
- image_file_content_type = 'image/jpeg'
203
- end
204
-
205
- # Prepare headers.
206
- _headers = {
207
- 'accept' => 'application/json'
208
- }
209
-
210
- # Prepare form parameters.
211
- _parameters = {
212
- 'request' => Faraday::UploadIO.new(
213
- StringIO.new(request.to_json),
214
- 'application/json'
215
- ),
216
- 'image_file' => Faraday::UploadIO.new(
217
- image_file_wrapper,
218
- image_file_content_type
219
- )
220
- }
221
- _parameters = APIHelper.form_encode_parameters(_parameters)
222
-
223
- # Prepare and execute HttpRequest.
224
- _request = config.http_client.post(
225
- _query_url,
226
- headers: _headers,
227
- parameters: _parameters
228
- )
229
- OAuth2.apply(config, _request)
230
- _response = execute_request(_request)
231
-
232
- # Return appropriate response type.
233
- decoded = APIHelper.json_deserialize(_response.raw_body)
234
- _errors = APIHelper.map_response(decoded, ['errors'])
235
- ApiResponse.new(
236
- _response, data: decoded, errors: _errors
237
- )
120
+ new_api_call_builder
121
+ .request(new_request_builder(HttpMethodEnum::POST,
122
+ '/v2/disputes/{dispute_id}/evidence-files',
123
+ 'default')
124
+ .template_param(new_parameter(dispute_id, key: 'dispute_id')
125
+ .should_encode(true))
126
+ .multipart_param(new_parameter(StringIO.new(request.to_json), key: 'request')
127
+ .default_content_type('application/json; charset=utf-8'))
128
+ .multipart_param(new_parameter(image_file, key: 'image_file')
129
+ .default_content_type('image/jpeg'))
130
+ .header_param(new_parameter('application/json', key: 'accept'))
131
+ .auth(Single.new('global')))
132
+ .response(new_response_handler
133
+ .deserializer(APIHelper.method(:json_deserialize))
134
+ .is_api_response(true)
135
+ .convertor(ApiResponse.method(:create)))
136
+ .execute
238
137
  end
239
138
 
240
139
  # Uploads text to use as evidence for a dispute challenge.
@@ -246,36 +145,22 @@ module Square
246
145
  # @return [CreateDisputeEvidenceTextResponse Hash] response from the API call
247
146
  def create_dispute_evidence_text(dispute_id:,
248
147
  body:)
249
- # Prepare query url.
250
- _query_builder = config.get_base_uri
251
- _query_builder << '/v2/disputes/{dispute_id}/evidence-text'
252
- _query_builder = APIHelper.append_url_with_template_parameters(
253
- _query_builder,
254
- 'dispute_id' => { 'value' => dispute_id, 'encode' => true }
255
- )
256
- _query_url = APIHelper.clean_url _query_builder
257
-
258
- # Prepare headers.
259
- _headers = {
260
- 'accept' => 'application/json',
261
- 'Content-Type' => 'application/json'
262
- }
263
-
264
- # Prepare and execute HttpRequest.
265
- _request = config.http_client.post(
266
- _query_url,
267
- headers: _headers,
268
- parameters: body.to_json
269
- )
270
- OAuth2.apply(config, _request)
271
- _response = execute_request(_request)
272
-
273
- # Return appropriate response type.
274
- decoded = APIHelper.json_deserialize(_response.raw_body)
275
- _errors = APIHelper.map_response(decoded, ['errors'])
276
- ApiResponse.new(
277
- _response, data: decoded, errors: _errors
278
- )
148
+ new_api_call_builder
149
+ .request(new_request_builder(HttpMethodEnum::POST,
150
+ '/v2/disputes/{dispute_id}/evidence-text',
151
+ 'default')
152
+ .template_param(new_parameter(dispute_id, key: 'dispute_id')
153
+ .should_encode(true))
154
+ .header_param(new_parameter('application/json', key: 'Content-Type'))
155
+ .body_param(new_parameter(body))
156
+ .header_param(new_parameter('application/json', key: 'accept'))
157
+ .body_serializer(proc do |param| param.to_json unless param.nil? end)
158
+ .auth(Single.new('global')))
159
+ .response(new_response_handler
160
+ .deserializer(APIHelper.method(:json_deserialize))
161
+ .is_api_response(true)
162
+ .convertor(ApiResponse.method(:create)))
163
+ .execute
279
164
  end
280
165
 
281
166
  # Removes specified evidence from a dispute.
@@ -287,35 +172,21 @@ module Square
287
172
  # @return [DeleteDisputeEvidenceResponse Hash] response from the API call
288
173
  def delete_dispute_evidence(dispute_id:,
289
174
  evidence_id:)
290
- # Prepare query url.
291
- _query_builder = config.get_base_uri
292
- _query_builder << '/v2/disputes/{dispute_id}/evidence/{evidence_id}'
293
- _query_builder = APIHelper.append_url_with_template_parameters(
294
- _query_builder,
295
- 'dispute_id' => { 'value' => dispute_id, 'encode' => true },
296
- 'evidence_id' => { 'value' => evidence_id, 'encode' => true }
297
- )
298
- _query_url = APIHelper.clean_url _query_builder
299
-
300
- # Prepare headers.
301
- _headers = {
302
- 'accept' => 'application/json'
303
- }
304
-
305
- # Prepare and execute HttpRequest.
306
- _request = config.http_client.delete(
307
- _query_url,
308
- headers: _headers
309
- )
310
- OAuth2.apply(config, _request)
311
- _response = execute_request(_request)
312
-
313
- # Return appropriate response type.
314
- decoded = APIHelper.json_deserialize(_response.raw_body)
315
- _errors = APIHelper.map_response(decoded, ['errors'])
316
- ApiResponse.new(
317
- _response, data: decoded, errors: _errors
318
- )
175
+ new_api_call_builder
176
+ .request(new_request_builder(HttpMethodEnum::DELETE,
177
+ '/v2/disputes/{dispute_id}/evidence/{evidence_id}',
178
+ 'default')
179
+ .template_param(new_parameter(dispute_id, key: 'dispute_id')
180
+ .should_encode(true))
181
+ .template_param(new_parameter(evidence_id, key: 'evidence_id')
182
+ .should_encode(true))
183
+ .header_param(new_parameter('application/json', key: 'accept'))
184
+ .auth(Single.new('global')))
185
+ .response(new_response_handler
186
+ .deserializer(APIHelper.method(:json_deserialize))
187
+ .is_api_response(true)
188
+ .convertor(ApiResponse.method(:create)))
189
+ .execute
319
190
  end
320
191
 
321
192
  # Returns the metadata for the evidence specified in the request URL path.
@@ -328,35 +199,21 @@ module Square
328
199
  # @return [RetrieveDisputeEvidenceResponse Hash] response from the API call
329
200
  def retrieve_dispute_evidence(dispute_id:,
330
201
  evidence_id:)
331
- # Prepare query url.
332
- _query_builder = config.get_base_uri
333
- _query_builder << '/v2/disputes/{dispute_id}/evidence/{evidence_id}'
334
- _query_builder = APIHelper.append_url_with_template_parameters(
335
- _query_builder,
336
- 'dispute_id' => { 'value' => dispute_id, 'encode' => true },
337
- 'evidence_id' => { 'value' => evidence_id, 'encode' => true }
338
- )
339
- _query_url = APIHelper.clean_url _query_builder
340
-
341
- # Prepare headers.
342
- _headers = {
343
- 'accept' => 'application/json'
344
- }
345
-
346
- # Prepare and execute HttpRequest.
347
- _request = config.http_client.get(
348
- _query_url,
349
- headers: _headers
350
- )
351
- OAuth2.apply(config, _request)
352
- _response = execute_request(_request)
353
-
354
- # Return appropriate response type.
355
- decoded = APIHelper.json_deserialize(_response.raw_body)
356
- _errors = APIHelper.map_response(decoded, ['errors'])
357
- ApiResponse.new(
358
- _response, data: decoded, errors: _errors
359
- )
202
+ new_api_call_builder
203
+ .request(new_request_builder(HttpMethodEnum::GET,
204
+ '/v2/disputes/{dispute_id}/evidence/{evidence_id}',
205
+ 'default')
206
+ .template_param(new_parameter(dispute_id, key: 'dispute_id')
207
+ .should_encode(true))
208
+ .template_param(new_parameter(evidence_id, key: 'evidence_id')
209
+ .should_encode(true))
210
+ .header_param(new_parameter('application/json', key: 'accept'))
211
+ .auth(Single.new('global')))
212
+ .response(new_response_handler
213
+ .deserializer(APIHelper.method(:json_deserialize))
214
+ .is_api_response(true)
215
+ .convertor(ApiResponse.method(:create)))
216
+ .execute
360
217
  end
361
218
 
362
219
  # Submits evidence to the cardholder's bank.
@@ -372,34 +229,19 @@ module Square
372
229
  # which you want to submit evidence.
373
230
  # @return [SubmitEvidenceResponse Hash] response from the API call
374
231
  def submit_evidence(dispute_id:)
375
- # Prepare query url.
376
- _query_builder = config.get_base_uri
377
- _query_builder << '/v2/disputes/{dispute_id}/submit-evidence'
378
- _query_builder = APIHelper.append_url_with_template_parameters(
379
- _query_builder,
380
- 'dispute_id' => { 'value' => dispute_id, 'encode' => true }
381
- )
382
- _query_url = APIHelper.clean_url _query_builder
383
-
384
- # Prepare headers.
385
- _headers = {
386
- 'accept' => 'application/json'
387
- }
388
-
389
- # Prepare and execute HttpRequest.
390
- _request = config.http_client.post(
391
- _query_url,
392
- headers: _headers
393
- )
394
- OAuth2.apply(config, _request)
395
- _response = execute_request(_request)
396
-
397
- # Return appropriate response type.
398
- decoded = APIHelper.json_deserialize(_response.raw_body)
399
- _errors = APIHelper.map_response(decoded, ['errors'])
400
- ApiResponse.new(
401
- _response, data: decoded, errors: _errors
402
- )
232
+ new_api_call_builder
233
+ .request(new_request_builder(HttpMethodEnum::POST,
234
+ '/v2/disputes/{dispute_id}/submit-evidence',
235
+ 'default')
236
+ .template_param(new_parameter(dispute_id, key: 'dispute_id')
237
+ .should_encode(true))
238
+ .header_param(new_parameter('application/json', key: 'accept'))
239
+ .auth(Single.new('global')))
240
+ .response(new_response_handler
241
+ .deserializer(APIHelper.method(:json_deserialize))
242
+ .is_api_response(true)
243
+ .convertor(ApiResponse.method(:create)))
244
+ .execute
403
245
  end
404
246
  end
405
247
  end