lib/link_thumbnailer/fetcher.rb in link_thumbnailer-1.0.2 vs lib/link_thumbnailer/fetcher.rb in link_thumbnailer-1.0.3

- old
+ new

@@ -2,21 +2,23 @@ module LinkThumbnailer class Fetcher + attr_accessor :url + def fetch(url, redirect_count = 0) if redirect_count > LinkThumbnailer.configuration.redirect_limit raise ArgumentError, "too many redirects (#{redirect_count})" end - uri = url.is_a?(URI) ? url : URI(url) + self.url = url.is_a?(URI) ? url : URI(url) - if uri.is_a?(URI::HTTP) + if self.url.is_a?(URI::HTTP) http = Net::HTTP::Persistent.new('linkthumbnailer') http.headers['User-Agent'] = 'linkthumbnailer' - resp = http.request(uri) + resp = http.request(self.url) case resp when Net::HTTPSuccess; resp.body when Net::HTTPRedirection; fetch(resp['location'], redirect_count + 1) else resp.error! end