Module: WeighflowCli::Credentials

Defined in:
lib/weighflow_cli/credentials.rb

Class Method Summary collapse

Class Method Details

.get_secretObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# 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 "\n        Saved Login Successfully!\n\n        You are now ready to begin using the CLI!\n\n\n      TEXT\n      break\n    else\n      puts \"-- invalid credentials --\"\n    end\n  end \n  nil\nend\n" 

.get_urlObject



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/weighflow_cli/credentials.rb', line 60

def self.get_url
  puts "\n    Please enter the URL for Weighflow API\n\n  TEXT\n  while url = Readline.readline(\"URL: \", true) do \n    if url.to_s.size > 10 \n      return url\n      puts <<-TEXT \n\n        Saved Login Successfully!\n\n        You are now ready to begin using the CLI!\n\n\n      TEXT\n      break\n    else\n      puts \"-- invalid credentials --\"\n    end\n  end \n  nil\nend\n"

.key_store_configObject



7
8
9
# File 'lib/weighflow_cli/credentials.rb', line 7

def self.key_store_config 
  File.join(WeighflowCli.data_path, '.config.yaml')
end

.load_config!Object



88
89
90
91
92
# 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

.loginObject



12
13
14
15
16
17
# File 'lib/weighflow_cli/credentials.rb', line 12

def self.
  welcome
  url = get_url
  secret = get_secret
  File.write(key_store_config, YAML.dump(secret: secret, url: url))      
end

.secret_failObject



94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/weighflow_cli/credentials.rb', line 94

def self.secret_fail
  puts "\n    Secret is not present, please login first\n\n    Example:\n\n    $ weighflow_cli login\n\n  TEXT\n  exit\nend\n"

.welcomeObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/weighflow_cli/credentials.rb', line 22

def self.welcome
  puts "    \n\n\n\n\n  Welcome to Weighflow Cli\n  ------------------------\n\n  Please registry an API Token, and login here.\n\n\n  TEXT\nend\n"