Skip to content

Commit

Permalink
Alexa country rank added
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexisMontagne committed Jan 18, 2013
1 parent 9643e3e commit 8c9883b
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/page_rankr/ranks.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require File.expand_path("../trackers", __FILE__)
require File.expand_path("../ranks/alexa_us", __FILE__)
require File.expand_path("../ranks/alexa_global", __FILE__)
require File.expand_path("../ranks/alexa_country", __FILE__)
require File.expand_path("../ranks/google", __FILE__)

module PageRankr
Expand Down
35 changes: 35 additions & 0 deletions lib/page_rankr/ranks/alexa_country.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
require File.expand_path('../../rank', __FILE__)

module PageRankr
class Ranks
class AlexaCountry
include Rank

def url
"http://data.alexa.com/data"
end

def params
{:cli => 10, :dat => "snbamz", :url => tracked_url}
end

# Alexa may sometimes return a result for the incorrect site and thus it is necessary to check if
# the results returned are for the site we want.
#
# For example, slocourts.net returns results for ca.gov, presumably because www.slocourts.ca.gov redirects
# to slocourts.net. Clearly something is wrong with how Alexa handles this case and so in the event this
# happens we treat the results as if there were no results.
def xpath
"//country/@rank"
end

def supported_components
[:domain]
end

def name
:ranks_alexa_country
end
end
end
end
2 changes: 1 addition & 1 deletion lib/page_rankr/ranks/alexa_us.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def params
# to slocourts.net. Clearly something is wrong with how Alexa handles this case and so in the event this
# happens we treat the results as if there were no results.
def xpath
"//popularity[contains(@url, '#{tracked_url}')]/../reach/@rank"
"//reach/@rank"
end

def supported_components
Expand Down
4 changes: 4 additions & 0 deletions spec/page_rankr_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,12 @@

it{ should have_key(:alexa_us) }
it{ should have_key(:alexa_global) }
it{ should have_key(:alexa_country) }
it{ should have_key(:google) }

it{ subject[:alexa_us].should be_number >= 1 }
it{ subject[:alexa_global].should be_number >= 1 }
it{ subject[:alexa_country].should be_number >= 1 }
it{ subject[:google].should be_in(0..10) }
end

Expand All @@ -75,10 +77,12 @@

it{ should have_key(:alexa_us) }
it{ should have_key(:alexa_global) }
it{ should have_key(:alexa_country) }
it{ should have_key(:google) }

it{ subject[:alexa_us].should be_nil }
it{ subject[:alexa_global].should be_nil }
it{ subject[:alexa_country].should be_nil }
it{ subject[:google].should be_nil }
end
end
Expand Down

0 comments on commit 8c9883b

Please sign in to comment.