Class: PageRankr::Indexes::Google

Inherits:
Object
  • Object
show all
Includes:
PageRankr::Index
Defined in:
lib/page_rankr/indexes/google.rb

Instance Attribute Summary

Attributes included from PageRankr::Index

#indexes

Instance Method Summary collapse

Methods included from PageRankr::Index

#clean

Constructor Details

#initialize(site) ⇒ Google

overloaded to use Google’s AJAX search API code.google.com/apis/ajaxsearch/documentation/



11
12
13
14
15
16
17
18
19
# File 'lib/page_rankr/indexes/google.rb', line 11

def initialize(site)
  @site = site
  
  request.on_complete do |response|
    json = JSON.parse(response.body)
    @indexes = clean(json["responseData"]["cursor"]["estimatedResultCount"].to_s)
    @indexes = nil if @indexes.zero?
  end
end

Instance Method Details

#requestObject



21
22
23
24
# File 'lib/page_rankr/indexes/google.rb', line 21

def request
  @request ||= Typhoeus::Request.new("http://ajax.googleapis.com/ajax/services/search/web",
      :params => {:v => "1.0", :rsz => 1, :q => "site:#{@site.to_s}"}, :method => :get)
end