Module: Spix::Parser
- Defined in:
- lib/spix_parser/config.rb,
lib/spix_parser/parser.rb,
lib/spix_parser/version.rb,
lib/spix_parser/datetime.rb,
lib/spix_parser/wrappers/feed.rb,
lib/spix_parser/wrappers/entry.rb,
lib/spix_parser/custom_parsers/rss.rb,
lib/spix_parser/custom_parsers/atom.rb,
lib/spix_parser/wrappers/parsing_error.rb,
lib/spix_parser/custom_parsers/enclosure.rb,
lib/spix_parser/custom_parsers/rss_entry.rb,
lib/spix_parser/custom_parsers/atom_entry.rb,
lib/spix_parser/wrappers/enclosure_interface.rb
Defined Under Namespace
Modules: Config, DateTimeUtilities, EnclosureInterface, Version Classes: Atom, AtomEntry, Enclosure, Feed, FeedEntry, ParsingError, RSS, RSSEntry
Class Method Summary collapse
Class Method Details
.parse(url, options = {}) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/spix_parser/parser.rb', line 4 def self.parse(url, = {}) feed = case .delete(:mode) when :local Feedzirra::Feed.parse(url) when :file Feedzirra::Feed.parse(File.read(url)) else Feedzirra::Feed.fetch_and_parse(url, ) end # Feedzirra has some issues with failure cases: # If the failure occurs on the parsing phase, then the on_failure callback is triggered # If the failure occurs on the fetching phase (i. e. a network error), the a number is returned # That number may represent an http status code or be 0 in case of other errors. # Also, we can't raise an exception on the on_failure callback, 'cause it will be raised even on success - that's really odd # So we need this 'safety net' here until we patch it to use an uniform error architecture if feed.nil? || (feed.is_a?(Fixnum) && feed == 0) Log.error("The parser couldn't fetch the feed at #{url}") return nil elsif feed.is_a?(Fixnum) feed else Spix::Parser::Feed.new(feed) end end |