lib/io_streams/paths/http.rb in iostreams-1.0.0.beta vs lib/io_streams/paths/http.rb in iostreams-1.0.0.beta2

- old
+ new

@@ -1,11 +1,11 @@ require 'net/http' require 'uri' module IOStreams module Paths class HTTP < IOStreams::Path - attr_reader :username, :password, :http_redirect_count + attr_reader :username, :password, :http_redirect_count, :url # Stream to/from a remote file over http(s). # # Parameters: # url: [String] @@ -32,13 +32,18 @@ end @username = username || uri.user @password = password || uri.password @http_redirect_count = http_redirect_count - super(url) + @url = url + super(uri.path) end + def to_s + url + end + # Read a file using an http get. # # For example: # IOStreams.path('https://www5.fdic.gov/idasp/Offices2.zip').reader {|file| puts file.read} # @@ -46,10 +51,10 @@ # IOStreams.path('https://www5.fdic.gov/idasp/Offices2.zip').stream(:none).reader {|file| puts file.read} # # Notes: # * Since Net::HTTP download only supports a push stream, the data is streamed into a tempfile first. def reader(&block) - handle_redirects(path, http_redirect_count, &block) + handle_redirects(url, http_redirect_count, &block) end def handle_redirects(uri, http_redirect_count, &block) uri = URI.parse(uri) unless uri.is_a?(URI) result = nil