Class: AppStage::UploadFile

Inherits:
Object
  • Object
show all
Defined in:
lib/upload_file.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ UploadFile

Returns a new instance of UploadFile.



6
7
8
# File 'lib/upload_file.rb', line 6

def initialize(options)
  @options = options
end

Instance Method Details

#executeObject



10
11
12
13
14
15
16
17
18
19
20
21
22
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/upload_file.rb', line 10

def execute
  begin
    host = @options[:host] || "https://www.appstage.io"

    raise('No file specified') unless @options[:upload]
    file_path = File.expand_path(@options[:upload])
    filename = File.basename(@options[:upload])

    raise('Invalid project token') unless @options[:jwt]
    token = @options[:jwt]

    puts "Uploading #{filename} #{File.size(file_path)} bytes..."

    json = {
      release_file: {
        cloud_stored_file: File.open(file_path)
      }
    }

    response = HTTParty.post(host+"/api/live_builds",
      :body => json,
      :multipart => true,
      :headers => {
        'Authorization' => "Bearer #{token}"
      },
      :verify => false
    )
    raise(JSON.parse(response.body)['error']) unless response.code == 200

    puts "Upload complete"
    0
  rescue Exception => e
    puts "Upload failed - #{e}"
    -1
  end
end