Class: ApiParticulier::Commons::Configuration
- Inherits:
-
Object
- Object
- ApiParticulier::Commons::Configuration
- Defined in:
- lib/api_particulier/commons/configuration.rb
Constant Summary collapse
- PRODUCTION =
:production- STAGING =
:staging- ENVIRONMENTS =
[PRODUCTION, STAGING].freeze
- DEFAULT_OPEN_TIMEOUT =
5- DEFAULT_READ_TIMEOUT =
30
Instance Attribute Summary collapse
-
#adapter ⇒ Object
readonly
Returns the value of attribute adapter.
-
#auth_strategy ⇒ Object
readonly
Returns the value of attribute auth_strategy.
-
#base_url ⇒ Object
readonly
Returns the value of attribute base_url.
-
#default_params ⇒ Object
readonly
Returns the value of attribute default_params.
-
#environment ⇒ Object
readonly
Returns the value of attribute environment.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#open_timeout ⇒ Object
readonly
Returns the value of attribute open_timeout.
-
#read_timeout ⇒ Object
readonly
Returns the value of attribute read_timeout.
-
#retry ⇒ Object
readonly
Returns the value of attribute retry.
-
#user_agent ⇒ Object
readonly
Returns the value of attribute user_agent.
Instance Method Summary collapse
-
#initialize(base_urls:, token: nil, auth_strategy: nil, environment: PRODUCTION, base_url: nil, default_params: {}, open_timeout: DEFAULT_OPEN_TIMEOUT, read_timeout: DEFAULT_READ_TIMEOUT, retry: nil, logger: nil, user_agent: nil, adapter: nil) ⇒ Configuration
constructor
A new instance of Configuration.
- #production? ⇒ Boolean
- #staging? ⇒ Boolean
- #with(**overrides) ⇒ Object (also: #copy)
Constructor Details
#initialize(base_urls:, token: nil, auth_strategy: nil, environment: PRODUCTION, base_url: nil, default_params: {}, open_timeout: DEFAULT_OPEN_TIMEOUT, read_timeout: DEFAULT_READ_TIMEOUT, retry: nil, logger: nil, user_agent: nil, adapter: nil) ⇒ Configuration
Returns a new instance of Configuration.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/api_particulier/commons/configuration.rb', line 27 def initialize( base_urls:, token: nil, auth_strategy: nil, environment: PRODUCTION, base_url: nil, default_params: {}, open_timeout: DEFAULT_OPEN_TIMEOUT, read_timeout: DEFAULT_READ_TIMEOUT, retry: nil, logger: nil, user_agent: nil, adapter: nil ) @base_urls = base_urls resolved_env = resolve_environment(environment) @environment = resolved_env @explicit_base_url = !base_url.nil? @base_url = base_url || base_urls.fetch(resolved_env) @auth_strategy = auth_strategy || build_bearer_strategy(token) @default_params = default_params.freeze @open_timeout = open_timeout @read_timeout = read_timeout @retry = binding.local_variable_get(:retry) @logger = logger @user_agent = user_agent @adapter = adapter freeze end |
Instance Attribute Details
#adapter ⇒ Object (readonly)
Returns the value of attribute adapter.
16 17 18 |
# File 'lib/api_particulier/commons/configuration.rb', line 16 def adapter @adapter end |
#auth_strategy ⇒ Object (readonly)
Returns the value of attribute auth_strategy.
16 17 18 |
# File 'lib/api_particulier/commons/configuration.rb', line 16 def auth_strategy @auth_strategy end |
#base_url ⇒ Object (readonly)
Returns the value of attribute base_url.
16 17 18 |
# File 'lib/api_particulier/commons/configuration.rb', line 16 def base_url @base_url end |
#default_params ⇒ Object (readonly)
Returns the value of attribute default_params.
16 17 18 |
# File 'lib/api_particulier/commons/configuration.rb', line 16 def default_params @default_params end |
#environment ⇒ Object (readonly)
Returns the value of attribute environment.
16 17 18 |
# File 'lib/api_particulier/commons/configuration.rb', line 16 def environment @environment end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
16 17 18 |
# File 'lib/api_particulier/commons/configuration.rb', line 16 def logger @logger end |
#open_timeout ⇒ Object (readonly)
Returns the value of attribute open_timeout.
16 17 18 |
# File 'lib/api_particulier/commons/configuration.rb', line 16 def open_timeout @open_timeout end |
#read_timeout ⇒ Object (readonly)
Returns the value of attribute read_timeout.
16 17 18 |
# File 'lib/api_particulier/commons/configuration.rb', line 16 def read_timeout @read_timeout end |
#retry ⇒ Object (readonly)
Returns the value of attribute retry.
16 17 18 |
# File 'lib/api_particulier/commons/configuration.rb', line 16 def retry @retry end |
#user_agent ⇒ Object (readonly)
Returns the value of attribute user_agent.
16 17 18 |
# File 'lib/api_particulier/commons/configuration.rb', line 16 def user_agent @user_agent end |
Instance Method Details
#production? ⇒ Boolean
62 63 64 |
# File 'lib/api_particulier/commons/configuration.rb', line 62 def production? environment == PRODUCTION end |
#staging? ⇒ Boolean
66 67 68 |
# File 'lib/api_particulier/commons/configuration.rb', line 66 def staging? environment == STAGING end |
#with(**overrides) ⇒ Object Also known as: copy
57 58 59 |
# File 'lib/api_particulier/commons/configuration.rb', line 57 def with(**overrides) self.class.new(**current_attrs.merge(overrides)) end |