Skip to content

Commit

Permalink
Using HTTPClient and correct urls.
Browse files Browse the repository at this point in the history
  • Loading branch information
lunks committed Nov 19, 2013
1 parent 0d71c84 commit 40f4942
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
13 changes: 6 additions & 7 deletions app/fotolog.rb
@@ -1,4 +1,3 @@
require 'net/http'
require 'httpclient'
require 'threadz'
class Fotolog
Expand All @@ -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
Expand Down Expand Up @@ -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

4 changes: 2 additions & 2 deletions spec/fotolog_spec.rb
Expand Up @@ -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.
Expand Down

0 comments on commit 40f4942

Please sign in to comment.