I use FeedTools (that Bleys linked to) to import and publish feeds. It makes things really easy (though publishing with .rxml Builder templates is also really easy, it's where importing feeds that makes FeedTools really valuable imo).
For importing feeds via URL:
Code:
require 'open-uri'
open @feed_url
feed = FeedTools::Feed.open(params[:feed_url])
your_model_params['url'] = item.link
your_model_params['title'] = item.title
your_model_params['description'] = item.description
# Build tags from the categories, if any.
tags = item.categories.collect {|c| c.term}.join(' ')
your_model = YourModel.new(your_model_params)
your_modeltag_with(tags)
if your_model.save
# do stuff
end
# do stuff
If you need to import from an uploaded file:
Code:
feed = FeedTools::Feed.new
feed.feed_data = params[:feed_file].read
# do the same stuff as before
Displaying your own feed is just a matter of setting up a FeedTools::Feed object in your controller and then doing this in your view (.rxml template):
Code:
@feed.build_xml(@flavor, @version, xml)
Check out the FeedTools RDocs for more on the API.
Bookmarks