gtools 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/.rspec +1 -0
- data/.rvmrc +34 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/README.rdoc +0 -0
- data/Rakefile +13 -0
- data/gtools.gemspec +28 -0
- data/lib/gtools/version.rb +3 -0
- data/lib/gtools.rb +104 -0
- data/spec/lib/gtools_spec.rb +116 -0
- data/spec/spec_helper.rb +1 -0
- metadata +147 -0
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color --format documentation
|
data/.rvmrc
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
|
3
|
+
# This is an RVM Project .rvmrc file, used to automatically load the ruby
|
4
|
+
# development environment upon cd'ing into the directory
|
5
|
+
|
6
|
+
# First we specify our desired <ruby>[@<gemset>], the @gemset name is optional,
|
7
|
+
# Only full ruby name is supported here, for short names use:
|
8
|
+
# echo "rvm use 1.9.3" > .rvmrc
|
9
|
+
environment_id="ruby-1.9.3-p327@gtools"
|
10
|
+
|
11
|
+
# Uncomment the following lines if you want to verify rvm version per project
|
12
|
+
# rvmrc_rvm_version="1.16.20 (stable)" # 1.10.1 seams as a safe start
|
13
|
+
# eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
|
14
|
+
# echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
|
15
|
+
# return 1
|
16
|
+
# }
|
17
|
+
|
18
|
+
# First we attempt to load the desired environment directly from the environment
|
19
|
+
# file. This is very fast and efficient compared to running through the entire
|
20
|
+
# CLI and selector. If you want feedback on which environment was used then
|
21
|
+
# insert the word 'use' after --create as this triggers verbose mode.
|
22
|
+
if [[ -d "${rvm_path:-$HOME/.rvm}/environments"
|
23
|
+
&& -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
|
24
|
+
then
|
25
|
+
\. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
|
26
|
+
[[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]] &&
|
27
|
+
\. "${rvm_path:-$HOME/.rvm}/hooks/after_use" || true
|
28
|
+
else
|
29
|
+
# If the environment file has not yet been created, use the RVM CLI to select.
|
30
|
+
rvm --create "$environment_id" || {
|
31
|
+
echo "Failed to create RVM environment '${environment_id}'."
|
32
|
+
return 1
|
33
|
+
}
|
34
|
+
fi
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Kamil Kocemba
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Gtools
|
2
|
+
|
3
|
+
A collection of Google SEO tools in Ruby.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'gtools'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install gtools
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/README.rdoc
ADDED
File without changes
|
data/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require "rspec/core/rake_task"
|
3
|
+
require 'rdoc/task'
|
4
|
+
|
5
|
+
RSpec::Core::RakeTask.new
|
6
|
+
|
7
|
+
RDoc::Task.new do |rd|
|
8
|
+
rd.main = "README.rdoc"
|
9
|
+
rd.rdoc_files.include("README.rdoc", "lib/**/*.rb")
|
10
|
+
end
|
11
|
+
|
12
|
+
task :default => :spec
|
13
|
+
task :test => :spec
|
data/gtools.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'gtools/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "gtools"
|
8
|
+
spec.version = Gtools::VERSION
|
9
|
+
spec.authors = ["Kamil Kocemba"]
|
10
|
+
spec.email = ["kamil@futureworkshops.com"]
|
11
|
+
spec.description = %{A set of Gooogle SEO tools in Ruby}
|
12
|
+
spec.summary = %q{Gathers statistics like PageRank, site index, page speed analysis and more.}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency 'rspec'
|
24
|
+
spec.add_development_dependency 'rdoc'
|
25
|
+
|
26
|
+
spec.add_runtime_dependency "httparty", "~> 0.11.0"
|
27
|
+
|
28
|
+
end
|
data/lib/gtools.rb
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
require "gtools/version"
|
2
|
+
require 'httparty'
|
3
|
+
|
4
|
+
module GTools
|
5
|
+
|
6
|
+
def self.page_rank(domain)
|
7
|
+
url = GToolsConfiguration.tbr_host + GToolsConfiguration.tbr_query % [GMath.hash(domain), domain]
|
8
|
+
r = HTTParty.get(url).parsed_response
|
9
|
+
(r =~ /(\d+)$/) ? Integer($1) : nil
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.pagespeed_analysis(url)
|
13
|
+
nil unless url
|
14
|
+
url = GToolsConfiguration.google_pagespeed_url % [URI.encode(url)]
|
15
|
+
HTTParty.get(url).parsed_response["results"]
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.pagespeed_score(url)
|
19
|
+
nil unless url && URI.parse(url)
|
20
|
+
r = pagespeed_analysis(url)
|
21
|
+
r ? r["score"] : nil
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.site_index(url)
|
25
|
+
nil unless url && URI.parse(url)
|
26
|
+
search_results "site:#{url}"
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.site_links(url)
|
30
|
+
nil unless url && URI.parse(url)
|
31
|
+
search_results "link:#{url}"
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.search_results(query)
|
35
|
+
nil unless query
|
36
|
+
url = GToolsConfiguration.google_apisearch_url % [1, URI.encode(query)]
|
37
|
+
r = HTTParty.get(url).parsed_response
|
38
|
+
return nil unless r['responseData']
|
39
|
+
count = r['responseData']['cursor']['estimatedResultCount']
|
40
|
+
count ? Integer(count) : nil
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.suggested_tld
|
44
|
+
url = GToolsConfiguration.google_tld_url
|
45
|
+
domain = HTTParty.get(url).parsed_response
|
46
|
+
domain =~ /google\.(.*)$/ ? $1 : nil
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
module GToolsConfiguration
|
51
|
+
|
52
|
+
class << self;
|
53
|
+
attr_accessor :google_apisearch_url, :google_pagespeed_url, :google_plusone_url, :google_tld_url, :tbr_host, :tbr_query;
|
54
|
+
end
|
55
|
+
|
56
|
+
self.google_apisearch_url = "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&rsz=%s&q=%s"
|
57
|
+
self.google_pagespeed_url = "https://developers.google.com/_apps/pagespeed/run_pagespeed?url=%s&format=json"
|
58
|
+
self.google_plusone_url = "https://plusone.google.com/u/0/_/+1/fastbutton?count=true&url=%s"
|
59
|
+
self.google_tld_url = "https://www.google.com/searchdomaincheck?format=domain&sourceid=navclient-ff"
|
60
|
+
self.tbr_host = "http://toolbarqueries.google.com/tbr"
|
61
|
+
self.tbr_query = "?features=Rank&client=navclient-auto&ch=%s&q=info:%s"
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
private
|
66
|
+
module GMath
|
67
|
+
|
68
|
+
class << self; attr_accessor :hash_seed; end
|
69
|
+
|
70
|
+
self.hash_seed = "Mining PageRank is AGAINST GOOGLE'S TERMS OF SERVICE. Yes, I'm talking to you, scammer."
|
71
|
+
|
72
|
+
def self.urshift(v, amt)
|
73
|
+
mask = (1 << (32 - amt)) - 1
|
74
|
+
(v >> amt) & mask
|
75
|
+
end
|
76
|
+
|
77
|
+
def self.fmod(v, x)
|
78
|
+
i = (v / x).floor
|
79
|
+
r = Integer(v - Float(i * x))
|
80
|
+
r
|
81
|
+
end
|
82
|
+
|
83
|
+
def self.hexenc(v)
|
84
|
+
x = urshift(v, 24).to_s(16).rjust(2, "0")
|
85
|
+
x += (urshift(v, 16) & 255).to_s(16).rjust(2, "0")
|
86
|
+
x += (urshift(v, 8) & 255).to_s(16).rjust(2, "0")
|
87
|
+
x + (v & 255).to_s(16).rjust(2, "0")
|
88
|
+
end
|
89
|
+
|
90
|
+
def self.hash(str)
|
91
|
+
v = 16909125
|
92
|
+
for i in 0..(str.length - 1)
|
93
|
+
v ^= self.hash_seed[i % 87].ord ^ str[i].ord
|
94
|
+
v = fmod(v, 0xFFFFFFFF + 1) if 0xFFFFFFFF < v || -0xFFFFFFFF > v
|
95
|
+
v -= 0xFFFFFFFF + 1 if 0x7FFFFFFF < v
|
96
|
+
v += 0xFFFFFFFF + 1 if -0x80000000 > v
|
97
|
+
v = urshift(v, 23) | v << 9
|
98
|
+
end
|
99
|
+
"8" + hexenc(v)
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
@@ -0,0 +1,116 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe GTools do
|
4
|
+
|
5
|
+
sleep_amount = 1
|
6
|
+
|
7
|
+
describe :page_rank do
|
8
|
+
|
9
|
+
it "should return page rank for a valid domain" do
|
10
|
+
page_rank = GTools.page_rank 'google.com'
|
11
|
+
page_rank.should_not be_nil
|
12
|
+
page_rank.should == 9
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should return nil for invalid domain" do
|
16
|
+
page_rank = GTools.page_rank 'test'
|
17
|
+
page_rank.should be_nil
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should raise error for bad URI" do
|
21
|
+
lambda {
|
22
|
+
GTools.page_rank '!@#$%'
|
23
|
+
}.should raise_error(URI::InvalidURIError)
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
describe :pagespeed_analysis do
|
29
|
+
|
30
|
+
it "should return data for a valid domain" do
|
31
|
+
data = GTools.pagespeed_analysis 'google.com'
|
32
|
+
data["rule_results"].should_not be_nil
|
33
|
+
data["score"].should_not be_nil
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should return nil for invalid domain" do
|
37
|
+
data = GTools.pagespeed_analysis 'test'
|
38
|
+
data.should be_nil
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
describe :pagespeed_score do
|
44
|
+
|
45
|
+
it "should return an integer for a valid domain" do
|
46
|
+
score = GTools.pagespeed_score 'google.com'
|
47
|
+
score.should_not be_nil
|
48
|
+
score.should be_a_kind_of(Fixnum)
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should return nil for invalid domain" do
|
52
|
+
score = GTools.pagespeed_score 'test'
|
53
|
+
score.should be_nil
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
describe :site_index do
|
59
|
+
|
60
|
+
it "should return an integer for a valid domain" do
|
61
|
+
sleep sleep_amount
|
62
|
+
index = GTools.site_index 'google.com'
|
63
|
+
index.should_not be_nil
|
64
|
+
index.should_not == 0
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should return nil for invalid domain" do
|
68
|
+
sleep sleep_amount
|
69
|
+
index = GTools.site_index 'test'
|
70
|
+
index.should be_nil
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
describe :site_links do
|
76
|
+
|
77
|
+
it "should return an integer for a valid domain" do
|
78
|
+
sleep sleep_amount
|
79
|
+
count = GTools.site_links 'google.com'
|
80
|
+
count.should_not be_nil
|
81
|
+
count.should_not == 0
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should return nil for invalid domain" do
|
85
|
+
sleep sleep_amount
|
86
|
+
count = GTools.site_links 'test'
|
87
|
+
count.should be_nil
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
|
92
|
+
describe :search_results do
|
93
|
+
|
94
|
+
it "should return an integer for a valid domain" do
|
95
|
+
sleep sleep_amount
|
96
|
+
count = GTools.search_results 'google.com'
|
97
|
+
count.should_not be_nil
|
98
|
+
count.should_not == 0
|
99
|
+
end
|
100
|
+
|
101
|
+
it "should return nil for invalid domain" do
|
102
|
+
sleep sleep_amount
|
103
|
+
count = GTools.search_results 'test'
|
104
|
+
count.should be_nil
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
describe :suggested_tld do
|
109
|
+
|
110
|
+
it "should return a string" do
|
111
|
+
tld = GTools.suggested_tld
|
112
|
+
end
|
113
|
+
|
114
|
+
end
|
115
|
+
|
116
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'gtools'
|
metadata
ADDED
@@ -0,0 +1,147 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gtools
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Kamil Kocemba
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-04-17 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.3'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.3'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rspec
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rdoc
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: httparty
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ~>
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: 0.11.0
|
86
|
+
type: :runtime
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ~>
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: 0.11.0
|
94
|
+
description: A set of Gooogle SEO tools in Ruby
|
95
|
+
email:
|
96
|
+
- kamil@futureworkshops.com
|
97
|
+
executables: []
|
98
|
+
extensions: []
|
99
|
+
extra_rdoc_files: []
|
100
|
+
files:
|
101
|
+
- .gitignore
|
102
|
+
- .rspec
|
103
|
+
- .rvmrc
|
104
|
+
- Gemfile
|
105
|
+
- LICENSE.txt
|
106
|
+
- README.md
|
107
|
+
- README.rdoc
|
108
|
+
- Rakefile
|
109
|
+
- gtools.gemspec
|
110
|
+
- lib/gtools.rb
|
111
|
+
- lib/gtools/version.rb
|
112
|
+
- spec/lib/gtools_spec.rb
|
113
|
+
- spec/spec_helper.rb
|
114
|
+
homepage: ''
|
115
|
+
licenses:
|
116
|
+
- MIT
|
117
|
+
post_install_message:
|
118
|
+
rdoc_options: []
|
119
|
+
require_paths:
|
120
|
+
- lib
|
121
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
122
|
+
none: false
|
123
|
+
requirements:
|
124
|
+
- - ! '>='
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '0'
|
127
|
+
segments:
|
128
|
+
- 0
|
129
|
+
hash: 4345568620700901684
|
130
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
131
|
+
none: false
|
132
|
+
requirements:
|
133
|
+
- - ! '>='
|
134
|
+
- !ruby/object:Gem::Version
|
135
|
+
version: '0'
|
136
|
+
segments:
|
137
|
+
- 0
|
138
|
+
hash: 4345568620700901684
|
139
|
+
requirements: []
|
140
|
+
rubyforge_project:
|
141
|
+
rubygems_version: 1.8.24
|
142
|
+
signing_key:
|
143
|
+
specification_version: 3
|
144
|
+
summary: Gathers statistics like PageRank, site index, page speed analysis and more.
|
145
|
+
test_files:
|
146
|
+
- spec/lib/gtools_spec.rb
|
147
|
+
- spec/spec_helper.rb
|