Permalink
Browse files

Change implementation to use name rather than class name.

  • Loading branch information...
1 parent cd1468c commit eea3e84d980a90127d6c5bc0e86bf317b9a4c2b0 @blatyo committed May 12, 2012
View
@@ -9,6 +9,8 @@ class DomainInvalid < StandardError; end
class SupportedComponentsInvalid < StandardError; end
class << self
+ attr_accessor :proxy_service
+
def backlinks(site, *search_engines)
Backlinks.new.lookup(Site.new(site), *search_engines)
end
@@ -16,6 +16,10 @@ def params
def xpath
"//linksin/@num"
end
+
+ def name
+ :backlinks_alexa
+ end
end
end
end
@@ -20,6 +20,10 @@ def xpath
def clean(backlink_count)
super(backlink_count.gsub('1-10', ''))
end
+
+ def name
+ :backlinks_bing
+ end
end
end
end
@@ -16,6 +16,10 @@ def params
def xpath
"//div[@id='subform_ctrl']/div[2]/text()"
end
+
+ def name
+ :backlinks_google
+ end
end
end
end
@@ -16,6 +16,10 @@ def params
def xpath
"//span[@id='resultCount']/text()"
end
+
+ def name
+ :backlinks_yahoo
+ end
end
end
end
@@ -20,6 +20,10 @@ def xpath
def clean(backlink_count)
super(backlink_count.gsub('1-10', ''))
end
+
+ def name
+ :indexes_bing
+ end
end
end
end
@@ -16,6 +16,10 @@ def params
def xpath
"//div[@id='subform_ctrl']/div[2]/text()"
end
+
+ def name
+ :indexes_google
+ end
end
end
end
@@ -16,6 +16,10 @@ def params
def xpath
"//span[@id='resultCount']/text()"
end
+
+ def name
+ :indexes_yahoo
+ end
end
end
end
@@ -5,7 +5,7 @@ def initialize(proxies)
@proxies = proxies
end
- def proxy(class_name, site)
+ def proxy(name, site)
@proxies[rand(@proxies.length)]
end
end
@@ -6,7 +6,7 @@ def initialize(proxies)
@index = 0
end
- def proxy(class_name, site)
+ def proxy(name, site)
@proxies[@index].tap do
@index = (@index + 1) % @proxies.length
end
@@ -26,6 +26,10 @@ def xpath
def supported_components
[:domain]
end
+
+ def name
+ :ranks_alexa_global
+ end
end
end
end
@@ -26,6 +26,10 @@ def xpath
def supported_components
[:domain]
end
+
+ def name
+ :ranks_alexa_us
+ end
end
end
end
@@ -13,6 +13,10 @@ def url
def xpath
"//div[@class='section score']/h4[2]/text()"
end
+
+ def name
+ :ranks_compete
+ end
end
end
end
@@ -28,6 +28,10 @@ def params
def regex
/Rank_\d+:\d+:(\d+)/
end
+
+ def name
+ :ranks_google
+ end
end
end
end
@@ -15,6 +15,7 @@ def initialize(site, options = {})
@options = {:method => method, :headers => {'User-Agent' => 'Page Rankr'}}
@options[:params] = params if respond_to? :params
+ @options[:proxy] = proxy
@options.merge!(options)
request.on_complete do |response|
@@ -44,6 +45,10 @@ def method
:get
end
+ def proxy
+ PageRankr.proxy_service.proxy(self.class.name, @site) if PageRankr.proxy_service
+ end
+
def run
hydra = Typhoeus::Hydra.new
hydra.queue request
@@ -73,5 +78,9 @@ def clean(content)
cleaned_content.to_i
end
end
+
+ def name
+ raise PageRankr::MethodRequired, "name is undefined for #{self.class.name}"
+ end
end
end
@@ -8,14 +8,14 @@
]
end
let(:site){PageRankr::Site("http://www.google.com")}
- let(:class_name){"PageRankr::Ranks::Google"}
+ let(:name){:ranks_google}
subject{PageRankr::ProxyServices::Random.new(proxies)}
it{should respond_to(:proxy).with(2).arguments}
it "should return a proxy from the list of proxies" do
10.times do
- proxies.should include(subject.proxy(class_name, site))
+ proxies.should include(subject.proxy(name, site))
end
end
end
@@ -8,23 +8,23 @@
]
end
let(:site){PageRankr::Site("http://www.google.com")}
- let(:class_name){"PageRankr::Ranks::Google"}
+ let(:name){:ranks_google}
subject{PageRankr::ProxyServices::RoundRobin.new(proxies)}
it{should respond_to(:proxy).with(2).arguments}
it "should return the first proxy on the first call" do
- subject.proxy(class_name, site).should == proxies.first
+ subject.proxy(name, site).should == proxies.first
end
it "should return the second proxy on the second call" do
- subject.proxy(class_name, site)
- subject.proxy(class_name, site).should == proxies.last
+ subject.proxy(name, site)
+ subject.proxy(name, site).should == proxies.last
end
it "should return the first proxy on the third call" do
- subject.proxy(class_name, site)
- subject.proxy(class_name, site)
- subject.proxy(class_name, site).should == proxies.first
+ subject.proxy(name, site)
+ subject.proxy(name, site)
+ subject.proxy(name, site).should == proxies.first
end
end

0 comments on commit eea3e84

Please sign in to comment.