Permalink
Browse files

Using HTTPClient and correct urls.

  • Loading branch information...
lunks committed Nov 19, 2013
1 parent 0d71c84 commit 40f4942a1695c3de08852b9580169b45090697d3
Showing with 8 additions and 9 deletions.
  1. +6 −7 app/fotolog.rb
  2. +2 −2 spec/fotolog_spec.rb
View
@@ -1,4 +1,3 @@
-require 'net/http'
require 'httpclient'
require 'threadz'
class Fotolog
@@ -13,19 +12,19 @@ def initialize user=nil
end
def valid?
- not Net::HTTP.get_response(URI.parse(archive_url)).is_a? Net::HTTPNotFound
+ @client.head(archive_url).status == 200
end
def year_archive_url year
- "http://www.fotolog.com.br/#{@user}/archive/1/#{year}"
+ "http://www.fotolog.com.br/#{@user}/archive/1/#{year}/"
end
def years
- Nokogiri::HTML(open(archive_url)).css('#list_years_calendar').text.scan(/\d{4}+/)
+ Nokogiri::HTML(@client.get_content(archive_url)).css('#list_years_calendar').text.scan(/\d{4}+/)
end
def archive_url
- "http://www.fotolog.com.br/#{@user}/archive"
+ "http://www.fotolog.com.br/#{@user}/archive/"
end
def photos
@@ -103,8 +102,8 @@ def update_cache
end
def last_photo
- doc = Nokogiri::HTML(open("http://www.fotolog.com/#{@user}/archive"))
- full_image_for doc.css('.last').css('.imageContainer img')[0].attributes['src'].value
+ doc = Nokogiri::HTML(@client.get_content("http://www.fotolog.com/#{@user}/archive/"))
+ full_image_for doc.css(".wall_img_container img")[0].attributes['src'].value
end
end
View
@@ -23,10 +23,10 @@
FakeWeb.register_uri(:get, "http://www.fotolog.com.br/marano/archive", :body => fixture_file('archive.html'))
end
it 'should retrieve user archive URL' do
- fotolog.archive_url.should == 'http://www.fotolog.com.br/marano/archive'
+ fotolog.archive_url.should == 'http://www.fotolog.com.br/marano/archive/'
end
it 'should retrieve year url' do
- fotolog.year_archive_url('2004').should == 'http://www.fotolog.com.br/marano/archive/1/2004'
+ fotolog.year_archive_url('2004').should == 'http://www.fotolog.com.br/marano/archive/1/2004/'
end
it 'should retrieve all years which have a photo on it' do
#TODO: Update to 2014 when time comes. Do not automate.

0 comments on commit 40f4942

Please sign in to comment.