Class: Umami::Configuration
- Inherits:
-
Object
- Object
- Umami::Configuration
- Defined in:
- lib/umami/configuration.rb
Overview
Configuration class for the Umami client.
Constant Summary collapse
- UMAMI_CLOUD_URL =
Base URL for Umami Cloud API (used for most API calls)
"https://api.umami.is".freeze
- UMAMI_CLOUD_SEND_URL =
Note:
The send endpoint uses a different base URL than other API calls
Base URL for Umami Cloud send endpoint (used only for send_event)
"https://cloud.umami.is".freeze
Instance Attribute Summary collapse
-
#access_token ⇒ String?
Access token for API authentication.
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#request_timeout ⇒ Integer
Request timeout in seconds (default: 120).
-
#uri_base ⇒ String?
Base URL for the Umami API.
-
#username ⇒ String?
readonly
Username for self-hosted authentication (set via credentials=).
Instance Method Summary collapse
-
#cloud? ⇒ Boolean
Check if configured for Umami Cloud.
-
#credentials=(creds) ⇒ Object
Set username/password credentials for self-hosted authentication.
-
#initialize ⇒ Configuration
constructor
Initialize a new Configuration with default values.
-
#validate! ⇒ Object
Validate the configuration and apply defaults.
Constructor Details
#initialize ⇒ Configuration
Initialize a new Configuration with default values
49 50 51 52 53 54 55 56 |
# File 'lib/umami/configuration.rb', line 49 def initialize @uri_base = nil @request_timeout = 120 @access_token = nil @username = nil @password = nil @dirty = false end |
Instance Attribute Details
#access_token ⇒ String?
Returns Access token for API authentication.
46 |
# File 'lib/umami/configuration.rb', line 46 attr_reader :uri_base, :request_timeout, :access_token, :username, :password |
#password ⇒ Object (readonly)
Returns the value of attribute password.
46 |
# File 'lib/umami/configuration.rb', line 46 attr_reader :uri_base, :request_timeout, :access_token, :username, :password |
#request_timeout ⇒ Integer
Returns Request timeout in seconds (default: 120).
46 |
# File 'lib/umami/configuration.rb', line 46 attr_reader :uri_base, :request_timeout, :access_token, :username, :password |
#uri_base ⇒ String?
Returns Base URL for the Umami API.
46 47 48 |
# File 'lib/umami/configuration.rb', line 46 def uri_base @uri_base end |
#username ⇒ String? (readonly)
Returns Username for self-hosted authentication (set via credentials=).
46 |
# File 'lib/umami/configuration.rb', line 46 attr_reader :uri_base, :request_timeout, :access_token, :username, :password |
Instance Method Details
#cloud? ⇒ Boolean
Check if configured for Umami Cloud
97 98 99 |
# File 'lib/umami/configuration.rb', line 97 def cloud? @access_token && @uri_base.nil? end |
#credentials=(creds) ⇒ Object
Setting credentials clears any access token
Set username/password credentials for self-hosted authentication
79 80 81 82 83 84 85 86 |
# File 'lib/umami/configuration.rb', line 79 def credentials=(creds) raise Umami::ConfigurationError, "Both username and password are required" unless creds[:username] && creds[:password] @username = creds[:username] @password = creds[:password] @access_token = nil @dirty = true end |
#validate! ⇒ Object
Validate the configuration and apply defaults
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/umami/configuration.rb', line 103 def validate! return unless @dirty if cloud? @uri_base = UMAMI_CLOUD_URL Umami.logger.info "Using Umami Cloud (#{UMAMI_CLOUD_URL})" end if @uri_base == UMAMI_CLOUD_URL && (@username || @password) raise Umami::ConfigurationError, "Username/password authentication is not supported for Umami Cloud" end if @access_token && (@username || @password) Umami.logger.warn "Both access token and credentials provided. Access token will be used." @username = nil @password = nil end if @uri_base && @uri_base != UMAMI_CLOUD_URL && !@access_token && !@username && !@password raise Umami::ConfigurationError, "Authentication is required for self-hosted instances" end @dirty = false end |