Class: Morpheus::FileCopyRequestInterface
- Inherits:
-
APIClient
- Object
- APIClient
- Morpheus::FileCopyRequestInterface
- Defined in:
- lib/morpheus/api/file_copy_request_interface.rb
Instance Method Summary collapse
- #create(local_file, params = {}) ⇒ Object
- #download_file_chunked(id, outfile, params = {}) ⇒ Object
- #execute_against_lease(id, local_file, params) ⇒ Object
- #get(id, params = {}) ⇒ Object
Instance Method Details
#create(local_file, params = {}) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/morpheus/api/file_copy_request_interface.rb', line 13 def create(local_file, params={}) # puts "upload_file #{local_file} to destination #{destination}" if !local_file.kind_of?(File) local_file = File.new(local_file, 'rb') end url = "#{@base_url}/api/file-copy-request/execute" headers = { :params => params, :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/octet-stream'} headers[:params][:filename] = File.basename(local_file) payload = local_file headers['Content-Length'] = local_file.size # File.size(local_file) execute(method: :post, url: url, headers: headers, payload: payload) end |
#download_file_chunked(id, outfile, params = {}) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/morpheus/api/file_copy_request_interface.rb', line 39 def download_file_chunked(id, outfile, params={}) raise "#{self.class}.download_file() passed a blank id!" if id.to_s == '' url = "#{@base_url}/api/file-copy-request/download/#{CGI::escape(id)}" headers = { params: params, authorization: "Bearer #{@access_token}" } opts = {method: :get, url: url, headers: headers} # execute(opts, {parse_json: false}) if Dir.exist?(outfile) raise "outfile is invalid. It is the name of an existing directory: #{outfile}" end # if @verify_ssl == false # opts[:verify_ssl] = OpenSSL::SSL::VERIFY_NONE # end if @dry_run return opts end http_response = nil File.open(outfile, 'w') {|f| block = proc { |response| response.read_body do |chunk| # writing to #{outfile} ..." f.write chunk end } opts[:block_response] = block http_response = Morpheus::RestClient.execute(opts) } return http_response end |
#execute_against_lease(id, local_file, params) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/morpheus/api/file_copy_request_interface.rb', line 26 def execute_against_lease(id, local_file, params) # puts "upload_file #{local_file} to destination #{destination}" if !local_file.kind_of?(File) local_file = File.new(local_file, 'rb') end url = "#{@base_url}/api/file-copy-request/lease/#{CGI::escape(id)}" headers = { :params => params, :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/octet-stream'} headers[:params][:filename] = File.basename(local_file) payload = local_file headers['Content-Length'] = local_file.size # File.size(local_file) execute(method: :post, url: url, headers: headers, payload: payload) end |
#get(id, params = {}) ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/morpheus/api/file_copy_request_interface.rb', line 5 def get(id, params={}) raise "#{self.class}.get() passed a blank id!" if id.to_s == '' url = "#{@base_url}/api/file-copy-request/#{id}" headers = { :params => params, authorization: "Bearer #{@access_token}"} opts = {method: :get, url: url, headers: headers} execute(opts) end |