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

Inherits:
BaseCommand show all
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



15
16
17
# File 'lib/superbot/cloud/cli/test/upload_command.rb', line 15

def execute
  upload_tests
end

#upload_testsObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/superbot/cloud/cli/test/upload_command.rb', line 19

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

    File.open(test_file) do |file|
      api_response = Superbot::Cloud::Api.request(
        :test_upload,
        params: {
          name: Zaru.sanitize!(File.basename(path)),
          organization_name: organization,
          file: UploadIO.new(file, content_type, filename)
        }
      )

      print filename, ' - ', api_response[:error] || 'Success'
      puts
    end
  end
end