Module: Vendor::CLI::Auth
Instance Method Summary collapse
- #api_key ⇒ Object
- #api_key=(value) ⇒ Object
- #fetch_api_key ⇒ Object
- #is_authenticated? ⇒ Boolean
- #with_api_key {|api_key| ... } ⇒ Object
Instance Method Details
#api_key ⇒ Object
11 12 13 |
# File 'lib/vendor/cli/auth.rb', line 11 def api_key Vendor::Config.get(:"credentials.vendorforge_api_key") end |
#api_key=(value) ⇒ Object
15 16 17 |
# File 'lib/vendor/cli/auth.rb', line 15 def api_key=(value) Vendor::Config.set(:"credentials.vendorforge_api_key", value) end |
#fetch_api_key ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/vendor/cli/auth.rb', line 19 def fetch_api_key Vendor.ui.warn "Please enter your vendorkit.com login and password" username = ask("Login: ") password = ask("Password: ") { |q| q.echo = false } Vendor::Config.set(:"credentials.vendorforge_api_key", Vendor::API.api_key(username, password)) end |
#is_authenticated? ⇒ Boolean
33 34 35 |
# File 'lib/vendor/cli/auth.rb', line 33 def is_authenticated? !api_key.nil? end |
#with_api_key {|api_key| ... } ⇒ Object
28 29 30 31 |
# File 'lib/vendor/cli/auth.rb', line 28 def with_api_key(&block) fetch_api_key unless is_authenticated? yield api_key if api_key end |