Class: VitableConnect::Client

Inherits:
Internal::Transport::BaseClient show all
Defined in:
lib/vitable_connect/client.rb,
sig/vitable_connect/client.rbs

Constant Summary collapse

DEFAULT_MAX_RETRIES =

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

Returns:

  • (2)
2
DEFAULT_TIMEOUT_IN_SECONDS =

Default per-request timeout.

Returns:

  • (Float)
60.0
DEFAULT_INITIAL_RETRY_DELAY =

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

Returns:

  • (Float)
0.5
DEFAULT_MAX_RETRY_DELAY =

Default max retry delay in seconds.

Returns:

  • (Float)
8.0
ENVIRONMENTS =

rubocop:disable Style/MutableConstant

Returns:

  • ({)
{production: "https://api.vitablehealth.com", environment_1: "https://api.uat.vitablehealth.com"}

Constants inherited from Internal::Transport::BaseClient

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

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, #send_request, should_retry?, validate!

Methods included from Internal::Util::SorbetRuntimeSupport

#const_missing, #define_sorbet_constant!, #sorbet_constant_defined?, #to_sorbet_type, to_sorbet_type

Constructor Details

#initialize(api_key: ENV["VITABLE_CONNECT_API_KEY"], environment: nil, base_url: ENV["VITABLE_CONNECT_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.

header. API keys use the vitapk prefix, access tokens use the vitat prefix. Defaults to ENV["VITABLE_CONNECT_API_KEY"]

Each environment maps to a different base URL:

  • production corresponds to https://api.vitablehealth.com
  • environment_1 corresponds to https://api.uat.vitablehealth.com

"https://api.example.com/v2/". Defaults to ENV["VITABLE_CONNECT_BASE_URL"]

Parameters:

  • api_key (String, nil) (defaults to: ENV["VITABLE_CONNECT_API_KEY"])

    API Key or Access Token authentication using Bearer token in Authorization

  • environment (:production, :environment_1, nil) (defaults to: nil)

    Specifies the environment to use for the API.

  • base_url (String, nil) (defaults to: ENV["VITABLE_CONNECT_BASE_URL"])

    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)


100
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
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/vitable_connect/client.rb', line 100

def initialize(
  api_key: ENV["VITABLE_CONNECT_API_KEY"],
  environment: nil,
  base_url: ENV["VITABLE_CONNECT_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 ||= VitableConnect::Client::ENVIRONMENTS.fetch(environment&.to_sym || :production) do
    message = "environment must be one of #{VitableConnect::Client::ENVIRONMENTS.keys}, got #{environment}"
    raise ArgumentError.new(message)
  end

  if api_key.nil?
    raise ArgumentError.new("api_key is required, and can be set via environ: \"VITABLE_CONNECT_API_KEY\"")
  end

  headers = {}
  custom_headers_env = ENV["VITABLE_CONNECT_CUSTOM_HEADERS"]
  unless custom_headers_env.nil?
    parsed = {}
    custom_headers_env.split("\n").each do |line|
      colon = line.index(":")
      unless colon.nil?
        parsed[line[0...colon].strip] = line[(colon + 1)..].strip
      end
    end
    headers = parsed.merge(headers)
  end

  @api_key = api_key.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
  )

  @auth = VitableConnect::Resources::Auth.new(client: self)
  @employees = VitableConnect::Resources::Employees.new(client: self)
  @employers = VitableConnect::Resources::Employers.new(client: self)
  @enrollments = VitableConnect::Resources::Enrollments.new(client: self)
  @webhook_events = VitableConnect::Resources::WebhookEvents.new(client: self)
  @groups = VitableConnect::Resources::Groups.new(client: self)
  @members = VitableConnect::Resources::Members.new(client: self)
  @organizations = VitableConnect::Resources::Organizations.new(client: self)
  @plans = VitableConnect::Resources::Plans.new(client: self)
end

Instance Attribute Details

#api_keyString (readonly)

API Key or Access Token authentication using Bearer token in Authorization header. API keys use the vitapk prefix, access tokens use the vitat prefix.

Returns:

  • (String)


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

def api_key
  @api_key
end

#authVitableConnect::Resources::Auth (readonly)

Issue short-lived access tokens for scoped API access



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

def auth
  @auth
end

#employeesVitableConnect::Resources::Employees (readonly)



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

def employees
  @employees
end

#employersVitableConnect::Resources::Employers (readonly)



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

def employers
  @employers
end

#enrollmentsVitableConnect::Resources::Enrollments (readonly)

Manage benefit enrollments and elections for employees



41
42
43
# File 'lib/vitable_connect/client.rb', line 41

def enrollments
  @enrollments
end

#groupsVitableConnect::Resources::Groups (readonly)



47
48
49
# File 'lib/vitable_connect/client.rb', line 47

def groups
  @groups
end

#membersVitableConnect::Resources::Members (readonly)

Browse the members covered across your book and read a member's profile



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

def members
  @members
end

#organizationsVitableConnect::Resources::Organizations (readonly)



54
55
56
# File 'lib/vitable_connect/client.rb', line 54

def organizations
  @organizations
end

#plansVitableConnect::Resources::Plans (readonly)



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

def plans
  @plans
end

#webhook_eventsVitableConnect::Resources::WebhookEvents (readonly)



44
45
46
# File 'lib/vitable_connect/client.rb', line 44

def webhook_events
  @webhook_events
end