Class: AppStage::UploadFile
- Inherits:
-
Object
- Object
- AppStage::UploadFile
- Defined in:
- lib/upload_file.rb
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(options) ⇒ UploadFile
constructor
A new instance of UploadFile.
Constructor Details
#initialize(options) ⇒ UploadFile
Returns a new instance of UploadFile.
6 7 8 |
# File 'lib/upload_file.rb', line 6 def initialize() = end |
Instance Method Details
#execute ⇒ Object
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 = [:host] || "https://www.appstage.io" raise('No file specified') unless [:upload] file_path = File.([:upload]) filename = File.basename([:upload]) raise('Invalid project token') unless [:jwt] token = [: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 |