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

Inherits:
Clamp::Command
  • Object
show all
Includes:
Superbot::Cloud::Validations, Validations
Defined in:
lib/superbot/cloud/cli/cloud/test/upload_command.rb

Instance Method Summary collapse

Methods included from Superbot::Cloud::Validations

#require_login

Instance Method Details

#executeObject



22
23
24
25
# File 'lib/superbot/cloud/cli/cloud/test/upload_command.rb', line 22

def execute
  
  upload_tests
end

#upload_testsObject



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

def upload_tests
  Dir.glob(File.join(path, '*.rb')) do |test_file|
    puts "Uploading files from #{path}..."
    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!(path),
          organization_name: organization,
          file: UploadIO.new(file, content_type, filename)
        }
      )

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