lib/page_rankr/ranks/compete.rb in PageRankr-1.7.1 vs lib/page_rankr/ranks/compete.rb in PageRankr-2.0.0

- old
+ new

@@ -1,23 +1,23 @@ -require 'open-uri' +require 'typhoeus' require 'cgi' require 'nokogiri' module PageRankr - class Ranks < Tracker - class Compete < Rank - def initialize(site) - @rank = Nokogiri::HTML(open(url(site))).search(xpath).to_s.gsub(',', '').to_i - rescue - @rank = 0 #compete only accepts urls without http:// and www, will be fixed in 2.0 - end + class Ranks + class Compete + include Rank def xpath "//div[@id='rank']/div[@class='number value']/text()" end - def url(site) - "http://siteanalytics.compete.com/#{CGI.escape(site)}/" + def request + @request ||= Typhoeus::Request.new("http://siteanalytics.compete.com/#{CGI.escape(@site.domain)}/") + end + + def clean(rank) + rank.to_s.gsub(',', '').to_i end end end end \ No newline at end of file