Skip to content

Commit

Permalink
changed the feed parsing to make the RSS parser work for .9, 1.0, and…
Browse files Browse the repository at this point in the history
… 2.0 types. Should remove the RDF classes later since they're no longer in use
  • Loading branch information
pauldix committed Feb 5, 2009
1 parent 52819f0 commit 9f0c4b4
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 deletions.
4 changes: 2 additions & 2 deletions lib/feedzirra/feed.rb
Expand Up @@ -13,7 +13,7 @@ def self.parse(xml)
end

def self.determine_feed_parser_for_xml(xml)
start_of_doc = xml.slice(0, 500)
start_of_doc = xml.slice(0, 1000)
feed_classes.detect {|klass| klass.able_to_parse?(start_of_doc)}
end

Expand All @@ -22,7 +22,7 @@ def self.add_feed_class(klass)
end

def self.feed_classes
@feed_classes ||= [RSS, RDF, AtomFeedBurner, Atom]
@feed_classes ||= [RSS, AtomFeedBurner, Atom]
end

# can take a single url or an array of urls
Expand Down
2 changes: 1 addition & 1 deletion lib/feedzirra/rss.rb
Expand Up @@ -9,7 +9,7 @@ class RSS
attr_accessor :feed_url

def self.able_to_parse?(xml)
xml =~ /rss.*version\=\"2\.0\"/
xml =~ /\<rss|rdf/
end
end
end
3 changes: 3 additions & 0 deletions lib/feedzirra/rss_entry.rb
Expand Up @@ -4,9 +4,12 @@ class RSSEntry
include FeedEntryUtilities
element :title
element :link, :as => :url

element :"dc:creator", :as => :author
element :"content:encoded", :as => :content
element :description, :as => :summary

element :pubDate, :as => :published
element :"dc:date", :as => :published
end
end
18 changes: 9 additions & 9 deletions spec/feedzirra/feed_spec.rb
Expand Up @@ -5,29 +5,29 @@
context "when there's an available parser" do
it "should parse an rdf feed" do
feed = Feedzirra::Feed.parse(sample_rdf_feed)
feed.class.should == Feedzirra::RDF
feed.title.should == "HREF Considered Harmful"
feed.entries.first.published.to_s.should == "Tue Sep 02 19:50:07 UTC 2008"
feed.entries.size.should == 10
end

it "should parse an rss feed" do
feed = Feedzirra::Feed.parse(sample_rss_feed)
feed.class.should == Feedzirra::RSS
feed.title.should == "Tender Lovemaking"
feed.entries.first.published.to_s.should == "Thu Dec 04 17:17:49 UTC 2008"
feed.entries.size.should == 10
end

it "should parse an atom feed" do
feed = Feedzirra::Feed.parse(sample_atom_feed)
feed.class.should == Feedzirra::Atom
feed.title.should == "Amazon Web Services Blog"
feed.entries.first.published.to_s.should == "Fri Jan 16 18:21:00 UTC 2009"
feed.entries.size.should == 10
end

it "should parse an feedburner atom feed" do
feed = Feedzirra::Feed.parse(sample_feedburner_atom_feed)
feed.class.should == Feedzirra::AtomFeedBurner
feed.title.should == "Paul Dix Explains Nothing"
feed.entries.first.published.to_s.should == "Thu Jan 22 15:50:22 UTC 2009"
feed.entries.size.should == 5
end
end
Expand All @@ -42,8 +42,8 @@

it "should parse an feedburner rss feed" do
feed = Feedzirra::Feed.parse(sample_rss_feed_burner_feed)
feed.class.should == Feedzirra::RDF
feed.title.should == "Sam Harris: Author, Philosopher, Essayist, Atheist"
feed.entries.first.published.to_s.should == "Tue Jan 13 17:20:28 UTC 2009"
feed.entries.size.should == 10
end
end
Expand All @@ -57,12 +57,12 @@
Feedzirra::Feed.determine_feed_parser_for_xml(sample_feedburner_atom_feed).should == Feedzirra::AtomFeedBurner
end

it "should return the Feedzirra::RDF class for an rdf/rss 1.0 feed" do
Feedzirra::Feed.determine_feed_parser_for_xml(sample_rdf_feed).should == Feedzirra::RDF
it "should return the Feedzirra::RSS class for an rdf/rss 1.0 feed" do
Feedzirra::Feed.determine_feed_parser_for_xml(sample_rdf_feed).should == Feedzirra::RSS
end

it "should return the Feedzirra::RDF class for an rss feedburner feed" do
Feedzirra::Feed.determine_feed_parser_for_xml(sample_rss_feed_burner_feed).should == Feedzirra::RDF
it "should return the Feedzirra::RSS class for an rss feedburner feed" do
Feedzirra::Feed.determine_feed_parser_for_xml(sample_rss_feed_burner_feed).should == Feedzirra::RSS
end

it "should return the Feedzirra::RSS object for an rss 2.0 feed" do
Expand Down

0 comments on commit 9f0c4b4

Please sign in to comment.