googlepagerank 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data.tar.gz.sig ADDED
Binary file
data/History.txt ADDED
@@ -0,0 +1,6 @@
1
+ === 1.0.0 / 2008-04-10
2
+
3
+ * 1 major enhancement
4
+
5
+ * Birthday!
6
+
data/Manifest.txt ADDED
@@ -0,0 +1,7 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.txt
4
+ Rakefile
5
+ bin/googlepagerank
6
+ lib/googlepagerank.rb
7
+ test/test_googlepagerank.rb
data/README.txt ADDED
@@ -0,0 +1,56 @@
1
+ = googlepagerank
2
+ by Fran Diéguez
3
+ http://googlepagerank.rubyforge.org/
4
+
5
+ == DESCRIPTION:
6
+
7
+ Ruby gem for fetching Google PageRank®. It returns the value of the Google PageRank® for a given domain name.
8
+ Googlepagerank calculation is powered and based on http://www.math.kobe-u.ac.jp/~kodama/gprank.rb
9
+ == FEATURES/PROBLEMS:
10
+
11
+ * Return the Google PageRank@ of a given domain name
12
+
13
+ == SYNOPSIS:
14
+
15
+
16
+ # Require all gems and libs needed...
17
+ require 'rubygems'
18
+ require 'googlepagerank'
19
+
20
+ # Fetching the page_rank, the 2 lastest operators are for not use a proxy on the connection...
21
+ page_rank = Googlepagerank.get(domain,port,nil,nil)
22
+
23
+ # See extracted data...
24
+ page_rank
25
+ == REQUIREMENTS:
26
+
27
+ * net/http
28
+
29
+ == INSTALL:
30
+
31
+ * sudo gem install googlepagerank
32
+
33
+ == LICENSE:
34
+
35
+ (The MIT License)
36
+
37
+ Copyright (c) 2008 FIX
38
+
39
+ Permission is hereby granted, free of charge, to any person obtaining
40
+ a copy of this software and associated documentation files (the
41
+ 'Software'), to deal in the Software without restriction, including
42
+ without limitation the rights to use, copy, modify, merge, publish,
43
+ distribute, sublicense, and/or sell copies of the Software, and to
44
+ permit persons to whom the Software is furnished to do so, subject to
45
+ the following conditions:
46
+
47
+ The above copyright notice and this permission notice shall be
48
+ included in all copies or substantial portions of the Software.
49
+
50
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
51
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
52
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
53
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
54
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
55
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
56
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,23 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'rubygems'
4
+ require 'hoe'
5
+ require './lib/googlepagerank.rb'
6
+
7
+ Hoe.new('googlepagerank', GooglePageRank::VERSION) do |p|
8
+ # p.rubyforge_name = 'googlepagerankx' # if different than lowercase project name
9
+ # p.developer('FIX', 'FIX@example.com')
10
+ p.name = "googlepagerank"
11
+ p.author = "Francisco Dieguez"
12
+ p.description = "Google PageRank for Ruby."
13
+ p.email = 'fran.dieguez@glug.es'
14
+ p.summary = "Google PageRank for Ruby."
15
+ p.url = "http://www.mabishu.com/projects/googlepagerank"
16
+ p.clean_globs = ['test/actual'] # Remove this directory on "rake clean"
17
+ p.remote_rdoc_dir = '' # Release to root
18
+ p.changes = p.paragraphs_of('CHANGELOG', 0..1).join("\n\n")
19
+ # * extra_deps - An array of rubygem dependencies.
20
+ end
21
+
22
+ # vim: syntax=Ruby
23
+
@@ -0,0 +1,50 @@
1
+ #!/usr/bin/ruby
2
+ require "rubygems"
3
+ #require "googlepagerank"
4
+ load "../lib/googlepagerank.rb"
5
+ require "getoptlong"
6
+ opt_url=""
7
+ opt_silent=0;
8
+
9
+ port=80 # 80 World Wide Web HTTP
10
+ proxy=nil; proxy_port=nil
11
+ # proxy="10.1.4.1"; proxy_port=8080 # 8080 HTTP Alternate
12
+
13
+ def usage
14
+ puts "usage: googlepagerank [-h] [-s] -u http://... "
15
+ puts "Options:\n";
16
+ puts "-h help\n";
17
+ puts "-s silent\n"
18
+ end;
19
+
20
+ arg_parser=GetoptLong.new
21
+ arg_parser.set_options(
22
+ ["-h", "--help" , GetoptLong::NO_ARGUMENT],
23
+ ["-s", "--silent" , GetoptLong::NO_ARGUMENT],
24
+ ["-u", "--url", GetoptLong::REQUIRED_ARGUMENT]
25
+ )
26
+ arg_parser.each{|opt,arg|
27
+ begin
28
+ case opt
29
+ when "-h"; usage; exit;
30
+ when "-s"; opt_silent=1;
31
+ when "-u"; opt_url=arg;
32
+ end;
33
+ rescue => err; puts err; break
34
+ end
35
+ }
36
+ #puts "opt_silent= #{opt_silent}"
37
+ #puts "opt_url= #{opt_url}"
38
+
39
+
40
+ if (opt_silent == 0) then
41
+ rank = GooglePageRank.get(opt_url,port,proxy,proxy_port)
42
+ if (rank >= 0) then
43
+ printf("PageRank: %d : %s\n", rank, opt_url);
44
+ else
45
+ printf("PageRank: NO_INDEX : %s\n", opt_url);
46
+ end
47
+ else
48
+ printf("%d\n", GooglePageRank.get(opt_url));
49
+ end
50
+ exit(0);
@@ -0,0 +1,84 @@
1
+ ## Pagerank calculation based on http://www.math.kobe-u.ac.jp/~kodama/gprank.rb
2
+
3
+ require "net/http"
4
+
5
+ class GooglePageRank
6
+ VERSION = '1.0.0'
7
+
8
+ M=0x100000000 # modulo for unsigned int 32bit(4byte)
9
+
10
+ def self.m1(a,b,c,d)
11
+ return (((a+(M-b)+(M-c))%M)^(d%M))%M # mix/power mod
12
+ end
13
+
14
+ def self.c2i(s="",k=0)
15
+ # char codes to int. Little Endian
16
+ return ((s[k+3].to_i*0x100+s[k+2].to_i)*0x100+s[k+1].to_i)*0x100+s[k].to_i
17
+ end
18
+
19
+ def self.mix(a,b,c)
20
+ a=a%M; b=b%M; c=c%M
21
+ a = m1(a,b,c, c >> 13); b = m1(b,c,a, a << 8); c = m1(c,a,b, b >> 13);
22
+ a = m1(a,b,c, c >> 12); b = m1(b,c,a, a << 16); c = m1(c,a,b, b >> 5);
23
+ a = m1(a,b,c, c >> 3); b = m1(b,c,a, a << 10); c = m1(c,a,b, b >> 15);
24
+ return [a,b,c];
25
+ end
26
+
27
+ def self.checkSum(url="http://sample/index.html")
28
+ a= 0x9E3779B9; b= 0x9E3779B9; c= 0xE6359A60;
29
+ iurl="info:"+url; len = iurl.size; k=0;
30
+ while (len>=k+12) do
31
+ a += c2i(iurl,k) ; b += c2i(iurl,k+4); c += c2i(iurl,k+8); a,b,c = mix(a,b,c);
32
+ k=k+12
33
+ end
34
+ a += c2i(iurl,k); b += c2i(iurl,k+4); c += (c2i(iurl,k+8)<<8)+len; a,b,c = mix(a,b,c);
35
+ return c;
36
+ end
37
+
38
+ # Old Version of get, after they changed the format
39
+ def self.get0(url="http://sample/index.html",port=80,proxy=nil,proxy_port=nil)
40
+ # get Google PageRank
41
+ # old version
42
+ ch = checkSum(url);
43
+ # printf("CheckSUM: 6%u\n", ch);
44
+ g_path=sprintf("/search?client=navclient-auto&failedip=216.239.51.102;821&ch=6%u&q=info:%s", ch, url);
45
+ p="" # rank
46
+ ##
47
+ printf("%s\n",g_path)
48
+ # http://www.google.co.jp/search?client=navclient-auto&ch=63055969557&features=Rank&q=info:http://www.hyperposition.com/se3blog/
49
+ # http://www.google.co.jp/search?client=navclient-auto&features=Rank&q=info:http://www.hyperposition.com/&ch=6768349016
50
+ g_server="toolbarqueries.google.com"
51
+ # toolbarqueries.google.co.jp
52
+ #g_server="www.google.co.jp"
53
+ Net::HTTP::new(g_server, port, proxy, proxy_port).get(g_path){|line|
54
+ printf("%s\n", line)
55
+ pos=line.index("<RK>") # format: <RK>(rank)</RK>
56
+ if( pos != nil) then p=(line[pos+4,2]).to_i; break; end;
57
+ }
58
+ if (p.size>0) then return p.to_i; else return -1; end
59
+ end
60
+
61
+ # Nueva version de get (16 july 2007)
62
+ def self.get(url="http://sample/index.html",port=80,proxy=nil,proxy_port=nil)
63
+ # get Google PageRank
64
+ # 2007.07.10
65
+ ch = checkSum(url);
66
+ # printf("CheckSUM: 6%u\n", ch);
67
+ ###### format changed
68
+ #g_path=sprintf("/search?client=navclient-auto&failedip=216.239.51.102;821&ch=6%u&q=info:%s", ch, url);
69
+ g_path=sprintf("/search?client=navclient-auto&features=Rank&failedip=216.239.51.102;821&q=info:%s&ch=6%u", url, ch);
70
+ p="" # rank
71
+ puts g_path
72
+ # printf("%s\n",g_path)
73
+ # http://www.google.co.jp/search?client=navclient-auto&ch=63055969557&features=Rank&q=info:http://www.hyperposition.com/se3blog/
74
+ # http://www.google.co.jp/search?client=navclient-auto&features=Rank&q=info:http://www.hyperposition.com/&ch=6768349016
75
+ g_server="toolbarqueries.google.com" # toolbarqueries.google.co.jp
76
+ Net::HTTP::new(g_server, port, proxy, proxy_port).get(g_path){|line|
77
+ # printf("%s\n", line)
78
+ ###### format changed
79
+ pos=line.index("Rank_1:1:") # format: Rank_1:1:4
80
+ if( pos != nil) then p=(line[pos+9,2]).to_i; break; end;
81
+ }
82
+ if (p.size>0) then return p.to_i; else return -1; end
83
+ end
84
+ end
@@ -0,0 +1,12 @@
1
+ require "test/unit"
2
+
3
+ require "googlepagerank"
4
+
5
+ class TestGooglePageRank < Test::Unit::TestCase
6
+ def test_valid_page
7
+ assert_equal(9, GooglePageRank.get("www.apple.com",80,nil,nil))
8
+ end
9
+ def test_invalid_page
10
+ assert_equal(-1, GooglePageRank.get("",80,nil,nil))
11
+ end
12
+ end
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: googlepagerank
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Francisco Dieguez
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIDNjCCAh6gAwIBAgIBADANBgkqhkiG9w0BAQUFADBBMRUwEwYDVQQDDAxmcmF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nT2Xjo8OwGOUr9aicRXBlWYpQc31ErbWu+XrXqd0LD/stC9AR
30
+ EHxmDQrhRAnf3g==
31
+ -----END CERTIFICATE-----
32
+
33
+ date: 2008-04-12 00:00:00 +02:00
34
+ default_executable:
35
+ dependencies:
36
+ - !ruby/object:Gem::Dependency
37
+ name: hoe
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 1.5.1
44
+ version:
45
+ description: Google PageRank for Ruby.
46
+ email: fran.dieguez@glug.es
47
+ executables:
48
+ - googlepagerank
49
+ extensions: []
50
+
51
+ extra_rdoc_files:
52
+ - History.txt
53
+ - Manifest.txt
54
+ - README.txt
55
+ files:
56
+ - History.txt
57
+ - Manifest.txt
58
+ - README.txt
59
+ - Rakefile
60
+ - bin/googlepagerank
61
+ - lib/googlepagerank.rb
62
+ - test/test_googlepagerank.rb
63
+ has_rdoc: true
64
+ homepage: http://www.mabishu.com/projects/googlepagerank
65
+ post_install_message:
66
+ rdoc_options:
67
+ - --main
68
+ - README.txt
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: "0"
76
+ version:
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: "0"
82
+ version:
83
+ requirements: []
84
+
85
+ rubyforge_project: googlepagerank
86
+ rubygems_version: 1.1.1
87
+ signing_key:
88
+ specification_version: 2
89
+ summary: Google PageRank for Ruby.
90
+ test_files:
91
+ - test/test_googlepagerank.rb
metadata.gz.sig ADDED
Binary file