lib/feedzirra/feed.rb in feedzirra-0.5.0 vs lib/feedzirra/feed.rb in feedzirra-0.6.0

- old
+ new

@@ -1,20 +1,37 @@ module Feedzirra class Feed USER_AGENT = "feedzirra http://github.com/pauldix/feedzirra/tree/master" + # Passes raw XML and callbacks to a parser. + # === Parameters + # [parser<Object>] The parser to pass arguments to - must respond to + # `parse` and should return a Feed object. + # [xml<String>] The XML that you would like parsed. + # === Returns + # An instance of the parser feed type. + def self.parse_with(parser, xml, &block) + parser.parse xml, &block + end + # Takes a raw XML feed and attempts to parse it. If no parser is available a Feedzirra::NoParserAvailable exception is raised. # You can pass a block to be called when there's an error during the parsing. # === Parameters # [xml<String>] The XML that you would like parsed. # === Returns - # An instance of the determined feed type. By default a Feedzirra::Atom, Feedzirra::AtomFeedBurner, Feedzirra::RDF, or Feedzirra::RSS object. + # An instance of the determined feed type. By default, one of these: + # * Feedzirra::Parser::RSSFeedBurner + # * Feedzirra::Parser::GoogleDocsAtom + # * Feedzirra::Parser::AtomFeedBurner + # * Feedzirra::Parser::Atom + # * Feedzirra::Parser::ITunesRSS + # * Feedzirra::Parser::RSS # === Raises # Feedzirra::NoParserAvailable : If no valid parser classes could be found for the feed. def self.parse(xml, &block) if parser = determine_feed_parser_for_xml(xml) - parser.parse(xml, block) + parse_with parser, xml, &block else raise NoParserAvailable.new("No valid parser for XML.") end end @@ -42,11 +59,18 @@ # 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::GoogleDocsAtom, Feedzirra::Parser::AtomFeedBurner, Feedzirra::Parser::Atom, Feedzirra::Parser::ITunesRSS, Feedzirra::Parser::RSS] + @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. # @@ -286,10 +310,10 @@ xml = decode_content(c) klass = determine_feed_parser_for_xml(xml) if klass begin - feed = klass.parse xml, on_parser_failure(url) + feed = parse_with klass, xml, &on_parser_failure(url) feed.feed_url = c.last_effective_url feed.etag = etag_from_header(c.header_str) feed.last_modified = last_modified_from_header(c.header_str) responses[url] = feed