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.
4 5 6 |
# File 'lib/upload_file.rb', line 4 def initialize() @options = end |
Instance Method Details
#execute ⇒ Object
8 9 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 |
# File 'lib/upload_file.rb', line 8 def execute begin host = @options[:host] || "https://www.appstage.io" raise('No file specified') unless @options[:upload] file_path = File.(@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 |