Skip to content

Commit

Permalink
adding the Feedbag.feed? method
Browse files Browse the repository at this point in the history
  • Loading branch information
damog committed Jan 12, 2009
1 parent bccd45e commit 2995805
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.markdown
Expand Up @@ -15,6 +15,10 @@ Feedbag is a feed auto-discovery Ruby library. You don't need to know more about
=> true
>> Feedbag.find "log.damog.net"
=> ["http://feeds.feedburner.com/TeoremaDelCerdoInfinito", "http://log.damog.net/comments/feed/"]
>> Feedbag.feed?("google.com")
=> false
>> Feedbag.feed?("http://planet.debian.org/rss20.xml")
=> true

### Installation

Expand Down
1 change: 1 addition & 0 deletions TODO
@@ -0,0 +1 @@
- Document Feedbag.feed?
115 changes: 115 additions & 0 deletions index.html
@@ -0,0 +1,115 @@
<h1>Feedbag</h1>

<blockquote>
<p>Do you want me to drag my sack across your face?
- Glenn Quagmire</p>
</blockquote>

<p>Feedbag is a feed auto-discovery Ruby library. You don't need to know more about it. It is said to be:</p>

<blockquote>
<p>Ruby's favorite auto-discovery tool/library!</p>
</blockquote>

<h3>Quick synopsis</h3>

<pre><code>&gt;&gt; require "rubygems"
=&gt; true
&gt;&gt; require "feedbag"
=&gt; true
&gt;&gt; Feedbag.find "log.damog.net"
=&gt; ["http://feeds.feedburner.com/TeoremaDelCerdoInfinito", "http://log.damog.net/comments/feed/"]
</code></pre>

<h3>Installation</h3>

<pre><code>$ sudo gem install damog-feedbag -s http://gems.github.com/
</code></pre>

<p>Or just grab feedbag.rb and use it on your own project:</p>

<pre><code>$ wget http://github.com/damog/feedbag/raw/master/lib/feedbag.rb
</code></pre>

<h2>Tutorial</h2>

<p>So you want to know more about it.</p>

<p>OK, if the URL passed to the find method is a feed itself, that only feed URL will be returned.</p>

<pre><code>&gt;&gt; Feedbag.find "github.com/damog.atom"
=&gt; ["http://github.com/damog.atom"]
&gt;&gt;
</code></pre>

<p>Otherwise, it will always return LINK feeds first, A (anchor tags) feeds later. Between A feeds, the ones hosted on the same URL's host, will have larger priority:</p>

<pre><code>&gt;&gt; Feedbag.find "http://ve.planetalinux.org"
=&gt; ["http://feedproxy.google.com/PlanetaLinuxVenezuela", "http://rendergraf.wordpress.com/feed/", "http://rootweiller.wordpress.com/feed/", "http://skatox.com/blog/feed/", "http://kodegeek.com/atom.xml", "http://blog.0x29.com.ve/?feed=rss2&amp;cat=8"]
&gt;&gt;
</code></pre>

<p>On your application you should only take the very first element of the array, most of the times:</p>

<pre><code>&gt;&gt; Feedbag.find("planet.debian.org").first(3)
=&gt; ["http://planet.debian.org/rss10.xml", "http://planet.debian.org/rss20.xml", "http://planet.debian.org/atom.xml"]
&gt;&gt;
</code></pre>

<p>(Try running that same example without the "first" method. That example's host is a blog aggregator, so it has hundreds of feed URLs:)</p>

<pre><code>&gt;&gt; Feedbag.find("planet.debian.org").size
=&gt; 104
&gt;&gt;
</code></pre>

<p>Feedbag will find them all, but it will return the most important ones on the first elements on the array returned.</p>

<pre><code>&gt;&gt; Feedbag.find("cnn.com")
=&gt; ["http://rss.cnn.com/rss/cnn_topstories.rss", "http://rss.cnn.com/rss/cnn_latest.rss", "http://rss.cnn.com/services/podcasting/robinmeade/rss.xml"]
&gt;&gt;
</code></pre>

<h3>Why should you use it?</h3>

<ul>
<li>Because it's cool.</li>
<li>Because it only uses <a href="https://code.whytheluckystiff.net/hpricot/">Hpricot</a> as dependency.</li>
<li>Because it follows modern feed filename conventions (like those ones used by WordPress blogs, or Blogger, etc).</li>
<li>Because it's a single file you can embed easily in your application.</li>
<li>Because it passes most of the Mark Pilgrim's <a href="http://diveintomark.org/tests/client/autodiscovery/">Atom auto-discovery test suite</a>. It doesn't pass them all because some of those tests are broken (citation needed).</li>
</ul>

<h3>Why did I build it?</h3>

<ul>
<li>Because I liked Benjamin Trott's <a href="http://search.cpan.org/~btrott/Feed-Find-0.06/lib/Feed/Find.pm">Feed::Find</a>.</li>
<li>Because I thought it would be good to have Feed::Find's functionality in Ruby.</li>
<li>Because I thought it was going to be easy to maintain.</li>
<li>Because I was going to use it on <a href="http://github.com/damog/rfeed">rFeed</a>.</li>
<li>And finally, because I didn't know <a href="http://rfeedfinder.rubyforge.org/">rfeedfinder</a> existed :-)</li>
</ul>

<h3>Bugs</h3>

<p>Please, report bugs to <a href="rt@support.axiombox.com">rt@support.axiombox.com</a> or directly to the author.</p>

<h3>Contribute</h3>

<blockquote>
<p>git clone git://github.com/damog/feedbag.git</p>
</blockquote>

<p>...patch, build, hack and make pull requests. I'll be glad.</p>

<h3>Author</h3>

<p><a href="http://damog.net/">David Moreno</a> &lt;<a href="mailto:david@axiombox.com">david@axiombox.com</a>>.</p>

<h3>Copyright</h3>

<p>This is free software. See <a href="http://github.com/damog/feedbag/master/COPYING">COPYING</a> for more information.</p>

<h3>Thanks</h3>

<p><a href="http://maggit.net">Raquel</a>, for making <a href="http://axiombox.com">Axiombox</a> and most of my dreams possible. Also, <a href="http://github.com">GitHub</a> for making a nice code sharing service that doesn't suck.</p>
15 changes: 15 additions & 0 deletions lib/feedbag.rb
Expand Up @@ -36,6 +36,21 @@ module Feedbag
$feeds = []
$base_uri = nil

def self.feed?(url)
res = self.find(url)

# use LWR::Simple.normalize some time
url_uri = URI.parse(url)
url = "#{url_uri.scheme or 'http'}://#{url_uri.host}#{url_uri.path}"

res = self.find(url)
if res.size == 1 and res.first == url
return true
else
return false
end
end

def self.find(url)
$feeds = []

Expand Down

0 comments on commit 2995805

Please sign in to comment.