Class: Superbot::Cloud::CLI::Token::ListCommand

Inherits:
BaseCommand show all
Defined in:
lib/superbot/cloud/cli/token/list_command.rb

Constant Summary collapse

OUTPUT_HEADERS =
{
  name: "Title",
  token: "Token",
  scope: "API scope"
}.freeze

Instance Method Summary collapse

Methods inherited from LoginRequiredCommand

#run, run

Methods included from Validations

#require_login

Instance Method Details

#executeObject



14
15
16
# File 'lib/superbot/cloud/cli/token/list_command.rb', line 14

def execute
  list_tokens
end

#list_tokensObject



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/superbot/cloud/cli/token/list_command.rb', line 18

def list_tokens
  api_response = Superbot::Cloud::Api.request(:access_token_list, params: { organization_name: organization })
  puts "Organization: #{api_response[:organization]}"
  puts "Access Tokens:"
  puts(api_response[:access_tokens].map { |m| m[:username] })

  puts "Organization: #{api_response[:organization]}"
  puts OUTPUT_HEADERS.values.map { |header| header.ljust(35) }.join
  puts ''.ljust(35 * OUTPUT_HEADERS.length, '-')
  api_response[:access_tokens].each do |webdriver_session|
    puts webdriver_session.slice(*OUTPUT_HEADERS.keys).values.map { |v| v.to_s.ljust(35) }.join
  end
end