lib/page_rankr/backlinks/google.rb in PageRankr-1.7.1 vs lib/page_rankr/backlinks/google.rb in PageRankr-2.0.0
- old
+ new
@@ -1,19 +1,25 @@
-require 'cgi'
require 'json'
module PageRankr
- class Backlinks < Tracker
- class Google < Backlink
+ class Backlinks
+ class Google
+ include Backlink
# overloaded to use Google's AJAX search API
# http://code.google.com/apis/ajaxsearch/documentation/
def initialize(site)
- @backlinks = clean JSON.parse( open( url(site)).read )["responseData"]["cursor"]["estimatedResultCount"].to_s
+ @site = site
+ request.on_complete do |response|
+ json = JSON.parse(response.body)
+ @backlinks = clean(json["responseData"]["cursor"]["estimatedResultCount"].to_s)
+ @backlinks = nil if @backlinks.zero?
+ end
end
- def url(site)
- "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&rsz=1&q=link%3A#{CGI.escape(site)}"
+ def request
+ @request ||= Typhoeus::Request.new("http://ajax.googleapis.com/ajax/services/search/web",
+ :params => {:v => "1.0", :rsz => 1, :q => "link:#{@site.to_s}"}, :method => :get)
end
end
end
end
\ No newline at end of file