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
  # EmployeesApi
3
3
  class EmployeesApi < BaseApi
4
- def initialize(config, http_call_back: nil)
5
- super(config, http_call_back: http_call_back)
6
- end
7
-
8
4
  # ListEmployees
9
5
  # @param [String] location_id Optional parameter: Example:
10
6
  # @param [EmployeeStatus] status Optional parameter: Specifies the
@@ -19,37 +15,21 @@ module Square
19
15
  limit: nil,
20
16
  cursor: nil)
21
17
  warn 'Endpoint list_employees in EmployeesApi is deprecated'
22
- # Prepare query url.
23
- _query_builder = config.get_base_uri
24
- _query_builder << '/v2/employees'
25
- _query_builder = APIHelper.append_url_with_query_parameters(
26
- _query_builder,
27
- 'location_id' => location_id,
28
- 'status' => status,
29
- 'limit' => limit,
30
- 'cursor' => cursor
31
- )
32
- _query_url = APIHelper.clean_url _query_builder
33
-
34
- # Prepare headers.
35
- _headers = {
36
- 'accept' => 'application/json'
37
- }
38
-
39
- # Prepare and execute HttpRequest.
40
- _request = config.http_client.get(
41
- _query_url,
42
- headers: _headers
43
- )
44
- OAuth2.apply(config, _request)
45
- _response = execute_request(_request)
46
-
47
- # Return appropriate response type.
48
- decoded = APIHelper.json_deserialize(_response.raw_body)
49
- _errors = APIHelper.map_response(decoded, ['errors'])
50
- ApiResponse.new(
51
- _response, data: decoded, errors: _errors
52
- )
18
+ new_api_call_builder
19
+ .request(new_request_builder(HttpMethodEnum::GET,
20
+ '/v2/employees',
21
+ 'default')
22
+ .query_param(new_parameter(location_id, key: 'location_id'))
23
+ .query_param(new_parameter(status, key: 'status'))
24
+ .query_param(new_parameter(limit, key: 'limit'))
25
+ .query_param(new_parameter(cursor, key: 'cursor'))
26
+ .header_param(new_parameter('application/json', key: 'accept'))
27
+ .auth(Single.new('global')))
28
+ .response(new_response_handler
29
+ .deserializer(APIHelper.method(:json_deserialize))
30
+ .is_api_response(true)
31
+ .convertor(ApiResponse.method(:create)))
32
+ .execute
53
33
  end
54
34
 
55
35
  # RetrieveEmployee
@@ -58,34 +38,19 @@ module Square
58
38
  # @return [RetrieveEmployeeResponse Hash] response from the API call
59
39
  def retrieve_employee(id:)
60
40
  warn 'Endpoint retrieve_employee in EmployeesApi is deprecated'
61
- # Prepare query url.
62
- _query_builder = config.get_base_uri
63
- _query_builder << '/v2/employees/{id}'
64
- _query_builder = APIHelper.append_url_with_template_parameters(
65
- _query_builder,
66
- 'id' => { 'value' => 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/employees/{id}',
44
+ 'default')
45
+ .template_param(new_parameter(id, key: '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
  end
91
56
  end
@@ -1,10 +1,6 @@
1
1
  module Square
2
2
  # GiftCardActivitiesApi
3
3
  class GiftCardActivitiesApi < BaseApi
4
- def initialize(config, http_call_back: nil)
5
- super(config, http_call_back: http_call_back)
6
- end
7
-
8
4
  # Lists gift card activities. By default, you get gift card activities for
9
5
  # all
10
6
  # gift cards in the seller's account. You can optionally specify query
@@ -54,41 +50,25 @@ module Square
54
50
  limit: nil,
55
51
  cursor: nil,
56
52
  sort_order: nil)
57
- # Prepare query url.
58
- _query_builder = config.get_base_uri
59
- _query_builder << '/v2/gift-cards/activities'
60
- _query_builder = APIHelper.append_url_with_query_parameters(
61
- _query_builder,
62
- 'gift_card_id' => gift_card_id,
63
- 'type' => type,
64
- 'location_id' => location_id,
65
- 'begin_time' => begin_time,
66
- 'end_time' => end_time,
67
- 'limit' => limit,
68
- 'cursor' => cursor,
69
- 'sort_order' => sort_order
70
- )
71
- _query_url = APIHelper.clean_url _query_builder
72
-
73
- # Prepare headers.
74
- _headers = {
75
- 'accept' => 'application/json'
76
- }
77
-
78
- # Prepare and execute HttpRequest.
79
- _request = config.http_client.get(
80
- _query_url,
81
- headers: _headers
82
- )
83
- OAuth2.apply(config, _request)
84
- _response = execute_request(_request)
85
-
86
- # Return appropriate response type.
87
- decoded = APIHelper.json_deserialize(_response.raw_body)
88
- _errors = APIHelper.map_response(decoded, ['errors'])
89
- ApiResponse.new(
90
- _response, data: decoded, errors: _errors
91
- )
53
+ new_api_call_builder
54
+ .request(new_request_builder(HttpMethodEnum::GET,
55
+ '/v2/gift-cards/activities',
56
+ 'default')
57
+ .query_param(new_parameter(gift_card_id, key: 'gift_card_id'))
58
+ .query_param(new_parameter(type, key: 'type'))
59
+ .query_param(new_parameter(location_id, key: 'location_id'))
60
+ .query_param(new_parameter(begin_time, key: 'begin_time'))
61
+ .query_param(new_parameter(end_time, key: 'end_time'))
62
+ .query_param(new_parameter(limit, key: 'limit'))
63
+ .query_param(new_parameter(cursor, key: 'cursor'))
64
+ .query_param(new_parameter(sort_order, key: 'sort_order'))
65
+ .header_param(new_parameter('application/json', key: 'accept'))
66
+ .auth(Single.new('global')))
67
+ .response(new_response_handler
68
+ .deserializer(APIHelper.method(:json_deserialize))
69
+ .is_api_response(true)
70
+ .convertor(ApiResponse.method(:create)))
71
+ .execute
92
72
  end
93
73
 
94
74
  # Creates a gift card activity to manage the balance or state of a [gift
@@ -101,32 +81,20 @@ module Square
101
81
  # object definition for field details.
102
82
  # @return [CreateGiftCardActivityResponse Hash] response from the API call
103
83
  def create_gift_card_activity(body:)
104
- # Prepare query url.
105
- _query_builder = config.get_base_uri
106
- _query_builder << '/v2/gift-cards/activities'
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
- )
84
+ new_api_call_builder
85
+ .request(new_request_builder(HttpMethodEnum::POST,
86
+ '/v2/gift-cards/activities',
87
+ 'default')
88
+ .header_param(new_parameter('application/json', key: 'Content-Type'))
89
+ .body_param(new_parameter(body))
90
+ .header_param(new_parameter('application/json', key: 'accept'))
91
+ .body_serializer(proc do |param| param.to_json unless param.nil? end)
92
+ .auth(Single.new('global')))
93
+ .response(new_response_handler
94
+ .deserializer(APIHelper.method(:json_deserialize))
95
+ .is_api_response(true)
96
+ .convertor(ApiResponse.method(:create)))
97
+ .execute
130
98
  end
131
99
  end
132
100
  end
@@ -1,10 +1,6 @@
1
1
  module Square
2
2
  # GiftCardsApi
3
3
  class GiftCardsApi < 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 gift cards. You can specify optional filters to retrieve
9
5
  # a subset of the gift cards. Results are sorted by `created_at` in
10
6
  # ascending order.
@@ -34,38 +30,22 @@ module Square
34
30
  limit: nil,
35
31
  cursor: nil,
36
32
  customer_id: nil)
37
- # Prepare query url.
38
- _query_builder = config.get_base_uri
39
- _query_builder << '/v2/gift-cards'
40
- _query_builder = APIHelper.append_url_with_query_parameters(
41
- _query_builder,
42
- 'type' => type,
43
- 'state' => state,
44
- 'limit' => limit,
45
- 'cursor' => cursor,
46
- 'customer_id' => customer_id
47
- )
48
- _query_url = APIHelper.clean_url _query_builder
49
-
50
- # Prepare headers.
51
- _headers = {
52
- 'accept' => 'application/json'
53
- }
54
-
55
- # Prepare and execute HttpRequest.
56
- _request = config.http_client.get(
57
- _query_url,
58
- headers: _headers
59
- )
60
- OAuth2.apply(config, _request)
61
- _response = execute_request(_request)
62
-
63
- # Return appropriate response type.
64
- decoded = APIHelper.json_deserialize(_response.raw_body)
65
- _errors = APIHelper.map_response(decoded, ['errors'])
66
- ApiResponse.new(
67
- _response, data: decoded, errors: _errors
68
- )
33
+ new_api_call_builder
34
+ .request(new_request_builder(HttpMethodEnum::GET,
35
+ '/v2/gift-cards',
36
+ 'default')
37
+ .query_param(new_parameter(type, key: 'type'))
38
+ .query_param(new_parameter(state, key: 'state'))
39
+ .query_param(new_parameter(limit, key: 'limit'))
40
+ .query_param(new_parameter(cursor, key: 'cursor'))
41
+ .query_param(new_parameter(customer_id, key: 'customer_id'))
42
+ .header_param(new_parameter('application/json', key: 'accept'))
43
+ .auth(Single.new('global')))
44
+ .response(new_response_handler
45
+ .deserializer(APIHelper.method(:json_deserialize))
46
+ .is_api_response(true)
47
+ .convertor(ApiResponse.method(:create)))
48
+ .execute
69
49
  end
70
50
 
71
51
  # Creates a digital gift card or registers a physical (plastic) gift card.
@@ -79,32 +59,20 @@ module Square
79
59
  # object definition for field details.
80
60
  # @return [CreateGiftCardResponse Hash] response from the API call
81
61
  def create_gift_card(body:)
82
- # Prepare query url.
83
- _query_builder = config.get_base_uri
84
- _query_builder << '/v2/gift-cards'
85
- _query_url = APIHelper.clean_url _query_builder
86
-
87
- # Prepare headers.
88
- _headers = {
89
- 'accept' => 'application/json',
90
- 'Content-Type' => 'application/json'
91
- }
92
-
93
- # Prepare and execute HttpRequest.
94
- _request = config.http_client.post(
95
- _query_url,
96
- headers: _headers,
97
- parameters: body.to_json
98
- )
99
- OAuth2.apply(config, _request)
100
- _response = execute_request(_request)
101
-
102
- # Return appropriate response type.
103
- decoded = APIHelper.json_deserialize(_response.raw_body)
104
- _errors = APIHelper.map_response(decoded, ['errors'])
105
- ApiResponse.new(
106
- _response, data: decoded, errors: _errors
107
- )
62
+ new_api_call_builder
63
+ .request(new_request_builder(HttpMethodEnum::POST,
64
+ '/v2/gift-cards',
65
+ 'default')
66
+ .header_param(new_parameter('application/json', key: 'Content-Type'))
67
+ .body_param(new_parameter(body))
68
+ .header_param(new_parameter('application/json', key: 'accept'))
69
+ .body_serializer(proc do |param| param.to_json unless param.nil? end)
70
+ .auth(Single.new('global')))
71
+ .response(new_response_handler
72
+ .deserializer(APIHelper.method(:json_deserialize))
73
+ .is_api_response(true)
74
+ .convertor(ApiResponse.method(:create)))
75
+ .execute
108
76
  end
109
77
 
110
78
  # Retrieves a gift card using the gift card account number (GAN).
@@ -113,32 +81,20 @@ module Square
113
81
  # object definition for field details.
114
82
  # @return [RetrieveGiftCardFromGANResponse Hash] response from the API call
115
83
  def retrieve_gift_card_from_gan(body:)
116
- # Prepare query url.
117
- _query_builder = config.get_base_uri
118
- _query_builder << '/v2/gift-cards/from-gan'
119
- _query_url = APIHelper.clean_url _query_builder
120
-
121
- # Prepare headers.
122
- _headers = {
123
- 'accept' => 'application/json',
124
- 'Content-Type' => 'application/json'
125
- }
126
-
127
- # Prepare and execute HttpRequest.
128
- _request = config.http_client.post(
129
- _query_url,
130
- headers: _headers,
131
- parameters: body.to_json
132
- )
133
- OAuth2.apply(config, _request)
134
- _response = execute_request(_request)
135
-
136
- # Return appropriate response type.
137
- decoded = APIHelper.json_deserialize(_response.raw_body)
138
- _errors = APIHelper.map_response(decoded, ['errors'])
139
- ApiResponse.new(
140
- _response, data: decoded, errors: _errors
141
- )
84
+ new_api_call_builder
85
+ .request(new_request_builder(HttpMethodEnum::POST,
86
+ '/v2/gift-cards/from-gan',
87
+ 'default')
88
+ .header_param(new_parameter('application/json', key: 'Content-Type'))
89
+ .body_param(new_parameter(body))
90
+ .header_param(new_parameter('application/json', key: 'accept'))
91
+ .body_serializer(proc do |param| param.to_json unless param.nil? end)
92
+ .auth(Single.new('global')))
93
+ .response(new_response_handler
94
+ .deserializer(APIHelper.method(:json_deserialize))
95
+ .is_api_response(true)
96
+ .convertor(ApiResponse.method(:create)))
97
+ .execute
142
98
  end
143
99
 
144
100
  # Retrieves a gift card using a secure payment token that represents the
@@ -148,32 +104,20 @@ module Square
148
104
  # corresponding object definition for field details.
149
105
  # @return [RetrieveGiftCardFromNonceResponse Hash] response from the API call
150
106
  def retrieve_gift_card_from_nonce(body:)
151
- # Prepare query url.
152
- _query_builder = config.get_base_uri
153
- _query_builder << '/v2/gift-cards/from-nonce'
154
- _query_url = APIHelper.clean_url _query_builder
155
-
156
- # Prepare headers.
157
- _headers = {
158
- 'accept' => 'application/json',
159
- 'Content-Type' => 'application/json'
160
- }
161
-
162
- # Prepare and execute HttpRequest.
163
- _request = config.http_client.post(
164
- _query_url,
165
- headers: _headers,
166
- parameters: body.to_json
167
- )
168
- OAuth2.apply(config, _request)
169
- _response = execute_request(_request)
170
-
171
- # Return appropriate response type.
172
- decoded = APIHelper.json_deserialize(_response.raw_body)
173
- _errors = APIHelper.map_response(decoded, ['errors'])
174
- ApiResponse.new(
175
- _response, data: decoded, errors: _errors
176
- )
107
+ new_api_call_builder
108
+ .request(new_request_builder(HttpMethodEnum::POST,
109
+ '/v2/gift-cards/from-nonce',
110
+ 'default')
111
+ .header_param(new_parameter('application/json', key: 'Content-Type'))
112
+ .body_param(new_parameter(body))
113
+ .header_param(new_parameter('application/json', key: 'accept'))
114
+ .body_serializer(proc do |param| param.to_json unless param.nil? end)
115
+ .auth(Single.new('global')))
116
+ .response(new_response_handler
117
+ .deserializer(APIHelper.method(:json_deserialize))
118
+ .is_api_response(true)
119
+ .convertor(ApiResponse.method(:create)))
120
+ .execute
177
121
  end
178
122
 
179
123
  # Links a customer to a gift card, which is also referred to as adding a
@@ -186,36 +130,22 @@ module Square
186
130
  # @return [LinkCustomerToGiftCardResponse Hash] response from the API call
187
131
  def link_customer_to_gift_card(gift_card_id:,
188
132
  body:)
189
- # Prepare query url.
190
- _query_builder = config.get_base_uri
191
- _query_builder << '/v2/gift-cards/{gift_card_id}/link-customer'
192
- _query_builder = APIHelper.append_url_with_template_parameters(
193
- _query_builder,
194
- 'gift_card_id' => { 'value' => gift_card_id, 'encode' => true }
195
- )
196
- _query_url = APIHelper.clean_url _query_builder
197
-
198
- # Prepare headers.
199
- _headers = {
200
- 'accept' => 'application/json',
201
- 'Content-Type' => 'application/json'
202
- }
203
-
204
- # Prepare and execute HttpRequest.
205
- _request = config.http_client.post(
206
- _query_url,
207
- headers: _headers,
208
- parameters: body.to_json
209
- )
210
- OAuth2.apply(config, _request)
211
- _response = execute_request(_request)
212
-
213
- # Return appropriate response type.
214
- decoded = APIHelper.json_deserialize(_response.raw_body)
215
- _errors = APIHelper.map_response(decoded, ['errors'])
216
- ApiResponse.new(
217
- _response, data: decoded, errors: _errors
218
- )
133
+ new_api_call_builder
134
+ .request(new_request_builder(HttpMethodEnum::POST,
135
+ '/v2/gift-cards/{gift_card_id}/link-customer',
136
+ 'default')
137
+ .template_param(new_parameter(gift_card_id, key: 'gift_card_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
219
149
  end
220
150
 
221
151
  # Unlinks a customer from a gift card, which is also referred to as removing
@@ -228,36 +158,22 @@ module Square
228
158
  # @return [UnlinkCustomerFromGiftCardResponse Hash] response from the API call
229
159
  def unlink_customer_from_gift_card(gift_card_id:,
230
160
  body:)
231
- # Prepare query url.
232
- _query_builder = config.get_base_uri
233
- _query_builder << '/v2/gift-cards/{gift_card_id}/unlink-customer'
234
- _query_builder = APIHelper.append_url_with_template_parameters(
235
- _query_builder,
236
- 'gift_card_id' => { 'value' => gift_card_id, 'encode' => true }
237
- )
238
- _query_url = APIHelper.clean_url _query_builder
239
-
240
- # Prepare headers.
241
- _headers = {
242
- 'accept' => 'application/json',
243
- 'Content-Type' => 'application/json'
244
- }
245
-
246
- # Prepare and execute HttpRequest.
247
- _request = config.http_client.post(
248
- _query_url,
249
- headers: _headers,
250
- parameters: body.to_json
251
- )
252
- OAuth2.apply(config, _request)
253
- _response = execute_request(_request)
254
-
255
- # Return appropriate response type.
256
- decoded = APIHelper.json_deserialize(_response.raw_body)
257
- _errors = APIHelper.map_response(decoded, ['errors'])
258
- ApiResponse.new(
259
- _response, data: decoded, errors: _errors
260
- )
161
+ new_api_call_builder
162
+ .request(new_request_builder(HttpMethodEnum::POST,
163
+ '/v2/gift-cards/{gift_card_id}/unlink-customer',
164
+ 'default')
165
+ .template_param(new_parameter(gift_card_id, key: 'gift_card_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
261
177
  end
262
178
 
263
179
  # Retrieves a gift card using the gift card ID.
@@ -265,34 +181,19 @@ module Square
265
181
  # retrieve.
266
182
  # @return [RetrieveGiftCardResponse Hash] response from the API call
267
183
  def retrieve_gift_card(id:)
268
- # Prepare query url.
269
- _query_builder = config.get_base_uri
270
- _query_builder << '/v2/gift-cards/{id}'
271
- _query_builder = APIHelper.append_url_with_template_parameters(
272
- _query_builder,
273
- 'id' => { 'value' => id, 'encode' => true }
274
- )
275
- _query_url = APIHelper.clean_url _query_builder
276
-
277
- # Prepare headers.
278
- _headers = {
279
- 'accept' => 'application/json'
280
- }
281
-
282
- # Prepare and execute HttpRequest.
283
- _request = config.http_client.get(
284
- _query_url,
285
- headers: _headers
286
- )
287
- OAuth2.apply(config, _request)
288
- _response = execute_request(_request)
289
-
290
- # Return appropriate response type.
291
- decoded = APIHelper.json_deserialize(_response.raw_body)
292
- _errors = APIHelper.map_response(decoded, ['errors'])
293
- ApiResponse.new(
294
- _response, data: decoded, errors: _errors
295
- )
184
+ new_api_call_builder
185
+ .request(new_request_builder(HttpMethodEnum::GET,
186
+ '/v2/gift-cards/{id}',
187
+ 'default')
188
+ .template_param(new_parameter(id, key: 'id')
189
+ .should_encode(true))
190
+ .header_param(new_parameter('application/json', key: 'accept'))
191
+ .auth(Single.new('global')))
192
+ .response(new_response_handler
193
+ .deserializer(APIHelper.method(:json_deserialize))
194
+ .is_api_response(true)
195
+ .convertor(ApiResponse.method(:create)))
196
+ .execute
296
197
  end
297
198
  end
298
199
  end