Rss and Atom feed parser built on top of Nokogiri. Supports custom sanitizers.
FeedParser gem is tested on Ruby 1.8.7 and 1.9.3.
Add to Gemfile
gem "feed_parser"
# the most basic use case
fp = FeedParser.new(:url => "http://example.com/feed/")
# with sanitizer
fp = FeedParser.new(:url => "http://example.com/feed/", :sanitizer => MyBestestSanitizer.new)
# sanitizing custom field set
fp = FeedParser.new(:url => "http://example.com/feed/", :sanitizer => MyBestestSanitizer.new, :fields_to_sanitize => [:title, :content])
# parse the feed
feed = fp.parse
# using parsed feed in your code
feed.as_json
# => {:title => "Feed title", :url => "http://example.com/feed/", :items => [{:guid => , :title => , :author => ...}]}
feed.items.each do |feed_item|
pp feed_item
end
# you can also pass http options to be used for the connection
# for available options, check out the OpenURI documentation: http://apidock.com/ruby/OpenURI
fp = FeedParser.new(:url => "http://example.com/feed/", :http => {:ssl_verify_mode => OpenSSL::SSL::VERIFY_NONE})
If the fetched XML is not a valid RSS or an ATOM feed, a FeedParser::UnknownFeedType is raised in FeedParser#parse.
Install dependencies by running bundle install
.
Run rspec tests:
$ bundle exec rake spec
Fork, hack, push, create a pull request.