Feedzirra - How to get updated RSS feed?

376 Views Asked by At

The following code is from the gist on Feedzirra to get the updated content from a RSS feed:

feed = Feedzirra::Feed.fetch_and_parse(feed_url)
feed = Feedzirra::Feed.update(feed)
do_something_with_new_feed(feed.new_entries) if feed.updated?

I don't understand how Feedzirra would know the feed has been updated. I can't get it working. In order to know, I would have to pass the Feed object that was returned previously (minutes or hours ago) Feedzirra::Feed.fetch_and_parse(feed_url) into Feedzirra::Feed.update, no? How does it know if it has been updated if I use the feed that I had just fetch_and_parse?

1

There are 1 best solutions below

0
On

Feeds (the sites you are accessing) can, but don't necessarily, maintain one or two fields that determine whether they have changed since your last access. These are etag and last modified. If the site supports either or both of these, they will be returned to you when you access the feed. Your model should maintain these fields for each feed of interest. Feedzirra::Feed.update uses them to determine whether or not the feed has been updated since your last access. These will allow Feedzirra::Feed.update to pull entries that are new or changed since your last access.

If you have neither etag nor last modified fields, either because it is your first access or because the site doesn't provide them, then Feedzirra::Feed.fetch_and_parse pulls all entries available from the site. This makes sense for the first access. It makes less sense for subsequent accesses, but if the site doesn't support it what can you do?

To be clear, Feedzirra::Feed.fetch_and_parse always pulls all available entries. Feedzirra::Feed.update only pulls entries that are new or changed since the etag and/or last modified date provided to it.

Entries maintain an update/published date as well.