module WeighflowCli::Credentials
Public Class Methods
get_secret()
click to toggle source
# File lib/weighflow_cli/credentials.rb, line 38 def self.get_secret while secret = Readline.readline("Enter Secret: ", true) do if secret.to_s.size > 20 return secret puts <<~TEXT Saved Login Successfully! You are now ready to begin using the CLI! TEXT break else puts "-- invalid credentials --" end end nil end
get_url()
click to toggle source
# File lib/weighflow_cli/credentials.rb, line 60 def self.get_url puts <<~TEXT Please enter the URL for Weighflow API TEXT while url = Readline.readline("URL: ", true) do if url.to_s.size > 10 return url puts <<-TEXT Saved Login Successfully! You are now ready to begin using the CLI! TEXT break else puts "-- invalid credentials --" end end nil end
key_store_config()
click to toggle source
# File lib/weighflow_cli/credentials.rb, line 7 def self.key_store_config File.join(WeighflowCli.data_path, '.config.yaml') end
load_config!()
click to toggle source
# File lib/weighflow_cli/credentials.rb, line 88 def self.load_config! secret_fail unless File.exists?(key_store_config) config = YAML.load(File.read(key_store_config)) config end
login()
click to toggle source
# File lib/weighflow_cli/credentials.rb, line 12 def self.login welcome url = get_url secret = get_secret File.write(key_store_config, YAML.dump(secret: secret, url: url)) end
secret_fail()
click to toggle source
# File lib/weighflow_cli/credentials.rb, line 94 def self.secret_fail puts <<-TEXT Secret is not present, please login first Example: $ weighflow_cli login TEXT exit end
welcome()
click to toggle source
# File lib/weighflow_cli/credentials.rb, line 22 def self.welcome puts <<~TEXT Welcome to Weighflow Cli ------------------------ Please registry an API Token, and login here. TEXT end