seotracker 0.0.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/.document +5 -0
- data/.rvmrc +1 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +43 -0
- data/README.rdoc +7 -0
- data/Rakefile +45 -0
- data/VERSION +1 -0
- data/lib/seotracker/google.rb +11 -0
- data/lib/seotracker/yandex.rb +11 -0
- data/lib/seotracker.rb +28 -0
- data/spec/lib/seotracker_spec.rb +53 -0
- data/spec/spec_helper.rb +5 -0
- metadata +105 -0
data/.document
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm 1.9.3
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
domain_name (0.5.2)
|
5
|
+
unf (~> 0.0.3)
|
6
|
+
git (1.2.5)
|
7
|
+
hpricot (0.8.6)
|
8
|
+
jeweler (1.8.3)
|
9
|
+
bundler (~> 1.0)
|
10
|
+
git (>= 1.2.5)
|
11
|
+
rake
|
12
|
+
rdoc
|
13
|
+
json (1.6.6)
|
14
|
+
mechanize (2.3)
|
15
|
+
domain_name (~> 0.5, >= 0.5.1)
|
16
|
+
mime-types (~> 1.17, >= 1.17.2)
|
17
|
+
net-http-digest_auth (~> 1.1, >= 1.1.1)
|
18
|
+
net-http-persistent (~> 2.5, >= 2.5.2)
|
19
|
+
nokogiri (~> 1.4)
|
20
|
+
ntlm-http (~> 0.1, >= 0.1.1)
|
21
|
+
webrobots (~> 0.0, >= 0.0.9)
|
22
|
+
mime-types (1.18)
|
23
|
+
minitest (2.11.4)
|
24
|
+
net-http-digest_auth (1.2)
|
25
|
+
net-http-persistent (2.6)
|
26
|
+
nokogiri (1.5.2)
|
27
|
+
ntlm-http (0.1.1)
|
28
|
+
rake (0.9.2.2)
|
29
|
+
rdoc (3.12)
|
30
|
+
json (~> 1.4)
|
31
|
+
unf (0.0.5)
|
32
|
+
unf_ext
|
33
|
+
unf_ext (0.0.4)
|
34
|
+
webrobots (0.0.13)
|
35
|
+
|
36
|
+
PLATFORMS
|
37
|
+
ruby
|
38
|
+
|
39
|
+
DEPENDENCIES
|
40
|
+
hpricot
|
41
|
+
jeweler
|
42
|
+
mechanize
|
43
|
+
minitest
|
data/README.rdoc
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "seotracker"
|
18
|
+
gem.homepage = "http://github.com/kiote/seotracker"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{track site position}
|
21
|
+
gem.description = %Q{track sites position in google or yandex by keyword}
|
22
|
+
gem.email = "kiote_the_one@mail.ru"
|
23
|
+
gem.authors = ["krivich ekaterina"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rake/testtask'
|
29
|
+
Rake::TestTask.new(:test) do |test|
|
30
|
+
test.libs << 'lib' << 'test'
|
31
|
+
test.pattern = 'test/**/test_*.rb'
|
32
|
+
test.verbose = true
|
33
|
+
end
|
34
|
+
|
35
|
+
task :default => :test
|
36
|
+
|
37
|
+
require 'rdoc/task'
|
38
|
+
Rake::RDocTask.new do |rdoc|
|
39
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
40
|
+
|
41
|
+
rdoc.rdoc_dir = 'rdoc'
|
42
|
+
rdoc.title = "seotracker #{version}"
|
43
|
+
rdoc.rdoc_files.include('README*')
|
44
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
45
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.0
|
@@ -0,0 +1,11 @@
|
|
1
|
+
class Seotracker::Google < Seotracker
|
2
|
+
SEARCH_URL = 'http://www.google.ru/search?ix=seb&sourceid=chrome&ie=UTF-8'
|
3
|
+
|
4
|
+
# получаем позицию сайта для слова
|
5
|
+
def get_position(site, word)
|
6
|
+
super(site) do
|
7
|
+
page = @agent.get(SEARCH_URL, q: word)
|
8
|
+
page.root.xpath('/html/body/div[5]/div/div/div[4]/div[2]/div[2]/div/div[2]/div/ol/li/div/h3/a')
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
class Seotracker::Yandex < Seotracker
|
2
|
+
SEARCH_URL = 'http://yandex.ru/yandsearch'
|
3
|
+
|
4
|
+
# получаем позицию сайта для слова
|
5
|
+
def get_position(site, word)
|
6
|
+
super(site) do
|
7
|
+
page = @agent.get(SEARCH_URL, text: word)
|
8
|
+
page.root.xpath('/html/body/div[3]/div/div/div[2]/ol/li/div/h2/a')
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
data/lib/seotracker.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'mechanize'
|
3
|
+
|
4
|
+
class Seotracker
|
5
|
+
USER_AGENT = 'Mac Safari'
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@agent = Mechanize.new
|
9
|
+
@agent.user_agent_alias = Seotracker::USER_AGENT
|
10
|
+
end
|
11
|
+
|
12
|
+
def get_position(site, &block)
|
13
|
+
links = yield
|
14
|
+
pos, found = 0, false
|
15
|
+
links.each do |l|
|
16
|
+
pos += 1
|
17
|
+
href = l.attribute('href').value.downcase
|
18
|
+
unless href.rindex(site).nil?
|
19
|
+
found = true
|
20
|
+
break
|
21
|
+
end
|
22
|
+
end
|
23
|
+
found ? pos : 0
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
require 'seotracker/yandex'
|
28
|
+
require 'seotracker/google'
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
$LOAD_PATH << File.expand_path('../../', __FILE__)
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Seotracker do
|
6
|
+
# общие моки, тут от природной лени несколько объектов используют один мок
|
7
|
+
# что может несколько напрягать в дальнейшем
|
8
|
+
def common_mocker
|
9
|
+
mock = MiniTest::Mock.new
|
10
|
+
mock.expect(:root, mock)
|
11
|
+
mock.expect(:attribute, mock, %w/href/)
|
12
|
+
mock.expect(:value, "http://#{@site}")
|
13
|
+
end
|
14
|
+
|
15
|
+
before do
|
16
|
+
@site = 'serialmaniak.ru'
|
17
|
+
@word = 'маньяки'
|
18
|
+
end
|
19
|
+
|
20
|
+
describe 'yandex' do
|
21
|
+
before do
|
22
|
+
@object = Seotracker::Yandex.new
|
23
|
+
|
24
|
+
# мокаем все неважное
|
25
|
+
mock = common_mocker
|
26
|
+
mock.expect(:get, mock, [Seotracker::Yandex::SEARCH_URL, {text: @word}])
|
27
|
+
mock.expect(:xpath, [mock], %w\/html/body/div[3]/div/div/div[2]/ol/li/div/h2/a\)
|
28
|
+
|
29
|
+
@object.instance_variable_set(:@agent, mock)
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should return valid position' do
|
33
|
+
@object.get_position(@site, @word).must_be :>, 0
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe 'google' do
|
38
|
+
before do
|
39
|
+
@object = Seotracker::Google.new
|
40
|
+
|
41
|
+
# мокаем все неважное
|
42
|
+
mock = common_mocker
|
43
|
+
mock.expect(:get, mock, [Seotracker::Google::SEARCH_URL, {q: @word}])
|
44
|
+
mock.expect(:xpath, [mock], %w\/html/body/div[5]/div/div/div[4]/div[2]/div[2]/div/div[2]/div/ol/li/div/h3/a\)
|
45
|
+
|
46
|
+
@object.instance_variable_set(:@agent, mock)
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'should return valid position' do
|
50
|
+
@object.get_position(@site, @word).must_be :>, 0
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: seotracker
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- krivich ekaterina
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-04-02 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: minitest
|
16
|
+
requirement: &70115954000500 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70115954000500
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: mechanize
|
27
|
+
requirement: &70115953999260 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70115953999260
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: hpricot
|
38
|
+
requirement: &70115953997700 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :runtime
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70115953997700
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: jeweler
|
49
|
+
requirement: &70115953996140 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :runtime
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *70115953996140
|
58
|
+
description: track sites position in google or yandex by keyword
|
59
|
+
email: kiote_the_one@mail.ru
|
60
|
+
executables: []
|
61
|
+
extensions: []
|
62
|
+
extra_rdoc_files:
|
63
|
+
- README.rdoc
|
64
|
+
files:
|
65
|
+
- .document
|
66
|
+
- .rvmrc
|
67
|
+
- Gemfile
|
68
|
+
- Gemfile.lock
|
69
|
+
- README.rdoc
|
70
|
+
- Rakefile
|
71
|
+
- VERSION
|
72
|
+
- lib/seotracker.rb
|
73
|
+
- lib/seotracker/google.rb
|
74
|
+
- lib/seotracker/yandex.rb
|
75
|
+
- spec/lib/seotracker_spec.rb
|
76
|
+
- spec/spec_helper.rb
|
77
|
+
homepage: http://github.com/kiote/seotracker
|
78
|
+
licenses:
|
79
|
+
- MIT
|
80
|
+
post_install_message:
|
81
|
+
rdoc_options: []
|
82
|
+
require_paths:
|
83
|
+
- lib
|
84
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
85
|
+
none: false
|
86
|
+
requirements:
|
87
|
+
- - ! '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
segments:
|
91
|
+
- 0
|
92
|
+
hash: 2642418524114022489
|
93
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
94
|
+
none: false
|
95
|
+
requirements:
|
96
|
+
- - ! '>='
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
requirements: []
|
100
|
+
rubyforge_project:
|
101
|
+
rubygems_version: 1.8.17
|
102
|
+
signing_key:
|
103
|
+
specification_version: 3
|
104
|
+
summary: track site position
|
105
|
+
test_files: []
|