Module: Aspera::UriReader
- Defined in:
- lib/aspera/uri_reader.rb
Overview
read some content from some URI, support file: , http: and https: schemes
Class Method Summary collapse
-
.read(uri_to_read) ⇒ Object
read some content from some URI, support file: , http: and https: schemes.
Class Method Details
.read(uri_to_read) ⇒ Object
read some content from some URI, support file: , http: and https: schemes
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/aspera/uri_reader.rb', line 11 def read(uri_to_read) uri = URI.parse(uri_to_read) case 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 = uri.path raise 'URL shall have a path, check syntax' if local_file_path.nil? local_file_path = File.(local_file_path.gsub(%r{^/}, '')) if %r{^/(~|.|..)/}.match?(local_file_path) return File.read(local_file_path) else raise "unknown scheme: [#{uri.scheme}] for [#{uri_to_read}]" end end |