square.rb 26.0.0.20221214 → 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.
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
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.0.0.20221214'
7
+ '26.2.0.20230315'
8
8
  end
9
9
 
10
10
  def square_version
@@ -18,244 +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 config
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 config
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 config
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 config
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 config
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 config
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 config
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 config
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 config
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 config
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 config
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 config
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 config
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 config
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 config
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 config
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 config
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 config
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 config
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 config
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 config
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 config
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 config
153
+ @locations ||= LocationsApi.new @global_configuration
154
+ end
155
+
156
+ # Access to location_custom_attributes controller.
157
+ # @return [LocationCustomAttributesApi] Returns the controller instance.
158
+ def location_custom_attributes
159
+ @location_custom_attributes ||= LocationCustomAttributesApi.new @global_configuration
154
160
  end
155
161
 
156
162
  # Access to checkout controller.
157
163
  # @return [CheckoutApi] Returns the controller instance.
158
164
  def checkout
159
- @checkout ||= CheckoutApi.new config
165
+ @checkout ||= CheckoutApi.new @global_configuration
160
166
  end
161
167
 
162
168
  # Access to transactions controller.
163
169
  # @return [TransactionsApi] Returns the controller instance.
164
170
  def transactions
165
- @transactions ||= TransactionsApi.new config
171
+ @transactions ||= TransactionsApi.new @global_configuration
166
172
  end
167
173
 
168
174
  # Access to loyalty controller.
169
175
  # @return [LoyaltyApi] Returns the controller instance.
170
176
  def loyalty
171
- @loyalty ||= LoyaltyApi.new config
177
+ @loyalty ||= LoyaltyApi.new @global_configuration
172
178
  end
173
179
 
174
180
  # Access to merchants controller.
175
181
  # @return [MerchantsApi] Returns the controller instance.
176
182
  def merchants
177
- @merchants ||= MerchantsApi.new config
183
+ @merchants ||= MerchantsApi.new @global_configuration
178
184
  end
179
185
 
180
186
  # Access to orders controller.
181
187
  # @return [OrdersApi] Returns the controller instance.
182
188
  def orders
183
- @orders ||= OrdersApi.new config
189
+ @orders ||= OrdersApi.new @global_configuration
184
190
  end
185
191
 
186
192
  # Access to order_custom_attributes controller.
187
193
  # @return [OrderCustomAttributesApi] Returns the controller instance.
188
194
  def order_custom_attributes
189
- @order_custom_attributes ||= OrderCustomAttributesApi.new config
195
+ @order_custom_attributes ||= OrderCustomAttributesApi.new @global_configuration
190
196
  end
191
197
 
192
198
  # Access to payments controller.
193
199
  # @return [PaymentsApi] Returns the controller instance.
194
200
  def payments
195
- @payments ||= PaymentsApi.new config
201
+ @payments ||= PaymentsApi.new @global_configuration
196
202
  end
197
203
 
198
204
  # Access to payouts controller.
199
205
  # @return [PayoutsApi] Returns the controller instance.
200
206
  def payouts
201
- @payouts ||= PayoutsApi.new config
207
+ @payouts ||= PayoutsApi.new @global_configuration
202
208
  end
203
209
 
204
210
  # Access to refunds controller.
205
211
  # @return [RefundsApi] Returns the controller instance.
206
212
  def refunds
207
- @refunds ||= RefundsApi.new config
213
+ @refunds ||= RefundsApi.new @global_configuration
208
214
  end
209
215
 
210
216
  # Access to sites controller.
211
217
  # @return [SitesApi] Returns the controller instance.
212
218
  def sites
213
- @sites ||= SitesApi.new config
219
+ @sites ||= SitesApi.new @global_configuration
214
220
  end
215
221
 
216
222
  # Access to snippets controller.
217
223
  # @return [SnippetsApi] Returns the controller instance.
218
224
  def snippets
219
- @snippets ||= SnippetsApi.new config
225
+ @snippets ||= SnippetsApi.new @global_configuration
220
226
  end
221
227
 
222
228
  # Access to subscriptions controller.
223
229
  # @return [SubscriptionsApi] Returns the controller instance.
224
230
  def subscriptions
225
- @subscriptions ||= SubscriptionsApi.new config
231
+ @subscriptions ||= SubscriptionsApi.new @global_configuration
226
232
  end
227
233
 
228
234
  # Access to team controller.
229
235
  # @return [TeamApi] Returns the controller instance.
230
236
  def team
231
- @team ||= TeamApi.new config
237
+ @team ||= TeamApi.new @global_configuration
232
238
  end
233
239
 
234
240
  # Access to terminal controller.
235
241
  # @return [TerminalApi] Returns the controller instance.
236
242
  def terminal
237
- @terminal ||= TerminalApi.new config
243
+ @terminal ||= TerminalApi.new @global_configuration
238
244
  end
239
245
 
240
246
  # Access to vendors controller.
241
247
  # @return [VendorsApi] Returns the controller instance.
242
248
  def vendors
243
- @vendors ||= VendorsApi.new config
249
+ @vendors ||= VendorsApi.new @global_configuration
244
250
  end
245
251
 
246
252
  # Access to webhook_subscriptions controller.
247
253
  # @return [WebhookSubscriptionsApi] Returns the controller instance.
248
254
  def webhook_subscriptions
249
- @webhook_subscriptions ||= WebhookSubscriptionsApi.new config
255
+ @webhook_subscriptions ||= WebhookSubscriptionsApi.new @global_configuration
250
256
  end
251
257
 
252
258
  def initialize(connection: nil, adapter: :net_http_persistent, timeout: 60,
253
259
  max_retries: 0, retry_interval: 1, backoff_factor: 2,
254
260
  retry_statuses: [408, 413, 429, 500, 502, 503, 504, 521, 522, 524],
255
- retry_methods: %i[get put], environment: 'production',
256
- custom_url: 'https://connect.squareup.com',
257
- square_version: '2022-12-14', access_token: '',
258
- user_agent_detail: '', additional_headers: {}, config: nil)
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)
259
266
  @config = if config.nil?
260
267
  Configuration.new(connection: connection, adapter: adapter,
261
268
  timeout: timeout, max_retries: max_retries,
@@ -263,15 +270,44 @@ module Square
263
270
  backoff_factor: backoff_factor,
264
271
  retry_statuses: retry_statuses,
265
272
  retry_methods: retry_methods,
273
+ http_callback: http_callback,
266
274
  environment: environment,
267
275
  custom_url: custom_url,
268
- square_version: square_version,
269
276
  access_token: access_token,
277
+ square_version: square_version,
270
278
  user_agent_detail: user_agent_detail,
271
279
  additional_headers: additional_headers)
272
280
  else
273
281
  config
274
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)
275
311
  end
276
312
  end
277
313
  end
@@ -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 :http_client, :connection, :adapter, :timeout, :max_retries, :retry_interval,
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], environment: 'production',
22
- custom_url: 'https://connect.squareup.com',
23
- square_version: '2022-12-14', access_token: '',
24
- user_agent_detail: '', additional_headers: {})
25
- # The Faraday connection object passed by the SDK user for making requests
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
- # The Faraday adapter object passed by the SDK user for performing http requests
29
- @adapter = adapter
30
-
31
- # The value to use for connection timeout
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
- @http_client = create_http_client
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, environment: nil,
75
- custom_url: nil, square_version: nil, access_token: nil,
76
- user_agent_detail: nil, additional_headers: nil)
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, environment: environment,
98
- custom_url: custom_url, square_version: square_version,
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 user_agent_detail.length < 128
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 < StandardError
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(:status_code, :reason_phrase, :headers, :raw_body, :request,
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
- @status_code = http_response.status_code
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
- # returns true if status_code is between 200-300
36
- def success?
37
- status_code >= 200 && status_code < 300
38
- end
39
-
40
- # returns true if status_code is between 400-600
41
- def error?
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
- # Add OAuth2 authentication to the http request.
5
- # @param [HttpRequest] The HttpRequest object to which authentication will
6
- # be added.
7
- def self.apply(config, http_request)
8
- token = config.access_token
9
- http_request.headers['Authorization'] = "Bearer #{token}"
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