Class: Mindee::HTTP::ApiSettingsV2
- Inherits:
-
Object
- Object
- Mindee::HTTP::ApiSettingsV2
- Defined in:
- lib/mindee/http/api_settings_v2.rb
Overview
API client for version 2.
Constant Summary collapse
- MINDEE_V2_API_KEY_ENV_NAME =
V2 API key's default environment key name.
'MINDEE_V2_API_KEY'- MINDEE_V2_API_KEY_DEFAULT =
V2 API key's default value.
nil- MINDEE_V2_BASE_URL_ENV_NAME =
V2 base URL default environment key name.
'MINDEE_V2_BASE_URL'- MINDEE_V2_BASE_URL_DEFAULT =
V2 base URL default value.
'https://api-v2.mindee.net/v2'- MINDEE_V2_REQUEST_TIMEOUT_ENV_NAME =
HTTP request timeout default environment key name.
'MINDEE_V2_REQUEST_TIMEOUT'- MINDEE_V2_TIMEOUT_DEFAULT =
HTTP request timeout default value.
120- USER_AGENT =
Default value for the user agent (same as V1).
"mindee-api-ruby@v#{Mindee::VERSION} ruby-v#{RUBY_VERSION} #{Mindee::PLATFORM}".freeze
Instance Attribute Summary collapse
- #api_key ⇒ String readonly
- #base_url ⇒ String readonly
- #request_timeout ⇒ Integer readonly
- #user_agent ⇒ String readonly
Instance Method Summary collapse
-
#check_api_key ⇒ Object
Checks API key for a value.
-
#initialize(api_key: nil) ⇒ ApiSettingsV2
constructor
A new instance of ApiSettingsV2.
Constructor Details
#initialize(api_key: nil) ⇒ ApiSettingsV2
Returns a new instance of ApiSettingsV2.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/mindee/http/api_settings_v2.rb', line 36 def initialize(api_key: nil) @request_timeout = ENV.fetch(MINDEE_V2_REQUEST_TIMEOUT_ENV_NAME, MINDEE_V2_TIMEOUT_DEFAULT).to_i if api_key.nil? && !ENV.fetch(MINDEE_V2_API_KEY_ENV_NAME, MINDEE_V2_API_KEY_DEFAULT).to_s.empty? logger.debug('API key set from environment') end @api_key = if api_key.nil? || api_key.empty? ENV.fetch(MINDEE_V2_API_KEY_ENV_NAME, MINDEE_V2_API_KEY_DEFAULT) else api_key end @base_url = ENV.fetch(MINDEE_V2_BASE_URL_ENV_NAME, MINDEE_V2_BASE_URL_DEFAULT).chomp('/') @user_agent = USER_AGENT end |
Instance Attribute Details
#api_key ⇒ String (readonly)
28 29 30 |
# File 'lib/mindee/http/api_settings_v2.rb', line 28 def api_key @api_key end |
#base_url ⇒ String (readonly)
32 33 34 |
# File 'lib/mindee/http/api_settings_v2.rb', line 32 def base_url @base_url end |
#request_timeout ⇒ Integer (readonly)
30 31 32 |
# File 'lib/mindee/http/api_settings_v2.rb', line 30 def request_timeout @request_timeout end |
#user_agent ⇒ String (readonly)
34 35 36 |
# File 'lib/mindee/http/api_settings_v2.rb', line 34 def user_agent @user_agent end |
Instance Method Details
#check_api_key ⇒ Object
Checks API key for a value.
54 55 56 57 58 59 60 |
# File 'lib/mindee/http/api_settings_v2.rb', line 54 def check_api_key return unless @api_key.nil? || @api_key.to_s.empty? raise Errors::MindeeAPIError, "Missing API key. check your Client Configuration.\nYou can set this using the " \ "'#{MINDEE_V2_API_KEY_ENV_NAME}' environment variable." end |