Class: RichUrls::UrlFetcher

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

Defined Under Namespace

Classes: UrlFetcherError

Constant Summary collapse

DEFAULT_TIMEOUT =

seconds

10

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, attributes, browser, cache_time) ⇒ UrlFetcher

Returns a new instance of UrlFetcher.



20
21
22
23
24
25
# File 'lib/url_fetcher.rb', line 20

def initialize(url, attributes, browser, cache_time)
  @url = url
  @attributes = attributes
  @browser = browser
  @cache_time = cache_time
end

Class Method Details

.fetch(url, attributes = [], browser: PatronBrowser.new, cache_time: nil) ⇒ Object



9
10
11
12
13
14
15
16
# File 'lib/url_fetcher.rb', line 9

def self.fetch(
  url,
  attributes = [],
  browser: PatronBrowser.new,
  cache_time: nil
)
  new(url, attributes, browser, cache_time).fetch
end

Instance Method Details

#fetchObject



27
28
29
30
31
32
33
34
35
36
# File 'lib/url_fetcher.rb', line 27

def fetch
  cached = RichUrls.cache.get(digest)

  if cached
    RichUrls.cache.extend(digest, @cache_time)
    Oj.load(cached)
  else
    patron_call
  end
end