|
Revision 202, 1.7 kB
(checked in by Brendan Taylor <whateley@…>, 5 months ago)
|
|
README-2.0
|
| Line | |
|---|
| 1 | = atom-tools README |
|---|
| 2 | |
|---|
| 3 | atom-tools is an all-in-one library for parsing, creating and manipulating Atom <http://www.w3.org/2005/Atom> feeds and entries. |
|---|
| 4 | It handles all the nasty XML and HTTP details so that you don't have to. |
|---|
| 5 | |
|---|
| 6 | == Example |
|---|
| 7 | |
|---|
| 8 | require "atom/feed" |
|---|
| 9 | require "open-uri" |
|---|
| 10 | |
|---|
| 11 | feed = Atom::Feed.new "http://www.tbray.org/ongoing/ongoing.atom" |
|---|
| 12 | # => <http://www.tbray.org/ongoing/ongoing.atom entries: 0 title=''> |
|---|
| 13 | |
|---|
| 14 | feed.update! |
|---|
| 15 | feed.entries.length |
|---|
| 16 | # => 20 |
|---|
| 17 | |
|---|
| 18 | feed.title.to_s |
|---|
| 19 | # => "ongoing" |
|---|
| 20 | |
|---|
| 21 | feed.authors.first.name |
|---|
| 22 | # => "Tim Bray" |
|---|
| 23 | |
|---|
| 24 | entry = feed.entries.first |
|---|
| 25 | # => #<Atom::Entry id:'http://www.tbray.org/ongoing/When/200x/2006/11/07/Munich'> |
|---|
| 26 | |
|---|
| 27 | entry.title.to_s |
|---|
| 28 | # => "M\303\274nchen" |
|---|
| 29 | |
|---|
| 30 | entry.links.last |
|---|
| 31 | # => {"href"=>"http://www.tbray.org/ongoing/When/200x/2006/11/07/Munich#comments", "rel"=>"replies", "type" => "application/xhtml+xml"} |
|---|
| 32 | |
|---|
| 33 | entry.summary.to_s |
|---|
| 34 | # => "That local spelling is nicer than the ugly English [...]" |
|---|
| 35 | |
|---|
| 36 | Things are explained in more detail in the RDoc. |
|---|
| 37 | |
|---|
| 38 | == The Atom Publishing Protocol |
|---|
| 39 | |
|---|
| 40 | require "atom/service" |
|---|
| 41 | |
|---|
| 42 | service = Atom::Service.new "http://necronomicorp.com/app.xml" |
|---|
| 43 | coll = service.workspaces.first.collections.first |
|---|
| 44 | # => <http://necronomicorp.com/testatom?app entries: 0 title='testing: entry endpoint'> |
|---|
| 45 | |
|---|
| 46 | coll.feed.update! |
|---|
| 47 | # => <http://necronomicorp.com/testatom?app entries: 10 title='testing the APP'> |
|---|
| 48 | |
|---|
| 49 | entry = coll.feed.entries.first |
|---|
| 50 | entry.title |
|---|
| 51 | # => 'html entities'#text |
|---|
| 52 | |
|---|
| 53 | # modify the title |
|---|
| 54 | entry.title = "HTML entities" |
|---|
| 55 | |
|---|
| 56 | # store the modified entry |
|---|
| 57 | coll.put! entry |
|---|
| 58 | # => #<Net::HTTPOK 200 OK readbody=true> |
|---|
| 59 | |
|---|
| 60 | coll.feed.entries.first.title |
|---|
| 61 | # => 'HTML entities'#text |
|---|
| 62 | |
|---|
| 63 | For details on authentication, see the documentation for Atom::HTTP. |
|---|