Module: Vendor::CLI::Auth

Extended by:
Auth
Included in:
Auth
Defined in:
lib/vendor/cli/auth.rb

Instance Method Summary collapse

Instance Method Details

#api_keyObject



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_keyObject



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

Returns:

  • (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

Yields:



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