Class: IOStreams::Paths::HTTP

Inherits:
IOStreams::Path show all
Defined in:
lib/io_streams/paths/http.rb

Instance Attribute Summary collapse

Attributes inherited from IOStreams::Path

#path

Attributes inherited from Stream

#io_stream

Instance Method Summary collapse

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_countObject (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

#passwordObject (readonly)

Returns the value of attribute password.



7
8
9
# File 'lib/io_streams/paths/http.rb', line 7

def password
  @password
end

#urlObject (readonly)

Returns the value of attribute url.



7
8
9
# File 'lib/io_streams/paths/http.rb', line 7

def url
  @url
end

#usernameObject (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

Returns:

  • (Boolean)


46
47
48
# File 'lib/io_streams/paths/http.rb', line 46

def relative?
  false
end

#to_sObject



50
51
52
# File 'lib/io_streams/paths/http.rb', line 50

def to_s
  url
end