Class: Dadata::Configuration
- Inherits:
-
Object
- Object
- Dadata::Configuration
- Includes:
- SensitiveData
- Defined in:
- lib/dadata.rb
Overview
Configuration class for the DaData API client
Constant Summary
Constants included from SensitiveData
SensitiveData::SENSITIVE_HEADERS
Instance Attribute Summary collapse
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#log_level ⇒ Object
Returns the value of attribute log_level.
-
#log_request_bodies ⇒ Object
Returns the value of attribute log_request_bodies.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#secret_key ⇒ Object
Returns the value of attribute secret_key.
-
#suggestions_count ⇒ Object
Returns the value of attribute suggestions_count.
-
#timeout_sec ⇒ Object
Returns the value of attribute timeout_sec.
Instance Method Summary collapse
-
#initialize ⇒ Configuration
constructor
Initialize a new Configuration instance with default values.
-
#validate! ⇒ void
Validates the configuration settings.
Methods included from SensitiveData
#sanitize_headers, #sanitize_message
Constructor Details
#initialize ⇒ Configuration
Initialize a new Configuration instance with default values
59 60 61 62 63 64 65 66 67 |
# File 'lib/dadata.rb', line 59 def initialize @suggestions_count = SUGGESTIONS_COUNT @timeout_sec = TIMEOUT_SEC @log_level = :info # Request payloads carry PII (passports, names, phones); never logged unless # a developer explicitly opts in for debugging. @log_request_bodies = false setup_logger end |
Instance Attribute Details
#api_key ⇒ Object
Returns the value of attribute api_key.
52 53 54 |
# File 'lib/dadata.rb', line 52 def api_key @api_key end |
#log_level ⇒ Object
Returns the value of attribute log_level.
52 53 54 |
# File 'lib/dadata.rb', line 52 def log_level @log_level end |
#log_request_bodies ⇒ Object
Returns the value of attribute log_request_bodies.
52 53 54 |
# File 'lib/dadata.rb', line 52 def log_request_bodies @log_request_bodies end |
#logger ⇒ Object
Returns the value of attribute logger.
54 55 56 |
# File 'lib/dadata.rb', line 54 def logger @logger end |
#secret_key ⇒ Object
Returns the value of attribute secret_key.
52 53 54 |
# File 'lib/dadata.rb', line 52 def secret_key @secret_key end |
#suggestions_count ⇒ Object
Returns the value of attribute suggestions_count.
54 55 56 |
# File 'lib/dadata.rb', line 54 def suggestions_count @suggestions_count end |
#timeout_sec ⇒ Object
Returns the value of attribute timeout_sec.
52 53 54 |
# File 'lib/dadata.rb', line 52 def timeout_sec @timeout_sec end |
Instance Method Details
#validate! ⇒ void
This method returns an undefined value.
Validates the configuration settings
73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/dadata.rb', line 73 def validate! if timeout_sec && timeout_sec <= 0 raise ConfigurationError, 'Timeout must be positive' end if suggestions_count && (suggestions_count < 1 || suggestions_count > MAX_SUGGESTIONS) raise ConfigurationError, "Suggestions count must be between 1 and #{MAX_SUGGESTIONS}" end if api_key.nil? || api_key.strip.empty? raise ConfigurationError, "API key can't be blank" end end |