lib/bandwidth/configuration.rb in bandwidth-sdk-3.9.0 vs lib/bandwidth/configuration.rb in bandwidth-sdk-3.10.0
- old
+ new
@@ -5,11 +5,12 @@
module Bandwidth
# An enum for SDK environments.
class Environment
ENVIRONMENT = [
- PRODUCTION = 'production'.freeze
+ PRODUCTION = 'production'.freeze,
+ CUSTOM = 'custom'.freeze
].freeze
end
# An enum for API servers.
class Server
@@ -30,10 +31,11 @@
attr_reader :timeout
attr_reader :max_retries
attr_reader :retry_interval
attr_reader :backoff_factor
attr_reader :environment
+ attr_reader :base_url
attr_reader :messaging_basic_auth_user_name
attr_reader :messaging_basic_auth_password
attr_reader :two_factor_auth_basic_auth_user_name
attr_reader :two_factor_auth_basic_auth_password
attr_reader :voice_basic_auth_user_name
@@ -45,10 +47,11 @@
attr_reader :environments
end
def initialize(timeout: 60, max_retries: 0, retry_interval: 1,
backoff_factor: 1, environment: Environment::PRODUCTION,
+ base_url: 'https://www.example.com',
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',
@@ -69,10 +72,13 @@
@backoff_factor = backoff_factor
# Current API environment
@environment = String(environment)
+ # baseUrl value
+ @base_url = base_url
+
# 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
@@ -98,11 +104,11 @@
# The Http Client to use for making requests.
@http_client = create_http_client
end
def clone_with(timeout: nil, max_retries: nil, retry_interval: nil,
- backoff_factor: nil, environment: nil,
+ backoff_factor: nil, environment: nil, base_url: 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,
@@ -112,10 +118,11 @@
timeout ||= self.timeout
max_retries ||= self.max_retries
retry_interval ||= self.retry_interval
backoff_factor ||= self.backoff_factor
environment ||= self.environment
+ base_url ||= self.base_url
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
@@ -124,11 +131,11 @@
web_rtc_basic_auth_password ||= self.web_rtc_basic_auth_password
Configuration.new(
timeout: timeout, max_retries: max_retries,
retry_interval: retry_interval, backoff_factor: backoff_factor,
- environment: environment,
+ environment: environment, base_url: base_url,
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,
@@ -150,17 +157,29 @@
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',
Server::WEBRTCDEFAULT => 'https://api.webrtc.bandwidth.com/v1'
+ },
+ Environment::CUSTOM => {
+ Server::DEFAULT => '{base_url}',
+ Server::MESSAGINGDEFAULT => '{base_url}',
+ Server::TWOFACTORAUTHDEFAULT => '{base_url}',
+ Server::VOICEDEFAULT => '{base_url}',
+ Server::WEBRTCDEFAULT => '{base_url}'
}
}.freeze
# 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.
def get_base_uri(server = Server::DEFAULT)
- ENVIRONMENTS[environment][server].clone
+ parameters = {
+ 'base_url' => { 'value' => base_url, 'encode' => false }
+ }
+ APIHelper.append_url_with_template_parameters(
+ ENVIRONMENTS[environment][server], parameters
+ )
end
end
end