Class: Downloadr::HTTP
- Inherits:
-
Object
- Object
- Downloadr::HTTP
- Defined in:
- lib/downloadr/http.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Class Method Summary collapse
Instance Method Summary collapse
- #download ⇒ Object
-
#initialize(uri, download_path = nil) ⇒ HTTP
constructor
A new instance of HTTP.
Constructor Details
#initialize(uri, download_path = nil) ⇒ HTTP
Returns a new instance of HTTP.
12 13 14 15 |
# File 'lib/downloadr/http.rb', line 12 def initialize(uri, download_path = nil) @uri = ::Addressable::URI.parse(uri) @path = normalize_path(download_path) end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
8 9 10 |
# File 'lib/downloadr/http.rb', line 8 def path @path end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
8 9 10 |
# File 'lib/downloadr/http.rb', line 8 def uri @uri end |
Class Method Details
Instance Method Details
#download ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/downloadr/http.rb', line 17 def download begin response = ::RestClient::Request.execute( :method => :get, :url => @uri.to_s, :timeout => 100, :open_timeout => 10 ) rescue ::SocketError raise Downloadr::SocketError rescue RestClient::ResourceNotFound raise Downloadr::ResourceNotFound end File.write(@path, response.to_str) end |