Class: Superbot::Cloud::CLI::Webdriver::ListCommand

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

Constant Summary collapse

OUTPUT_HEADERS =
{
  session_id: "Session ID",
  created_at: "Created at",
  updated_at: "Last activity"
}.freeze

Instance Method Summary collapse

Methods inherited from LoginRequiredCommand

#run, run

Methods included from Validations

#require_login

Instance Method Details

#executeObject



17
18
19
# File 'lib/superbot/cloud/cli/webdriver/list_command.rb', line 17

def execute
  list_sessions
end

#list_sessionsObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/superbot/cloud/cli/webdriver/list_command.rb', line 21

def list_sessions
  states = all? ? nil : %w[idle proxying]
  api_response = Superbot::Cloud::Api.request(:webdriver_session_list, params: { organization_name: organization, 'aasm_state[]': states })
  abort "No active sessions found for #{api_response[:organization]} organization" if api_response[:webdriver_sessions].empty?

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