gtools 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE.txt +2 -1
- data/Rakefile +1 -1
- data/gtools.gemspec +1 -1
- data/lib/gtools.rb +60 -13
- data/lib/gtools/version.rb +7 -2
- data/spec/lib/gtools_spec.rb +18 -19
- data/spec/spec_helper.rb +5 -0
- metadata +5 -5
data/LICENSE.txt
CHANGED
data/Rakefile
CHANGED
data/gtools.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ["kamil@futureworkshops.com"]
|
11
11
|
spec.description = %{A set of Gooogle SEO tools in Ruby}
|
12
12
|
spec.summary = %q{Gathers statistics like PageRank, site index, page speed analysis and more.}
|
13
|
-
spec.homepage = ""
|
13
|
+
spec.homepage = "https://github.com/kkodev/gtools"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
16
|
spec.files = `git ls-files`.split($/)
|
data/lib/gtools.rb
CHANGED
@@ -1,45 +1,84 @@
|
|
1
|
+
##
|
2
|
+
# GTools
|
3
|
+
# Copyright (c) 2013 Kamil Kocemba <kkocemba@gmail.com>
|
4
|
+
#
|
5
|
+
|
1
6
|
require "gtools/version"
|
2
7
|
require 'httparty'
|
3
8
|
|
4
9
|
module GTools
|
5
10
|
|
11
|
+
##
|
12
|
+
# Returns Google Page Rank for specified domain
|
13
|
+
#
|
14
|
+
# <tt>Note: mining Page Rank violates Google ToS.</tt>
|
15
|
+
#
|
6
16
|
def self.page_rank(domain)
|
7
17
|
url = GToolsConfiguration.tbr_host + GToolsConfiguration.tbr_query % [GMath.hash(domain), domain]
|
8
18
|
r = HTTParty.get(url).parsed_response
|
9
19
|
(r =~ /(\d+)$/) ? Integer($1) : nil
|
10
20
|
end
|
11
21
|
|
22
|
+
##
|
23
|
+
# Returns a dictionary of Google pagespeed analysis results for specified URL.
|
24
|
+
#
|
25
|
+
# Notable fields: <tt>rule_results</tt>, <tt>score</tt>
|
26
|
+
#
|
12
27
|
def self.pagespeed_analysis(url)
|
13
|
-
nil unless url
|
28
|
+
return nil unless valid_url url
|
14
29
|
url = GToolsConfiguration.google_pagespeed_url % [URI.encode(url)]
|
15
30
|
HTTParty.get(url).parsed_response["results"]
|
16
31
|
end
|
17
32
|
|
33
|
+
##
|
34
|
+
# Returns pagespeed score for specified URL.
|
35
|
+
#
|
18
36
|
def self.pagespeed_score(url)
|
19
|
-
nil unless
|
37
|
+
return nil unless valid_url url
|
20
38
|
r = pagespeed_analysis(url)
|
21
39
|
r ? r["score"] : nil
|
22
40
|
end
|
23
41
|
|
24
|
-
|
25
|
-
|
26
|
-
|
42
|
+
##
|
43
|
+
# Returns estimated number of indexed pages for specified domain.
|
44
|
+
#
|
45
|
+
# <tt>Provide user_ip param to avoid ToS violation.</tt>
|
46
|
+
#
|
47
|
+
def self.site_index(url, user_ip = nil)
|
48
|
+
return nil unless valid_url url
|
49
|
+
search_results "site:#{url}", user_ip
|
27
50
|
end
|
28
51
|
|
29
|
-
|
30
|
-
|
31
|
-
|
52
|
+
##
|
53
|
+
#
|
54
|
+
# Returns a number of results for link:domain query.
|
55
|
+
# This gives an overview of backlink portfolio.
|
56
|
+
#
|
57
|
+
# <tt>Note: this method is not intended to be used for accurate backlink analysis.</tt>
|
58
|
+
#
|
59
|
+
def self.site_links(url, user_ip = nil)
|
60
|
+
return nil unless valid_url url
|
61
|
+
search_results "link:#{url}", user_ip
|
32
62
|
end
|
33
63
|
|
34
|
-
|
35
|
-
|
64
|
+
##
|
65
|
+
# Returns estimated number of results for specified search query.
|
66
|
+
#
|
67
|
+
# <tt>Provide user_ip param to avoid ToS violation.</tt>
|
68
|
+
#
|
69
|
+
def self.search_results(query, user_ip = nil)
|
70
|
+
return nil unless query
|
36
71
|
url = GToolsConfiguration.google_apisearch_url % [1, URI.encode(query)]
|
72
|
+
url += "&userip=#{user_ip}" if user_ip
|
37
73
|
r = HTTParty.get(url).parsed_response
|
38
74
|
return nil unless r['responseData']
|
39
75
|
count = r['responseData']['cursor']['estimatedResultCount']
|
40
76
|
count ? Integer(count) : nil
|
41
77
|
end
|
42
78
|
|
79
|
+
##
|
80
|
+
# Returns Google tld suggestion based on current IP.
|
81
|
+
#
|
43
82
|
def self.suggested_tld
|
44
83
|
url = GToolsConfiguration.google_tld_url
|
45
84
|
domain = HTTParty.get(url).parsed_response
|
@@ -47,12 +86,20 @@ module GTools
|
|
47
86
|
end
|
48
87
|
|
49
88
|
private
|
50
|
-
|
89
|
+
def self.valid_url(url) # :nodoc:
|
90
|
+
false unless url
|
91
|
+
url += 'http://' unless url =~ /http:\/\//
|
92
|
+
!!(URI.parse(url) && url =~ URI::regexp)
|
93
|
+
rescue URI::InvalidURIError
|
94
|
+
false
|
95
|
+
end
|
96
|
+
|
97
|
+
private
|
98
|
+
module GToolsConfiguration # :nodoc:
|
51
99
|
|
52
100
|
class << self;
|
53
101
|
attr_accessor :google_apisearch_url, :google_pagespeed_url, :google_plusone_url, :google_tld_url, :tbr_host, :tbr_query;
|
54
102
|
end
|
55
|
-
|
56
103
|
self.google_apisearch_url = "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&rsz=%s&q=%s"
|
57
104
|
self.google_pagespeed_url = "https://developers.google.com/_apps/pagespeed/run_pagespeed?url=%s&format=json"
|
58
105
|
self.google_plusone_url = "https://plusone.google.com/u/0/_/+1/fastbutton?count=true&url=%s"
|
@@ -63,7 +110,7 @@ module GTools
|
|
63
110
|
end
|
64
111
|
|
65
112
|
private
|
66
|
-
module GMath
|
113
|
+
module GMath # :nodoc:
|
67
114
|
|
68
115
|
class << self; attr_accessor :hash_seed; end
|
69
116
|
|
data/lib/gtools/version.rb
CHANGED
data/spec/lib/gtools_spec.rb
CHANGED
@@ -1,9 +1,12 @@
|
|
1
|
+
##
|
2
|
+
# GTools
|
3
|
+
# Copyright (c) 2013 Kamil Kocemba <kkocemba@gmail.com>
|
4
|
+
#
|
5
|
+
|
1
6
|
require 'spec_helper'
|
2
7
|
|
3
8
|
describe GTools do
|
4
9
|
|
5
|
-
sleep_amount = 1
|
6
|
-
|
7
10
|
describe :page_rank do
|
8
11
|
|
9
12
|
it "should return page rank for a valid domain" do
|
@@ -58,15 +61,13 @@ describe GTools do
|
|
58
61
|
describe :site_index do
|
59
62
|
|
60
63
|
it "should return an integer for a valid domain" do
|
61
|
-
|
62
|
-
index = GTools.site_index 'google.com'
|
64
|
+
index = GTools.site_index 'google.com', '50.19.85.156'
|
63
65
|
index.should_not be_nil
|
64
66
|
index.should_not == 0
|
65
67
|
end
|
66
68
|
|
67
|
-
it "should return nil for invalid
|
68
|
-
|
69
|
-
index = GTools.site_index 'test'
|
69
|
+
it "should return nil for invalid url" do
|
70
|
+
index = GTools.site_index '@#$%', '50.19.85.156'
|
70
71
|
index.should be_nil
|
71
72
|
end
|
72
73
|
|
@@ -75,15 +76,13 @@ describe GTools do
|
|
75
76
|
describe :site_links do
|
76
77
|
|
77
78
|
it "should return an integer for a valid domain" do
|
78
|
-
|
79
|
-
count = GTools.site_links 'google.com'
|
79
|
+
count = GTools.site_links 'google.com', '50.18.169.106'
|
80
80
|
count.should_not be_nil
|
81
81
|
count.should_not == 0
|
82
82
|
end
|
83
83
|
|
84
|
-
it "should return nil for invalid
|
85
|
-
|
86
|
-
count = GTools.site_links 'test'
|
84
|
+
it "should return nil for invalid url" do
|
85
|
+
count = GTools.site_links '@#$%', '50.18.169.106'
|
87
86
|
count.should be_nil
|
88
87
|
end
|
89
88
|
|
@@ -91,18 +90,18 @@ describe GTools do
|
|
91
90
|
|
92
91
|
describe :search_results do
|
93
92
|
|
94
|
-
it "should return an integer for a valid
|
95
|
-
|
96
|
-
count = GTools.search_results 'google.com'
|
93
|
+
it "should return an integer for a valid query" do
|
94
|
+
count = GTools.search_results 'lolcat', '199.59.148.82'
|
97
95
|
count.should_not be_nil
|
98
96
|
count.should_not == 0
|
99
97
|
end
|
100
98
|
|
101
|
-
it "should
|
102
|
-
|
103
|
-
count
|
104
|
-
count.
|
99
|
+
it "should work without providing IP" do
|
100
|
+
count = GTools.search_results 'google.com'
|
101
|
+
count.should_not be_nil
|
102
|
+
count.should_not == 0
|
105
103
|
end
|
104
|
+
|
106
105
|
end
|
107
106
|
|
108
107
|
describe :suggested_tld do
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gtools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-04-
|
12
|
+
date: 2013-04-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -111,7 +111,7 @@ files:
|
|
111
111
|
- lib/gtools/version.rb
|
112
112
|
- spec/lib/gtools_spec.rb
|
113
113
|
- spec/spec_helper.rb
|
114
|
-
homepage:
|
114
|
+
homepage: https://github.com/kkodev/gtools
|
115
115
|
licenses:
|
116
116
|
- MIT
|
117
117
|
post_install_message:
|
@@ -126,7 +126,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
126
126
|
version: '0'
|
127
127
|
segments:
|
128
128
|
- 0
|
129
|
-
hash:
|
129
|
+
hash: 1773892807361118976
|
130
130
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
131
131
|
none: false
|
132
132
|
requirements:
|
@@ -135,7 +135,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
135
135
|
version: '0'
|
136
136
|
segments:
|
137
137
|
- 0
|
138
|
-
hash:
|
138
|
+
hash: 1773892807361118976
|
139
139
|
requirements: []
|
140
140
|
rubyforge_project:
|
141
141
|
rubygems_version: 1.8.24
|