Class: UntitledApi::Configuration
- Inherits:
-
CoreLibrary::HttpClientConfiguration
- Object
- CoreLibrary::HttpClientConfiguration
- UntitledApi::Configuration
- Defined in:
- lib/untitled_api/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 => 'https://{defaultHost}' } }.freeze
Class Attribute Summary collapse
-
.environments ⇒ Object
readonly
Returns the value of attribute environments.
Instance Attribute Summary collapse
-
#custom_header_authentication_credentials ⇒ Object
readonly
The attribute readers for properties.
-
#default_host ⇒ Object
readonly
The attribute readers for properties.
-
#environment ⇒ Object
readonly
The attribute readers for properties.
Instance Method Summary collapse
- #authorization ⇒ Object
- #clone_with(connection: nil, adapter: nil, timeout: nil, max_retries: nil, retry_interval: nil, backoff_factor: nil, retry_statuses: nil, retry_methods: nil, http_callback: nil, environment: nil, default_host: nil, authorization: nil, custom_header_authentication_credentials: nil) ⇒ Object
- #create_auth_credentials_object(authorization, custom_header_authentication_credentials) ⇒ Object
-
#get_base_uri(server = Server::DEFAULT) ⇒ String
Generates the appropriate base URI for the environment and the server.
-
#initialize(connection: nil, adapter: :net_http_persistent, timeout: 60, max_retries: 0, retry_interval: 1, backoff_factor: 2, retry_statuses: [408, 413, 429, 500, 502, 503, 504, 521, 522, 524], retry_methods: %i[get put],, http_callback: nil, environment: Environment::PRODUCTION, default_host: 'www.example.com', authorization: nil, custom_header_authentication_credentials: nil) ⇒ Configuration
constructor
A new instance of Configuration.
Constructor Details
#initialize(connection: nil, adapter: :net_http_persistent, timeout: 60, max_retries: 0, retry_interval: 1, backoff_factor: 2, retry_statuses: [408, 413, 429, 500, 502, 503, 504, 521, 522, 524], retry_methods: %i[get put],, http_callback: nil, environment: Environment::PRODUCTION, default_host: 'www.example.com', authorization: nil, custom_header_authentication_credentials: nil) ⇒ Configuration
Returns a new instance of Configuration.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/untitled_api/configuration.rb', line 36 def initialize( connection: nil, adapter: :net_http_persistent, timeout: 60, max_retries: 0, retry_interval: 1, backoff_factor: 2, retry_statuses: [408, 413, 429, 500, 502, 503, 504, 521, 522, 524], retry_methods: %i[get put], http_callback: nil, environment: Environment::PRODUCTION, default_host: 'www.example.com', authorization: nil, custom_header_authentication_credentials: nil ) super connection: connection, adapter: adapter, timeout: timeout, max_retries: max_retries, retry_interval: retry_interval, backoff_factor: backoff_factor, retry_statuses: retry_statuses, retry_methods: retry_methods, http_callback: http_callback # Current API environment @environment = String(environment) # defaultHost value @default_host = default_host # Token-based authentication with required prefix "Token" @authorization = # Initializing Custom Header Signature credentials with the provided auth parameters @custom_header_authentication_credentials = create_auth_credentials_object( , custom_header_authentication_credentials ) # The Http Client to use for making requests. set_http_client CoreLibrary::FaradayClient.new(self) end |
Class Attribute Details
.environments ⇒ Object (readonly)
Returns the value of attribute environments.
33 34 35 |
# File 'lib/untitled_api/configuration.rb', line 33 def environments @environments end |
Instance Attribute Details
#custom_header_authentication_credentials ⇒ Object (readonly)
The attribute readers for properties.
29 30 31 |
# File 'lib/untitled_api/configuration.rb', line 29 def custom_header_authentication_credentials @custom_header_authentication_credentials end |
#default_host ⇒ Object (readonly)
The attribute readers for properties.
29 30 31 |
# File 'lib/untitled_api/configuration.rb', line 29 def default_host @default_host end |
#environment ⇒ Object (readonly)
The attribute readers for properties.
29 30 31 |
# File 'lib/untitled_api/configuration.rb', line 29 def environment @environment end |
Instance Method Details
#authorization ⇒ Object
24 25 26 |
# File 'lib/untitled_api/configuration.rb', line 24 def @custom_header_authentication_credentials. end |
#clone_with(connection: nil, adapter: nil, timeout: nil, max_retries: nil, retry_interval: nil, backoff_factor: nil, retry_statuses: nil, retry_methods: nil, http_callback: nil, environment: nil, default_host: nil, authorization: nil, custom_header_authentication_credentials: nil) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/untitled_api/configuration.rb', line 68 def clone_with(connection: nil, adapter: nil, timeout: nil, max_retries: nil, retry_interval: nil, backoff_factor: nil, retry_statuses: nil, retry_methods: nil, http_callback: nil, environment: nil, default_host: nil, authorization: nil, custom_header_authentication_credentials: nil) connection ||= self.connection adapter ||= self.adapter timeout ||= self.timeout max_retries ||= self.max_retries retry_interval ||= self.retry_interval backoff_factor ||= self.backoff_factor retry_statuses ||= self.retry_statuses retry_methods ||= self.retry_methods http_callback ||= self.http_callback environment ||= self.environment default_host ||= self.default_host custom_header_authentication_credentials = create_auth_credentials_object( , custom_header_authentication_credentials || self.custom_header_authentication_credentials ) Configuration.new( connection: connection, adapter: adapter, timeout: timeout, max_retries: max_retries, retry_interval: retry_interval, backoff_factor: backoff_factor, retry_statuses: retry_statuses, retry_methods: retry_methods, http_callback: http_callback, environment: environment, default_host: default_host, custom_header_authentication_credentials: custom_header_authentication_credentials ) end |
#create_auth_credentials_object(authorization, custom_header_authentication_credentials) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/untitled_api/configuration.rb', line 99 def create_auth_credentials_object(, custom_header_authentication_credentials) return custom_header_authentication_credentials if .nil? warn('The \'authorization\' params are deprecated. Use \'custom_header_a'\ 'uthentication_credentials\' param instead.') unless custom_header_authentication_credentials.nil? return custom_header_authentication_credentials.clone_with( authorization: ) end CustomHeaderAuthenticationCredentials.new(authorization: ) end |
#get_base_uri(server = Server::DEFAULT) ⇒ String
Generates the appropriate base URI for the environment and the server. required.
126 127 128 129 130 131 132 133 |
# File 'lib/untitled_api/configuration.rb', line 126 def get_base_uri(server = Server::DEFAULT) parameters = { 'defaultHost' => { 'value' => default_host, 'encode' => false } } APIHelper.append_url_with_template_parameters( ENVIRONMENTS[environment][server], parameters ) end |