This is an example of how to use the FeedTools gem to parse a feed. FeedTools supports atom, rss, and so on...

The only negative thing about FeedTools is that the project is abandoned, the author said this in a comment from March 2008:
“I’ve effectively abandoned it, so I’m really not going to go taking on huge code reorganization efforts.”

Feed updater

There's also a feed updater tool that can fetch feeds in the background, but I haven't had time to look at it yet.

sudo gem install feedupdater

Character set/encoding bug

As always, there are bugs that you need to be aware of, Feedtools is no different. There's an encoding bug, FeedTools encodes everything to ISO-8859-1, instead UTF-8 which should be the default encoding.

Time estimation

By default FeedTools will try to estimate when a feed item was published, if it's not available from the feed. This annoys me and will create weird publish dates, so usually it's a good idea to disable it with the timestamp_estimation_enabled option:

This snippet explains how to do conditional gets with Feedzirra 0.0.17:

# First create a dummy parser, any type of parser will do
f = Feedzirra::Parser::RSS.new
# Set the required Feedzirra values with data from your database
f.feed_url = feed_from_db.url
f.etag = feed_from_db.etag
f.last_modified = feed_from_db.last_modified_at
# Set the last entry. This step is important.
# This allows Feedzirra to detect if a feed that doesn't support last modified and etag has been updated.
last_entry = Feedzirra::Parser::RSSEntry.new
# Do we have a last entry in the database? If so let Feedzirra know
if feed_from_db.items.last
last_entry.url = feed_from_db.items.last.link
end
# Without this Feedzirra will return an empty array or some other surprise
f.entries << last_entry
# Update the feed
Feedzirra::Feed.update f