Skip to content
bct edited this page Sep 13, 2010 · 3 revisions

Building

Building entries and feeds is simple:

#!ruby
require "atom/feed"

e = Atom::Entry.new
e.title = "a new entry"

e.content = "some <em>boring</em> HTML"
e.content.type = "html"

e.categories.new :term => "Test Entry"

feed = Atom::Feed.new

feed << e
feed.to_s
# => "<feed xmlns='http://www.w3.org/2005/Atom'><entry><title>a new entry</title><content type='html'>some &lt;em&gt;boring&lt;/em&gt; HTML</content><category term='Test Entry'/></entry></feed>"

atom-tools won’t complain if you’ve forgotten to include all the bits you need, so you should run the final product through the Feed Validator before you publish.

Parsing

#!ruby
require "atom/feed"

f = Atom::Feed.new("http://www.tbray.org/ongoing/ongoing.atom")

f.entries
# => []

f.update!
f.entries
# => [#<Atom::Entry>, ...]

f.entries.first.title.to_s
# => "Tag Scheme?"

More Complex Things

  • Simon Rozet has written several simple Atom Publishing Protocol servers
  • atom-tools/bin/atom-cp — an Atom Publishing Protocol client that can copy entries from one feed to another
  • VoxApi — faking the Atom API
  • HtmlToXhtml — convert @type=‘html’ to @type=‘xhtml’
Clone this wiki locally