Class: AnswerLayer::Configuration
- Inherits:
-
Object
- Object
- AnswerLayer::Configuration
- Defined in:
- lib/answerlayer/configuration.rb
Constant Summary collapse
- DEFAULT_BASE_URL =
"https://app.answerlayer.io/api/v1"
Instance Attribute Summary collapse
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#base_url ⇒ Object
Returns the value of attribute base_url.
-
#bearer_token ⇒ Object
Returns the value of attribute bearer_token.
-
#open_timeout ⇒ Object
Returns the value of attribute open_timeout.
-
#read_timeout ⇒ Object
Returns the value of attribute read_timeout.
-
#subject_org_id ⇒ Object
Returns the value of attribute subject_org_id.
-
#subject_user_id ⇒ Object
Returns the value of attribute subject_user_id.
Instance Method Summary collapse
- #base_uri ⇒ Object
-
#initialize(api_key: nil, bearer_token: nil, subject_org_id: nil, subject_user_id: nil, base_url: nil, open_timeout: 10, read_timeout: 30) ⇒ Configuration
constructor
A new instance of Configuration.
- #validate!(auth_mode: :api_key) ⇒ Object
Constructor Details
#initialize(api_key: nil, bearer_token: nil, subject_org_id: nil, subject_user_id: nil, base_url: nil, open_timeout: 10, read_timeout: 30) ⇒ Configuration
Returns a new instance of Configuration.
9 10 11 12 13 14 15 16 17 |
# File 'lib/answerlayer/configuration.rb', line 9 def initialize(api_key: nil, bearer_token: nil, subject_org_id: nil, subject_user_id: nil, base_url: nil, open_timeout: 10, read_timeout: 30) @api_key = explicit_or_env(api_key, "ANSWERLAYER_API_KEY") @bearer_token = explicit_or_env(bearer_token, "ANSWERLAYER_BEARER_TOKEN") @subject_org_id = subject_org_id @subject_user_id = subject_user_id @base_url = base_url || DEFAULT_BASE_URL @open_timeout = open_timeout @read_timeout = read_timeout end |
Instance Attribute Details
#api_key ⇒ Object
Returns the value of attribute api_key.
7 8 9 |
# File 'lib/answerlayer/configuration.rb', line 7 def api_key @api_key end |
#base_url ⇒ Object
Returns the value of attribute base_url.
7 8 9 |
# File 'lib/answerlayer/configuration.rb', line 7 def base_url @base_url end |
#bearer_token ⇒ Object
Returns the value of attribute bearer_token.
7 8 9 |
# File 'lib/answerlayer/configuration.rb', line 7 def bearer_token @bearer_token end |
#open_timeout ⇒ Object
Returns the value of attribute open_timeout.
7 8 9 |
# File 'lib/answerlayer/configuration.rb', line 7 def open_timeout @open_timeout end |
#read_timeout ⇒ Object
Returns the value of attribute read_timeout.
7 8 9 |
# File 'lib/answerlayer/configuration.rb', line 7 def read_timeout @read_timeout end |
#subject_org_id ⇒ Object
Returns the value of attribute subject_org_id.
7 8 9 |
# File 'lib/answerlayer/configuration.rb', line 7 def subject_org_id @subject_org_id end |
#subject_user_id ⇒ Object
Returns the value of attribute subject_user_id.
7 8 9 |
# File 'lib/answerlayer/configuration.rb', line 7 def subject_user_id @subject_user_id end |
Instance Method Details
#base_uri ⇒ Object
35 36 37 38 39 |
# File 'lib/answerlayer/configuration.rb', line 35 def base_uri URI(base_url) rescue URI::InvalidURIError raise ConfigurationError, "base_url must be a valid URL" end |
#validate!(auth_mode: :api_key) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/answerlayer/configuration.rb', line 19 def validate!(auth_mode: :api_key) raise ConfigurationError, "base_url is required" if blank?(base_url) case auth_mode when :api_key, :oauth raise ConfigurationError, "api_key is required" if blank?(api_key) when :bearer raise ConfigurationError, "bearer_token is required" if blank?(bearer_token) when :none true else raise ConfigurationError, "unsupported auth mode: #{auth_mode}" end self end |