Class: ApimaticCalculator::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/apimatic_calculator/configuration.rb

Overview

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

Constant Summary collapse

ENVIRONMENTS =

All the environments the SDK can run in.

{
  Environment::PRODUCTION => {
    Server::CALCULATOR => 'http://examples.apimatic.io/apps/calculator'
  }
}.freeze

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(timeout: 60, max_retries: 0, retry_interval: 1, backoff_factor: 1, environment: Environment::PRODUCTION) ⇒ Configuration

Returns a new instance of Configuration.



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# 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

Class Attribute Details

.environmentsObject (readonly)

Returns the value of attribute environments.



34
35
36
# File 'lib/apimatic_calculator/configuration.rb', line 34

def environments
  @environments
end

Instance Attribute Details

#backoff_factorObject (readonly)

Returns the value of attribute backoff_factor.



30
31
32
# File 'lib/apimatic_calculator/configuration.rb', line 30

def backoff_factor
  @backoff_factor
end

#environmentObject (readonly)

Returns the value of attribute environment.



31
32
33
# File 'lib/apimatic_calculator/configuration.rb', line 31

def environment
  @environment
end

#http_clientObject (readonly)

The attribute readers for properties.



26
27
28
# File 'lib/apimatic_calculator/configuration.rb', line 26

def http_client
  @http_client
end

#max_retriesObject (readonly)

Returns the value of attribute max_retries.



28
29
30
# File 'lib/apimatic_calculator/configuration.rb', line 28

def max_retries
  @max_retries
end

#retry_intervalObject (readonly)

Returns the value of attribute retry_interval.



29
30
31
# File 'lib/apimatic_calculator/configuration.rb', line 29

def retry_interval
  @retry_interval
end

#timeoutObject (readonly)

Returns the value of attribute timeout.



27
28
29
# File 'lib/apimatic_calculator/configuration.rb', line 27

def timeout
  @timeout
end

Instance Method Details

#clone_with(timeout: nil, max_retries: nil, retry_interval: nil, backoff_factor: nil, environment: nil) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
# 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_clientObject



73
74
75
76
77
# 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) ⇒ String

Generates the appropriate base URI for the environment and the server. required.

Parameters:

  • The (Configuration::Server)

    server enum for which the base URI is

Returns:

  • (String)

    The base URI.



90
91
92
# File 'lib/apimatic_calculator/configuration.rb', line 90

def get_base_uri(server = Server::CALCULATOR)
  ENVIRONMENTS[environment][server].clone
end