Class: Refile::Download
- Inherits:
-
Object
- Object
- Refile::Download
- Extended by:
- Forwardable
- Defined in:
- lib/refile/download.rb
Overview
This class downloads a given URL and returns its IO, size, content type and original file name.
Usage:
download = Refile::Download.new('http://example.com/my/data.bin')
download.io
#=> #<StringIO:0x00007fdcb3932fc8 ...>
download.size
#=> 389620
download.content_type
#=> "application/octet-stream"
download.original_file_name
#=> "data.bin"
Constant Summary collapse
- OPTIONS =
{ "User-Agent" => "Refile/#{Refile::VERSION}", open_timeout: 30, read_timeout: 30, redirect: false }.freeze
Instance Attribute Summary collapse
-
#io ⇒ Object
readonly
Returns the value of attribute io.
-
#original_filename ⇒ Object
readonly
Returns the value of attribute original_filename.
Instance Method Summary collapse
-
#initialize(uri) ⇒ Download
constructor
A new instance of Download.
Constructor Details
#initialize(uri) ⇒ Download
Returns a new instance of Download.
33 34 35 36 |
# File 'lib/refile/download.rb', line 33 def initialize(uri) @io = download(uri) @original_filename = extract_original_filename end |
Instance Attribute Details
#io ⇒ Object (readonly)
Returns the value of attribute io.
31 32 33 |
# File 'lib/refile/download.rb', line 31 def io @io end |
#original_filename ⇒ Object (readonly)
Returns the value of attribute original_filename.
31 32 33 |
# File 'lib/refile/download.rb', line 31 def original_filename @original_filename end |