seo_info 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGELOG.md ADDED
@@ -0,0 +1,9 @@
1
+ v0.0.2
2
+ ======
3
+
4
+ * Google page rank for pages and web-sites
5
+
6
+ v0.0.1
7
+ ======
8
+
9
+ * number of pages indexed by Google
data/README.md CHANGED
@@ -3,13 +3,21 @@ Description
3
3
 
4
4
  seo_info gem gets different seo information for web-sites.
5
5
 
6
- Features
7
- ========
6
+ Usage
7
+ =====
8
8
 
9
9
  Things that you are able to do right now with this gem:
10
10
 
11
+ * Google Page Rank for pages and web-sites:
12
+
13
+ google = SeoInfo::Google.new('example.com')
14
+ google.page_rank
15
+
11
16
  * Number of pages indexed by Google
12
17
 
18
+ google = SeoInfo::Google.new('example.com')
19
+ google.indexed_pages
20
+
13
21
  Install
14
22
  =======
15
23
 
@@ -1,3 +1,5 @@
1
+ require 'cgi'
2
+
1
3
  module SeoInfo
2
4
  class Google
3
5
  attr_accessor :site_url
@@ -10,14 +12,68 @@ module SeoInfo
10
12
 
11
13
  def indexed_pages
12
14
  results[:indexed_pages] ||= begin
13
- page = Nokogiri::HTML(get_page)
15
+ page = Nokogiri::HTML(indexed_pages_page)
14
16
  page.xpath('//div[@id="subform_ctrl"]/div/b/text()')[2].text.gsub(/[^\d]/,'').to_i
15
17
  end
16
18
  end
17
19
 
20
+ def page_rank
21
+ page_rank_page.split(':').last.to_i rescue nil
22
+ end
23
+
18
24
  private
19
- def get_page
25
+ def indexed_pages_page
20
26
  open("https://www.google.com/search?hl=en&safe=off&q=site%3A#{site_url}&btnG=Search").read
21
27
  end
28
+
29
+ def page_rank_page
30
+ open("http://toolbarqueries.google.com/tbr?client=navclient-auto&ch=#{checksum(site_url)}&ie=UTF-8&oe=UTF-8&features=Rank&q=info:#{CGI::escape(site_url)}").read
31
+ end
32
+
33
+ def checksum(str)
34
+ check1 = str_to_num(str, 0x1505, 0x21)
35
+ check2 = str_to_num(str, 0, 0x1003F)
36
+ check1 >>= 2
37
+ check1 = ((check1 >> 4) & 0x3FFFFC0) | (check1 & 0x3F)
38
+ check1 = ((check1 >> 4) & 0x3FFC00) | (check1 & 0x3FF)
39
+ check1 = ((check1 >> 4) & 0x3C000) | (check1 & 0x3FFF)
40
+ t1 = ((((check1 & 0x3C0) << 4) | (check1 & 0x3C)) << 2) | (check2 & 0xF0F)
41
+ t2 = ((((check1 & 0xFFFFC000) << 4) | (check1 & 0x3C00)) << 0xA) | (check2 & 0xF0F0000)
42
+ hash = (t1 | t2)
43
+ check_byte = 0
44
+ flag = 0
45
+ hash_str = sprintf('%u', hash)
46
+ (hash_str.size - 1).downto(0) do |i|
47
+ re = hash_str[i..i].to_i
48
+ if (1 == (flag % 2))
49
+ re += re
50
+ re = (re / 10).to_i + (re % 10)
51
+ end
52
+ check_byte += re
53
+ flag += 1
54
+ end
55
+ check_byte %= 10
56
+ if (0 != check_byte)
57
+ check_byte = 10 - check_byte
58
+ if (1 == (flag % 2))
59
+ check_byte += 9 if (1 == (check_byte % 2))
60
+ check_byte >>= 1
61
+ end
62
+ end
63
+ return '7' + check_byte.to_s + hash_str;
64
+ end
65
+
66
+ def str_to_num(str, check, magic)
67
+ int32 = 4294967296 # 2^32
68
+ str.each_byte do |char|
69
+ check *= magic
70
+ if check >= int32
71
+ check = (check - int32 * (check / int32).to_i)
72
+ check = (check < -2147483648) ? check + int32 : check
73
+ end
74
+ check += char
75
+ end
76
+ return check
77
+ end
22
78
  end
23
79
  end
@@ -1,3 +1,3 @@
1
1
  module SeoInfo
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/seo_info.gemspec CHANGED
@@ -7,7 +7,7 @@ Gem::Specification.new do |s|
7
7
  s.version = SeoInfo::VERSION
8
8
  s.authors = ["Sergey Parizhskiy", "Dina Zhyliaieva"]
9
9
  s.email = ["parizhskiy@gmail.com", "dinaionenko@reevoo.com"]
10
- s.homepage = ""
10
+ s.homepage = "https://github.com/HeeL/seo_info"
11
11
  s.summary = %q{SEO information for web-sites}
12
12
  s.description = %q{Gets different seo information such as Page Rank, Alexa Rank, number of indexed pages in different search engines and so on.}
13
13
 
@@ -1,15 +1,30 @@
1
1
  require 'spec_helper.rb'
2
2
 
3
3
  describe SeoInfo::Google do
4
- let(:google) do
5
- path = 'spec/data/google_search.html'
6
- google = SeoInfo::Google.new('example.com')
7
- google.stub(:get_page).and_return(File.read(path))
8
- google
4
+
5
+ describe 'indexed_pages' do
6
+ let(:google) do
7
+ path = 'spec/data/google_search.html'
8
+ google = SeoInfo::Google.new('example.com')
9
+ google.stub(:indexed_pages_page).and_return(File.read(path))
10
+ google
11
+ end
12
+
13
+ it "returns number greater than zero" do
14
+ google.indexed_pages.should > 0
15
+ end
9
16
  end
10
17
 
11
- it "returns number greater than zero" do
12
- google.indexed_pages.should > 0
18
+ describe 'page rank' do
19
+ let(:google) do
20
+ google = SeoInfo::Google.new('example.com')
21
+ google.stub(:page_rank_page).and_return('Rank_1:1:3')
22
+ google
23
+ end
24
+
25
+ it "splits the result correctly" do
26
+ google.page_rank.should == 3
27
+ end
13
28
  end
14
29
 
15
30
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: seo_info
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2011-12-22 00:00:00.000000000 Z
13
+ date: 2012-01-05 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rspec
17
- requirement: &2153233340 !ruby/object:Gem::Requirement
17
+ requirement: &2152543480 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: '0'
23
23
  type: :development
24
24
  prerelease: false
25
- version_requirements: *2153233340
25
+ version_requirements: *2152543480
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: nokogiri
28
- requirement: &2153232920 !ruby/object:Gem::Requirement
28
+ requirement: &2152543060 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ! '>='
@@ -33,7 +33,7 @@ dependencies:
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *2153232920
36
+ version_requirements: *2152543060
37
37
  description: Gets different seo information such as Page Rank, Alexa Rank, number
38
38
  of indexed pages in different search engines and so on.
39
39
  email:
@@ -45,7 +45,7 @@ extra_rdoc_files: []
45
45
  files:
46
46
  - .gitignore
47
47
  - .rspec
48
- - CHANGELOG.MD
48
+ - CHANGELOG.md
49
49
  - Gemfile
50
50
  - README.md
51
51
  - Rakefile
@@ -56,7 +56,7 @@ files:
56
56
  - spec/data/google_search.html
57
57
  - spec/spec_helper.rb
58
58
  - spec/specs/google_spec.rb
59
- homepage: ''
59
+ homepage: https://github.com/HeeL/seo_info
60
60
  licenses: []
61
61
  post_install_message:
62
62
  rdoc_options: []
data/CHANGELOG.MD DELETED
@@ -1,4 +0,0 @@
1
- v0.0.1
2
- ======
3
-
4
- * number of pages indexed by Google