Class: IOStreams::Paths::HTTP
- Inherits:
-
IOStreams::Path
- Object
- Stream
- IOStreams::Path
- IOStreams::Paths::HTTP
- Defined in:
- lib/io_streams/paths/http.rb
Instance Attribute Summary collapse
-
#http_redirect_count ⇒ Object
readonly
Returns the value of attribute http_redirect_count.
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Attributes inherited from IOStreams::Path
Attributes inherited from Stream
Instance Method Summary collapse
-
#initialize(url, username: nil, password: nil, http_redirect_count: 10, parameters: nil) ⇒ HTTP
constructor
Stream to/from a remote file over http(s).
-
#relative? ⇒ Boolean
Does not support relative file names since there is no concept of current working directory.
- #to_s ⇒ Object
Methods inherited from IOStreams::Path
#<=>, #==, #absolute?, #children, #compressed?, #copy_from, #delete, #delete_all, #directory, #each_child, #encrypted?, #exist?, #inspect, #join, #mkdir, #mkpath, #move_to, #partial_files_visible?, #realpath, #size
Methods inherited from Stream
#basename, #copy_from, #copy_to, #dirname, #each, #extension, #extname, #file_name, #file_name=, #format, #format=, #format_options, #format_options=, #option, #option_or_stream, #pipeline, #read, #reader, #setting, #stream, #write, #writer
Constructor Details
#initialize(url, username: nil, password: nil, http_redirect_count: 10, parameters: nil) ⇒ HTTP
Stream to/from a remote file over http(s).
Parameters:
url: [String]
URI of the file to download.
Example:
https://www5.fdic.gov/idasp/Offices2.zip
http://hostname/path/file_name
Full url showing all the optional elements that can be set via the url:
https://username:password@hostname/path/file_name
username: [String]
When supplied, basic authentication is used with the username and password.
password: [String]
Password to use use with basic authentication when the username is supplied.
http_redirect_count: [Integer]
Maximum number of http redirects to follow.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/io_streams/paths/http.rb', line 29 def initialize(url, username: nil, password: nil, http_redirect_count: 10, parameters: nil) uri = URI.parse(url) unless %w[http https].include?(uri.scheme) raise( ArgumentError, "Invalid URL. Required Format: 'http://<host_name>/<file_name>', or 'https://<host_name>/<file_name>'" ) end @username = username || uri.user @password = password || uri.password @http_redirect_count = http_redirect_count @url = parameters ? "#{url}?#{URI.encode_www_form(parameters)}" : url super(uri.path) end |
Instance Attribute Details
#http_redirect_count ⇒ Object (readonly)
Returns the value of attribute http_redirect_count.
7 8 9 |
# File 'lib/io_streams/paths/http.rb', line 7 def http_redirect_count @http_redirect_count end |
#password ⇒ Object (readonly)
Returns the value of attribute password.
7 8 9 |
# File 'lib/io_streams/paths/http.rb', line 7 def password @password end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
7 8 9 |
# File 'lib/io_streams/paths/http.rb', line 7 def url @url end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
7 8 9 |
# File 'lib/io_streams/paths/http.rb', line 7 def username @username end |
Instance Method Details
#relative? ⇒ Boolean
Does not support relative file names since there is no concept of current working directory
46 47 48 |
# File 'lib/io_streams/paths/http.rb', line 46 def relative? false end |
#to_s ⇒ Object
50 51 52 |
# File 'lib/io_streams/paths/http.rb', line 50 def to_s url end |