Class: Gemical::Auth
Instance Method Summary collapse
-
#basic_auth ⇒ Array
Basic authentication credentials, for API request.
-
#configuration ⇒ Gemical::Configuration
The configuration.
-
#credentials ⇒ [String, String]
Username and password.
-
#find_vault(name) ⇒ Gemical::Vault
A vault object for the given name.
-
#primary_vault ⇒ String
The user’s primary vault setting.
-
#vaults ⇒ Array<Gemical::Vault>
Available vaults.
-
#verify_account! ⇒ Hash
Verifies account, asks for credentials if not setup.
-
#verify_vault! ⇒ Hash
Verifies account, asks for primary choice if not setup.
Methods included from Singleton
Instance Method Details
#basic_auth ⇒ Array
Returns Basic authentication credentials, for API request.
55 56 57 |
# File 'lib/gemical/auth.rb', line 55 def basic_auth [credentials.last, 'x'] if credentials end |
#configuration ⇒ Gemical::Configuration
Returns The configuration.
6 7 8 |
# File 'lib/gemical/auth.rb', line 6 def configuration Gemical.configuration end |
#credentials ⇒ [String, String]
Returns Username and password.
47 48 49 50 51 |
# File 'lib/gemical/auth.rb', line 47 def credentials return nil unless configuration.credentials? pair = configuration.credentials.read.split(/\s+/)[0..1] pair if pair.size == 2 && pair.all? {|v| string_value?(v) } end |
#find_vault(name) ⇒ Gemical::Vault
Returns A vault object for the given name.
71 72 73 74 |
# File 'lib/gemical/auth.rb', line 71 def find_vault(name) ensure_vaults! vaults.find {|v| v == name } end |
#primary_vault ⇒ String
Returns The user’s primary vault setting.
61 62 63 64 65 |
# File 'lib/gemical/auth.rb', line 61 def primary_vault return nil unless configuration.primary_vault? value = configuration.primary_vault.read.split(/\s+/).first value if string_value?(value) end |
#vaults ⇒ Array<Gemical::Vault>
Returns Available vaults.
38 39 40 41 42 43 |
# File 'lib/gemical/auth.rb', line 38 def vaults verify_account! @vaults ||= Gemical.connection.get("/vaults").map do |hash| Gemical::Vault.new(hash) end end |
#verify_account! ⇒ Hash
Verifies account, asks for credentials if not setup
13 14 15 16 17 18 19 20 21 |
# File 'lib/gemical/auth.rb', line 13 def verify_account! @verified_account ||= if credentials get_account else say_ok "\nWelcome to Gemical! You are new, right?" say_ok "We need to authenticate your account:" collect_credentials end end |
#verify_vault! ⇒ Hash
Verifies account, asks for primary choice if not setup
26 27 28 29 30 31 32 33 34 |
# File 'lib/gemical/auth.rb', line 26 def verify_vault! verify_account! @verified_vault ||= if primary_vault find_vault(primary_vault) || collect_vault("Ooops, you don't seem to have access to '#{primary_vault}' anymore.") else collect_vault("You haven't specified your primary vault yet.") end end |