googlepagerank 1.0.1 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
data.tar.gz.sig CHANGED
Binary file
@@ -1,3 +1,11 @@
1
+ === 1.0.3 / 2008-05-17
2
+
3
+ * A little modifications
4
+
5
+ * Refactoring
6
+ * Better Tests
7
+
8
+
1
9
  === 1.0.0 / 2008-04-10
2
10
 
3
11
  * 1 major enhancement
data/README.txt CHANGED
@@ -1,27 +1,28 @@
1
1
  = googlepagerank
2
- by Fran Diéguez
3
- http://googlepagerank.rubyforge.org/
2
+ * by Fran Dieguez
3
+ * http://googlepagerank.rubyforge.org/
4
4
 
5
5
  == DESCRIPTION:
6
6
 
7
7
  Ruby gem for fetching Google PageRank®. It returns the value of the Google PageRank® for a given domain name.
8
8
  Googlepagerank calculation is powered and based on http://www.math.kobe-u.ac.jp/~kodama/gprank.rb
9
+
9
10
  == FEATURES/PROBLEMS:
10
11
 
11
12
  * Return the Google PageRank@ of a given domain name
12
13
 
13
14
  == SYNOPSIS:
14
15
 
15
-
16
16
  # Require all gems and libs needed...
17
17
  require 'rubygems'
18
18
  require 'googlepagerank'
19
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)
20
+ # Fetching the page_rank
21
+ page_rank = Googlepagerank.get(domain,port)
22
22
 
23
23
  # See extracted data...
24
24
  page_rank
25
+
25
26
  == REQUIREMENTS:
26
27
 
27
28
  * net/http
@@ -34,7 +35,7 @@ page_rank
34
35
 
35
36
  (The MIT License)
36
37
 
37
- Copyright (c) 2008 FIX
38
+ Copyright (c) 2008 Fran Dieguez
38
39
 
39
40
  Permission is hereby granted, free of charge, to any person obtaining
40
41
  a copy of this software and associated documentation files (the
data/Rakefile CHANGED
@@ -6,18 +6,7 @@ require './lib/googlepagerank.rb'
6
6
 
7
7
  Hoe.new('googlepagerank', GooglePageRank::VERSION) do |p|
8
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 Gem 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.
9
+ p.developer('Fran Dieguez', 'fran.dieguez@glug.es')
20
10
  end
21
11
 
22
12
  # vim: syntax=Ruby
23
-
@@ -3,6 +3,8 @@
3
3
  # == Synopsis
4
4
  #
5
5
  # Fetch the Google PageRank for a given url
6
+ #
7
+ # from command line
6
8
  #
7
9
  # ==
8
10
  #
@@ -22,6 +24,12 @@
22
24
  require "rubygems"
23
25
  require "googlepagerank"
24
26
  require "getoptlong"
27
+ def usage
28
+ puts "Usage: googlepagerank [-h] [-s] -u domain.com "
29
+ puts "Options:\n";
30
+ puts "\t-h help\n";
31
+ puts "\t-s silent\n"
32
+ end;
25
33
  opt_url=""
26
34
  opt_silent=0;
27
35
 
@@ -29,12 +37,6 @@ port=80 # 80 World Wide Web HTTP
29
37
  proxy=nil; proxy_port=nil
30
38
  # proxy="10.1.4.1"; proxy_port=8080 # 8080 HTTP Alternate
31
39
 
32
- def usage
33
- puts "usage: googlepagerank [-h] [-s] -u http://... "
34
- puts "Options:\n";
35
- puts "-h help\n";
36
- puts "-s silent\n"
37
- end;
38
40
 
39
41
  arg_parser=GetoptLong.new
40
42
  arg_parser.set_options(
@@ -55,15 +57,18 @@ arg_parser.each{|opt,arg|
55
57
  #puts "opt_silent= #{opt_silent}"
56
58
  #puts "opt_url= #{opt_url}"
57
59
 
58
-
59
- if (opt_silent == 0) then
60
- rank = GooglePageRank.get(opt_url,port,proxy,proxy_port)
61
- if (rank >= 0) then
62
- printf("PageRank: %d : %s\n", rank, opt_url);
63
- else
64
- printf("PageRank: NO_INDEX : %s\n", opt_url);
65
- end
60
+ if opt_url.nil? or opt_url == ""
61
+ usage()
66
62
  else
67
- printf("%d\n", GooglePageRank.get(opt_url));
63
+ if (opt_silent == 0) then
64
+ rank = GooglePageRank.get(opt_url,port,proxy,proxy_port)
65
+ if (rank >= 0) then
66
+ printf("PageRank: %d : %s\n", rank, opt_url);
67
+ else
68
+ printf("PageRank: NO_INDEX : %s\n", opt_url);
69
+ end
70
+ else
71
+ printf("%d\n", GooglePageRank.get(opt_url));
72
+ end
68
73
  end
69
74
  exit(0);
@@ -3,38 +3,11 @@
3
3
  require "net/http"
4
4
 
5
5
  class GooglePageRank
6
- VERSION = '1.0.1'
6
+ VERSION = '1.0.3'
7
7
 
8
8
  M=0x100000000 # modulo for unsigned int 32bit(4byte)
9
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
10
 
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
11
  # Calculates the PageRank for the given _url_
39
12
  # ATENTION: Old version, use the GooglePageRak.get() instead
40
13
  #
@@ -118,4 +91,35 @@ class GooglePageRank
118
91
  }
119
92
  if (p.size>0) then return p.to_i; else return -1; end
120
93
  end
94
+
95
+ private
96
+
97
+ def self.m1(a,b,c,d)
98
+ return (((a+(M-b)+(M-c))%M)^(d%M))%M # mix/power mod
99
+ end
100
+
101
+ def self.c2i(s="",k=0)
102
+ # char codes to int. Little Endian
103
+ return ((s[k+3].to_i*0x100+s[k+2].to_i)*0x100+s[k+1].to_i)*0x100+s[k].to_i
104
+ end
105
+
106
+ def self.mix(a,b,c)
107
+ a=a%M; b=b%M; c=c%M
108
+ a = m1(a,b,c, c >> 13); b = m1(b,c,a, a << 8); c = m1(c,a,b, b >> 13);
109
+ a = m1(a,b,c, c >> 12); b = m1(b,c,a, a << 16); c = m1(c,a,b, b >> 5);
110
+ a = m1(a,b,c, c >> 3); b = m1(b,c,a, a << 10); c = m1(c,a,b, b >> 15);
111
+ return [a,b,c];
112
+ end
113
+
114
+ def self.checkSum(url="http://sample/index.html")
115
+ a= 0x9E3779B9; b= 0x9E3779B9; c= 0xE6359A60;
116
+ iurl="info:"+url; len = iurl.size; k=0;
117
+ while (len>=k+12) do
118
+ a += c2i(iurl,k) ; b += c2i(iurl,k+4); c += c2i(iurl,k+8); a,b,c = mix(a,b,c);
119
+ k=k+12
120
+ end
121
+ a += c2i(iurl,k); b += c2i(iurl,k+4); c += (c2i(iurl,k+8)<<8)+len; a,b,c = mix(a,b,c);
122
+ return c;
123
+ end
124
+
121
125
  end
@@ -3,10 +3,13 @@ require "test/unit"
3
3
  require "googlepagerank"
4
4
 
5
5
  class TestGooglePageRank < Test::Unit::TestCase
6
- def test_valid_page
6
+ def test_valid_domain
7
7
  assert_equal(9, GooglePageRank.get("www.apple.com",80,nil,nil))
8
8
  end
9
- def test_invalid_page
10
- assert_equal(-1, GooglePageRank.get("wwwtesting.com",80,nil,nil))
9
+ def test_invalid_domain
10
+ assert_equal(-1, GooglePageRank.get("w.w.w.com",80))
11
+ end
12
+ def test_malformed_domain
13
+ assert_equal(-1, GooglePageRank.get("@@@",80))
11
14
  end
12
15
  end
metadata CHANGED
@@ -1,10 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: googlepagerank
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
- - Francisco Dieguez
7
+ - Fran Dieguez
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain:
@@ -30,7 +30,7 @@ cert_chain:
30
30
  EHxmDQrhRAnf3g==
31
31
  -----END CERTIFICATE-----
32
32
 
33
- date: 2008-04-13 00:00:00 +02:00
33
+ date: 2008-05-19 00:00:00 +02:00
34
34
  default_executable:
35
35
  dependencies:
36
36
  - !ruby/object:Gem::Dependency
@@ -42,8 +42,9 @@ dependencies:
42
42
  - !ruby/object:Gem::Version
43
43
  version: 1.5.1
44
44
  version:
45
- description: Google PageRank Gem for Ruby.
46
- email: fran.dieguez@glug.es
45
+ description: "Ruby gem for fetching Google PageRank\xC2\xAE. It returns the value of the Google PageRank\xC2\xAE for a given domain name. Googlepagerank calculation is powered and based on http://www.math.kobe-u.ac.jp/~kodama/gprank.rb"
46
+ email:
47
+ - fran.dieguez@glug.es
47
48
  executables:
48
49
  - googlepagerank
49
50
  extensions: []
@@ -61,7 +62,7 @@ files:
61
62
  - lib/googlepagerank.rb
62
63
  - test/test_googlepagerank.rb
63
64
  has_rdoc: true
64
- homepage: http://www.mabishu.com/projects/googlepagerank
65
+ homepage: by Fran Dieguez
65
66
  post_install_message:
66
67
  rdoc_options:
67
68
  - --main
@@ -86,6 +87,6 @@ rubyforge_project: googlepagerank
86
87
  rubygems_version: 1.1.1
87
88
  signing_key:
88
89
  specification_version: 2
89
- summary: Google PageRank for Ruby.
90
+ summary: "Ruby gem for fetching Google PageRank\xC2\xAE"
90
91
  test_files:
91
92
  - test/test_googlepagerank.rb
metadata.gz.sig CHANGED
Binary file