Class: Ogpr::Fetcher::HtmlFetcher
- Inherits:
-
Object
- Object
- Ogpr::Fetcher::HtmlFetcher
- Defined in:
- lib/ogpr/fetcher/html_fetcher.rb
Instance Method Summary collapse
- #fetch(headers = {}) ⇒ Object
-
#initialize(url) ⇒ HtmlFetcher
constructor
A new instance of HtmlFetcher.
Constructor Details
#initialize(url) ⇒ HtmlFetcher
Returns a new instance of HtmlFetcher.
10 11 12 13 |
# File 'lib/ogpr/fetcher/html_fetcher.rb', line 10 def initialize(url) @uri = URI.parse(url) @accept_types = %w(text/html text/plain) end |
Instance Method Details
#fetch(headers = {}) ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/ogpr/fetcher/html_fetcher.rb', line 15 def fetch(headers = {}) head = send_request(:head, @uri, headers) acceptable_content!(head.headers[:content_type]) res = send_request(:get, @uri, headers) Kconv.toutf8(res.to_str) rescue => e raise e end |