<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -7,8 +7,21 @@ class RssFeed &lt; ActiveRecord::Base
   validates_presence_of :title
   validates_presence_of :url
   
-  def process_rss_feed(xml)
-    rss = Hpricot.XML(xml)
+  def process_feed(xml)
+    doc = Hpricot.XML(xml)
+    
+    if doc.search(:rss).size &gt; 0
+      process_rss_feed(doc)
+      return 'rss'
+    elsif doc.search(:feed).size &gt; 0
+      process_atom_feed(doc)
+      return 'atom'
+    else
+      raise RuntimeError, 'Unknown Feed Type! Only RSS 2.0 &amp; Atom can be read.'
+    end
+  end
+  
+  def process_rss_feed(rss)
     time_offset = 1
     
     (rss/:channel/:item).each do |item|
@@ -18,7 +31,7 @@ class RssFeed &lt; ActiveRecord::Base
         rss_article = RssArticle.new
         rss_article.rss_feed = self
         rss_article.title = (item/:title).inner_html
-        rss_article.link = (item/:link).inner_html
+        rss_article.link = link
         rss_article.author = (item/:author).inner_html
         rss_article.content = (item/:description).inner_html
         rss_article.published = (item/:pubDate).inner_html
@@ -37,6 +50,35 @@ class RssFeed &lt; ActiveRecord::Base
     end
   end
   
+  def process_atom_feed(atom)
+    time_offset = 1
+    
+    (atom/:entry).each do |item|
+      link = (item/:link).attr('href')
+      
+      if not RssArticle.find_by_link(link)
+        atom_article = RssArticle.new
+        atom_article.rss_feed = self
+        atom_article.title = (item/:title).inner_html
+        atom_article.link = link
+        atom_article.author = (item/:author/:name).inner_html
+        atom_article.content = (item/:summary).inner_html
+        atom_article.published = (item/:published).inner_html
+        
+        if not atom_article.published
+          atom_article.published = Time.now - time_offset.hours
+          time_offset += 1
+        end
+        
+        # Fix the content to be HTML once again...
+        atom_article.title = bring_back_the_html(atom_article.title)
+        atom_article.content = bring_back_the_html(atom_article.content)
+        
+        atom_article.save()
+      end
+    end
+  end
+  
   def pull_feed
     the_rss = &quot;&quot;
     
@@ -59,12 +101,4 @@ class RssFeed &lt; ActiveRecord::Base
     stringy.gsub!('&amp;quot;', '&quot;')
     stringy
   end
-  
-  def test_feed
-    f = open('/Users/daniel/Desktop/SW.xml', 'r')
-    sw = f.read
-    f.close
-    
-    process_rss_feed(sw)
-  end
 end</diff>
      <filename>app/models/rss_feed.rb</filename>
    </modified>
    <modified>
      <diff>@@ -23,8 +23,8 @@ ActiveRecord::Schema.define(:version =&gt; 2) do
   end
 
   create_table &quot;rss_feeds&quot;, :force =&gt; true do |t|
-    t.string   &quot;title&quot;,      :default =&gt; &quot;&quot;, :null =&gt; false
-    t.string   &quot;url&quot;,        :default =&gt; &quot;&quot;, :null =&gt; false
+    t.string   &quot;title&quot;,      :null =&gt; false
+    t.string   &quot;url&quot;,        :null =&gt; false
     t.datetime &quot;created_at&quot;
     t.datetime &quot;updated_at&quot;
   end</diff>
      <filename>db/schema.rb</filename>
    </modified>
    <modified>
      <diff>@@ -6,8 +6,8 @@ namespace :feedme do
     feeds = RssFeed.find(:all)
     
     feeds.each do |feed|
-      the_rss = feed.pull_feed
-      feed.process_rss_feed(the_rss)
+      the_feed_xml = feed.pull_feed
+      feed.process_feed(the_feed_xml)
     end
   end
 end
\ No newline at end of file</diff>
      <filename>lib/tasks/feedme.rake</filename>
    </modified>
    <modified>
      <diff>@@ -1,8 +1,109 @@
 require File.dirname(__FILE__) + '/../test_helper'
 
 class RssFeedTest &lt; ActiveSupport::TestCase
+  def setup
+    @sample_rss = &lt;&lt;RSS
+&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
+&lt;rss version=&quot;2.0&quot;&gt;
+    &lt;channel&gt;
+        &lt;title&gt;Snow-Wolf.net Recent Entries&lt;/title&gt;
+        &lt;link&gt;http://snow-wolf.net/&lt;/link&gt;
+        &lt;description&gt;We Are Tumblin'!&lt;/description&gt;
+        &lt;language&gt;en-us&lt;/language&gt;
+        &lt;lastBuildDate&gt;Mon, 31 Mar 2008 02:30:36 -0000&lt;/lastBuildDate&gt;
+        &lt;item&gt;
+            &lt;title&gt;All Your (Code) Base Are Belong To GitHub&lt;/title&gt;
+            &lt;link&gt;http://snow-wolf.net/entry/2008/3/all-your-code-base-are-belong-github/&lt;/link&gt;
+            &lt;description&gt;Yay for a worn-out meme and a bigger hurrah for an awesome service! &amp;amp;lt;a href=&amp;amp;quot;http://github.com/&amp;amp;quot; title=&amp;amp;quot;GitHub&amp;amp;quot;&amp;amp;gt;GitHub&amp;amp;lt;/a&amp;amp;gt; is a hosting solution for the &amp;amp;lt;a href=&amp;amp;quot;http://git.or.cz/&amp;amp;quot; title=&amp;amp;quot;Git - Distributed Version Control&amp;amp;quot;&amp;amp;gt;Git&amp;amp;lt;/a&amp;amp;gt; version control system.
+
+Why Git? Git provides a different model for version control from traditional centralized version control systems.  Git uses a distributed model where every checkout is actually a complete repository.  This means you have complete history along with all branches.  Others can clone out of your checkout. And merging, something that traditionally very painful in systems like Subversion, is easy and pain-free.  Not mention Git being extremely fast, space efficient and able to be used even while offline.
+
+GitHub takes all the power and provides a great interface, easy code sharing and the ability to easily fork other projects hosted on GitHub.  Built by &amp;amp;lt;a href=&amp;amp;quot;http://ozmm.org/&amp;amp;quot; title=&amp;amp;quot;Chris Wanstrath&amp;amp;quot;&amp;amp;gt;Chris Wanstrath&amp;amp;lt;/a&amp;amp;gt;, &amp;amp;lt;a href=&amp;amp;quot;http://rubyisawesome.com/&amp;amp;quot; title=&amp;amp;quot;Tom Preston-Werner&amp;amp;quot;&amp;amp;gt;Tom Preston-Werner&amp;amp;lt;/a&amp;amp;gt; and (apparently) &amp;amp;lt;a href=&amp;amp;quot;http://www.pjhyett.com/&amp;amp;quot; title=&amp;amp;quot;PJ Hyett&amp;amp;quot;&amp;amp;gt;PJ Hyett&amp;amp;lt;/a&amp;amp;gt;, the app is already solid for a beta and there&amp;amp;#39;s going to be quite a few more goodies added before launch.  Others have already noted the interesting social aspects so I won&amp;amp;#39;t dog on that point too much.
+
+GitHub comes highly recommended and I still have two invites available if anyone&amp;amp;#39;s interested.&lt;/description&gt;
+            &lt;dc:creator xmlns:dc=&quot;http://purl.org/dc/elements/1.1/&quot;&gt;Daniel&lt;/dc:creator&gt;
+            &lt;guid&gt;http://snow-wolf.net/entry/2008/3/all-your-code-base-are-belong-github/&lt;/guid&gt;
+        &lt;/item&gt;
+        &lt;item&gt;
+            &lt;title&gt;HTML Elements Quiz&lt;/title&gt;
+            &lt;link&gt;http://snow-wolf.net/entry/2008/3/html-elements-quiz/&lt;/link&gt;
+            &lt;description&gt;&amp;amp;lt;a href=&amp;amp;quot;http://www.justsayhi.com/bb/html_quiz&amp;amp;quot; title=&amp;amp;quot;HTML Quiz&amp;amp;quot;&amp;amp;gt;How Many HTML Elements Can You Name In 5 Minutes?&amp;amp;lt;/a&amp;amp;gt; - Got a 53 out of 91 one handed (&amp;amp;lt;strong&amp;amp;gt;Number Two&amp;amp;lt;/strong&amp;amp;gt; was in the other arm).&lt;/description&gt;
+            &lt;dc:creator xmlns:dc=&quot;http://purl.org/dc/elements/1.1/&quot;&gt;Daniel&lt;/dc:creator&gt;
+            &lt;guid&gt;http://snow-wolf.net/entry/2008/3/html-elements-quiz/&lt;/guid&gt;
+        &lt;/item&gt;
+    &lt;/channel&gt;
+&lt;/rss&gt;    
+RSS
+    @sample_atom = &lt;&lt;ATOM
+&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
+&lt;feed xmlns=&quot;http://www.w3.org/2005/Atom&quot; xml:lang=&quot;en-us&quot;&gt;
+    &lt;title&gt;Snow-Wolf.net Recent Entries&lt;/title&gt;
+    &lt;link href=&quot;http://snow-wolf.net/&quot; rel=&quot;alternate&quot;/&gt;
+    &lt;link href=&quot;http://snow-wolf.net/feeds/atom/&quot; rel=&quot;self&quot;/&gt;
+    &lt;id&gt;http://snow-wolf.net/&lt;/id&gt;
+    &lt;updated&gt;2008-03-29T17:17:16Z&lt;/updated&gt;
+    &lt;entry&gt;
+        &lt;title&gt;All Your (Code) Base Are Belong To GitHub&lt;/title&gt;
+        &lt;link href=&quot;http://snow-wolf.net/entry/2008/3/all-your-code-base-are-belong-github/&quot; rel=&quot;alternate&quot;/&gt;
+        &lt;author&gt;
+            &lt;name&gt;Daniel&lt;/name&gt;
+        &lt;/author&gt;
+        &lt;id&gt;http://snow-wolf.net/entry/2008/3/all-your-code-base-are-belong-github/&lt;/id&gt;
+        &lt;summary type=&quot;html&quot;&gt;Yay for a worn-out meme and a bigger hurrah for an awesome service! &amp;amp;lt;a href=&amp;amp;quot;http://github.com/&amp;amp;quot; title=&amp;amp;quot;GitHub&amp;amp;quot;&amp;amp;gt;GitHub&amp;amp;lt;/a&amp;amp;gt; is a hosting solution for the &amp;amp;lt;a href=&amp;amp;quot;http://git.or.cz/&amp;amp;quot; title=&amp;amp;quot;Git - Distributed Version Control&amp;amp;quot;&amp;amp;gt;Git&amp;amp;lt;/a&amp;amp;gt; version control system.
+
+Why Git? Git provides a different model for version control from traditional centralized version control systems.  Git uses a distributed model where every checkout is actually a complete repository.  This means you have complete history along with all branches.  Others can clone out of your checkout. And merging, something that traditionally very painful in systems like Subversion, is easy and pain-free.  Not mention Git being extremely fast, space efficient and able to be used even while offline.
+
+GitHub takes all the power and provides a great interface, easy code sharing and the ability to easily fork other projects hosted on GitHub.  Built by &amp;amp;lt;a href=&amp;amp;quot;http://ozmm.org/&amp;amp;quot; title=&amp;amp;quot;Chris Wanstrath&amp;amp;quot;&amp;amp;gt;Chris Wanstrath&amp;amp;lt;/a&amp;amp;gt;, &amp;amp;lt;a href=&amp;amp;quot;http://rubyisawesome.com/&amp;amp;quot; title=&amp;amp;quot;Tom Preston-Werner&amp;amp;quot;&amp;amp;gt;Tom Preston-Werner&amp;amp;lt;/a&amp;amp;gt; and (apparently) &amp;amp;lt;a href=&amp;amp;quot;http://www.pjhyett.com/&amp;amp;quot; title=&amp;amp;quot;PJ Hyett&amp;amp;quot;&amp;amp;gt;PJ Hyett&amp;amp;lt;/a&amp;amp;gt;, the app is already solid for a beta and there&amp;amp;#39;s going to be quite a few more goodies added before launch.  Others have already noted the interesting social aspects so I won&amp;amp;#39;t dog on that point too much.
+
+GitHub comes highly recommended and I still have two invites available if anyone&amp;amp;#39;s interested.&lt;/summary&gt;
+    &lt;/entry&gt;
+    &lt;entry&gt;
+        &lt;title&gt;HTML Elements Quiz&lt;/title&gt;
+        &lt;link href=&quot;http://snow-wolf.net/entry/2008/3/html-elements-quiz/&quot; rel=&quot;alternate&quot;/&gt;
+        &lt;author&gt;
+            &lt;name&gt;Daniel&lt;/name&gt;
+        &lt;/author&gt;
+        &lt;id&gt;http://snow-wolf.net/entry/2008/3/html-elements-quiz/&lt;/id&gt;
+        &lt;summary type=&quot;html&quot;&gt;&amp;amp;lt;a href=&amp;amp;quot;http://www.justsayhi.com/bb/html_quiz&amp;amp;quot; title=&amp;amp;quot;HTML Quiz&amp;amp;quot;&amp;amp;gt;How Many HTML Elements Can You Name In 5 Minutes?&amp;amp;lt;/a&amp;amp;gt; - Got a 53 out of 91 one handed (&amp;amp;lt;strong&amp;amp;gt;Number Two&amp;amp;lt;/strong&amp;amp;gt; was in the other arm).&lt;/summary&gt;
+    &lt;/entry&gt;
+&lt;/feed&gt;
+ATOM
+    
+    @rf = RssFeed.create(:title =&gt; 'Test Feed', :url =&gt; 'http://www.snow-wolf.net/')
+    @rss_feed_doc = Hpricot.XML(@sample_rss)
+    @atom_feed_doc = Hpricot.XML(@sample_atom)
+  end
+  
   # Replace this with your real tests.
   def test_truth
     assert true
   end
+  
+  def test_process_rss_feed
+    assert_nothing_raised(RuntimeError) { @rf.process_rss_feed(@rss_feed_doc) }
+    
+    rf = RssFeed.find(:first)
+    assert_equal(2, rf.rss_articles.size)
+    assert_equal('All Your (Code) Base Are Belong To GitHub', rf.rss_articles[0].title)
+    assert_equal('HTML Elements Quiz', rf.rss_articles[1].title)
+  end
+  
+  def test_process_atom_feed
+    assert_nothing_raised(RuntimeError) { @rf.process_atom_feed(@atom_feed_doc) }
+    
+    rf = RssFeed.find(:first)
+    assert_equal(2, rf.rss_articles.size)
+    assert_equal('All Your (Code) Base Are Belong To GitHub', rf.rss_articles[0].title)
+    assert_equal('HTML Elements Quiz', rf.rss_articles[1].title)
+  end
+  
+  def test_process_feed
+    assert_nothing_raised(RuntimeError) { @rf.process_feed(@sample_rss) }
+    assert_equal('rss', @rf.process_feed(@sample_rss))
+    
+    assert_nothing_raised(RuntimeError) { @rf.process_feed(@sample_atom) }
+    assert_equal('atom', @rf.process_feed(@sample_atom))
+    
+    assert_raise(RuntimeError) { @rf.process_feed('&lt;?xml version=&quot;1.0&quot;?&gt;&lt;foo&gt;&lt;bar&gt;Hello world.&lt;/bar&gt;&lt;/moof&gt;&lt;/foo&gt;') }
+  end
 end</diff>
      <filename>test/unit/rss_feed_test.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>567df17a49f1c1da3d969aee1f86a2cd96670c49</id>
    </parent>
  </parents>
  <author>
    <name>Daniel Lindsley</name>
    <email>daniel@snow-wolf.net</email>
  </author>
  <url>http://github.com/toastdriven/feedme/commit/63bfeb3802878d525d7b8536041291a3096a5bf2</url>
  <id>63bfeb3802878d525d7b8536041291a3096a5bf2</id>
  <committed-date>2008-03-30T20:09:06-07:00</committed-date>
  <authored-date>2008-03-30T20:09:06-07:00</authored-date>
  <message>Added Atom support and unit tests.</message>
  <tree>bc5e11825cd2e36fd96a0916a2646f04e5c6805d</tree>
  <committer>
    <name>Daniel Lindsley</name>
    <email>daniel@snow-wolf.net</email>
  </committer>
</commit>
