Class: Superbot::Cloud::CLI::Test::UploadCommand

Inherits:
BaseCommand show all
Includes:
Validations
Defined in:
lib/superbot/cloud/cli/test/upload_command.rb

Instance Method Summary collapse

Methods inherited from LoginRequiredCommand

#run, run

Methods included from Validations

#require_login

Instance Method Details

#executeObject



19
20
21
# File 'lib/superbot/cloud/cli/test/upload_command.rb', line 19

def execute
  upload_tests
end

#upload_testsObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/superbot/cloud/cli/test/upload_command.rb', line 23

def upload_tests
  puts "Uploading files from #{path}..."
  files = Dir.glob(File.join(path, '*')).map do |test_file|
    filename = File.basename(test_file)
    content_type = Marcel::MimeType.for(Pathname.new(test_file), name: filename)
    UploadIO.new(File.open(test_file), content_type, filename)
  end
  test_name = Zaru.sanitize!(File.basename(path))

  api_response = Superbot::Cloud::Api.request(
    :test_upload,
    params: {
      name: test_name,
      organization_name: organization,
      'files[]': files
    }
  )

  puts "Successfully uploaded!"
  puts "Organization: #{api_response[:organization]}"
  puts "Test name: #{api_response[:name]}"
  puts("Files:", api_response[:files].map { |f| f[:filename].prepend('  ') })
end