Class: Bandwidth::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/bandwidth/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::DEFAULT => 'api.bandwidth.com',
    Server::MESSAGINGDEFAULT => 'https://messaging.bandwidth.com/api/v2',
    Server::TWOFACTORAUTHDEFAULT => 'https://mfa.bandwidth.com/api/v1/',
    Server::VOICEDEFAULT => 'https://voice.bandwidth.com'
  }
}.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, messaging_basic_auth_user_name: 'TODO: Replace', messaging_basic_auth_password: 'TODO: Replace', two_factor_auth_basic_auth_user_name: 'TODO: Replace', two_factor_auth_basic_auth_password: 'TODO: Replace', voice_basic_auth_user_name: 'TODO: Replace', voice_basic_auth_password: 'TODO: Replace') ⇒ Configuration

Returns a new instance of Configuration.



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/bandwidth/configuration.rb', line 45

def initialize(timeout: 60, max_retries: 0, retry_interval: 1,
               backoff_factor: 1, environment: Environment::PRODUCTION,
               messaging_basic_auth_user_name: 'TODO: Replace',
               messaging_basic_auth_password: 'TODO: Replace',
               two_factor_auth_basic_auth_user_name: 'TODO: Replace',
               two_factor_auth_basic_auth_password: 'TODO: Replace',
               voice_basic_auth_user_name: 'TODO: Replace',
               voice_basic_auth_password: 'TODO: Replace')
  # 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 username to use with basic authentication
  @messaging_basic_auth_user_name = messaging_basic_auth_user_name

  # The password to use with basic authentication
  @messaging_basic_auth_password = messaging_basic_auth_password

  # The username to use with basic authentication
  @two_factor_auth_basic_auth_user_name = two_factor_auth_basic_auth_user_name

  # The password to use with basic authentication
  @two_factor_auth_basic_auth_password = two_factor_auth_basic_auth_password

  # The username to use with basic authentication
  @voice_basic_auth_user_name = voice_basic_auth_user_name

  # The password to use with basic authentication
  @voice_basic_auth_password = voice_basic_auth_password

  # 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.



42
43
44
# File 'lib/bandwidth/configuration.rb', line 42

def environments
  @environments
end

Instance Attribute Details

#backoff_factorObject (readonly)

Returns the value of attribute backoff_factor.



32
33
34
# File 'lib/bandwidth/configuration.rb', line 32

def backoff_factor
  @backoff_factor
end

#environmentObject (readonly)

Returns the value of attribute environment.



33
34
35
# File 'lib/bandwidth/configuration.rb', line 33

def environment
  @environment
end

#http_clientObject (readonly)

The attribute readers for properties.



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

def http_client
  @http_client
end

#max_retriesObject (readonly)

Returns the value of attribute max_retries.



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

def max_retries
  @max_retries
end

#messaging_basic_auth_passwordObject (readonly)

Returns the value of attribute messaging_basic_auth_password.



35
36
37
# File 'lib/bandwidth/configuration.rb', line 35

def messaging_basic_auth_password
  @messaging_basic_auth_password
end

#messaging_basic_auth_user_nameObject (readonly)

Returns the value of attribute messaging_basic_auth_user_name.



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

def messaging_basic_auth_user_name
  @messaging_basic_auth_user_name
end

#retry_intervalObject (readonly)

Returns the value of attribute retry_interval.



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

def retry_interval
  @retry_interval
end

#timeoutObject (readonly)

Returns the value of attribute timeout.



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

def timeout
  @timeout
end

#two_factor_auth_basic_auth_passwordObject (readonly)

Returns the value of attribute two_factor_auth_basic_auth_password.



37
38
39
# File 'lib/bandwidth/configuration.rb', line 37

def two_factor_auth_basic_auth_password
  @two_factor_auth_basic_auth_password
end

#two_factor_auth_basic_auth_user_nameObject (readonly)

Returns the value of attribute two_factor_auth_basic_auth_user_name.



36
37
38
# File 'lib/bandwidth/configuration.rb', line 36

def two_factor_auth_basic_auth_user_name
  @two_factor_auth_basic_auth_user_name
end

#voice_basic_auth_passwordObject (readonly)

Returns the value of attribute voice_basic_auth_password.



39
40
41
# File 'lib/bandwidth/configuration.rb', line 39

def voice_basic_auth_password
  @voice_basic_auth_password
end

#voice_basic_auth_user_nameObject (readonly)

Returns the value of attribute voice_basic_auth_user_name.



38
39
40
# File 'lib/bandwidth/configuration.rb', line 38

def voice_basic_auth_user_name
  @voice_basic_auth_user_name
end

Instance Method Details

#clone_with(timeout: nil, max_retries: nil, retry_interval: nil, backoff_factor: nil, environment: nil, messaging_basic_auth_user_name: nil, messaging_basic_auth_password: nil, two_factor_auth_basic_auth_user_name: nil, two_factor_auth_basic_auth_password: nil, voice_basic_auth_user_name: nil, voice_basic_auth_password: nil) ⇒ Object



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/bandwidth/configuration.rb', line 91

def clone_with(timeout: nil, max_retries: nil, retry_interval: nil,
               backoff_factor: nil, environment: nil,
               messaging_basic_auth_user_name: nil,
               messaging_basic_auth_password: nil,
               two_factor_auth_basic_auth_user_name: nil,
               two_factor_auth_basic_auth_password: nil,
               voice_basic_auth_user_name: nil,
               voice_basic_auth_password: nil)
  timeout ||= self.timeout
  max_retries ||= self.max_retries
  retry_interval ||= self.retry_interval
  backoff_factor ||= self.backoff_factor
  environment ||= self.environment
  messaging_basic_auth_user_name ||= self.messaging_basic_auth_user_name
  messaging_basic_auth_password ||= self.messaging_basic_auth_password
  two_factor_auth_basic_auth_user_name ||= self.two_factor_auth_basic_auth_user_name
  two_factor_auth_basic_auth_password ||= self.two_factor_auth_basic_auth_password
  voice_basic_auth_user_name ||= self.voice_basic_auth_user_name
  voice_basic_auth_password ||= self.voice_basic_auth_password

  Configuration.new(
    timeout: timeout, max_retries: max_retries,
    retry_interval: retry_interval, backoff_factor: backoff_factor,
    environment: environment,
    messaging_basic_auth_user_name: messaging_basic_auth_user_name,
    messaging_basic_auth_password: messaging_basic_auth_password,
    two_factor_auth_basic_auth_user_name: two_factor_auth_basic_auth_user_name,
    two_factor_auth_basic_auth_password: two_factor_auth_basic_auth_password,
    voice_basic_auth_user_name: voice_basic_auth_user_name,
    voice_basic_auth_password: voice_basic_auth_password
  )
end

#create_http_clientObject



124
125
126
127
128
# File 'lib/bandwidth/configuration.rb', line 124

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) ⇒ 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.



144
145
146
# File 'lib/bandwidth/configuration.rb', line 144

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