square.rb 26.1.0.20230119 → 26.2.0.20230315
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.
- checksums.yaml +4 -4
- data/lib/square/api/apple_pay_api.rb +14 -30
- data/lib/square/api/bank_accounts_api.rb +40 -90
- data/lib/square/api/base_api.rb +42 -42
- data/lib/square/api/booking_custom_attributes_api.rb +164 -329
- data/lib/square/api/bookings_api.rb +135 -260
- data/lib/square/api/cards_api.rb +56 -118
- data/lib/square/api/cash_drawers_api.rb +47 -103
- data/lib/square/api/catalog_api.rb +197 -423
- data/lib/square/api/checkout_api.rb +85 -175
- data/lib/square/api/customer_custom_attributes_api.rb +150 -303
- data/lib/square/api/customer_groups_api.rb +69 -145
- data/lib/square/api/customer_segments_api.rb +26 -61
- data/lib/square/api/customers_api.rb +147 -294
- data/lib/square/api/devices_api.rb +42 -89
- data/lib/square/api/disputes_api.rb +130 -288
- data/lib/square/api/employees_api.rb +28 -63
- data/lib/square/api/gift_card_activities_api.rb +33 -65
- data/lib/square/api/gift_cards_api.rb +103 -202
- data/lib/square/api/inventory_api.rb +179 -366
- data/lib/square/api/invoices_api.rb +118 -237
- data/lib/square/api/labor_api.rb +223 -459
- data/lib/square/api/location_custom_attributes_api.rb +166 -331
- data/lib/square/api/locations_api.rb +54 -112
- data/lib/square/api/loyalty_api.rb +259 -512
- data/lib/square/api/merchants_api.rb +25 -60
- data/lib/square/api/mobile_authorization_api.rb +14 -30
- data/lib/square/api/o_auth_api.rb +54 -109
- data/lib/square/api/order_custom_attributes_api.rb +168 -333
- data/lib/square/api/orders_api.rb +115 -222
- data/lib/square/api/payments_api.rb +106 -208
- data/lib/square/api/payouts_api.rb +47 -100
- data/lib/square/api/refunds_api.rb +46 -93
- data/lib/square/api/sites_api.rb +11 -28
- data/lib/square/api/snippets_api.rb +42 -90
- data/lib/square/api/subscriptions_api.rb +150 -299
- data/lib/square/api/team_api.rb +114 -224
- data/lib/square/api/terminal_api.rb +162 -328
- data/lib/square/api/transactions_api.rb +62 -126
- data/lib/square/api/v1_transactions_api.rb +155 -296
- data/lib/square/api/vendors_api.rb +99 -192
- data/lib/square/api/webhook_subscriptions_api.rb +115 -235
- data/lib/square/api_helper.rb +1 -437
- data/lib/square/client.rb +77 -47
- data/lib/square/configuration.rb +28 -53
- data/lib/square/exceptions/api_exception.rb +1 -11
- data/lib/square/http/api_response.rb +13 -19
- data/lib/square/http/auth/o_auth2.rb +14 -7
- data/lib/square/http/http_call_back.rb +1 -15
- data/lib/square/http/http_method_enum.rb +1 -4
- data/lib/square/http/http_request.rb +1 -45
- data/lib/square/http/http_response.rb +1 -20
- data/lib/square/utilities/date_time_helper.rb +1 -146
- data/lib/square/utilities/file_wrapper.rb +5 -5
- data/lib/square.rb +6 -6
- data/spec/user_journey_spec.rb +2 -2
- data/test/api/api_test_base.rb +13 -5
- data/test/api/test_catalog_api.rb +5 -4
- data/test/api/test_customers_api.rb +3 -2
- data/test/api/test_employees_api.rb +4 -3
- data/test/api/test_labor_api.rb +6 -5
- data/test/api/test_locations_api.rb +3 -2
- data/test/api/test_merchants_api.rb +4 -3
- data/test/api/test_payments_api.rb +4 -3
- data/test/api/test_refunds_api.rb +4 -3
- metadata +11 -111
- data/lib/square/exceptions/validation_exception.rb +0 -13
- data/lib/square/http/faraday_client.rb +0 -93
- data/lib/square/http/http_client.rb +0 -118
- data/test/test_helper.rb +0 -89
data/lib/square/client.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
module Square
|
2
2
|
# square client class.
|
3
3
|
class Client
|
4
|
-
attr_reader :config
|
4
|
+
attr_reader :config, :auth_managers
|
5
5
|
|
6
6
|
def sdk_version
|
7
|
-
'26.
|
7
|
+
'26.2.0.20230315'
|
8
8
|
end
|
9
9
|
|
10
10
|
def square_version
|
@@ -18,250 +18,251 @@ module Square
|
|
18
18
|
# Access to mobile_authorization controller.
|
19
19
|
# @return [MobileAuthorizationApi] Returns the controller instance.
|
20
20
|
def mobile_authorization
|
21
|
-
@mobile_authorization ||= MobileAuthorizationApi.new
|
21
|
+
@mobile_authorization ||= MobileAuthorizationApi.new @global_configuration
|
22
22
|
end
|
23
23
|
|
24
24
|
# Access to o_auth controller.
|
25
25
|
# @return [OAuthApi] Returns the controller instance.
|
26
26
|
def o_auth
|
27
|
-
@o_auth ||= OAuthApi.new
|
27
|
+
@o_auth ||= OAuthApi.new @global_configuration
|
28
28
|
end
|
29
29
|
|
30
30
|
# Access to v1_transactions controller.
|
31
31
|
# @return [V1TransactionsApi] Returns the controller instance.
|
32
32
|
def v1_transactions
|
33
|
-
@v1_transactions ||= V1TransactionsApi.new
|
33
|
+
@v1_transactions ||= V1TransactionsApi.new @global_configuration
|
34
34
|
end
|
35
35
|
|
36
36
|
# Access to apple_pay controller.
|
37
37
|
# @return [ApplePayApi] Returns the controller instance.
|
38
38
|
def apple_pay
|
39
|
-
@apple_pay ||= ApplePayApi.new
|
39
|
+
@apple_pay ||= ApplePayApi.new @global_configuration
|
40
40
|
end
|
41
41
|
|
42
42
|
# Access to bank_accounts controller.
|
43
43
|
# @return [BankAccountsApi] Returns the controller instance.
|
44
44
|
def bank_accounts
|
45
|
-
@bank_accounts ||= BankAccountsApi.new
|
45
|
+
@bank_accounts ||= BankAccountsApi.new @global_configuration
|
46
46
|
end
|
47
47
|
|
48
48
|
# Access to bookings controller.
|
49
49
|
# @return [BookingsApi] Returns the controller instance.
|
50
50
|
def bookings
|
51
|
-
@bookings ||= BookingsApi.new
|
51
|
+
@bookings ||= BookingsApi.new @global_configuration
|
52
52
|
end
|
53
53
|
|
54
54
|
# Access to booking_custom_attributes controller.
|
55
55
|
# @return [BookingCustomAttributesApi] Returns the controller instance.
|
56
56
|
def booking_custom_attributes
|
57
|
-
@booking_custom_attributes ||= BookingCustomAttributesApi.new
|
57
|
+
@booking_custom_attributes ||= BookingCustomAttributesApi.new @global_configuration
|
58
58
|
end
|
59
59
|
|
60
60
|
# Access to cards controller.
|
61
61
|
# @return [CardsApi] Returns the controller instance.
|
62
62
|
def cards
|
63
|
-
@cards ||= CardsApi.new
|
63
|
+
@cards ||= CardsApi.new @global_configuration
|
64
64
|
end
|
65
65
|
|
66
66
|
# Access to cash_drawers controller.
|
67
67
|
# @return [CashDrawersApi] Returns the controller instance.
|
68
68
|
def cash_drawers
|
69
|
-
@cash_drawers ||= CashDrawersApi.new
|
69
|
+
@cash_drawers ||= CashDrawersApi.new @global_configuration
|
70
70
|
end
|
71
71
|
|
72
72
|
# Access to catalog controller.
|
73
73
|
# @return [CatalogApi] Returns the controller instance.
|
74
74
|
def catalog
|
75
|
-
@catalog ||= CatalogApi.new
|
75
|
+
@catalog ||= CatalogApi.new @global_configuration
|
76
76
|
end
|
77
77
|
|
78
78
|
# Access to customers controller.
|
79
79
|
# @return [CustomersApi] Returns the controller instance.
|
80
80
|
def customers
|
81
|
-
@customers ||= CustomersApi.new
|
81
|
+
@customers ||= CustomersApi.new @global_configuration
|
82
82
|
end
|
83
83
|
|
84
84
|
# Access to customer_custom_attributes controller.
|
85
85
|
# @return [CustomerCustomAttributesApi] Returns the controller instance.
|
86
86
|
def customer_custom_attributes
|
87
|
-
@customer_custom_attributes ||= CustomerCustomAttributesApi.new
|
87
|
+
@customer_custom_attributes ||= CustomerCustomAttributesApi.new @global_configuration
|
88
88
|
end
|
89
89
|
|
90
90
|
# Access to customer_groups controller.
|
91
91
|
# @return [CustomerGroupsApi] Returns the controller instance.
|
92
92
|
def customer_groups
|
93
|
-
@customer_groups ||= CustomerGroupsApi.new
|
93
|
+
@customer_groups ||= CustomerGroupsApi.new @global_configuration
|
94
94
|
end
|
95
95
|
|
96
96
|
# Access to customer_segments controller.
|
97
97
|
# @return [CustomerSegmentsApi] Returns the controller instance.
|
98
98
|
def customer_segments
|
99
|
-
@customer_segments ||= CustomerSegmentsApi.new
|
99
|
+
@customer_segments ||= CustomerSegmentsApi.new @global_configuration
|
100
100
|
end
|
101
101
|
|
102
102
|
# Access to devices controller.
|
103
103
|
# @return [DevicesApi] Returns the controller instance.
|
104
104
|
def devices
|
105
|
-
@devices ||= DevicesApi.new
|
105
|
+
@devices ||= DevicesApi.new @global_configuration
|
106
106
|
end
|
107
107
|
|
108
108
|
# Access to disputes controller.
|
109
109
|
# @return [DisputesApi] Returns the controller instance.
|
110
110
|
def disputes
|
111
|
-
@disputes ||= DisputesApi.new
|
111
|
+
@disputes ||= DisputesApi.new @global_configuration
|
112
112
|
end
|
113
113
|
|
114
114
|
# Access to employees controller.
|
115
115
|
# @return [EmployeesApi] Returns the controller instance.
|
116
116
|
def employees
|
117
|
-
@employees ||= EmployeesApi.new
|
117
|
+
@employees ||= EmployeesApi.new @global_configuration
|
118
118
|
end
|
119
119
|
|
120
120
|
# Access to gift_cards controller.
|
121
121
|
# @return [GiftCardsApi] Returns the controller instance.
|
122
122
|
def gift_cards
|
123
|
-
@gift_cards ||= GiftCardsApi.new
|
123
|
+
@gift_cards ||= GiftCardsApi.new @global_configuration
|
124
124
|
end
|
125
125
|
|
126
126
|
# Access to gift_card_activities controller.
|
127
127
|
# @return [GiftCardActivitiesApi] Returns the controller instance.
|
128
128
|
def gift_card_activities
|
129
|
-
@gift_card_activities ||= GiftCardActivitiesApi.new
|
129
|
+
@gift_card_activities ||= GiftCardActivitiesApi.new @global_configuration
|
130
130
|
end
|
131
131
|
|
132
132
|
# Access to inventory controller.
|
133
133
|
# @return [InventoryApi] Returns the controller instance.
|
134
134
|
def inventory
|
135
|
-
@inventory ||= InventoryApi.new
|
135
|
+
@inventory ||= InventoryApi.new @global_configuration
|
136
136
|
end
|
137
137
|
|
138
138
|
# Access to invoices controller.
|
139
139
|
# @return [InvoicesApi] Returns the controller instance.
|
140
140
|
def invoices
|
141
|
-
@invoices ||= InvoicesApi.new
|
141
|
+
@invoices ||= InvoicesApi.new @global_configuration
|
142
142
|
end
|
143
143
|
|
144
144
|
# Access to labor controller.
|
145
145
|
# @return [LaborApi] Returns the controller instance.
|
146
146
|
def labor
|
147
|
-
@labor ||= LaborApi.new
|
147
|
+
@labor ||= LaborApi.new @global_configuration
|
148
148
|
end
|
149
149
|
|
150
150
|
# Access to locations controller.
|
151
151
|
# @return [LocationsApi] Returns the controller instance.
|
152
152
|
def locations
|
153
|
-
@locations ||= LocationsApi.new
|
153
|
+
@locations ||= LocationsApi.new @global_configuration
|
154
154
|
end
|
155
155
|
|
156
156
|
# Access to location_custom_attributes controller.
|
157
157
|
# @return [LocationCustomAttributesApi] Returns the controller instance.
|
158
158
|
def location_custom_attributes
|
159
|
-
@location_custom_attributes ||= LocationCustomAttributesApi.new
|
159
|
+
@location_custom_attributes ||= LocationCustomAttributesApi.new @global_configuration
|
160
160
|
end
|
161
161
|
|
162
162
|
# Access to checkout controller.
|
163
163
|
# @return [CheckoutApi] Returns the controller instance.
|
164
164
|
def checkout
|
165
|
-
@checkout ||= CheckoutApi.new
|
165
|
+
@checkout ||= CheckoutApi.new @global_configuration
|
166
166
|
end
|
167
167
|
|
168
168
|
# Access to transactions controller.
|
169
169
|
# @return [TransactionsApi] Returns the controller instance.
|
170
170
|
def transactions
|
171
|
-
@transactions ||= TransactionsApi.new
|
171
|
+
@transactions ||= TransactionsApi.new @global_configuration
|
172
172
|
end
|
173
173
|
|
174
174
|
# Access to loyalty controller.
|
175
175
|
# @return [LoyaltyApi] Returns the controller instance.
|
176
176
|
def loyalty
|
177
|
-
@loyalty ||= LoyaltyApi.new
|
177
|
+
@loyalty ||= LoyaltyApi.new @global_configuration
|
178
178
|
end
|
179
179
|
|
180
180
|
# Access to merchants controller.
|
181
181
|
# @return [MerchantsApi] Returns the controller instance.
|
182
182
|
def merchants
|
183
|
-
@merchants ||= MerchantsApi.new
|
183
|
+
@merchants ||= MerchantsApi.new @global_configuration
|
184
184
|
end
|
185
185
|
|
186
186
|
# Access to orders controller.
|
187
187
|
# @return [OrdersApi] Returns the controller instance.
|
188
188
|
def orders
|
189
|
-
@orders ||= OrdersApi.new
|
189
|
+
@orders ||= OrdersApi.new @global_configuration
|
190
190
|
end
|
191
191
|
|
192
192
|
# Access to order_custom_attributes controller.
|
193
193
|
# @return [OrderCustomAttributesApi] Returns the controller instance.
|
194
194
|
def order_custom_attributes
|
195
|
-
@order_custom_attributes ||= OrderCustomAttributesApi.new
|
195
|
+
@order_custom_attributes ||= OrderCustomAttributesApi.new @global_configuration
|
196
196
|
end
|
197
197
|
|
198
198
|
# Access to payments controller.
|
199
199
|
# @return [PaymentsApi] Returns the controller instance.
|
200
200
|
def payments
|
201
|
-
@payments ||= PaymentsApi.new
|
201
|
+
@payments ||= PaymentsApi.new @global_configuration
|
202
202
|
end
|
203
203
|
|
204
204
|
# Access to payouts controller.
|
205
205
|
# @return [PayoutsApi] Returns the controller instance.
|
206
206
|
def payouts
|
207
|
-
@payouts ||= PayoutsApi.new
|
207
|
+
@payouts ||= PayoutsApi.new @global_configuration
|
208
208
|
end
|
209
209
|
|
210
210
|
# Access to refunds controller.
|
211
211
|
# @return [RefundsApi] Returns the controller instance.
|
212
212
|
def refunds
|
213
|
-
@refunds ||= RefundsApi.new
|
213
|
+
@refunds ||= RefundsApi.new @global_configuration
|
214
214
|
end
|
215
215
|
|
216
216
|
# Access to sites controller.
|
217
217
|
# @return [SitesApi] Returns the controller instance.
|
218
218
|
def sites
|
219
|
-
@sites ||= SitesApi.new
|
219
|
+
@sites ||= SitesApi.new @global_configuration
|
220
220
|
end
|
221
221
|
|
222
222
|
# Access to snippets controller.
|
223
223
|
# @return [SnippetsApi] Returns the controller instance.
|
224
224
|
def snippets
|
225
|
-
@snippets ||= SnippetsApi.new
|
225
|
+
@snippets ||= SnippetsApi.new @global_configuration
|
226
226
|
end
|
227
227
|
|
228
228
|
# Access to subscriptions controller.
|
229
229
|
# @return [SubscriptionsApi] Returns the controller instance.
|
230
230
|
def subscriptions
|
231
|
-
@subscriptions ||= SubscriptionsApi.new
|
231
|
+
@subscriptions ||= SubscriptionsApi.new @global_configuration
|
232
232
|
end
|
233
233
|
|
234
234
|
# Access to team controller.
|
235
235
|
# @return [TeamApi] Returns the controller instance.
|
236
236
|
def team
|
237
|
-
@team ||= TeamApi.new
|
237
|
+
@team ||= TeamApi.new @global_configuration
|
238
238
|
end
|
239
239
|
|
240
240
|
# Access to terminal controller.
|
241
241
|
# @return [TerminalApi] Returns the controller instance.
|
242
242
|
def terminal
|
243
|
-
@terminal ||= TerminalApi.new
|
243
|
+
@terminal ||= TerminalApi.new @global_configuration
|
244
244
|
end
|
245
245
|
|
246
246
|
# Access to vendors controller.
|
247
247
|
# @return [VendorsApi] Returns the controller instance.
|
248
248
|
def vendors
|
249
|
-
@vendors ||= VendorsApi.new
|
249
|
+
@vendors ||= VendorsApi.new @global_configuration
|
250
250
|
end
|
251
251
|
|
252
252
|
# Access to webhook_subscriptions controller.
|
253
253
|
# @return [WebhookSubscriptionsApi] Returns the controller instance.
|
254
254
|
def webhook_subscriptions
|
255
|
-
@webhook_subscriptions ||= WebhookSubscriptionsApi.new
|
255
|
+
@webhook_subscriptions ||= WebhookSubscriptionsApi.new @global_configuration
|
256
256
|
end
|
257
257
|
|
258
258
|
def initialize(connection: nil, adapter: :net_http_persistent, timeout: 60,
|
259
259
|
max_retries: 0, retry_interval: 1, backoff_factor: 2,
|
260
260
|
retry_statuses: [408, 413, 429, 500, 502, 503, 504, 521, 522, 524],
|
261
|
-
retry_methods: %i[get put],
|
262
|
-
|
263
|
-
|
264
|
-
|
261
|
+
retry_methods: %i[get put], http_callback: nil,
|
262
|
+
environment: 'production',
|
263
|
+
custom_url: 'https://connect.squareup.com', access_token: '',
|
264
|
+
square_version: '2023-03-15', user_agent_detail: '',
|
265
|
+
additional_headers: {}, config: nil)
|
265
266
|
@config = if config.nil?
|
266
267
|
Configuration.new(connection: connection, adapter: adapter,
|
267
268
|
timeout: timeout, max_retries: max_retries,
|
@@ -269,15 +270,44 @@ module Square
|
|
269
270
|
backoff_factor: backoff_factor,
|
270
271
|
retry_statuses: retry_statuses,
|
271
272
|
retry_methods: retry_methods,
|
273
|
+
http_callback: http_callback,
|
272
274
|
environment: environment,
|
273
275
|
custom_url: custom_url,
|
274
|
-
square_version: square_version,
|
275
276
|
access_token: access_token,
|
277
|
+
square_version: square_version,
|
276
278
|
user_agent_detail: user_agent_detail,
|
277
279
|
additional_headers: additional_headers)
|
278
280
|
else
|
279
281
|
config
|
280
282
|
end
|
283
|
+
|
284
|
+
custom_user_agent_parameters = {
|
285
|
+
'{api-version}' => { 'value': @config.square_version, 'encode': false },
|
286
|
+
'{detail}' => { 'value': @config.user_agent_detail, 'encode': true }
|
287
|
+
}
|
288
|
+
|
289
|
+
user_agent_params = BaseApi.user_agent_parameters.merge!(custom_user_agent_parameters)
|
290
|
+
|
291
|
+
@global_configuration = GlobalConfiguration.new(client_configuration: @config)
|
292
|
+
.base_uri_executor(@config.method(:get_base_uri))
|
293
|
+
.user_agent(BaseApi.user_agent,
|
294
|
+
agent_parameters: user_agent_params)
|
295
|
+
.additional_headers(@config.additional_headers)
|
296
|
+
.global_header('Square-Version', @config.square_version)
|
297
|
+
.sdk_module(Square)
|
298
|
+
.symbolize_hash(true)
|
299
|
+
|
300
|
+
initialize_auth_managers(@global_configuration)
|
301
|
+
@global_configuration = @global_configuration.auth_managers(@auth_managers)
|
302
|
+
end
|
303
|
+
|
304
|
+
# Initializes the auth managers hash used for authenticating API calls.
|
305
|
+
# @param [GlobalConfiguration] global_config The global configuration of the SDK)
|
306
|
+
def initialize_auth_managers(global_config)
|
307
|
+
@auth_managers = {}
|
308
|
+
http_client_config = global_config.client_configuration
|
309
|
+
['global'].each { |auth| @auth_managers[auth] = nil }
|
310
|
+
@auth_managers['global'] = OAuth2.new(http_client_config.access_token)
|
281
311
|
end
|
282
312
|
end
|
283
313
|
end
|
data/lib/square/configuration.rb
CHANGED
@@ -1,11 +1,9 @@
|
|
1
1
|
module Square
|
2
2
|
# All configuration including auth info and base URI for the API access
|
3
3
|
# are configured in this class.
|
4
|
-
class Configuration
|
4
|
+
class Configuration < CoreLibrary::HttpClientConfiguration
|
5
5
|
# The attribute readers for properties.
|
6
|
-
attr_reader :
|
7
|
-
:backoff_factor, :retry_statuses, :retry_methods, :environment, :custom_url,
|
8
|
-
:square_version, :access_token, :user_agent_detail
|
6
|
+
attr_reader :environment, :custom_url, :access_token, :square_version, :user_agent_detail
|
9
7
|
|
10
8
|
def additional_headers
|
11
9
|
@additional_headers.clone
|
@@ -18,34 +16,16 @@ module Square
|
|
18
16
|
def initialize(connection: nil, adapter: :net_http_persistent, timeout: 60,
|
19
17
|
max_retries: 0, retry_interval: 1, backoff_factor: 2,
|
20
18
|
retry_statuses: [408, 413, 429, 500, 502, 503, 504, 521, 522, 524],
|
21
|
-
retry_methods: %i[get put],
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
@connection = connection
|
19
|
+
retry_methods: %i[get put], http_callback: nil,
|
20
|
+
environment: 'production',
|
21
|
+
custom_url: 'https://connect.squareup.com', access_token: '',
|
22
|
+
square_version: '2023-03-15', user_agent_detail: '',
|
23
|
+
additional_headers: {})
|
27
24
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
@timeout = timeout
|
33
|
-
|
34
|
-
# The number of times to retry an endpoint call if it fails
|
35
|
-
@max_retries = max_retries
|
36
|
-
|
37
|
-
# Pause in seconds between retries
|
38
|
-
@retry_interval = retry_interval
|
39
|
-
|
40
|
-
# The amount to multiply each successive retry's interval amount
|
41
|
-
# by in order to provide backoff
|
42
|
-
@backoff_factor = backoff_factor
|
43
|
-
|
44
|
-
# A list of HTTP statuses to retry
|
45
|
-
@retry_statuses = retry_statuses
|
46
|
-
|
47
|
-
# A list of HTTP methods to retry
|
48
|
-
@retry_methods = retry_methods
|
25
|
+
super connection: connection, adapter: adapter, timeout: timeout,
|
26
|
+
max_retries: max_retries, retry_interval: retry_interval,
|
27
|
+
backoff_factor: backoff_factor, retry_statuses: retry_statuses,
|
28
|
+
retry_methods: retry_methods, http_callback: http_callback
|
49
29
|
|
50
30
|
# Current API environment
|
51
31
|
@environment = String(environment)
|
@@ -53,17 +33,17 @@ module Square
|
|
53
33
|
# Sets the base URL requests are made to. Defaults to `https://connect.squareup.com`
|
54
34
|
@custom_url = custom_url
|
55
35
|
|
56
|
-
# Square Connect API versions
|
57
|
-
@square_version = square_version
|
58
|
-
|
59
36
|
# The OAuth 2.0 Access Token to use for API requests.
|
60
37
|
@access_token = access_token
|
61
38
|
|
39
|
+
# Square Connect API versions
|
40
|
+
@square_version = square_version
|
41
|
+
|
62
42
|
# Additional headers to add to each API request
|
63
43
|
@additional_headers = additional_headers.clone
|
64
44
|
|
65
45
|
# The Http Client to use for making requests.
|
66
|
-
|
46
|
+
set_http_client CoreLibrary::FaradayClient.new(self)
|
67
47
|
|
68
48
|
# User agent detail, to be appended with user-agent header.
|
69
49
|
@user_agent_detail = get_user_agent(user_agent_detail)
|
@@ -71,9 +51,10 @@ module Square
|
|
71
51
|
|
72
52
|
def clone_with(connection: nil, adapter: nil, timeout: nil,
|
73
53
|
max_retries: nil, retry_interval: nil, backoff_factor: nil,
|
74
|
-
retry_statuses: nil, retry_methods: nil,
|
75
|
-
|
76
|
-
|
54
|
+
retry_statuses: nil, retry_methods: nil, http_callback: nil,
|
55
|
+
environment: nil, custom_url: nil, access_token: nil,
|
56
|
+
square_version: nil, user_agent_detail: nil,
|
57
|
+
additional_headers: nil)
|
77
58
|
connection ||= self.connection
|
78
59
|
adapter ||= self.adapter
|
79
60
|
timeout ||= self.timeout
|
@@ -82,10 +63,11 @@ module Square
|
|
82
63
|
backoff_factor ||= self.backoff_factor
|
83
64
|
retry_statuses ||= self.retry_statuses
|
84
65
|
retry_methods ||= self.retry_methods
|
66
|
+
http_callback ||= self.http_callback
|
85
67
|
environment ||= self.environment
|
86
68
|
custom_url ||= self.custom_url
|
87
|
-
square_version ||= self.square_version
|
88
69
|
access_token ||= self.access_token
|
70
|
+
square_version ||= self.square_version
|
89
71
|
user_agent_detail ||= self.user_agent_detail
|
90
72
|
additional_headers ||= self.additional_headers
|
91
73
|
|
@@ -94,24 +76,17 @@ module Square
|
|
94
76
|
retry_interval: retry_interval,
|
95
77
|
backoff_factor: backoff_factor,
|
96
78
|
retry_statuses: retry_statuses,
|
97
|
-
retry_methods: retry_methods,
|
98
|
-
|
99
|
-
access_token: access_token,
|
79
|
+
retry_methods: retry_methods,
|
80
|
+
http_callback: http_callback, environment: environment,
|
81
|
+
custom_url: custom_url, access_token: access_token,
|
82
|
+
square_version: square_version,
|
100
83
|
user_agent_detail: user_agent_detail,
|
101
84
|
additional_headers: additional_headers)
|
102
85
|
end
|
103
86
|
|
104
|
-
def create_http_client
|
105
|
-
FaradayClient.new(timeout: timeout, max_retries: max_retries,
|
106
|
-
retry_interval: retry_interval,
|
107
|
-
backoff_factor: backoff_factor,
|
108
|
-
retry_statuses: retry_statuses,
|
109
|
-
retry_methods: retry_methods, connection: connection,
|
110
|
-
adapter: adapter)
|
111
|
-
end
|
112
|
-
|
113
87
|
def get_user_agent(user_agent_detail)
|
114
|
-
raise ArgumentError, 'The length of user-agent detail should not exceed 128 characters.' unless
|
88
|
+
raise ArgumentError, 'The length of user-agent detail should not exceed 128 characters.' unless
|
89
|
+
user_agent_detail.length < 128
|
115
90
|
|
116
91
|
user_agent_detail
|
117
92
|
end
|
@@ -130,7 +105,7 @@ module Square
|
|
130
105
|
}.freeze
|
131
106
|
|
132
107
|
# Generates the appropriate base URI for the environment and the server.
|
133
|
-
# @param [Configuration::Server] The server enum for which the base URI is
|
108
|
+
# @param [Configuration::Server] server The server enum for which the base URI is
|
134
109
|
# required.
|
135
110
|
# @return [String] The base URI.
|
136
111
|
def get_base_uri(server = 'default')
|
@@ -1,15 +1,5 @@
|
|
1
1
|
module Square
|
2
2
|
# Class for exceptions when there is a network error, status code error, etc.
|
3
|
-
class APIException <
|
4
|
-
attr_reader :response, :response_code
|
5
|
-
|
6
|
-
# The constructor.
|
7
|
-
# @param [String] The reason for raising an exception.
|
8
|
-
# @param [HttpResponse] The HttpReponse of the API call.
|
9
|
-
def initialize(reason, response)
|
10
|
-
super(reason)
|
11
|
-
@response = response
|
12
|
-
@response_code = response.status_code
|
13
|
-
end
|
3
|
+
class APIException < CoreLibrary::ApiException
|
14
4
|
end
|
15
5
|
end
|
@@ -1,21 +1,16 @@
|
|
1
1
|
module Square
|
2
2
|
# Http response received.
|
3
|
-
class ApiResponse
|
4
|
-
attr_reader
|
5
|
-
:data, :errors, :body, :cursor)
|
3
|
+
class ApiResponse < CoreLibrary::ApiResponse
|
4
|
+
attr_reader :body, :cursor
|
6
5
|
|
7
6
|
# The constructor
|
8
|
-
# @param [HttpResponse] The original, raw response from the api.
|
9
|
-
# @param [Object] The data field specified for the response.
|
10
|
-
# @param [Array<String>] Any errors returned by the server.
|
7
|
+
# @param [HttpResponse] http_response The original, raw response from the api.
|
8
|
+
# @param [Object] data The data field specified for the response.
|
9
|
+
# @param [Array<String>] errors Any errors returned by the server.
|
11
10
|
def initialize(http_response,
|
12
11
|
data: nil,
|
13
12
|
errors: nil)
|
14
|
-
|
15
|
-
@reason_phrase = http_response.reason_phrase
|
16
|
-
@headers = http_response.headers
|
17
|
-
@raw_body = http_response.raw_body
|
18
|
-
@request = http_response.request
|
13
|
+
super
|
19
14
|
@errors = errors
|
20
15
|
|
21
16
|
if (data.is_a? Hash) && data.keys.any?
|
@@ -32,14 +27,13 @@ module Square
|
|
32
27
|
end
|
33
28
|
end
|
34
29
|
|
35
|
-
#
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
status_code >= 400 && status_code < 600
|
30
|
+
# The factory method for creating the API Response instance of the SDK from its parent instance in the core lirbary.
|
31
|
+
# @param [CoreLibrary::HttpResponse] parent_instance The Api Response instance from core library.
|
32
|
+
def self.create(parent_instance)
|
33
|
+
ApiResponse.new(CoreLibrary::HttpResponse
|
34
|
+
.new(parent_instance.status_code, parent_instance.reason_phrase,
|
35
|
+
parent_instance.headers, parent_instance.raw_body, parent_instance.request),
|
36
|
+
data: parent_instance.data, errors: parent_instance.errors)
|
43
37
|
end
|
44
38
|
end
|
45
39
|
end
|
@@ -1,12 +1,19 @@
|
|
1
1
|
module Square
|
2
2
|
# Utility class for OAuth 2 authorization and token management.
|
3
|
-
class OAuth2
|
4
|
-
#
|
5
|
-
# @
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
3
|
+
class OAuth2 < CoreLibrary::HeaderAuth
|
4
|
+
# Display error message on occurrence of authentication failure.
|
5
|
+
# @returns [String] The oAuth error message.
|
6
|
+
def error_message
|
7
|
+
'BearerAuth: access_token is undefined.'
|
8
|
+
end
|
9
|
+
|
10
|
+
# Initialization constructor.
|
11
|
+
def initialize(access_token)
|
12
|
+
auth_params = {}
|
13
|
+
@_access_token = access_token
|
14
|
+
auth_params['Authorization'] = "Bearer #{@_access_token}" unless @_access_token.nil?
|
15
|
+
|
16
|
+
super auth_params
|
10
17
|
end
|
11
18
|
end
|
12
19
|
end
|
@@ -1,19 +1,5 @@
|
|
1
1
|
module Square
|
2
2
|
# HttpCallBack allows defining callables for pre and post API calls.
|
3
|
-
class HttpCallBack
|
4
|
-
# A controller will call this method before making an HTTP Request.
|
5
|
-
# @param [HttpRequest] The HttpRequest object which the HttpClient
|
6
|
-
# will execute.
|
7
|
-
def on_before_request(_http_request)
|
8
|
-
raise NotImplementedError, 'This method needs
|
9
|
-
to be implemented in a child class.'
|
10
|
-
end
|
11
|
-
|
12
|
-
# A controller will call this method after making an HTTP Request.
|
13
|
-
# @param [HttpResponse] The HttpReponse of the API call.
|
14
|
-
def on_after_response(_http_response)
|
15
|
-
raise NotImplementedError, 'This method needs
|
16
|
-
to be implemented in a child class.'
|
17
|
-
end
|
3
|
+
class HttpCallBack < CoreLibrary::HttpCallback
|
18
4
|
end
|
19
5
|
end
|
@@ -1,8 +1,5 @@
|
|
1
1
|
module Square
|
2
2
|
# HTTP Methods Enumeration.
|
3
|
-
class HttpMethodEnum
|
4
|
-
HTTPMETHODENUM = [GET = 'GET'.freeze, POST = 'POST'.freeze,
|
5
|
-
PUT = 'PUT'.freeze, PATCH = 'PATCH'.freeze,
|
6
|
-
DELETE = 'DELETE'.freeze, HEAD = 'HEAD'.freeze].freeze
|
3
|
+
class HttpMethodEnum < CoreLibrary::HttpMethod
|
7
4
|
end
|
8
5
|
end
|