Permalink
Browse files

Implemented Atom content as (x)HTML and Entry#author is filled in usi…

…ng Feed#author when Entry#author empty
  • Loading branch information...
1 parent 1c37b63 commit 64ee1532fea0cc1809a5d0a9dd2040c7b3880c0f @zedtux committed Aug 21, 2012
View
@@ -1,7 +1,7 @@
class Urss::Feed
# ~~~~ Attributes ~~~~
- attr_accessor :title, :url, :description, :updated_at, :entries
+ attr_accessor :title, :url, :description, :updated_at, :entries, :author
# ~~~~ Class methods ~~~~
@@ -12,6 +12,12 @@ def initialize
self.description = nil
self.updated_at = nil
self.entries = []
+ self.author = nil
+ end
+
+ def finalize!
+ # Fill in all entries author field with the Feed#author content when entry author field is empty
+ self.entries.each{|entry| entry.author = self.author if entry.author.nil? || entry.author == ""}
end
end
View
@@ -13,6 +13,7 @@ def self.build(nokogiri_instance, namespace, root_node)
feed_rss.url = nokogiri_instance.xpath("//#{namespace}#{root_node}/#{namespace}link[@rel='self']").attr("href").value
feed_rss.description = nokogiri_instance.xpath("//#{namespace}#{root_node}/#{namespace}subtitle").text.strip
feed_rss.updated_at = nokogiri_instance.xpath("//#{namespace}#{root_node}/#{namespace}updated").text
+ feed_rss.author = nokogiri_instance.xpath("//#{namespace}#{root_node}/#{namespace}author/#{namespace}name").text
nokogiri_instance.xpath("//#{namespace}entry").each {|item| feed_rss.entries << Urss::Feed::Atom::Entry.build(item, namespace)}
feed_rss
@@ -11,10 +11,17 @@ def self.build(nokogiri_instance, namespace=nil)
entry.url = nokogiri_instance.xpath("./#{namespace}link[@rel='alternate']").attr("href").value
entry.created_at = nokogiri_instance.xpath("./#{namespace}published").text
entry.author = nokogiri_instance.xpath("./#{namespace}author/#{namespace}name").text
- entry.content = nokogiri_instance.xpath("./description").text
+ entry.content = case nokogiri_instance.xpath("./#{namespace}content").attr("type").value
+ when "xhtml", "html"
+ nokogiri_instance.xpath("./#{namespace}content").inner_html
+ else
+ nokogiri_instance.xpath("./#{namespace}content").text
+ end
- if media_url = nokogiri_instance.xpath("./#{namespace}link[@rel='enclosure']").attr("href").value
- entry.medias << Urss::Media.new(:content_url => media_url)
+ unless (media = nokogiri_instance.xpath("./#{namespace}link[@rel='enclosure']")).empty?
+ if media_url = media.attr("href").value
+ entry.medias << Urss::Media.new(:content_url => media_url)
+ end
end
entry
View
@@ -16,5 +16,5 @@ def initialize
self.content = nil
self.medias = []
end
-
+
end
View
@@ -17,6 +17,9 @@ def self.build(nokogiri_instance)
when "feed"
Urss::Feed::Atom
end.build(root_instance, namespace, root)
+
+ rss_object.finalize!
+
return rss_object
break
end
View
@@ -12,6 +12,15 @@
require "urss"
+# Logging is enabled when logs/ folder exists
+logs_path = "logs"
+if File.exists?(logs_path)
+ require "logger"
+ log_file_path = File.join(logs_path, "test.log")
+ FileUtils.touch(log_file_path) unless File.exists?(log_file_path)
+ @@logger = Logger.new(log_file_path)
+end
+
RSpec.configure do |config|
end
@@ -0,0 +1,82 @@
+<?xml version="1.0" encoding="utf-8"?>
+<feed xmlns:im="http://itunes.apple.com/rss" xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
+ <id>http://itunes.apple.com/lu/rss/topalbums/limit=10/xml</id>
+ <title>iTunes Store: Top Albums</title>
+ <updated>2012-08-20T10:51:05-07:00</updated>
+ <link rel="alternate" type="text/html" href="http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewTop?id=29763&amp;popId=11&amp;s=143451"/>
+ <link rel="self" href="http://itunes.apple.com/lu/rss/topalbums/limit=10/xml"/>
+ <icon>http://itunes.apple.com/favicon.ico</icon>
+ <author>
+ <name>iTunes Store</name>
+ <uri>http://www.apple.com/uk/itunes/</uri>
+ </author>
+ <rights>Copyright 2008 Apple Inc.</rights>
+ <entry>
+ <updated>2012-08-20T10:51:05-07:00</updated>
+ <id im:id="538385017">http://itunes.apple.com/lu/album/nrj-party-summer-edition-2012/id538385017?uo=2</id>
+ <title>NRJ Party Summer Edition - 2012 - Various Artists</title>
+ <im:name>NRJ Party Summer Edition - 2012</im:name>
+ <link rel="alternate" type="text/html" href="http://itunes.apple.com/lu/album/nrj-party-summer-edition-2012/id538385017?uo=2"/>
+ <im:contentType term="Music" label="Music">
+ <im:contentType term="Album" label="Album"/>
+ </im:contentType>
+ <category im:id="17" term="Dance" scheme="http://itunes.apple.com/lu/genre/music-dance/id17?uo=2" label="Dance"/>
+ <im:artist>Various Artists</im:artist>
+ <im:price amount="9.99000" currency="EUR">9,99 €</im:price>
+ <im:image height="55">http://a5.mzstatic.com/us/r1000/085/Music/v4/81/12/01/811201e7-96da-4c95-4fc1-c85ac3e716b1/5414165055532.55x55-70.jpg</im:image>
+ <im:image height="60">http://a2.mzstatic.com/us/r1000/085/Music/v4/81/12/01/811201e7-96da-4c95-4fc1-c85ac3e716b1/5414165055532.60x60-50.jpg</im:image>
+ <im:image height="170">http://a1.mzstatic.com/us/r1000/085/Music/v4/81/12/01/811201e7-96da-4c95-4fc1-c85ac3e716b1/5414165055532.170x170-75.jpg</im:image>
+ <rights>℗ 2012 541 / N.E.W.S.</rights>
+ <im:releaseDate label="29 June 2012">2012-06-29T00:00:00-07:00</im:releaseDate>
+ <im:itemCount>25</im:itemCount>
+ <content type="html">&lt;table border="0" width="100%"&gt;
+ &lt;tr&gt;
+ &lt;td&gt;
+ &lt;table border="0" width="100%" cellspacing="0" cellpadding="0"&gt;
+ &lt;tr valign="top" align="left"&gt;
+
+ &lt;td align="center" width="166" valign="top"&gt;
+ &lt;a href="http://itunes.apple.com/lu/album/nrj-party-summer-edition-2012/id538385017?uo=2"&gt;&lt;img border="0" alt="NRJ Party Summer Edition - 2012artwork" src="http://a1.mzstatic.com/us/r1000/085/Music/v4/81/12/01/811201e7-96da-4c95-4fc1-c85ac3e716b1/5414165055532.170x170-75.jpg" /&gt;&lt;/a&gt;
+ &lt;/td&gt;
+ &lt;td width="10"&gt;&lt;img alt="" width="10" height="1" src="http://r.mzstatic.com/images/spacer.gif" /&gt;&lt;/td&gt;
+ &lt;td width="95%"&gt;
+
+
+ &lt;b&gt;&lt;a href="http://itunes.apple.com/lu/album/nrj-party-summer-edition-2012/id538385017?uo=2"&gt;NRJ Party Summer Edition - 2012&lt;/a&gt;&lt;/b&gt;&lt;br/&gt;
+
+
+
+
+
+ Various Artists
+
+ &lt;font size="2" face="Helvetica,Arial,Geneva,Swiss,SunSans-Regular"&gt;
+
+ &lt;br/&gt;
+ &lt;b&gt;Genre:&lt;/b&gt; &lt;a href="http://itunes.apple.com/lu/genre/music-dance/id17?uo=2"&gt;Dance&lt;/a&gt;
+
+ &lt;br/&gt;
+ &lt;b&gt;Price:&lt;/b&gt; 9,99 €
+
+ &lt;br/&gt;
+ &lt;b&gt;Release Date:&lt;/b&gt; 29 June 2012
+
+ &lt;/font&gt;
+ &lt;/td&gt;
+ &lt;/tr&gt;
+ &lt;/table&gt;
+ &lt;/td&gt;
+ &lt;/tr&gt;
+ &lt;tr&gt;
+ &lt;td&gt;
+
+
+
+ &lt;font size="2" face="Helvetica,Arial,Geneva,Swiss,SunSans-Regular"&gt; &amp;#169; ℗ 2012 541 / N.E.W.S.&lt;/font&gt;
+
+ &lt;/td&gt;
+ &lt;/tr&gt;
+&lt;/table&gt;
+ </content>
+ </entry>
+</feed>
View
@@ -6,4 +6,5 @@
stub_request(:get, "http://example.org/feed.atom").to_return(:status => 200, :body => File.open(File.join(File.dirname(__FILE__), "fixtures", "atom.xml")).read, :headers => {})
stub_request(:get, "http://api.flickr.com/services/feeds/photos_public.gne?format=rss_200&id=90313708@N00&lang=en-us").to_return(:status => 200, :body => File.open(File.join(File.dirname(__FILE__), "fixtures", "flickr_rss_200.xml")).read, :headers => {})
stub_request(:get, "http://api.flickr.com/services/feeds/photos_public.gne?id=90313708@N00&lang=en-us&format=atom").to_return(:status => 200, :body => File.open(File.join(File.dirname(__FILE__), "fixtures", "flickr_atom.xml")).read, :headers => {})
-stub_request(:get, "http://api.flickr.com/services/feeds/geo/?id=90313708@N00&lang=en-us").to_return(:status => 200, :body => File.open(File.join(File.dirname(__FILE__), "fixtures", "flickr_geo.xml")).read, :headers => {})
+stub_request(:get, "http://api.flickr.com/services/feeds/geo/?id=90313708@N00&lang=en-us").to_return(:status => 200, :body => File.open(File.join(File.dirname(__FILE__), "fixtures", "flickr_geo.xml")).read, :headers => {})
+stub_request(:get, "http://example.org/feed.atom-html").to_return(:status => 200, :body => File.open(File.join(File.dirname(__FILE__), "fixtures", "atom_with_html.xml")).read, :headers => {})
View
@@ -27,6 +27,11 @@
subject.should respond_to(:entries)
subject.should respond_to(:entries=)
end
+
+ it "should have an attribute :author" do
+ subject.should respond_to(:author)
+ subject.should respond_to(:author=)
+ end
end
end
Oops, something went wrong.

0 comments on commit 64ee153

Please sign in to comment.