Class: Umami::Configuration
- Inherits:
-
Object
- Object
- Umami::Configuration
- Defined in:
- lib/umami/configuration.rb
Constant Summary collapse
- UMAMI_CLOUD_URL =
"https://api.umami.is".freeze
Instance Attribute Summary collapse
-
#access_token ⇒ Object
Returns the value of attribute access_token.
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#request_timeout ⇒ Object
readonly
Returns the value of attribute request_timeout.
-
#uri_base ⇒ Object
Returns the value of attribute uri_base.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Instance Method Summary collapse
- #cloud? ⇒ Boolean
- #credentials=(creds) ⇒ Object
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #validate! ⇒ Object
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
7 8 9 10 11 12 13 14 |
# File 'lib/umami/configuration.rb', line 7 def initialize @uri_base = nil @request_timeout = 120 @access_token = nil @username = nil @password = nil @dirty = false end |
Instance Attribute Details
#access_token ⇒ Object
Returns the value of attribute access_token.
5 6 7 |
# File 'lib/umami/configuration.rb', line 5 def access_token @access_token end |
#password ⇒ Object (readonly)
Returns the value of attribute password.
5 6 7 |
# File 'lib/umami/configuration.rb', line 5 def password @password end |
#request_timeout ⇒ Object (readonly)
Returns the value of attribute request_timeout.
5 6 7 |
# File 'lib/umami/configuration.rb', line 5 def request_timeout @request_timeout end |
#uri_base ⇒ Object
Returns the value of attribute uri_base.
5 6 7 |
# File 'lib/umami/configuration.rb', line 5 def uri_base @uri_base end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
5 6 7 |
# File 'lib/umami/configuration.rb', line 5 def username @username end |
Instance Method Details
#cloud? ⇒ Boolean
37 38 39 |
# File 'lib/umami/configuration.rb', line 37 def cloud? @access_token && @uri_base.nil? end |
#credentials=(creds) ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/umami/configuration.rb', line 28 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
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/umami/configuration.rb', line 41 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 |