From e6083e760dae76d777528c069170a9f2c3155f98 Mon Sep 17 00:00:00 2001 From: joshua stein Date: Sat, 30 Jun 2012 17:45:57 -0500 Subject: [PATCH] use new title fetcher --- app/controllers/stories_controller.rb | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/app/controllers/stories_controller.rb b/app/controllers/stories_controller.rb index 4dca58d..3f962b6 100644 --- a/app/controllers/stories_controller.rb +++ b/app/controllers/stories_controller.rb @@ -51,19 +51,12 @@ class StoriesController < ApplicationController end def fetch_url_title - begin - s = Sponge.new - s.timeout = 3 - text = s.fetch(params[:fetch_url], :get, nil, nil, - { "User-agent" => "lobste.rs! via #{request.remote_ip}" }, 3) + s = Story.new + s.url = params[:fetch_url] - if m = text.match(/<\s*title\s*>([^<]+)<\/\s*title\s*>/i) - return render :json => { :title => m[1] } - else - raise "no title found" - end - - rescue => e + if (title = s.fetched_title(request.remote_ip)).present? + return render :json => { :title => title } + else return render :json => "error" end end