Module: Aspera::UriReader

Defined in:
lib/aspera/uri_reader.rb

Class Method Summary collapse

Class Method Details

.read(uri_to_read) ⇒ Object

read some content from some URI, support file: , http: and https: schemes



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/aspera/uri_reader.rb', line 10

def read(uri_to_read)
  proxy_uri = URI.parse(uri_to_read)
  case proxy_uri.scheme
  when 'http', 'https'
    return Rest.new(base_url: uri_to_read, redirect_max: 5).call(operation: 'GET', subpath: '', headers: {'Accept' => 'text/plain'})[:data]
  when 'file', NilClass
    local_file_path = proxy_uri.path
    raise 'URL shall have a path, check syntax' if local_file_path.nil?
    local_file_path = File.expand_path(local_file_path.gsub(%r{^/}, '')) if %r{^/(~|.|..)/}.match?(local_file_path)
    return File.read(local_file_path)
  else
    raise "unknown scheme: [#{proxy_uri.scheme}] for [#{uri_to_read}]"
  end
end