public
Fork of sr/atom-tools
Description: A Ruby library for Atom and the Atom Publishing Protocol.
Home | Edit | New

ExampleCode

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’
Last edited by bct, Fri Oct 17 13:27:16 -0700 2008
Home | Edit | New
Versions: