<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>config/extend.yml</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -10,12 +10,28 @@ raise ArgumentError, &quot;Sin comando&quot; unless ARGV[0]
 
 cmd = ARGV.shift
 case cmd
+	when &quot;update&quot;
+		fs = Feed.find :all
+		fs.each do |f|
+			f.update
+		end
+
 	when &quot;post&quot;
 	when &quot;add&quot;
 	when &quot;new&quot;
 		raise ArgumentError, &quot;No feed specified&quot; unless ARGV[0]
 		f =	Feed.new :feed =&gt; ARGV[0]
-		pp f
+		if f.save
+			puts &quot;Successfully subscribed: #{f.id}:#{f.feed_url}&quot;
+		else
+			unless f.errors.full_messages.empty?
+				$stderr.puts &quot;ERROR:&quot;
+				f.errors.full_messages.each do |e|
+					$stderr.puts &quot; #{e}&quot;
+				end
+			end
+		end
+
 	else
 		raise ArgumentError, &quot;No comand found for `#{cmd}'&quot;
 end</diff>
      <filename>bin/rfeed</filename>
    </modified>
    <modified>
      <diff>@@ -20,35 +20,4 @@ Dir[&quot;#{File.expand_path(File.dirname(__FILE__))}/rfeed/*.rb&quot;].each do |r|
 	require &quot;#{r}&quot;
 end
 
-module Rfeed
-	def self.version
-		&quot;0.1&quot;
-	end
-
-	def self.add
-		puts &quot;I will add a new feed&quot;
-	end
-
-	def self.feed_new(url)
-
-		# validamos primero el link
-		# - si no es una URL, error
-		# - verificar que rfeedparser pueda leerlo
-
-		unless url =~ /((http|https):\/\/)?[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/.*)?/
-			puts &quot;'#{url}' doesn't look like a URL&quot;
-			exit 1
-		end
-
-		feed = Feed.new
-		feed.feed_url = url
-
-		unless feed.save
-			puts feed.errors.full_messages
-			exit 1
-		end
-
-	end
-
-end
-
+# TODO: Make sure extend.yml is being used</diff>
      <filename>lib/rfeed.rb</filename>
    </modified>
    <modified>
      <diff>@@ -5,50 +5,76 @@ require &quot;goodies/goodies/lwr-simple&quot;
 class Feed &lt; ActiveRecord::Base
 	has_many :posts
 
-	validates_presence_of :link, :feed_url
+	validates_presence_of :feed_url, :message =&gt; &quot;wasn't found&quot;
+	validates_presence_of :link, :message =&gt; &quot;wasn't found on `feed_url'&quot;
+	validates_uniqueness_of :feed_url, :message =&gt; &quot;already exists on database&quot;
 
-	def feed=(url)
-		url = LWR::Simple.normalize(url).to_s
-
-		# checking that the url is a feed:
-		feedbag = Feedbag.find(url)
-		if feedbag.size == 1 and feedbag.first == url
-			# si es
-		elsif feedbag.first.nil?
-			$stderr.puts &quot;URL not a feed and not feeds found&quot;
-			return nil
-		else
-			url = feedbag.first
-			$stderr.puts &quot;URL provided not a feed but using `#{url}'&quot;
-		end
+	attr_accessor :fp
+
+	def parse(url)
+    url = LWR::Simple.normalize(url).to_s
+
+    # checking that the url is a feed:
+    feedbag = Feedbag.find(url)
+    if feedbag.size == 1 and feedbag.first == url
+      # si es
+    elsif feedbag.first.nil?
+      $stderr.puts &quot;URL not a feed and not feeds found&quot;
+      return nil
+    else
+      url = feedbag.first
+      $stderr.puts &quot;URL provided not a feed but using `#{url}'&quot;
+    end
 
 		fp = FeedParser.parse url
 
 		if fp.status.nil? or fp.status &gt;= 400.to_s
-			$stderr.puts &quot;Errors with #{url}!&quot;
-			return nil
+      $stderr.puts &quot;Errors with #{url}!&quot;
+      return nil
+    end
+
+    # there's no real easy way to do this
+    # so we'll only do if the feed_validator gem is available
+    validate = false # assuming it's not there
+    if fp.entries.empty?
+      begin
+        require &quot;feed_validator&quot;
+        validate = true
+      rescue LoadError
+        $stderr.puts &quot;Not using feed_validator&quot;
+      end
+
+      if validate
+        v = W3C::FeedValidator.new
+        v.validate_url url
+        unless v.valid?
+          $stderr.puts &quot;Invalid feed&quot;
+          return nil
+        end
+      end
+    end
+		
+		self.link = fp.feed.link
+		self.title = fp.feed.title
+		self.etag = fp.etag
+		self.last_modified = fp.modified_time
+		self.feed_url = url
+		self.fp = fp
+	end
+
+	def update
+		p = self.parse(self.feed_url)
+
+		p.entries.each do |e|
+#			Post.new  !!!!
 		end
+	end
 
-		# there's no real easy way to do this
-		# so we'll only do if the feed_validator gem is available
-		validate = false # assuming it's not there
-		if fp.entries.empty?
-			begin
-				require &quot;feed_validator&quot;
-				validate = true
-			rescue LoadError
-				$stderr.puts &quot;Not using feed_validator&quot;
-			end
-
-			if validate
-				v = W3C::FeedValidator.new
-				v.validate_url url
-				unless v.valid?
-					$stderr.puts &quot;Invalid feed&quot;
-					return nil
-				end
-			end
+	def feed=(url)
+		p = self.parse(url)
+
+		if p.nil?
+			return nil
 		end
-		self.feed_url = url
 	end
 end</diff>
      <filename>lib/rfeed/models/Feed.rb</filename>
    </modified>
  </modified>
  <removed type="array">
    <removed>
      <filename>lib/rfeed/models/.Feed.rb.swp</filename>
    </removed>
  </removed>
  <parents type="array">
    <parent>
      <id>590b8ee6976fd8a280fdaa562806c16eb7687982</id>
    </parent>
  </parents>
  <author>
    <name>David Moreno</name>
    <email>david@axiombox.com</email>
  </author>
  <url>http://github.com/damog/rfeed/commit/471905fe43779d13a62da0d4847e6ad7acf97715</url>
  <id>471905fe43779d13a62da0d4847e6ad7acf97715</id>
  <committed-date>2009-01-10T15:49:14-08:00</committed-date>
  <authored-date>2009-01-10T15:49:14-08:00</authored-date>
  <message>moving forward</message>
  <tree>af7be1188b5deced6b67125d3d3a1875f635928c</tree>
  <committer>
    <name>David Moreno</name>
    <email>david@axiombox.com</email>
  </committer>
</commit>
