Using Web Feeds in Ruby (Mini-Facebook-like News Feed in 20 Lines of Ruby) and More

Hello,

  FYI: The slides from this week's Vienna.rb talk titled "Using Web
Feeds to Build Planet Sites in Ruby." [1] Use left/right cursor keys
(or space bar) to browse the slides. Or check the all-in-one-page
markdown source [2].

Build yourself a Mini-Facebook-like News Feed in 20 Lines of Ruby e.g.

planet.rb:

···

--------------

require 'open-uri'
require 'feedutils'
require 'erb'

# step 1) read a list of web feeds

FEED_URLS = [
  'http://vienna-rb.at/atom.xml',
  'http://www.meetup.com/vienna-rb/events/rss/vienna.rb/',
  'http://www.1stfloorgraphics.nl/blog/feed/',
  'http://lab.an-ti.eu/atom.xml',
  'http://abangratz.github.io/atom.xml'
]

items = []

FEED_URLS.each do |url|
  feed = FeedUtils::Parser.parse( open( url ).read )
  items += feed.items
end

# step 2) mix up all postings in a new page

FEED_ITEM_TEMPLATE = <<EOS
<% items.each do |item| %>
  <div class="item">
    <h2><a href="<%= item.url %>"><%= item.title %></a></h2>
    <div><%= item.content %></div>
  </div>
<% end %>
EOS

puts ERB.new( FEED_ITEM_TEMPLATE ).result

Run the script:

$ ruby planet.rb

or just use the ready-to-use Pluto feed reader gem command line tool
[3] to make it one line

$ pluto build newsfeed

  Cheers. Happy Planet.

[1] http://slideshow-s9.github.io/webfeeds.html
[2] https://github.com/slideshow-s9/slideshow-s9.github.io/blob/master/talks/webfeeds.md
[3] http://feedreader.github.io