keyword_ranking 1.0
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 +1 -0
- data/Gemfile +9 -0
- data/Gemfile.lock +28 -0
- data/LICENSE +0 -0
- data/README +19 -0
- data/Rakefile +2 -0
- data/keyword_ranking.gemspec +37 -0
- data/lib/keyword_ranking.rb +60 -0
- data/spec/keyword_ranking_spec.rb +20 -0
- data/spec/spec.opts +5 -0
- metadata +116 -0
data/CHANGELOG
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
v1.0. First draft
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
keyword_ranking (1.0)
|
5
|
+
nokogiri
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: http://rubygems.org/
|
9
|
+
specs:
|
10
|
+
echoe (4.3.1)
|
11
|
+
gemcutter
|
12
|
+
rubyforge
|
13
|
+
gemcutter (0.6.1)
|
14
|
+
json_pure (1.4.6)
|
15
|
+
nokogiri (1.4.3.1)
|
16
|
+
rspec (1.3.0)
|
17
|
+
rubyforge (2.0.4)
|
18
|
+
json_pure (>= 1.1.7)
|
19
|
+
|
20
|
+
PLATFORMS
|
21
|
+
ruby
|
22
|
+
|
23
|
+
DEPENDENCIES
|
24
|
+
bundler
|
25
|
+
echoe
|
26
|
+
keyword_ranking!
|
27
|
+
nokogiri
|
28
|
+
rspec
|
data/LICENSE
ADDED
File without changes
|
data/README
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Keyword Ranking
|
2
|
+
|
3
|
+
Use this gem to calculate the keyword ranking in Bing, Yahoo or Google as follows:
|
4
|
+
|
5
|
+
get_ranking(:keyword => 'one_keyword', :url => 'www.mydomain.com', :engine => :bing, :limit => 100)
|
6
|
+
|
7
|
+
Note:
|
8
|
+
|
9
|
+
* :engine can receive any of these values --> :google, :yahoo or :bing
|
10
|
+
* :limit by default is 200 (defined in RES_LIMIT constant)
|
11
|
+
* You can change the results per page desired changing the value of RES_PER_PAGE having in mind that not all the 3 engines support more than 10 results per page with this utility
|
12
|
+
|
13
|
+
More updates coming
|
14
|
+
|
15
|
+
TODO:
|
16
|
+
|
17
|
+
* Testing code
|
18
|
+
* GEM for Rails structure
|
19
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{keyword_ranking}
|
5
|
+
s.version = "1.0"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Luis Alberto Velasco"]
|
9
|
+
s.date = %q{2010-08-17}
|
10
|
+
s.description = %q{Create keyword rankings from the 3 major browsers}
|
11
|
+
s.email = %q{whizkas@hotmail.com}
|
12
|
+
s.extra_rdoc_files = ["CHANGELOG", "LICENSE", "README", "lib/keyword_ranking.rb"]
|
13
|
+
s.files = ["CHANGELOG", "Gemfile", "Gemfile.lock", "LICENSE", "README", "Rakefile", "lib/keyword_ranking.rb", "spec/keyword_ranking_spec.rb", "spec/spec.opts", "keyword_ranking.gemspec"]
|
14
|
+
s.homepage = %q{http://github.com/whizkas/keyword_ranking}
|
15
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Keyword_ranking", "--main", "README"]
|
16
|
+
s.require_paths = ["lib"]
|
17
|
+
s.rubyforge_project = %q{keyword_ranking}
|
18
|
+
s.rubygems_version = %q{1.3.7}
|
19
|
+
s.summary = %q{Get keyword rankings from Google, Yahoo and Bing}
|
20
|
+
|
21
|
+
if s.respond_to? :specification_version then
|
22
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
23
|
+
s.specification_version = 3
|
24
|
+
|
25
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
26
|
+
s.add_runtime_dependency(%q<nokogiri>, [">= 1.4.3.1"])
|
27
|
+
s.add_development_dependency(%q<bundler>, [">= 0.9.26"])
|
28
|
+
else
|
29
|
+
s.add_dependency(%q<nokogiri>, [">= 1.4.3.1"])
|
30
|
+
s.add_dependency(%q<bundler>, [">= 0.9.26"])
|
31
|
+
end
|
32
|
+
else
|
33
|
+
s.add_dependency(%q<nokogiri>, [">= 1.4.3.1"])
|
34
|
+
s.add_dependency(%q<bundler>, [">= 0.9.26"])
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
require 'nokogiri'
|
3
|
+
|
4
|
+
class Array
|
5
|
+
def extract_options!
|
6
|
+
last.is_a?(::Hash) ? pop : {}
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
module KeywordRanking
|
11
|
+
class Ranking
|
12
|
+
|
13
|
+
RES_LIMIT = 200
|
14
|
+
RES_PER_PAGE = 10 #careful, it doesn't work with more than 10 for all search engines!
|
15
|
+
|
16
|
+
include Singleton
|
17
|
+
|
18
|
+
def get(*args) # keyword, url, engine, limit
|
19
|
+
options = args.extract_options!
|
20
|
+
limit = options[:limit] ? options[:limit].to_i : RES_LIMIT
|
21
|
+
site_uri = options[:url].gsub(/(http:\/\/|https:\/\/)/, '').gsub(/^www/, '')
|
22
|
+
validate_arguments options
|
23
|
+
find_ranking(options[:keyword], site_uri, limit, options[:engine])
|
24
|
+
end
|
25
|
+
|
26
|
+
protected
|
27
|
+
|
28
|
+
def validate_arguments(options)
|
29
|
+
raise "Keyword and site parameters must be Strings" unless options[:keyword].is_a?(String) and options[:url].is_a?(String)
|
30
|
+
raise "Limit of #{RES_LIMIT} results at most" if options[:limit] > RES_LIMIT
|
31
|
+
raise "Engine should be 'bing', 'google' or 'yahoo'" unless [:bing, :google, :yahoo].include?(options[:engine].to_sym)
|
32
|
+
end
|
33
|
+
|
34
|
+
def find_ranking(keyword, site, limit, engine)
|
35
|
+
request_url, results_container, cite_container = case engine.to_sym
|
36
|
+
when :bing
|
37
|
+
["http://www.bing.com/search?q=#{keyword}&count=#{RES_PER_PAGE}&first=", '#wg0 > li', 'cite']
|
38
|
+
when :google
|
39
|
+
["http://www.google.com/search?q=#{keyword}&num=#{RES_PER_PAGE}&start=", '#ires > ol > li', 'cite']
|
40
|
+
when :yahoo
|
41
|
+
["http://search.yahoo.com/search?p=#{keyword}&n=#{RES_PER_PAGE}&b=", '#web > ol > li', 'span']
|
42
|
+
end
|
43
|
+
count, rank = 0, nil
|
44
|
+
loop {
|
45
|
+
results = Nokogiri.parse(%x{ curl -A Mozilla "#{request_url}#{count}" }).css(results_container)
|
46
|
+
rank = results.index(results.detect{ |result| result.css(cite_container).text.match Regexp.new(site) })
|
47
|
+
if count > RES_LIMIT
|
48
|
+
break
|
49
|
+
elsif rank.present?
|
50
|
+
rank = count + rank
|
51
|
+
break
|
52
|
+
end
|
53
|
+
count += RES_PER_PAGE
|
54
|
+
}
|
55
|
+
rank.try(:next)
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
@@ -0,0 +1,20 @@
|
|
1
|
+
$LOAD_PATH << File.expand_path('../../lib' , __FILE__)
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
Bundler.setup(:development)
|
6
|
+
require 'keyword_ranking'
|
7
|
+
|
8
|
+
module KeywordRanking
|
9
|
+
|
10
|
+
describe Ranking do
|
11
|
+
|
12
|
+
describe "#start" do
|
13
|
+
it "creates a ranking instance" do
|
14
|
+
Ranking.instance.should_not be(nil)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
data/spec/spec.opts
ADDED
metadata
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: keyword_ranking
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 15
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
version: "1.0"
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Luis Alberto Velasco
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-08-17 00:00:00 -05:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: nokogiri
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 113
|
29
|
+
segments:
|
30
|
+
- 1
|
31
|
+
- 4
|
32
|
+
- 3
|
33
|
+
- 1
|
34
|
+
version: 1.4.3.1
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: bundler
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 15
|
46
|
+
segments:
|
47
|
+
- 0
|
48
|
+
- 9
|
49
|
+
- 26
|
50
|
+
version: 0.9.26
|
51
|
+
type: :development
|
52
|
+
version_requirements: *id002
|
53
|
+
description: Create keyword rankings from the 3 major browsers
|
54
|
+
email: whizkas@hotmail.com
|
55
|
+
executables: []
|
56
|
+
|
57
|
+
extensions: []
|
58
|
+
|
59
|
+
extra_rdoc_files:
|
60
|
+
- CHANGELOG
|
61
|
+
- LICENSE
|
62
|
+
- README
|
63
|
+
- lib/keyword_ranking.rb
|
64
|
+
files:
|
65
|
+
- CHANGELOG
|
66
|
+
- Gemfile
|
67
|
+
- Gemfile.lock
|
68
|
+
- LICENSE
|
69
|
+
- README
|
70
|
+
- Rakefile
|
71
|
+
- lib/keyword_ranking.rb
|
72
|
+
- spec/keyword_ranking_spec.rb
|
73
|
+
- spec/spec.opts
|
74
|
+
- keyword_ranking.gemspec
|
75
|
+
has_rdoc: true
|
76
|
+
homepage: http://github.com/whizkas/keyword_ranking
|
77
|
+
licenses: []
|
78
|
+
|
79
|
+
post_install_message:
|
80
|
+
rdoc_options:
|
81
|
+
- --line-numbers
|
82
|
+
- --inline-source
|
83
|
+
- --title
|
84
|
+
- Keyword_ranking
|
85
|
+
- --main
|
86
|
+
- README
|
87
|
+
require_paths:
|
88
|
+
- lib
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
hash: 3
|
95
|
+
segments:
|
96
|
+
- 0
|
97
|
+
version: "0"
|
98
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
|
+
none: false
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
hash: 11
|
104
|
+
segments:
|
105
|
+
- 1
|
106
|
+
- 2
|
107
|
+
version: "1.2"
|
108
|
+
requirements: []
|
109
|
+
|
110
|
+
rubyforge_project: keyword_ranking
|
111
|
+
rubygems_version: 1.3.7
|
112
|
+
signing_key:
|
113
|
+
specification_version: 3
|
114
|
+
summary: Get keyword rankings from Google, Yahoo and Bing
|
115
|
+
test_files: []
|
116
|
+
|