Class: ReevooMark::Fetcher

Inherits:
Object
  • Object
show all
Defined in:
lib/reevoomark/fetcher.rb

Constant Summary collapse

FetchError =
Class.new(RuntimeError)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(timeout) ⇒ Fetcher

Returns a new instance of Fetcher.



6
7
8
9
10
11
12
13
14
# File 'lib/reevoomark/fetcher.rb', line 6

def initialize(timeout)
  @timeout = timeout
  @http_client = HTTPClient.new
  @http_client.connect_timeout = timeout
  @headers = {
    'User-Agent' => "ReevooMark Ruby Widget/#{ReevooMark::VERSION}",
    'Referer' => "http://#{Socket::gethostname}"
  }
end

Instance Attribute Details

#headersObject (readonly)

Returns the value of attribute headers.



4
5
6
# File 'lib/reevoomark/fetcher.rb', line 4

def headers
  @headers
end

Instance Method Details

#fetch(remote_url) ⇒ Object



16
17
18
19
20
21
# File 'lib/reevoomark/fetcher.rb', line 16

def fetch(remote_url)
  response = fetch_http(remote_url)
  ReevooMark::Document.from_response(response)
rescue FetchError
  ReevooMark::Document.error
end