1

I am using Feedjira's fetch_and_parse method to parse RSS feeds in my app, but some RSS feeds that I feed it are feed URLS that redirect to another feed URL, and Feedjira doesn't follow these redirects and my fetch_and_parse fails. Is there a way to get Feedjira to follow RSS redirects?

tommybond
  • 650
  • 6
  • 19

1 Answers1

1

I ran into this same problem, and solved it by manually fetching feeds (using Faraday) and calling FeedJira::Feed.parse with the resulting XML:

def fetch(host, url)
  conn = Faraday.new(:url => host) do |faraday|
    faraday.use FaradayMiddleware::FollowRedirects, limit: 3
  end

  response = conn.get url
  return response.body
end

xml = fetch("http://www.npr.org", "/templates/rss/podcast.php?id=510298")
podcast = Feedjira::Feed.parse(xml)

You could also monkey-patch Feedjira's connection method to do the same thing, though I wouldn't recommend it:

module Feedjira
  class Feed
    def self.connection(url)
      Faraday.new(url: url) do |conn|
        conn.use FaradayMiddleware::FollowRedirects, limit: 3
      end
    end
  end
end

podcast = Feedjira::Feed.fetch_and_parse("http://www.npr.org/templates/rss/podcast.php?id=510298")
Doches
  • 3,276
  • 2
  • 19
  • 26
  • This is how I ended up solving this problem a long time ago. Thanks for the answer! I forgot to update this question with it. – tommybond Dec 03 '15 at 18:42