lib/page_rankr/tracker.rb in PageRankr-3.2.1 vs lib/page_rankr/tracker.rb in PageRankr-4.0.0
- old
+ new
@@ -1,36 +1,26 @@
-require 'typhoeus'
require 'nokogiri'
require 'json'
require 'jsonpath'
+require 'uri'
require File.expand_path('../site', __FILE__)
+require File.expand_path('../request', __FILE__)
module PageRankr
module Tracker
attr_accessor :tracked
attr_accessor :raw
attr_accessor :body
def initialize(site, options = {})
@site = PageRankr::Site(site)
+ @options = options
- @options = {:method => method, :headers => {'User-Agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_0) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.12 Safari/535.11'}}
- @options[:params] = params if respond_to? :params
- @options[:proxy] = proxy
- @options.merge!(options)
-
- request.on_complete do |response|
- self.body = response.body
- self.raw = content(body)
- self.tracked = clean(raw)
- end
+ # Initialize proxy, so threads don't need to synchronize the proxy service.
+ proxy
end
- def request
- @request ||= Typhoeus::Request.new(url, @options)
- end
-
def url
raise PageRankr::MethodRequired, "A url method defining the url to the service with the value you wish to extract must be defined."
end
def tracked_url
@@ -44,16 +34,18 @@
def method
:get
end
def proxy
- PageRankr.proxy_service.proxy(name, @site) if PageRankr.proxy_service
+ @proxy ||= URI.parse(PageRankr.proxy_service.proxy(name, @site)) if PageRankr.proxy_service
end
def run
- hydra = Typhoeus::Hydra.new
- hydra.queue request
- hydra.run
+ PageRankr::Request.new(self, @options).perform do |body|
+ self.body = body
+ self.raw = content(body)
+ self.tracked = clean(raw)
+ end
tracked
end
def content(body)
\ No newline at end of file