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
  # MerchantsApi
3
3
  class MerchantsApi < BaseApi
4
- def initialize(config, http_call_back: nil)
5
- super(config, http_call_back: http_call_back)
6
- end
7
-
8
4
  # Provides details about the merchant associated with a given access token.
9
5
  # The access token used to connect your application to a Square seller is
10
6
  # associated
@@ -20,34 +16,18 @@ module Square
20
16
  # previous response.
21
17
  # @return [ListMerchantsResponse Hash] response from the API call
22
18
  def list_merchants(cursor: nil)
23
- # Prepare query url.
24
- _query_builder = config.get_base_uri
25
- _query_builder << '/v2/merchants'
26
- _query_builder = APIHelper.append_url_with_query_parameters(
27
- _query_builder,
28
- 'cursor' => cursor
29
- )
30
- _query_url = APIHelper.clean_url _query_builder
31
-
32
- # Prepare headers.
33
- _headers = {
34
- 'accept' => 'application/json'
35
- }
36
-
37
- # Prepare and execute HttpRequest.
38
- _request = config.http_client.get(
39
- _query_url,
40
- headers: _headers
41
- )
42
- OAuth2.apply(config, _request)
43
- _response = execute_request(_request)
44
-
45
- # Return appropriate response type.
46
- decoded = APIHelper.json_deserialize(_response.raw_body)
47
- _errors = APIHelper.map_response(decoded, ['errors'])
48
- ApiResponse.new(
49
- _response, data: decoded, errors: _errors
50
- )
19
+ new_api_call_builder
20
+ .request(new_request_builder(HttpMethodEnum::GET,
21
+ '/v2/merchants',
22
+ 'default')
23
+ .query_param(new_parameter(cursor, key: 'cursor'))
24
+ .header_param(new_parameter('application/json', key: 'accept'))
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
51
31
  end
52
32
 
53
33
  # Retrieves the `Merchant` object for the given `merchant_id`.
@@ -56,34 +36,19 @@ module Square
56
36
  # merchant that is currently accessible to this call.
57
37
  # @return [RetrieveMerchantResponse Hash] response from the API call
58
38
  def retrieve_merchant(merchant_id:)
59
- # Prepare query url.
60
- _query_builder = config.get_base_uri
61
- _query_builder << '/v2/merchants/{merchant_id}'
62
- _query_builder = APIHelper.append_url_with_template_parameters(
63
- _query_builder,
64
- 'merchant_id' => { 'value' => merchant_id, 'encode' => true }
65
- )
66
- _query_url = APIHelper.clean_url _query_builder
67
-
68
- # Prepare headers.
69
- _headers = {
70
- 'accept' => 'application/json'
71
- }
72
-
73
- # Prepare and execute HttpRequest.
74
- _request = config.http_client.get(
75
- _query_url,
76
- headers: _headers
77
- )
78
- OAuth2.apply(config, _request)
79
- _response = execute_request(_request)
80
-
81
- # Return appropriate response type.
82
- decoded = APIHelper.json_deserialize(_response.raw_body)
83
- _errors = APIHelper.map_response(decoded, ['errors'])
84
- ApiResponse.new(
85
- _response, data: decoded, errors: _errors
86
- )
39
+ new_api_call_builder
40
+ .request(new_request_builder(HttpMethodEnum::GET,
41
+ '/v2/merchants/{merchant_id}',
42
+ 'default')
43
+ .template_param(new_parameter(merchant_id, key: 'merchant_id')
44
+ .should_encode(true))
45
+ .header_param(new_parameter('application/json', key: 'accept'))
46
+ .auth(Single.new('global')))
47
+ .response(new_response_handler
48
+ .deserializer(APIHelper.method(:json_deserialize))
49
+ .is_api_response(true)
50
+ .convertor(ApiResponse.method(:create)))
51
+ .execute
87
52
  end
88
53
  end
89
54
  end
@@ -1,10 +1,6 @@
1
1
  module Square
2
2
  # MobileAuthorizationApi
3
3
  class MobileAuthorizationApi < BaseApi
4
- def initialize(config, http_call_back: nil)
5
- super(config, http_call_back: http_call_back)
6
- end
7
-
8
4
  # Generates code to authorize a mobile application to connect to a Square
9
5
  # card reader.
10
6
  # Authorization codes are one-time-use codes and expire 60 minutes after
@@ -23,32 +19,20 @@ module Square
23
19
  # corresponding object definition for field details.
24
20
  # @return [CreateMobileAuthorizationCodeResponse Hash] response from the API call
25
21
  def create_mobile_authorization_code(body:)
26
- # Prepare query url.
27
- _query_builder = config.get_base_uri
28
- _query_builder << '/mobile/authorization-code'
29
- _query_url = APIHelper.clean_url _query_builder
30
-
31
- # Prepare headers.
32
- _headers = {
33
- 'accept' => 'application/json',
34
- 'Content-Type' => 'application/json'
35
- }
36
-
37
- # Prepare and execute HttpRequest.
38
- _request = config.http_client.post(
39
- _query_url,
40
- headers: _headers,
41
- parameters: body.to_json
42
- )
43
- OAuth2.apply(config, _request)
44
- _response = execute_request(_request)
45
-
46
- # Return appropriate response type.
47
- decoded = APIHelper.json_deserialize(_response.raw_body)
48
- _errors = APIHelper.map_response(decoded, ['errors'])
49
- ApiResponse.new(
50
- _response, data: decoded, errors: _errors
51
- )
22
+ new_api_call_builder
23
+ .request(new_request_builder(HttpMethodEnum::POST,
24
+ '/mobile/authorization-code',
25
+ 'default')
26
+ .header_param(new_parameter('application/json', key: 'Content-Type'))
27
+ .body_param(new_parameter(body))
28
+ .header_param(new_parameter('application/json', key: 'accept'))
29
+ .body_serializer(proc do |param| param.to_json unless param.nil? end)
30
+ .auth(Single.new('global')))
31
+ .response(new_response_handler
32
+ .deserializer(APIHelper.method(:json_deserialize))
33
+ .is_api_response(true)
34
+ .convertor(ApiResponse.method(:create)))
35
+ .execute
52
36
  end
53
37
  end
54
38
  end
@@ -1,10 +1,6 @@
1
1
  module Square
2
2
  # OAuthApi
3
3
  class OAuthApi < BaseApi
4
- def initialize(config, http_call_back: nil)
5
- super(config, http_call_back: http_call_back)
6
- end
7
-
8
4
  # `RenewToken` is deprecated. For information about refreshing OAuth access
9
5
  # tokens, see
10
6
  # [Migrate from Renew to Refresh OAuth
@@ -39,36 +35,22 @@ module Square
39
35
  body:,
40
36
  authorization:)
41
37
  warn 'Endpoint renew_token in OAuthApi is deprecated'
42
- # Prepare query url.
43
- _query_builder = config.get_base_uri
44
- _query_builder << '/oauth2/clients/{client_id}/access-token/renew'
45
- _query_builder = APIHelper.append_url_with_template_parameters(
46
- _query_builder,
47
- 'client_id' => { 'value' => client_id, 'encode' => true }
48
- )
49
- _query_url = APIHelper.clean_url _query_builder
50
-
51
- # Prepare headers.
52
- _headers = {
53
- 'accept' => 'application/json',
54
- 'Content-Type' => 'application/json',
55
- 'Authorization' => authorization
56
- }
57
-
58
- # Prepare and execute HttpRequest.
59
- _request = config.http_client.post(
60
- _query_url,
61
- headers: _headers,
62
- parameters: body.to_json
63
- )
64
- _response = execute_request(_request)
65
-
66
- # Return appropriate response type.
67
- decoded = APIHelper.json_deserialize(_response.raw_body)
68
- _errors = APIHelper.map_response(decoded, ['errors'])
69
- ApiResponse.new(
70
- _response, data: decoded, errors: _errors
71
- )
38
+ new_api_call_builder
39
+ .request(new_request_builder(HttpMethodEnum::POST,
40
+ '/oauth2/clients/{client_id}/access-token/renew',
41
+ 'default')
42
+ .template_param(new_parameter(client_id, key: 'client_id')
43
+ .should_encode(true))
44
+ .header_param(new_parameter('application/json', key: 'Content-Type'))
45
+ .body_param(new_parameter(body))
46
+ .header_param(new_parameter(authorization, key: 'Authorization'))
47
+ .header_param(new_parameter('application/json', key: 'accept'))
48
+ .body_serializer(proc do |param| param.to_json unless param.nil? end))
49
+ .response(new_response_handler
50
+ .deserializer(APIHelper.method(:json_deserialize))
51
+ .is_api_response(true)
52
+ .convertor(ApiResponse.method(:create)))
53
+ .execute
72
54
  end
73
55
 
74
56
  # Revokes an access token generated with the OAuth flow.
@@ -93,32 +75,20 @@ module Square
93
75
  # @return [RevokeTokenResponse Hash] response from the API call
94
76
  def revoke_token(body:,
95
77
  authorization:)
96
- # Prepare query url.
97
- _query_builder = config.get_base_uri
98
- _query_builder << '/oauth2/revoke'
99
- _query_url = APIHelper.clean_url _query_builder
100
-
101
- # Prepare headers.
102
- _headers = {
103
- 'accept' => 'application/json',
104
- 'Content-Type' => 'application/json',
105
- 'Authorization' => authorization
106
- }
107
-
108
- # Prepare and execute HttpRequest.
109
- _request = config.http_client.post(
110
- _query_url,
111
- headers: _headers,
112
- parameters: body.to_json
113
- )
114
- _response = execute_request(_request)
115
-
116
- # Return appropriate response type.
117
- decoded = APIHelper.json_deserialize(_response.raw_body)
118
- _errors = APIHelper.map_response(decoded, ['errors'])
119
- ApiResponse.new(
120
- _response, data: decoded, errors: _errors
121
- )
78
+ new_api_call_builder
79
+ .request(new_request_builder(HttpMethodEnum::POST,
80
+ '/oauth2/revoke',
81
+ 'default')
82
+ .header_param(new_parameter('application/json', key: 'Content-Type'))
83
+ .body_param(new_parameter(body))
84
+ .header_param(new_parameter(authorization, key: 'Authorization'))
85
+ .header_param(new_parameter('application/json', key: 'accept'))
86
+ .body_serializer(proc do |param| param.to_json unless param.nil? end))
87
+ .response(new_response_handler
88
+ .deserializer(APIHelper.method(:json_deserialize))
89
+ .is_api_response(true)
90
+ .convertor(ApiResponse.method(:create)))
91
+ .execute
122
92
  end
123
93
 
124
94
  # Returns an OAuth access token and a refresh token unless the
@@ -142,31 +112,19 @@ module Square
142
112
  # definition for field details.
143
113
  # @return [ObtainTokenResponse Hash] response from the API call
144
114
  def obtain_token(body:)
145
- # Prepare query url.
146
- _query_builder = config.get_base_uri
147
- _query_builder << '/oauth2/token'
148
- _query_url = APIHelper.clean_url _query_builder
149
-
150
- # Prepare headers.
151
- _headers = {
152
- 'accept' => 'application/json',
153
- 'Content-Type' => 'application/json'
154
- }
155
-
156
- # Prepare and execute HttpRequest.
157
- _request = config.http_client.post(
158
- _query_url,
159
- headers: _headers,
160
- parameters: body.to_json
161
- )
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
- )
115
+ new_api_call_builder
116
+ .request(new_request_builder(HttpMethodEnum::POST,
117
+ '/oauth2/token',
118
+ 'default')
119
+ .header_param(new_parameter('application/json', key: 'Content-Type'))
120
+ .body_param(new_parameter(body))
121
+ .header_param(new_parameter('application/json', key: 'accept'))
122
+ .body_serializer(proc do |param| param.to_json unless param.nil? end))
123
+ .response(new_response_handler
124
+ .deserializer(APIHelper.method(:json_deserialize))
125
+ .is_api_response(true)
126
+ .convertor(ApiResponse.method(:create)))
127
+ .execute
170
128
  end
171
129
 
172
130
  # Returns information about an [OAuth access
@@ -190,30 +148,17 @@ module Square
190
148
  # APPLICATION_SECRET
191
149
  # @return [RetrieveTokenStatusResponse Hash] response from the API call
192
150
  def retrieve_token_status(authorization:)
193
- # Prepare query url.
194
- _query_builder = config.get_base_uri
195
- _query_builder << '/oauth2/token/status'
196
- _query_url = APIHelper.clean_url _query_builder
197
-
198
- # Prepare headers.
199
- _headers = {
200
- 'accept' => 'application/json',
201
- 'Authorization' => authorization
202
- }
203
-
204
- # Prepare and execute HttpRequest.
205
- _request = config.http_client.post(
206
- _query_url,
207
- headers: _headers
208
- )
209
- _response = execute_request(_request)
210
-
211
- # Return appropriate response type.
212
- decoded = APIHelper.json_deserialize(_response.raw_body)
213
- _errors = APIHelper.map_response(decoded, ['errors'])
214
- ApiResponse.new(
215
- _response, data: decoded, errors: _errors
216
- )
151
+ new_api_call_builder
152
+ .request(new_request_builder(HttpMethodEnum::POST,
153
+ '/oauth2/token/status',
154
+ 'default')
155
+ .header_param(new_parameter(authorization, key: 'Authorization'))
156
+ .header_param(new_parameter('application/json', key: 'accept')))
157
+ .response(new_response_handler
158
+ .deserializer(APIHelper.method(:json_deserialize))
159
+ .is_api_response(true)
160
+ .convertor(ApiResponse.method(:create)))
161
+ .execute
217
162
  end
218
163
  end
219
164
  end