gotascii-crags 1.4.3 → 1.4.4
Sign up to get free protection for your applications and to get access to all the features.
- data/crags.gemspec +1 -1
- data/lib/crags.rb +1 -1
- data/lib/crags/fetch.rb +9 -1
- data/lib/crags/searcher.rb +15 -2
- data/test/crags/fetch_test.rb +12 -0
- metadata +1 -1
data/crags.gemspec
CHANGED
data/lib/crags.rb
CHANGED
data/lib/crags/fetch.rb
CHANGED
@@ -5,7 +5,15 @@ module Crags
|
|
5
5
|
end
|
6
6
|
|
7
7
|
def fetch_html(url)
|
8
|
-
Curl::Easy.perform(url)
|
8
|
+
req = Curl::Easy.perform(url)
|
9
|
+
req.body_str
|
10
|
+
end
|
11
|
+
|
12
|
+
def fetch_request(url)
|
13
|
+
req = Curl::Easy.new(url)
|
14
|
+
req.follow_location = true
|
15
|
+
req.perform
|
16
|
+
req
|
9
17
|
end
|
10
18
|
end
|
11
19
|
end
|
data/lib/crags/searcher.rb
CHANGED
@@ -7,8 +7,16 @@ module Crags
|
|
7
7
|
url.gsub(/http\:\/\/(.*)(\/|(.html))/,'\1\3')
|
8
8
|
end
|
9
9
|
|
10
|
+
def location_link(country)
|
11
|
+
"http://geo.craigslist.org/iso/#{country}"
|
12
|
+
end
|
13
|
+
|
10
14
|
def location_doc(country)
|
11
|
-
fetch_doc(
|
15
|
+
fetch_doc(location_link(country))
|
16
|
+
end
|
17
|
+
|
18
|
+
def location_request(country)
|
19
|
+
fetch_request(location_link(country))
|
12
20
|
end
|
13
21
|
|
14
22
|
def location_links(country)
|
@@ -16,7 +24,12 @@ module Crags
|
|
16
24
|
end
|
17
25
|
|
18
26
|
def locations(country)
|
19
|
-
location_links(country)
|
27
|
+
linkz = location_links(country)
|
28
|
+
if linkz.empty?
|
29
|
+
[location_request(country).last_effective_url]
|
30
|
+
else
|
31
|
+
linkz.collect{|link| strip_http(link["href"]) }
|
32
|
+
end
|
20
33
|
end
|
21
34
|
|
22
35
|
def categories
|
data/test/crags/fetch_test.rb
CHANGED
@@ -17,5 +17,17 @@ class Crags::FetchTest < Test::Unit::TestCase
|
|
17
17
|
Curl::Easy.expects(:perform).with("url").returns(curb)
|
18
18
|
fetch_html("url").should == "uhh"
|
19
19
|
end
|
20
|
+
|
21
|
+
should "create a new request" do
|
22
|
+
req = stub(:follow_location= => nil, :perform => nil)
|
23
|
+
Curl::Easy.expects(:new).with("url").returns(req)
|
24
|
+
fetch_request("url").should == req
|
25
|
+
end
|
26
|
+
|
27
|
+
should "follow redirects for fetched requests" do
|
28
|
+
req = mock(:follow_location= => nil, :perform => nil)
|
29
|
+
Curl::Easy.stubs(:new).returns(req)
|
30
|
+
fetch_request("url")
|
31
|
+
end
|
20
32
|
end
|
21
33
|
end
|