square.rb 26.1.0.20230119 → 27.0.0.20230419

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +4 -0
  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 +171 -336
  7. data/lib/square/api/bookings_api.rb +140 -263
  8. data/lib/square/api/cards_api.rb +58 -120
  9. data/lib/square/api/cash_drawers_api.rb +47 -103
  10. data/lib/square/api/catalog_api.rb +200 -426
  11. data/lib/square/api/checkout_api.rb +86 -176
  12. data/lib/square/api/customer_custom_attributes_api.rb +157 -310
  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 +132 -290
  18. data/lib/square/api/employees_api.rb +28 -63
  19. data/lib/square/api/gift_card_activities_api.rb +34 -66
  20. data/lib/square/api/gift_cards_api.rb +109 -207
  21. data/lib/square/api/inventory_api.rb +204 -391
  22. data/lib/square/api/invoices_api.rb +121 -240
  23. data/lib/square/api/labor_api.rb +223 -459
  24. data/lib/square/api/location_custom_attributes_api.rb +173 -338
  25. data/lib/square/api/locations_api.rb +54 -112
  26. data/lib/square/api/loyalty_api.rb +283 -535
  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 +174 -339
  31. data/lib/square/api/orders_api.rb +115 -222
  32. data/lib/square/api/payments_api.rb +118 -217
  33. data/lib/square/api/payouts_api.rb +54 -107
  34. data/lib/square/api/refunds_api.rb +59 -104
  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 +64 -128
  41. data/lib/square/api/v1_transactions_api.rb +155 -296
  42. data/lib/square/api/vendors_api.rb +100 -193
  43. data/lib/square/api/webhook_subscriptions_api.rb +124 -244
  44. data/lib/square/api_helper.rb +1 -437
  45. data/lib/square/client.rb +77 -47
  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 +6 -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 +11 -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
@@ -18,7 +14,7 @@ module Square
18
14
  # card. Otherwise, the endpoint returns all gift card activities for the
19
15
  # seller.
20
16
  # @param [String] type Optional parameter: If a
21
- # [type]($m/GiftCardActivityType) is provided, the endpoint returns gift
17
+ # [type](entity:GiftCardActivityType) is provided, the endpoint returns gift
22
18
  # card activities of the specified type. Otherwise, the endpoint returns
23
19
  # all types of gift card activities.
24
20
  # @param [String] location_id Optional parameter: If a location ID is
@@ -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,19 +1,16 @@
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.
11
- # @param [String] type Optional parameter: If a [type]($m/GiftCardType) is
12
- # provided, the endpoint returns gift cards of the specified type.
7
+ # @param [String] type Optional parameter: If a [type](entity:GiftCardType)
8
+ # is provided, the endpoint returns gift cards of the specified type.
13
9
  # Otherwise, the endpoint returns gift cards of all types.
14
- # @param [String] state Optional parameter: If a [state]($m/GiftCardStatus)
15
- # is provided, the endpoint returns the gift cards in the specified state.
16
- # Otherwise, the endpoint returns the gift cards of all states.
10
+ # @param [String] state Optional parameter: If a
11
+ # [state](entity:GiftCardStatus) is provided, the endpoint returns the gift
12
+ # cards in the specified state. Otherwise, the endpoint returns the gift
13
+ # cards of all states.
17
14
  # @param [Integer] limit Optional parameter: If a limit is provided, the
18
15
  # endpoint returns only the specified number of results per page. The
19
16
  # maximum value is 50. The default value is 30. For more information, see
@@ -34,38 +31,22 @@ module Square
34
31
  limit: nil,
35
32
  cursor: nil,
36
33
  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
- )
34
+ new_api_call_builder
35
+ .request(new_request_builder(HttpMethodEnum::GET,
36
+ '/v2/gift-cards',
37
+ 'default')
38
+ .query_param(new_parameter(type, key: 'type'))
39
+ .query_param(new_parameter(state, key: 'state'))
40
+ .query_param(new_parameter(limit, key: 'limit'))
41
+ .query_param(new_parameter(cursor, key: 'cursor'))
42
+ .query_param(new_parameter(customer_id, key: 'customer_id'))
43
+ .header_param(new_parameter('application/json', key: 'accept'))
44
+ .auth(Single.new('global')))
45
+ .response(new_response_handler
46
+ .deserializer(APIHelper.method(:json_deserialize))
47
+ .is_api_response(true)
48
+ .convertor(ApiResponse.method(:create)))
49
+ .execute
69
50
  end
70
51
 
71
52
  # Creates a digital gift card or registers a physical (plastic) gift card.
@@ -79,32 +60,20 @@ module Square
79
60
  # object definition for field details.
80
61
  # @return [CreateGiftCardResponse Hash] response from the API call
81
62
  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
- )
63
+ new_api_call_builder
64
+ .request(new_request_builder(HttpMethodEnum::POST,
65
+ '/v2/gift-cards',
66
+ 'default')
67
+ .header_param(new_parameter('application/json', key: 'Content-Type'))
68
+ .body_param(new_parameter(body))
69
+ .header_param(new_parameter('application/json', key: 'accept'))
70
+ .body_serializer(proc do |param| param.to_json unless param.nil? end)
71
+ .auth(Single.new('global')))
72
+ .response(new_response_handler
73
+ .deserializer(APIHelper.method(:json_deserialize))
74
+ .is_api_response(true)
75
+ .convertor(ApiResponse.method(:create)))
76
+ .execute
108
77
  end
109
78
 
110
79
  # Retrieves a gift card using the gift card account number (GAN).
@@ -113,32 +82,20 @@ module Square
113
82
  # object definition for field details.
114
83
  # @return [RetrieveGiftCardFromGANResponse Hash] response from the API call
115
84
  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
- )
85
+ new_api_call_builder
86
+ .request(new_request_builder(HttpMethodEnum::POST,
87
+ '/v2/gift-cards/from-gan',
88
+ 'default')
89
+ .header_param(new_parameter('application/json', key: 'Content-Type'))
90
+ .body_param(new_parameter(body))
91
+ .header_param(new_parameter('application/json', key: 'accept'))
92
+ .body_serializer(proc do |param| param.to_json unless param.nil? end)
93
+ .auth(Single.new('global')))
94
+ .response(new_response_handler
95
+ .deserializer(APIHelper.method(:json_deserialize))
96
+ .is_api_response(true)
97
+ .convertor(ApiResponse.method(:create)))
98
+ .execute
142
99
  end
143
100
 
144
101
  # Retrieves a gift card using a secure payment token that represents the
@@ -148,32 +105,20 @@ module Square
148
105
  # corresponding object definition for field details.
149
106
  # @return [RetrieveGiftCardFromNonceResponse Hash] response from the API call
150
107
  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
- )
108
+ new_api_call_builder
109
+ .request(new_request_builder(HttpMethodEnum::POST,
110
+ '/v2/gift-cards/from-nonce',
111
+ 'default')
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
177
122
  end
178
123
 
179
124
  # Links a customer to a gift card, which is also referred to as adding a
@@ -186,36 +131,22 @@ module Square
186
131
  # @return [LinkCustomerToGiftCardResponse Hash] response from the API call
187
132
  def link_customer_to_gift_card(gift_card_id:,
188
133
  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
- )
134
+ new_api_call_builder
135
+ .request(new_request_builder(HttpMethodEnum::POST,
136
+ '/v2/gift-cards/{gift_card_id}/link-customer',
137
+ 'default')
138
+ .template_param(new_parameter(gift_card_id, key: 'gift_card_id')
139
+ .should_encode(true))
140
+ .header_param(new_parameter('application/json', key: 'Content-Type'))
141
+ .body_param(new_parameter(body))
142
+ .header_param(new_parameter('application/json', key: 'accept'))
143
+ .body_serializer(proc do |param| param.to_json unless param.nil? end)
144
+ .auth(Single.new('global')))
145
+ .response(new_response_handler
146
+ .deserializer(APIHelper.method(:json_deserialize))
147
+ .is_api_response(true)
148
+ .convertor(ApiResponse.method(:create)))
149
+ .execute
219
150
  end
220
151
 
221
152
  # Unlinks a customer from a gift card, which is also referred to as removing
@@ -228,36 +159,22 @@ module Square
228
159
  # @return [UnlinkCustomerFromGiftCardResponse Hash] response from the API call
229
160
  def unlink_customer_from_gift_card(gift_card_id:,
230
161
  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
- )
162
+ new_api_call_builder
163
+ .request(new_request_builder(HttpMethodEnum::POST,
164
+ '/v2/gift-cards/{gift_card_id}/unlink-customer',
165
+ 'default')
166
+ .template_param(new_parameter(gift_card_id, key: 'gift_card_id')
167
+ .should_encode(true))
168
+ .header_param(new_parameter('application/json', key: 'Content-Type'))
169
+ .body_param(new_parameter(body))
170
+ .header_param(new_parameter('application/json', key: 'accept'))
171
+ .body_serializer(proc do |param| param.to_json unless param.nil? end)
172
+ .auth(Single.new('global')))
173
+ .response(new_response_handler
174
+ .deserializer(APIHelper.method(:json_deserialize))
175
+ .is_api_response(true)
176
+ .convertor(ApiResponse.method(:create)))
177
+ .execute
261
178
  end
262
179
 
263
180
  # Retrieves a gift card using the gift card ID.
@@ -265,34 +182,19 @@ module Square
265
182
  # retrieve.
266
183
  # @return [RetrieveGiftCardResponse Hash] response from the API call
267
184
  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
- )
185
+ new_api_call_builder
186
+ .request(new_request_builder(HttpMethodEnum::GET,
187
+ '/v2/gift-cards/{id}',
188
+ 'default')
189
+ .template_param(new_parameter(id, key: 'id')
190
+ .should_encode(true))
191
+ .header_param(new_parameter('application/json', key: 'accept'))
192
+ .auth(Single.new('global')))
193
+ .response(new_response_handler
194
+ .deserializer(APIHelper.method(:json_deserialize))
195
+ .is_api_response(true)
196
+ .convertor(ApiResponse.method(:create)))
197
+ .execute
296
198
  end
297
199
  end
298
200
  end