class ApimaticCalculator::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]
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) click to toggle source
# File lib/apimatic_calculator/configuration.rb, line 37
def initialize(timeout: 60, max_retries: 0, retry_interval: 1,
               backoff_factor: 1, environment: Environment::PRODUCTION)
  # 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)

  # 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) click to toggle source
# File lib/apimatic_calculator/configuration.rb, line 59
def clone_with(timeout: nil, max_retries: nil, retry_interval: nil,
               backoff_factor: nil, environment: nil)
  timeout ||= self.timeout
  max_retries ||= self.max_retries
  retry_interval ||= self.retry_interval
  backoff_factor ||= self.backoff_factor
  environment ||= self.environment

  Configuration.new(timeout: timeout, max_retries: max_retries,
                    retry_interval: retry_interval,
                    backoff_factor: backoff_factor,
                    environment: environment)
end
create_http_client() click to toggle source
# File lib/apimatic_calculator/configuration.rb, line 73
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::CALCULATOR) 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/apimatic_calculator/configuration.rb, line 90
def get_base_uri(server = Server::CALCULATOR)
  ENVIRONMENTS[environment][server].clone
end