Class: Opener::Daemons::Downloader
- Inherits:
-
Object
- Object
- Opener::Daemons::Downloader
- Defined in:
- lib/opener/daemons/downloader.rb
Overview
Downloads and validates text/XML documents used as input.
Instance Attribute Summary collapse
- #http ⇒ HTTPClient readonly
Instance Method Summary collapse
-
#download(url) ⇒ String
Downloads the document located at ‘url`.
-
#initialize ⇒ Downloader
constructor
A new instance of Downloader.
Constructor Details
#initialize ⇒ Downloader
Returns a new instance of Downloader.
12 13 14 15 16 |
# File 'lib/opener/daemons/downloader.rb', line 12 def initialize @http = HTTPClient.new @http.ssl_config. |= OpenSSL::SSL::OP_NO_SSLv3 end |
Instance Attribute Details
#http ⇒ HTTPClient (readonly)
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/opener/daemons/downloader.rb', line 9 class Downloader attr_reader :http def initialize @http = HTTPClient.new @http.ssl_config. |= OpenSSL::SSL::OP_NO_SSLv3 end ## # Downloads the document located at `url`. # # @param [String] url # @return [String] # def download(url) resp = http.get(url, :follow_redirect => true) unless resp.ok? raise( HTTPClient::BadResponseError, "Got HTTP #{resp.status}: #{resp.body}" ) end return resp.body.force_encoding('UTF-8') end end |
Instance Method Details
#download(url) ⇒ String
Downloads the document located at ‘url`.
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/opener/daemons/downloader.rb', line 24 def download(url) resp = http.get(url, :follow_redirect => true) unless resp.ok? raise( HTTPClient::BadResponseError, "Got HTTP #{resp.status}: #{resp.body}" ) end return resp.body.force_encoding('UTF-8') end |