class Beaver::Configuration

All configuration including auth info and base URI for the API access are configured in this class.

Constants

ENVIRONMENTS

All the environments the SDK can run in.

Attributes

environments[R]
app_token[R]
backoff_factor[R]
environment[R]
http_client[R]

The attribute readers for properties.

max_retries[R]
retry_interval[R]
timeout[R]

Public Class Methods

new(timeout: 60, max_retries: 0, retry_interval: 1, backoff_factor: 1, environment: Environment::PRODUCTION, app_token: '') click to toggle source
# File lib/beaver/configuration.rb, line 44
def initialize(timeout: 60, max_retries: 0, retry_interval: 1,
               backoff_factor: 1, environment: Environment::PRODUCTION,
               app_token: '')
  # The value to use for connection timeout
  @timeout = timeout

  # The number of times to retry an endpoint call if it fails
  @max_retries = max_retries

  # Pause in seconds between retries
  @retry_interval = retry_interval

  # The amount to multiply each successive retry's interval amount
  # by in order to provide backoff
  @backoff_factor = backoff_factor

  # Current API environment
  @environment = String(environment)

  # TODO: Replace
  @app_token = app_token

  # The Http Client to use for making requests.
  @http_client = create_http_client
end

Public Instance Methods

clone_with(timeout: nil, max_retries: nil, retry_interval: nil, backoff_factor: nil, environment: nil, app_token: nil) click to toggle source
# File lib/beaver/configuration.rb, line 70
def clone_with(timeout: nil, max_retries: nil, retry_interval: nil,
               backoff_factor: nil, environment: nil, app_token: nil)
  timeout ||= self.timeout
  max_retries ||= self.max_retries
  retry_interval ||= self.retry_interval
  backoff_factor ||= self.backoff_factor
  environment ||= self.environment
  app_token ||= self.app_token

  Configuration.new(timeout: timeout, max_retries: max_retries,
                    retry_interval: retry_interval,
                    backoff_factor: backoff_factor,
                    environment: environment, app_token: app_token)
end
create_http_client() click to toggle source
# File lib/beaver/configuration.rb, line 85
def create_http_client
  FaradayClient.new(timeout: timeout, max_retries: max_retries,
                    retry_interval: retry_interval,
                    backoff_factor: backoff_factor)
end
get_base_uri(server = Server::DEFAULT) click to toggle source

Generates the appropriate base URI for the environment and the server. @param [Configuration::Server] The server enum for which the base URI is required. @return [String] The base URI.

# File lib/beaver/configuration.rb, line 111
def get_base_uri(server = Server::DEFAULT)
  ENVIRONMENTS[environment][server].clone
end