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
  # TeamApi
3
3
  class TeamApi < 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 single `TeamMember` object. The `TeamMember` object is returned
9
5
  # on successful creates.
10
6
  # You must provide the following values in your request to this endpoint:
@@ -18,32 +14,20 @@ module Square
18
14
  # object definition for field details.
19
15
  # @return [CreateTeamMemberResponse Hash] response from the API call
20
16
  def create_team_member(body:)
21
- # Prepare query url.
22
- _query_builder = config.get_base_uri
23
- _query_builder << '/v2/team-members'
24
- _query_url = APIHelper.clean_url _query_builder
25
-
26
- # Prepare headers.
27
- _headers = {
28
- 'accept' => 'application/json',
29
- 'Content-Type' => 'application/json'
30
- }
31
-
32
- # Prepare and execute HttpRequest.
33
- _request = config.http_client.post(
34
- _query_url,
35
- headers: _headers,
36
- parameters: body.to_json
37
- )
38
- OAuth2.apply(config, _request)
39
- _response = execute_request(_request)
40
-
41
- # Return appropriate response type.
42
- decoded = APIHelper.json_deserialize(_response.raw_body)
43
- _errors = APIHelper.map_response(decoded, ['errors'])
44
- ApiResponse.new(
45
- _response, data: decoded, errors: _errors
46
- )
17
+ new_api_call_builder
18
+ .request(new_request_builder(HttpMethodEnum::POST,
19
+ '/v2/team-members',
20
+ 'default')
21
+ .header_param(new_parameter('application/json', key: 'Content-Type'))
22
+ .body_param(new_parameter(body))
23
+ .header_param(new_parameter('application/json', key: 'accept'))
24
+ .body_serializer(proc do |param| param.to_json unless param.nil? end)
25
+ .auth(Single.new('global')))
26
+ .response(new_response_handler
27
+ .deserializer(APIHelper.method(:json_deserialize))
28
+ .is_api_response(true)
29
+ .convertor(ApiResponse.method(:create)))
30
+ .execute
47
31
  end
48
32
 
49
33
  # Creates multiple `TeamMember` objects. The created `TeamMember` objects
@@ -61,32 +45,20 @@ module Square
61
45
  # object definition for field details.
62
46
  # @return [BulkCreateTeamMembersResponse Hash] response from the API call
63
47
  def bulk_create_team_members(body:)
64
- # Prepare query url.
65
- _query_builder = config.get_base_uri
66
- _query_builder << '/v2/team-members/bulk-create'
67
- _query_url = APIHelper.clean_url _query_builder
68
-
69
- # Prepare headers.
70
- _headers = {
71
- 'accept' => 'application/json',
72
- 'Content-Type' => 'application/json'
73
- }
74
-
75
- # Prepare and execute HttpRequest.
76
- _request = config.http_client.post(
77
- _query_url,
78
- headers: _headers,
79
- parameters: body.to_json
80
- )
81
- OAuth2.apply(config, _request)
82
- _response = execute_request(_request)
83
-
84
- # Return appropriate response type.
85
- decoded = APIHelper.json_deserialize(_response.raw_body)
86
- _errors = APIHelper.map_response(decoded, ['errors'])
87
- ApiResponse.new(
88
- _response, data: decoded, errors: _errors
89
- )
48
+ new_api_call_builder
49
+ .request(new_request_builder(HttpMethodEnum::POST,
50
+ '/v2/team-members/bulk-create',
51
+ 'default')
52
+ .header_param(new_parameter('application/json', key: 'Content-Type'))
53
+ .body_param(new_parameter(body))
54
+ .header_param(new_parameter('application/json', key: 'accept'))
55
+ .body_serializer(proc do |param| param.to_json unless param.nil? end)
56
+ .auth(Single.new('global')))
57
+ .response(new_response_handler
58
+ .deserializer(APIHelper.method(:json_deserialize))
59
+ .is_api_response(true)
60
+ .convertor(ApiResponse.method(:create)))
61
+ .execute
90
62
  end
91
63
 
92
64
  # Updates multiple `TeamMember` objects. The updated `TeamMember` objects
@@ -104,32 +76,20 @@ module Square
104
76
  # object definition for field details.
105
77
  # @return [BulkUpdateTeamMembersResponse Hash] response from the API call
106
78
  def bulk_update_team_members(body:)
107
- # Prepare query url.
108
- _query_builder = config.get_base_uri
109
- _query_builder << '/v2/team-members/bulk-update'
110
- _query_url = APIHelper.clean_url _query_builder
111
-
112
- # Prepare headers.
113
- _headers = {
114
- 'accept' => 'application/json',
115
- 'Content-Type' => 'application/json'
116
- }
117
-
118
- # Prepare and execute HttpRequest.
119
- _request = config.http_client.post(
120
- _query_url,
121
- headers: _headers,
122
- parameters: body.to_json
123
- )
124
- OAuth2.apply(config, _request)
125
- _response = execute_request(_request)
126
-
127
- # Return appropriate response type.
128
- decoded = APIHelper.json_deserialize(_response.raw_body)
129
- _errors = APIHelper.map_response(decoded, ['errors'])
130
- ApiResponse.new(
131
- _response, data: decoded, errors: _errors
132
- )
79
+ new_api_call_builder
80
+ .request(new_request_builder(HttpMethodEnum::POST,
81
+ '/v2/team-members/bulk-update',
82
+ 'default')
83
+ .header_param(new_parameter('application/json', key: 'Content-Type'))
84
+ .body_param(new_parameter(body))
85
+ .header_param(new_parameter('application/json', key: 'accept'))
86
+ .body_serializer(proc do |param| param.to_json unless param.nil? end)
87
+ .auth(Single.new('global')))
88
+ .response(new_response_handler
89
+ .deserializer(APIHelper.method(:json_deserialize))
90
+ .is_api_response(true)
91
+ .convertor(ApiResponse.method(:create)))
92
+ .execute
133
93
  end
134
94
 
135
95
  # Returns a paginated list of `TeamMember` objects for a business.
@@ -141,32 +101,20 @@ module Square
141
101
  # object definition for field details.
142
102
  # @return [SearchTeamMembersResponse Hash] response from the API call
143
103
  def search_team_members(body:)
144
- # Prepare query url.
145
- _query_builder = config.get_base_uri
146
- _query_builder << '/v2/team-members/search'
147
- _query_url = APIHelper.clean_url _query_builder
148
-
149
- # Prepare headers.
150
- _headers = {
151
- 'accept' => 'application/json',
152
- 'Content-Type' => 'application/json'
153
- }
154
-
155
- # Prepare and execute HttpRequest.
156
- _request = config.http_client.post(
157
- _query_url,
158
- headers: _headers,
159
- parameters: body.to_json
160
- )
161
- OAuth2.apply(config, _request)
162
- _response = execute_request(_request)
163
-
164
- # Return appropriate response type.
165
- decoded = APIHelper.json_deserialize(_response.raw_body)
166
- _errors = APIHelper.map_response(decoded, ['errors'])
167
- ApiResponse.new(
168
- _response, data: decoded, errors: _errors
169
- )
104
+ new_api_call_builder
105
+ .request(new_request_builder(HttpMethodEnum::POST,
106
+ '/v2/team-members/search',
107
+ 'default')
108
+ .header_param(new_parameter('application/json', key: 'Content-Type'))
109
+ .body_param(new_parameter(body))
110
+ .header_param(new_parameter('application/json', key: 'accept'))
111
+ .body_serializer(proc do |param| param.to_json unless param.nil? end)
112
+ .auth(Single.new('global')))
113
+ .response(new_response_handler
114
+ .deserializer(APIHelper.method(:json_deserialize))
115
+ .is_api_response(true)
116
+ .convertor(ApiResponse.method(:create)))
117
+ .execute
170
118
  end
171
119
 
172
120
  # Retrieves a `TeamMember` object for the given `TeamMember.id`.
@@ -177,34 +125,19 @@ module Square
177
125
  # member to retrieve.
178
126
  # @return [RetrieveTeamMemberResponse Hash] response from the API call
179
127
  def retrieve_team_member(team_member_id:)
180
- # Prepare query url.
181
- _query_builder = config.get_base_uri
182
- _query_builder << '/v2/team-members/{team_member_id}'
183
- _query_builder = APIHelper.append_url_with_template_parameters(
184
- _query_builder,
185
- 'team_member_id' => { 'value' => team_member_id, 'encode' => true }
186
- )
187
- _query_url = APIHelper.clean_url _query_builder
188
-
189
- # Prepare headers.
190
- _headers = {
191
- 'accept' => 'application/json'
192
- }
193
-
194
- # Prepare and execute HttpRequest.
195
- _request = config.http_client.get(
196
- _query_url,
197
- headers: _headers
198
- )
199
- OAuth2.apply(config, _request)
200
- _response = execute_request(_request)
201
-
202
- # Return appropriate response type.
203
- decoded = APIHelper.json_deserialize(_response.raw_body)
204
- _errors = APIHelper.map_response(decoded, ['errors'])
205
- ApiResponse.new(
206
- _response, data: decoded, errors: _errors
207
- )
128
+ new_api_call_builder
129
+ .request(new_request_builder(HttpMethodEnum::GET,
130
+ '/v2/team-members/{team_member_id}',
131
+ 'default')
132
+ .template_param(new_parameter(team_member_id, key: 'team_member_id')
133
+ .should_encode(true))
134
+ .header_param(new_parameter('application/json', key: 'accept'))
135
+ .auth(Single.new('global')))
136
+ .response(new_response_handler
137
+ .deserializer(APIHelper.method(:json_deserialize))
138
+ .is_api_response(true)
139
+ .convertor(ApiResponse.method(:create)))
140
+ .execute
208
141
  end
209
142
 
210
143
  # Updates a single `TeamMember` object. The `TeamMember` object is returned
@@ -220,36 +153,22 @@ module Square
220
153
  # @return [UpdateTeamMemberResponse Hash] response from the API call
221
154
  def update_team_member(team_member_id:,
222
155
  body:)
223
- # Prepare query url.
224
- _query_builder = config.get_base_uri
225
- _query_builder << '/v2/team-members/{team_member_id}'
226
- _query_builder = APIHelper.append_url_with_template_parameters(
227
- _query_builder,
228
- 'team_member_id' => { 'value' => team_member_id, 'encode' => true }
229
- )
230
- _query_url = APIHelper.clean_url _query_builder
231
-
232
- # Prepare headers.
233
- _headers = {
234
- 'accept' => 'application/json',
235
- 'Content-Type' => 'application/json'
236
- }
237
-
238
- # Prepare and execute HttpRequest.
239
- _request = config.http_client.put(
240
- _query_url,
241
- headers: _headers,
242
- parameters: body.to_json
243
- )
244
- OAuth2.apply(config, _request)
245
- _response = execute_request(_request)
246
-
247
- # Return appropriate response type.
248
- decoded = APIHelper.json_deserialize(_response.raw_body)
249
- _errors = APIHelper.map_response(decoded, ['errors'])
250
- ApiResponse.new(
251
- _response, data: decoded, errors: _errors
252
- )
156
+ new_api_call_builder
157
+ .request(new_request_builder(HttpMethodEnum::PUT,
158
+ '/v2/team-members/{team_member_id}',
159
+ 'default')
160
+ .template_param(new_parameter(team_member_id, key: 'team_member_id')
161
+ .should_encode(true))
162
+ .header_param(new_parameter('application/json', key: 'Content-Type'))
163
+ .body_param(new_parameter(body))
164
+ .header_param(new_parameter('application/json', key: 'accept'))
165
+ .body_serializer(proc do |param| param.to_json unless param.nil? end)
166
+ .auth(Single.new('global')))
167
+ .response(new_response_handler
168
+ .deserializer(APIHelper.method(:json_deserialize))
169
+ .is_api_response(true)
170
+ .convertor(ApiResponse.method(:create)))
171
+ .execute
253
172
  end
254
173
 
255
174
  # Retrieves a `WageSetting` object for a team member specified
@@ -261,34 +180,19 @@ module Square
261
180
  # member for which to retrieve the wage setting.
262
181
  # @return [RetrieveWageSettingResponse Hash] response from the API call
263
182
  def retrieve_wage_setting(team_member_id:)
264
- # Prepare query url.
265
- _query_builder = config.get_base_uri
266
- _query_builder << '/v2/team-members/{team_member_id}/wage-setting'
267
- _query_builder = APIHelper.append_url_with_template_parameters(
268
- _query_builder,
269
- 'team_member_id' => { 'value' => team_member_id, 'encode' => true }
270
- )
271
- _query_url = APIHelper.clean_url _query_builder
272
-
273
- # Prepare headers.
274
- _headers = {
275
- 'accept' => 'application/json'
276
- }
277
-
278
- # Prepare and execute HttpRequest.
279
- _request = config.http_client.get(
280
- _query_url,
281
- headers: _headers
282
- )
283
- OAuth2.apply(config, _request)
284
- _response = execute_request(_request)
285
-
286
- # Return appropriate response type.
287
- decoded = APIHelper.json_deserialize(_response.raw_body)
288
- _errors = APIHelper.map_response(decoded, ['errors'])
289
- ApiResponse.new(
290
- _response, data: decoded, errors: _errors
291
- )
183
+ new_api_call_builder
184
+ .request(new_request_builder(HttpMethodEnum::GET,
185
+ '/v2/team-members/{team_member_id}/wage-setting',
186
+ 'default')
187
+ .template_param(new_parameter(team_member_id, key: 'team_member_id')
188
+ .should_encode(true))
189
+ .header_param(new_parameter('application/json', key: 'accept'))
190
+ .auth(Single.new('global')))
191
+ .response(new_response_handler
192
+ .deserializer(APIHelper.method(:json_deserialize))
193
+ .is_api_response(true)
194
+ .convertor(ApiResponse.method(:create)))
195
+ .execute
292
196
  end
293
197
 
294
198
  # Creates or updates a `WageSetting` object. The object is created if a
@@ -307,36 +211,22 @@ module Square
307
211
  # @return [UpdateWageSettingResponse Hash] response from the API call
308
212
  def update_wage_setting(team_member_id:,
309
213
  body:)
310
- # Prepare query url.
311
- _query_builder = config.get_base_uri
312
- _query_builder << '/v2/team-members/{team_member_id}/wage-setting'
313
- _query_builder = APIHelper.append_url_with_template_parameters(
314
- _query_builder,
315
- 'team_member_id' => { 'value' => team_member_id, 'encode' => true }
316
- )
317
- _query_url = APIHelper.clean_url _query_builder
318
-
319
- # Prepare headers.
320
- _headers = {
321
- 'accept' => 'application/json',
322
- 'Content-Type' => 'application/json'
323
- }
324
-
325
- # Prepare and execute HttpRequest.
326
- _request = config.http_client.put(
327
- _query_url,
328
- headers: _headers,
329
- parameters: body.to_json
330
- )
331
- OAuth2.apply(config, _request)
332
- _response = execute_request(_request)
333
-
334
- # Return appropriate response type.
335
- decoded = APIHelper.json_deserialize(_response.raw_body)
336
- _errors = APIHelper.map_response(decoded, ['errors'])
337
- ApiResponse.new(
338
- _response, data: decoded, errors: _errors
339
- )
214
+ new_api_call_builder
215
+ .request(new_request_builder(HttpMethodEnum::PUT,
216
+ '/v2/team-members/{team_member_id}/wage-setting',
217
+ 'default')
218
+ .template_param(new_parameter(team_member_id, key: 'team_member_id')
219
+ .should_encode(true))
220
+ .header_param(new_parameter('application/json', key: 'Content-Type'))
221
+ .body_param(new_parameter(body))
222
+ .header_param(new_parameter('application/json', key: 'accept'))
223
+ .body_serializer(proc do |param| param.to_json unless param.nil? end)
224
+ .auth(Single.new('global')))
225
+ .response(new_response_handler
226
+ .deserializer(APIHelper.method(:json_deserialize))
227
+ .is_api_response(true)
228
+ .convertor(ApiResponse.method(:create)))
229
+ .execute
340
230
  end
341
231
  end
342
232
  end