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 CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{crags}
5
- s.version = "1.4.3"
5
+ s.version = "1.4.4"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Justin Marney"]
data/lib/crags.rb CHANGED
@@ -4,7 +4,7 @@ require 'hpricot'
4
4
  require 'erb'
5
5
 
6
6
  module Crags
7
- VERSION = '1.4.3'
7
+ VERSION = '1.4.4'
8
8
  LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
9
9
  PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
10
10
 
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).body_str
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
@@ -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("http://geo.craigslist.org/iso/#{country}")
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).collect{|link| strip_http(link["href"]) }
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
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gotascii-crags
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.3
4
+ version: 1.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Marney