Class: MangoApps::Config
- Inherits:
-
Object
- Object
- MangoApps::Config
- Defined in:
- lib/mangoapps/config.rb
Instance Attribute Summary collapse
-
#access_token ⇒ Object
Returns the value of attribute access_token.
-
#client_id ⇒ Object
Returns the value of attribute client_id.
-
#client_secret ⇒ Object
Returns the value of attribute client_secret.
-
#domain ⇒ Object
Returns the value of attribute domain.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#open_timeout ⇒ Object
Returns the value of attribute open_timeout.
-
#redirect_uri ⇒ Object
Returns the value of attribute redirect_uri.
-
#refresh_token ⇒ Object
Returns the value of attribute refresh_token.
-
#scope ⇒ Object
Returns the value of attribute scope.
-
#timeout ⇒ Object
Returns the value of attribute timeout.
-
#token_store ⇒ Object
Returns the value of attribute token_store.
Instance Method Summary collapse
- #api_base ⇒ Object
- #base_url ⇒ Object
- #has_valid_token? ⇒ Boolean
-
#initialize(domain: nil, client_id: nil, client_secret: nil, redirect_uri: nil, scope: nil, token_store: nil, timeout: 30, open_timeout: 10, logger: nil) ⇒ Config
constructor
rubocop:disable Metrics/ParameterLists.
- #token_expired? ⇒ Boolean
Constructor Details
#initialize(domain: nil, client_id: nil, client_secret: nil, redirect_uri: nil, scope: nil, token_store: nil, timeout: 30, open_timeout: 10, logger: nil) ⇒ Config
rubocop:disable Metrics/ParameterLists
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/mangoapps/config.rb', line 10 def initialize(domain: nil, client_id: nil, client_secret: nil, redirect_uri: nil, scope: nil, # rubocop:disable Metrics/ParameterLists token_store: nil, timeout: 30, open_timeout: 10, logger: nil) # Load environment variables from .env file Dotenv.load if File.exist?(".env") @domain = domain || ENV.fetch("MANGOAPPS_DOMAIN", nil) @client_id = client_id || ENV.fetch("MANGOAPPS_CLIENT_ID", nil) @client_secret = client_secret || ENV.fetch("MANGOAPPS_CLIENT_SECRET", nil) @redirect_uri = redirect_uri || ENV["MANGOAPPS_REDIRECT_URI"] || "https://localhost:3000/oauth/callback" @scope = scope || ENV["MANGOAPPS_SCOPE"] || "openid profile email" @access_token = ENV["MANGOAPPS_ACCESS_TOKEN"] @refresh_token = ENV["MANGOAPPS_REFRESH_TOKEN"] @token_store = token_store @timeout = timeout @open_timeout = open_timeout @logger = logger validate_required_fields! end |
Instance Attribute Details
#access_token ⇒ Object
Returns the value of attribute access_token.
7 8 9 |
# File 'lib/mangoapps/config.rb', line 7 def access_token @access_token end |
#client_id ⇒ Object
Returns the value of attribute client_id.
7 8 9 |
# File 'lib/mangoapps/config.rb', line 7 def client_id @client_id end |
#client_secret ⇒ Object
Returns the value of attribute client_secret.
7 8 9 |
# File 'lib/mangoapps/config.rb', line 7 def client_secret @client_secret end |
#domain ⇒ Object
Returns the value of attribute domain.
7 8 9 |
# File 'lib/mangoapps/config.rb', line 7 def domain @domain end |
#logger ⇒ Object
Returns the value of attribute logger.
7 8 9 |
# File 'lib/mangoapps/config.rb', line 7 def logger @logger end |
#open_timeout ⇒ Object
Returns the value of attribute open_timeout.
7 8 9 |
# File 'lib/mangoapps/config.rb', line 7 def open_timeout @open_timeout end |
#redirect_uri ⇒ Object
Returns the value of attribute redirect_uri.
7 8 9 |
# File 'lib/mangoapps/config.rb', line 7 def redirect_uri @redirect_uri end |
#refresh_token ⇒ Object
Returns the value of attribute refresh_token.
7 8 9 |
# File 'lib/mangoapps/config.rb', line 7 def refresh_token @refresh_token end |
#scope ⇒ Object
Returns the value of attribute scope.
7 8 9 |
# File 'lib/mangoapps/config.rb', line 7 def scope @scope end |
#timeout ⇒ Object
Returns the value of attribute timeout.
7 8 9 |
# File 'lib/mangoapps/config.rb', line 7 def timeout @timeout end |
#token_store ⇒ Object
Returns the value of attribute token_store.
7 8 9 |
# File 'lib/mangoapps/config.rb', line 7 def token_store @token_store end |
Instance Method Details
#api_base ⇒ Object
31 |
# File 'lib/mangoapps/config.rb', line 31 def api_base = "#{base_url}/api/" |
#base_url ⇒ Object
30 |
# File 'lib/mangoapps/config.rb', line 30 def base_url = "https://#{domain}" |
#has_valid_token? ⇒ Boolean
38 39 40 |
# File 'lib/mangoapps/config.rb', line 38 def has_valid_token? @access_token && !token_expired? end |
#token_expired? ⇒ Boolean
33 34 35 36 |
# File 'lib/mangoapps/config.rb', line 33 def token_expired? return true unless ENV["MANGOAPPS_TOKEN_EXPIRES_AT"] Time.now.to_i >= ENV["MANGOAPPS_TOKEN_EXPIRES_AT"].to_i end |