Class: FinchAPI::Client

Inherits:
Internal::Transport::BaseClient show all
Defined in:
lib/finch_api/client.rb

Constant Summary collapse

DEFAULT_MAX_RETRIES =

Default max number of retries to attempt after a failed retryable request.

2
DEFAULT_TIMEOUT_IN_SECONDS =

Default per-request timeout.

60.0
DEFAULT_INITIAL_RETRY_DELAY =

Default initial retry delay in seconds. Overall delay is calculated using exponential backoff + jitter.

0.5
DEFAULT_MAX_RETRY_DELAY =

Default max retry delay in seconds.

8.0

Constants inherited from Internal::Transport::BaseClient

Internal::Transport::BaseClient::MAX_REDIRECTS, Internal::Transport::BaseClient::PLATFORM_HEADERS

Instance Attribute Summary collapse

Attributes inherited from Internal::Transport::BaseClient

#base_url, #headers, #idempotency_header, #initial_retry_delay, #max_retries, #max_retry_delay, #requester, #timeout

Instance Method Summary collapse

Methods inherited from Internal::Transport::BaseClient

follow_redirect, #inspect, reap_connection!, #request, should_retry?, validate!

Methods included from Internal::Util::SorbetRuntimeSupport

#const_missing, #define_sorbet_constant!

Constructor Details

#initialize(client_id: , client_secret: , access_token: nil, base_url: , max_retries: self.class::DEFAULT_MAX_RETRIES, timeout: self.class::DEFAULT_TIMEOUT_IN_SECONDS, initial_retry_delay: self.class::DEFAULT_INITIAL_RETRY_DELAY, max_retry_delay: self.class::DEFAULT_MAX_RETRY_DELAY) ⇒ Client

Creates and returns a new client for interacting with the API.

‘“api.example.com/v2/”`. Defaults to `ENV`

Parameters:

  • client_id (String, nil) (defaults to: )

    Defaults to ‘ENV`

  • client_secret (String, nil) (defaults to: )

    Defaults to ‘ENV`

  • access_token (String, nil) (defaults to: nil)
  • base_url (String, nil) (defaults to: )

    Override the default base URL for the API, e.g.,

  • max_retries (Integer) (defaults to: self.class::DEFAULT_MAX_RETRIES)

    Max number of retries to attempt after a failed retryable request.

  • timeout (Float) (defaults to: self.class::DEFAULT_TIMEOUT_IN_SECONDS)
  • initial_retry_delay (Float) (defaults to: self.class::DEFAULT_INITIAL_RETRY_DELAY)
  • max_retry_delay (Float) (defaults to: self.class::DEFAULT_MAX_RETRY_DELAY)


101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/finch_api/client.rb', line 101

def initialize(
  client_id: ENV["FINCH_CLIENT_ID"],
  client_secret: ENV["FINCH_CLIENT_SECRET"],
  access_token: nil,
  base_url: ENV["FINCH_BASE_URL"],
  max_retries: self.class::DEFAULT_MAX_RETRIES,
  timeout: self.class::DEFAULT_TIMEOUT_IN_SECONDS,
  initial_retry_delay: self.class::DEFAULT_INITIAL_RETRY_DELAY,
  max_retry_delay: self.class::DEFAULT_MAX_RETRY_DELAY
)
  base_url ||= "https://api.tryfinch.com"

  headers = {
    "finch-api-version" => "2020-09-17"
  }

  @client_id = client_id&.to_s
  @client_secret = client_secret&.to_s
  @access_token = access_token&.to_s

  super(
    base_url: base_url,
    timeout: timeout,
    max_retries: max_retries,
    initial_retry_delay: initial_retry_delay,
    max_retry_delay: max_retry_delay,
    headers: headers
  )

  @access_tokens = FinchAPI::Resources::AccessTokens.new(client: self)
  @hris = FinchAPI::Resources::HRIS.new(client: self)
  @providers = FinchAPI::Resources::Providers.new(client: self)
  @account = FinchAPI::Resources::Account.new(client: self)
  @webhooks = FinchAPI::Resources::Webhooks.new(client: self)
  @request_forwarding = FinchAPI::Resources::RequestForwarding.new(client: self)
  @jobs = FinchAPI::Resources::Jobs.new(client: self)
  @sandbox = FinchAPI::Resources::Sandbox.new(client: self)
  @payroll = FinchAPI::Resources::Payroll.new(client: self)
  @connect = FinchAPI::Resources::Connect.new(client: self)
end

Instance Attribute Details

#access_tokenString? (readonly)

Returns:

  • (String, nil)


19
20
21
# File 'lib/finch_api/client.rb', line 19

def access_token
  @access_token
end

#access_tokensFinchAPI::Resources::AccessTokens (readonly)



28
29
30
# File 'lib/finch_api/client.rb', line 28

def access_tokens
  @access_tokens
end

#accountFinchAPI::Resources::Account (readonly)



37
38
39
# File 'lib/finch_api/client.rb', line 37

def 
  @account
end

#client_idString? (readonly)

Returns:

  • (String, nil)


22
23
24
# File 'lib/finch_api/client.rb', line 22

def client_id
  @client_id
end

#client_secretString? (readonly)

Returns:

  • (String, nil)


25
26
27
# File 'lib/finch_api/client.rb', line 25

def client_secret
  @client_secret
end

#connectFinchAPI::Resources::Connect (readonly)



55
56
57
# File 'lib/finch_api/client.rb', line 55

def connect
  @connect
end

#hrisFinchAPI::Resources::HRIS (readonly)



31
32
33
# File 'lib/finch_api/client.rb', line 31

def hris
  @hris
end

#jobsFinchAPI::Resources::Jobs (readonly)



46
47
48
# File 'lib/finch_api/client.rb', line 46

def jobs
  @jobs
end

#payrollFinchAPI::Resources::Payroll (readonly)



52
53
54
# File 'lib/finch_api/client.rb', line 52

def payroll
  @payroll
end

#providersFinchAPI::Resources::Providers (readonly)



34
35
36
# File 'lib/finch_api/client.rb', line 34

def providers
  @providers
end

#request_forwardingFinchAPI::Resources::RequestForwarding (readonly)



43
44
45
# File 'lib/finch_api/client.rb', line 43

def request_forwarding
  @request_forwarding
end

#sandboxFinchAPI::Resources::Sandbox (readonly)



49
50
51
# File 'lib/finch_api/client.rb', line 49

def sandbox
  @sandbox
end

#webhooksFinchAPI::Resources::Webhooks (readonly)



40
41
42
# File 'lib/finch_api/client.rb', line 40

def webhooks
  @webhooks
end