Module: GTools
- Defined in:
- lib/gtools.rb
Defined Under Namespace
Modules: GMath, GToolsConfiguration
Class Method Summary collapse
-
.page_rank(domain) ⇒ Object
Returns Google Page Rank for specified domain.
-
.pagespeed_analysis(url) ⇒ Object
Returns a dictionary of Google pagespeed analysis results for specified URL.
-
.pagespeed_score(url) ⇒ Object
Returns pagespeed score for specified URL.
-
.search_results(query, user_ip = nil) ⇒ Object
Returns estimated number of results for specified search query.
-
.site_index(url, user_ip = nil) ⇒ Object
Returns estimated number of indexed pages for specified domain.
-
.site_links(url, user_ip = nil) ⇒ Object
Returns a number of results for domain query.
-
.suggested_tld ⇒ Object
Returns Google tld suggestion based on current IP.
Class Method Details
.page_rank(domain) ⇒ Object
Returns Google Page Rank for specified domain
Note: mining Page Rank violates Google ToS.
16 17 18 19 20 |
# File 'lib/gtools.rb', line 16 def self.page_rank(domain) url = GToolsConfiguration.tbr_host + GToolsConfiguration.tbr_query % [GMath.hash(domain), domain] r = HTTParty.get(url).parsed_response (r =~ /(\d+)$/) ? Integer($1) : nil end |
.pagespeed_analysis(url) ⇒ Object
Returns a dictionary of Google pagespeed analysis results for specified URL.
Notable fields: rule_results
, score
27 28 29 30 31 |
# File 'lib/gtools.rb', line 27 def self.pagespeed_analysis(url) return nil unless valid_url url url = GToolsConfiguration.google_pagespeed_url % [URI.encode(url)] HTTParty.get(url).parsed_response["results"] end |
.pagespeed_score(url) ⇒ Object
Returns pagespeed score for specified URL.
36 37 38 39 40 |
# File 'lib/gtools.rb', line 36 def self.pagespeed_score(url) return nil unless valid_url url r = pagespeed_analysis(url) r ? r["score"] : nil end |
.search_results(query, user_ip = nil) ⇒ Object
Returns estimated number of results for specified search query.
Provide user_ip param to avoid ToS violation.
69 70 71 72 73 74 75 76 77 |
# File 'lib/gtools.rb', line 69 def self.search_results(query, user_ip = nil) return nil unless query url = GToolsConfiguration.google_apisearch_url % [1, URI.encode(query)] url += "&userip=#{user_ip}" if user_ip r = HTTParty.get(url).parsed_response return nil unless r['responseData'] count = r['responseData']['cursor']['estimatedResultCount'] count ? Integer(count) : nil end |
.site_index(url, user_ip = nil) ⇒ Object
Returns estimated number of indexed pages for specified domain.
Provide user_ip param to avoid ToS violation.
47 48 49 50 |
# File 'lib/gtools.rb', line 47 def self.site_index(url, user_ip = nil) return nil unless valid_url url search_results "site:#{url}", user_ip end |
.site_links(url, user_ip = nil) ⇒ Object
Returns a number of results for domain query. This gives an overview of backlink portfolio.
Note: this method is not intended to be used for accurate backlink analysis.
59 60 61 62 |
# File 'lib/gtools.rb', line 59 def self.site_links(url, user_ip = nil) return nil unless valid_url url search_results "link:#{url}", user_ip end |
.suggested_tld ⇒ Object
Returns Google tld suggestion based on current IP.
82 83 84 85 86 |
# File 'lib/gtools.rb', line 82 def self.suggested_tld url = GToolsConfiguration.google_tld_url domain = HTTParty.get(url).parsed_response domain =~ /google\.(.*)$/ ? $1 : nil end |