Class: Ralph::CLI::Commands::Token

Inherits:
Base
  • Object
show all
Defined in:
lib/ralph/cli/commands/token.rb

Instance Method Summary collapse

Methods inherited from Base

#gen_client

Instance Method Details

#call(username:) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/ralph/cli/commands/token.rb', line 8

def call(username:, **)
  password = STDIN.noecho { Readline.readline("Password: ").tap { puts } }

  client = gen_client
  req = client.post("/api-token-auth/",{username:username, password:password}).body

  if token = req["token"]
    puts token
  else
    code, msg = req.to_a.first
    puts "Error(#{code}): #{msg}"
  end
end