Class: Square::Client

Inherits:
Object
  • Object
show all
Includes:
CoreLibrary
Defined in:
lib/square/client.rb

Overview

square client class.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection: nil, adapter: :net_http_persistent, timeout: 60, max_retries: 0, retry_interval: 1, backoff_factor: 2, retry_statuses: [408, 413, 429, 500, 502, 503, 504, 521, 522, 524], retry_methods: %i[get put],, http_callback: nil, environment: 'production', custom_url: 'https://connect.squareup.com', access_token: nil, bearer_auth_credentials: nil, square_version: '2024-11-20', user_agent_detail: '', additional_headers: {}, config: nil) ⇒ Client

Returns a new instance of Client.



271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
# File 'lib/square/client.rb', line 271

def initialize(
  connection: nil, adapter: :net_http_persistent, timeout: 60,
  max_retries: 0, retry_interval: 1, backoff_factor: 2,
  retry_statuses: [408, 413, 429, 500, 502, 503, 504, 521, 522, 524],
  retry_methods: %i[get put], http_callback: nil, environment: 'production',
  custom_url: 'https://connect.squareup.com', access_token: nil,
  bearer_auth_credentials: nil, square_version: '2024-11-20',
  user_agent_detail: '', additional_headers: {}, config: nil
)
  @config = if config.nil?
              Configuration.new(
                connection: connection, adapter: adapter, timeout: timeout,
                max_retries: max_retries, retry_interval: retry_interval,
                backoff_factor: backoff_factor,
                retry_statuses: retry_statuses,
                retry_methods: retry_methods, http_callback: http_callback,
                environment: environment, custom_url: custom_url,
                access_token: access_token,
                bearer_auth_credentials: bearer_auth_credentials,
                square_version: square_version,
                user_agent_detail: user_agent_detail,
                additional_headers: additional_headers
              )
            else
              config
            end

  custom_user_agent_parameters = {
    '{api-version}' => { 'value': @config.square_version, 'encode': false },
    '{detail}' => { 'value': @config.user_agent_detail, 'encode': true }
  }

  user_agent_params = BaseApi.user_agent_parameters.merge!(custom_user_agent_parameters)

  @global_configuration = GlobalConfiguration.new(client_configuration: @config)
                                             .base_uri_executor(@config.method(:get_base_uri))
                                             .user_agent(BaseApi.user_agent,
                                                         agent_parameters: user_agent_params)
                                             .additional_headers(@config.additional_headers)
                                             .global_header('Square-Version', @config.square_version)
                                             .symbolize_hash(true)

  initialize_auth_managers(@global_configuration)
  @global_configuration = @global_configuration.auth_managers(@auth_managers)
end

Instance Attribute Details

#auth_managersObject (readonly)

Returns the value of attribute auth_managers.



5
6
7
# File 'lib/square/client.rb', line 5

def auth_managers
  @auth_managers
end

#configObject (readonly)

Returns the value of attribute config.



5
6
7
# File 'lib/square/client.rb', line 5

def config
  @config
end

Instance Method Details

#apple_payApplePayApi

Access to apple_pay controller.

Returns:



39
40
41
# File 'lib/square/client.rb', line 39

def apple_pay
  @apple_pay ||= ApplePayApi.new @global_configuration
end

#bank_accountsBankAccountsApi

Access to bank_accounts controller.

Returns:



45
46
47
# File 'lib/square/client.rb', line 45

def bank_accounts
  @bank_accounts ||= BankAccountsApi.new @global_configuration
end

#booking_custom_attributesBookingCustomAttributesApi

Access to booking_custom_attributes controller.

Returns:



57
58
59
# File 'lib/square/client.rb', line 57

def booking_custom_attributes
  @booking_custom_attributes ||= BookingCustomAttributesApi.new @global_configuration
end

#bookingsBookingsApi

Access to bookings controller.

Returns:



51
52
53
# File 'lib/square/client.rb', line 51

def bookings
  @bookings ||= BookingsApi.new @global_configuration
end

#cardsCardsApi

Access to cards controller.

Returns:

  • (CardsApi)

    Returns the controller instance.



63
64
65
# File 'lib/square/client.rb', line 63

def cards
  @cards ||= CardsApi.new @global_configuration
end

#cash_drawersCashDrawersApi

Access to cash_drawers controller.

Returns:



69
70
71
# File 'lib/square/client.rb', line 69

def cash_drawers
  @cash_drawers ||= CashDrawersApi.new @global_configuration
end

#catalogCatalogApi

Access to catalog controller.

Returns:

  • (CatalogApi)

    Returns the controller instance.



75
76
77
# File 'lib/square/client.rb', line 75

def catalog
  @catalog ||= CatalogApi.new @global_configuration
end

#checkoutCheckoutApi

Access to checkout controller.

Returns:



171
172
173
# File 'lib/square/client.rb', line 171

def checkout
  @checkout ||= CheckoutApi.new @global_configuration
end

#customer_custom_attributesCustomerCustomAttributesApi

Access to customer_custom_attributes controller.

Returns:



87
88
89
# File 'lib/square/client.rb', line 87

def customer_custom_attributes
  @customer_custom_attributes ||= CustomerCustomAttributesApi.new @global_configuration
end

#customer_groupsCustomerGroupsApi

Access to customer_groups controller.

Returns:



93
94
95
# File 'lib/square/client.rb', line 93

def customer_groups
  @customer_groups ||= CustomerGroupsApi.new @global_configuration
end

#customer_segmentsCustomerSegmentsApi

Access to customer_segments controller.

Returns:



99
100
101
# File 'lib/square/client.rb', line 99

def customer_segments
  @customer_segments ||= CustomerSegmentsApi.new @global_configuration
end

#customersCustomersApi

Access to customers controller.

Returns:



81
82
83
# File 'lib/square/client.rb', line 81

def customers
  @customers ||= CustomersApi.new @global_configuration
end

#devicesDevicesApi

Access to devices controller.

Returns:

  • (DevicesApi)

    Returns the controller instance.



105
106
107
# File 'lib/square/client.rb', line 105

def devices
  @devices ||= DevicesApi.new @global_configuration
end

#disputesDisputesApi

Access to disputes controller.

Returns:



111
112
113
# File 'lib/square/client.rb', line 111

def disputes
  @disputes ||= DisputesApi.new @global_configuration
end

#employeesEmployeesApi

Access to employees controller.

Returns:



117
118
119
# File 'lib/square/client.rb', line 117

def employees
  @employees ||= EmployeesApi.new @global_configuration
end

#eventsEventsApi

Access to events controller.

Returns:

  • (EventsApi)

    Returns the controller instance.



123
124
125
# File 'lib/square/client.rb', line 123

def events
  @events ||= EventsApi.new @global_configuration
end

#gift_card_activitiesGiftCardActivitiesApi

Access to gift_card_activities controller.

Returns:



135
136
137
# File 'lib/square/client.rb', line 135

def gift_card_activities
  @gift_card_activities ||= GiftCardActivitiesApi.new @global_configuration
end

#gift_cardsGiftCardsApi

Access to gift_cards controller.

Returns:



129
130
131
# File 'lib/square/client.rb', line 129

def gift_cards
  @gift_cards ||= GiftCardsApi.new @global_configuration
end

#initialize_auth_managers(global_config) ⇒ Object

Initializes the auth managers hash used for authenticating API calls.

Parameters:

  • global_config (GlobalConfiguration)

    The global configuration of the SDK)



319
320
321
322
323
324
# File 'lib/square/client.rb', line 319

def initialize_auth_managers(global_config)
  @auth_managers = {}
  http_client_config = global_config.client_configuration
  %w[global].each { |auth| @auth_managers[auth] = nil }
  @auth_managers['global'] = OAuth2.new(http_client_config.bearer_auth_credentials)
end

#inventoryInventoryApi

Access to inventory controller.

Returns:



141
142
143
# File 'lib/square/client.rb', line 141

def inventory
  @inventory ||= InventoryApi.new @global_configuration
end

#invoicesInvoicesApi

Access to invoices controller.

Returns:



147
148
149
# File 'lib/square/client.rb', line 147

def invoices
  @invoices ||= InvoicesApi.new @global_configuration
end

#laborLaborApi

Access to labor controller.

Returns:

  • (LaborApi)

    Returns the controller instance.



153
154
155
# File 'lib/square/client.rb', line 153

def labor
  @labor ||= LaborApi.new @global_configuration
end

#location_custom_attributesLocationCustomAttributesApi

Access to location_custom_attributes controller.

Returns:



165
166
167
# File 'lib/square/client.rb', line 165

def location_custom_attributes
  @location_custom_attributes ||= LocationCustomAttributesApi.new @global_configuration
end

#locationsLocationsApi

Access to locations controller.

Returns:



159
160
161
# File 'lib/square/client.rb', line 159

def locations
  @locations ||= LocationsApi.new @global_configuration
end

#loyaltyLoyaltyApi

Access to loyalty controller.

Returns:

  • (LoyaltyApi)

    Returns the controller instance.



183
184
185
# File 'lib/square/client.rb', line 183

def loyalty
  @loyalty ||= LoyaltyApi.new @global_configuration
end

#merchant_custom_attributesMerchantCustomAttributesApi

Access to merchant_custom_attributes controller.

Returns:



195
196
197
# File 'lib/square/client.rb', line 195

def merchant_custom_attributes
  @merchant_custom_attributes ||= MerchantCustomAttributesApi.new @global_configuration
end

#merchantsMerchantsApi

Access to merchants controller.

Returns:



189
190
191
# File 'lib/square/client.rb', line 189

def merchants
  @merchants ||= MerchantsApi.new @global_configuration
end

#mobile_authorizationMobileAuthorizationApi

Access to mobile_authorization controller.

Returns:



21
22
23
# File 'lib/square/client.rb', line 21

def mobile_authorization
  @mobile_authorization ||= MobileAuthorizationApi.new @global_configuration
end

#o_authOAuthApi

Access to o_auth controller.

Returns:

  • (OAuthApi)

    Returns the controller instance.



27
28
29
# File 'lib/square/client.rb', line 27

def o_auth
  @o_auth ||= OAuthApi.new @global_configuration
end

#order_custom_attributesOrderCustomAttributesApi

Access to order_custom_attributes controller.

Returns:



207
208
209
# File 'lib/square/client.rb', line 207

def order_custom_attributes
  @order_custom_attributes ||= OrderCustomAttributesApi.new @global_configuration
end

#ordersOrdersApi

Access to orders controller.

Returns:

  • (OrdersApi)

    Returns the controller instance.



201
202
203
# File 'lib/square/client.rb', line 201

def orders
  @orders ||= OrdersApi.new @global_configuration
end

#paymentsPaymentsApi

Access to payments controller.

Returns:



213
214
215
# File 'lib/square/client.rb', line 213

def payments
  @payments ||= PaymentsApi.new @global_configuration
end

#payoutsPayoutsApi

Access to payouts controller.

Returns:

  • (PayoutsApi)

    Returns the controller instance.



219
220
221
# File 'lib/square/client.rb', line 219

def payouts
  @payouts ||= PayoutsApi.new @global_configuration
end

#refundsRefundsApi

Access to refunds controller.

Returns:

  • (RefundsApi)

    Returns the controller instance.



225
226
227
# File 'lib/square/client.rb', line 225

def refunds
  @refunds ||= RefundsApi.new @global_configuration
end

#sdk_versionObject



7
8
9
# File 'lib/square/client.rb', line 7

def sdk_version
  '40.0.0.20241120'
end

#sitesSitesApi

Access to sites controller.

Returns:

  • (SitesApi)

    Returns the controller instance.



231
232
233
# File 'lib/square/client.rb', line 231

def sites
  @sites ||= SitesApi.new @global_configuration
end

#snippetsSnippetsApi

Access to snippets controller.

Returns:



237
238
239
# File 'lib/square/client.rb', line 237

def snippets
  @snippets ||= SnippetsApi.new @global_configuration
end

#square_versionObject



11
12
13
# File 'lib/square/client.rb', line 11

def square_version
  config.square_version
end

#subscriptionsSubscriptionsApi

Access to subscriptions controller.

Returns:



243
244
245
# File 'lib/square/client.rb', line 243

def subscriptions
  @subscriptions ||= SubscriptionsApi.new @global_configuration
end

#teamTeamApi

Access to team controller.

Returns:

  • (TeamApi)

    Returns the controller instance.



249
250
251
# File 'lib/square/client.rb', line 249

def team
  @team ||= TeamApi.new @global_configuration
end

#terminalTerminalApi

Access to terminal controller.

Returns:



255
256
257
# File 'lib/square/client.rb', line 255

def terminal
  @terminal ||= TerminalApi.new @global_configuration
end

#transactionsTransactionsApi

Access to transactions controller.

Returns:



177
178
179
# File 'lib/square/client.rb', line 177

def transactions
  @transactions ||= TransactionsApi.new @global_configuration
end

#user_agent_detailObject



15
16
17
# File 'lib/square/client.rb', line 15

def user_agent_detail
  config.user_agent_detail
end

#v1_transactionsV1TransactionsApi

Access to v1_transactions controller.

Returns:



33
34
35
# File 'lib/square/client.rb', line 33

def v1_transactions
  @v1_transactions ||= V1TransactionsApi.new @global_configuration
end

#vendorsVendorsApi

Access to vendors controller.

Returns:

  • (VendorsApi)

    Returns the controller instance.



261
262
263
# File 'lib/square/client.rb', line 261

def vendors
  @vendors ||= VendorsApi.new @global_configuration
end

#webhook_subscriptionsWebhookSubscriptionsApi

Access to webhook_subscriptions controller.

Returns:



267
268
269
# File 'lib/square/client.rb', line 267

def webhook_subscriptions
  @webhook_subscriptions ||= WebhookSubscriptionsApi.new @global_configuration
end