Domanda

I want to use Ruby's RSS class to parse both Atom and RSS feeds, so I can pull the links from them. How do I distinguish between the two types inside the code?

I've got a parser response readied like so.

response = RSS::Parser.parse(rss_url, false)
È stato utile?

Soluzione

I found the .feed_type method for the feed object, and used it like so:

if response.feed_type == "rss"
  puts "hey rss"
  response.channel.items.each{ |item| links += "'#{item.link}'," }
elsif response.feed_type == "atom"
  puts "hey atom"
  response.entries.each{ |entry| links += "'#{entry.link.href}'," }
else
  puts "something went wrong"
end
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top