Class: Gusto::AsyncClient

Inherits:
BaseAsyncClient show all
Defined in:
lib/fern_gusto.rb

Defined Under Namespace

Classes: Options

Instance Attribute Summary

Attributes inherited from BaseAsyncClient

#ach_transactions, #companies, #contractors, #employees, #events, #flows, #generated_documents, #holiday_pay_policies, #invoices, #notifications, #payroll, #recovery_cases, #reports, #time_off_policies, #token, #webhooks, #wire_in_requests

Instance Method Summary collapse

Constructor Details

#initialize(auth:, environment: Gusto::Environment::DEMO, base_url: nil, max_retries: nil, timeout_in_seconds: nil, gusto_api_version: nil) ⇒ Gusto::AsyncClient

Instantiate a new asynchronous Gusto API client

Examples:

Create async client with system access token auth

auth = Gusto::SystemAccessTokenAuth.new(
  type: :system_access_token,
  client_id: 'client_id',
  client_secret: 'client_secret'
)
client = Gusto::AsyncClient.new(auth: auth, environment: :production)

Create async client with company access token auth

auth = Gusto::CompanyAccessTokenAuth.new(
  type: :company_access_token,
  client_id: 'client_id',
  client_secret: 'client_secret',
  redirect_uri: 'https://example.com/callback',
  refresh_token: 'refresh_token',
  access_token: 'access_token'
)
client = Gusto::AsyncClient.new(auth: auth, environment: :production)

Create async client with token auth

auth = Gusto::TokenAuth.new(
  type: :token,
  token: 'token'
)
client = Gusto::AsyncClient.new(auth: auth, environment: :production)

Parameters:

  • auth (SystemAccessTokenAuth, CompanyAccessTokenAuth, TokenAuth)

    Authentication configuration

  • environment (Gusto::Environment) (defaults to: Gusto::Environment::DEMO)

    The Gusto environment to connect to

  • base_url (String) (defaults to: nil)

    The base URL for API requests

  • max_retries (Long) (defaults to: nil)

    The number of times to retry a failed request, defaults to 2

  • timeout_in_seconds (Long) (defaults to: nil)

    The timeout for API requests in seconds

  • gusto_api_version (String) (defaults to: nil)

    Determines the date-based API version associated with your API call



209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
# File 'lib/fern_gusto.rb', line 209

def initialize(auth:, environment: Gusto::Environment::DEMO, base_url: nil, max_retries: nil, timeout_in_seconds: nil, gusto_api_version: nil)
  token_supplier = case auth
  when SystemAccessTokenAuth
    refresher = SystemAccessTokenRefresher.new(
      auth.client_id,
      auth.client_secret
    )
    -> { refresher.get_token }
  when CompanyAccessTokenAuth
    refresher = CompanyAccessTokenRefresher.new(
      auth.client_id,
      auth.client_secret,
      auth.redirect_uri,
      auth.refresh_token
    )
    -> { refresher.get_token }
  when TokenAuth
    -> { auth.token }
  end

  @async_request_client = Gusto::AsyncRequestClient.new(
    base_url: base_url,
    environment: environment,
    max_retries: max_retries,
    timeout_in_seconds: timeout_in_seconds,
    token: token_supplier,
    gusto_api_version: gusto_api_version
  )

  super(
    environment: environment,
    token: token_supplier
  )
end