class Opener::Daemons::Downloader

Downloads and validates text/XML documents used as input.

@!attribute [r] http

@return [HTTPClient]

Attributes

http[R]

Public Class Methods

new() click to toggle source
# File lib/opener/daemons/downloader.rb, line 12
def initialize
  @http = HTTPClient.new

  @http.ssl_config.options |= OpenSSL::SSL::OP_NO_SSLv3
end

Public Instance Methods

download(url) click to toggle source

Downloads the document located at `url`.

@param [String] url @return [String]

# 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