lib/feedzirra/feed.rb in feedzirra-0.2.0.rc2 vs lib/feedzirra/feed.rb in feedzirra-0.2.1

- old
+ new

@@ -42,11 +42,11 @@ # Provides a list of registered feed parsing classes. # # === Returns # A array of class names. def self.feed_classes - @feed_classes ||= [Feedzirra::Parser::RSSFeedBurner, Feedzirra::Parser::RSS, Feedzirra::Parser::GoogleDocsAtom, Feedzirra::Parser::AtomFeedBurner, Feedzirra::Parser::Atom, Feedzirra::Parser::ITunesRSS] + @feed_classes ||= [Feedzirra::Parser::RSSFeedBurner, Feedzirra::Parser::GoogleDocsAtom, Feedzirra::Parser::AtomFeedBurner, Feedzirra::Parser::Atom, Feedzirra::Parser::ITunesRSS, Feedzirra::Parser::RSS] end # Makes all registered feeds types look for the passed in element to parse. # This is actually just a call to element (a SAXMachine call) in the class. # @@ -245,11 +245,11 @@ feed_queue.slice!(0, 30).each do |feed| add_feed_to_multi(multi, feed, feed_queue, responses, options) end multi.perform - responses.is_a?(Array)? responses.values : responses.values.first + feeds.is_a?(Array) ? responses : responses.values.first end # An abstraction for adding a feed by URL to the passed Curb::multi stack. # # === Parameters @@ -290,11 +290,23 @@ # puts "Error determining parser for #{url} - #{c.last_effective_url}" # raise NoParserAvailable.new("no valid parser for content.") (this would unfortunately fail the whole 'multi', so it's not really usable) options[:on_failure].call(url, c.response_code, c.header_str, c.body_str) if options.has_key?(:on_failure) end end - + + # + # trigger on_failure for 404s + # + curl.on_complete do |c| + add_url_to_multi(multi, url_queue.shift, url_queue, responses, options) unless url_queue.empty? + responses[url] = c.response_code + + if c.response_code == 404 && options.has_key?(:on_failure) + options[:on_failure].call(url, c.response_code, c.header_str, c.body_str) + end + end + curl.on_failure do |c, err| add_url_to_multi(multi, url_queue.shift, url_queue, responses, options) unless url_queue.empty? responses[url] = c.response_code if c.response_code == 304 # it's not modified. this isn't an error condition options[:on_success].call(url, nil) if options.has_key?(:on_success) @@ -374,9 +386,9 @@ # [header<String>] Raw request header returned from the request # === Returns # A Time object of the last modified date or nil if it cannot be found in the headers. def self.last_modified_from_header(header) header =~ /.*Last-Modified:\s(.*)\r/ - Time.parse($1) if $1 + Time.parse_safely($1) if $1 end end end