ratom-nokogiri 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +5 -0
- data/.travis.yml +6 -0
- data/Gemfile +7 -0
- data/History.txt +164 -0
- data/LICENSE +20 -0
- data/README.rdoc +309 -0
- data/Rakefile +10 -0
- data/lib/atom.rb +797 -0
- data/lib/atom/configuration.rb +24 -0
- data/lib/atom/pub.rb +243 -0
- data/lib/atom/version.rb +3 -0
- data/lib/atom/xml/parser.rb +413 -0
- data/ratom.gemspec +27 -0
- data/spec/app/member_entry.atom +31 -0
- data/spec/app/service.xml +36 -0
- data/spec/app/service_xml_base.xml +37 -0
- data/spec/atom/pub_spec.rb +517 -0
- data/spec/atom_spec.rb +1449 -0
- data/spec/conformance/atom.rng +600 -0
- data/spec/conformance/baseuri.atom +19 -0
- data/spec/conformance/divtest.atom +32 -0
- data/spec/conformance/linktests.xml +103 -0
- data/spec/conformance/nondefaultnamespace-baseline.atom +25 -0
- data/spec/conformance/nondefaultnamespace-xhtml.atom +25 -0
- data/spec/conformance/nondefaultnamespace.atom +25 -0
- data/spec/conformance/ordertest.xml +112 -0
- data/spec/conformance/title/html-cdata.atom +22 -0
- data/spec/conformance/title/html-entity.atom +22 -0
- data/spec/conformance/title/html-ncr.atom +22 -0
- data/spec/conformance/title/text-cdata.atom +22 -0
- data/spec/conformance/title/text-entity.atom +21 -0
- data/spec/conformance/title/text-ncr.atom +21 -0
- data/spec/conformance/title/xhtml-entity.atom +21 -0
- data/spec/conformance/title/xhtml-ncr.atom +21 -0
- data/spec/conformance/unknown-namespace.atom +25 -0
- data/spec/conformance/xmlbase.atom +133 -0
- data/spec/fixtures/complex_single_entry.atom +45 -0
- data/spec/fixtures/created_entry.atom +31 -0
- data/spec/fixtures/entry.atom +30 -0
- data/spec/fixtures/entry_with_custom_content_type.atom +10 -0
- data/spec/fixtures/entry_with_custom_extensions.atom +8 -0
- data/spec/fixtures/entry_with_simple_extensions.atom +31 -0
- data/spec/fixtures/entry_with_single_custom_extension.atom +6 -0
- data/spec/fixtures/external_content_single_entry.atom +21 -0
- data/spec/fixtures/multiple_entry.atom +0 -0
- data/spec/fixtures/simple_single_entry.atom +21 -0
- data/spec/fixtures/with_stylesheet.atom +8 -0
- data/spec/paging/first_paged_feed.atom +21 -0
- data/spec/paging/last_paged_feed.atom +21 -0
- data/spec/paging/middle_paged_feed.atom +22 -0
- data/spec/property.rb +31 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +40 -0
- metadata +201 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c899ba607457b5fd43308f1b4cd5f70cd90c0a77
|
4
|
+
data.tar.gz: 0cb7d18ce58a75a08331dea8efae5632abd592d9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2c2f6cad975bdb7f1cbee58a6518c4bc882a1327d83d2235593dddcbea2b86d064c2a4174f39975b1ebcddb6fa908975c1851709b92aa654d604caec603bea77
|
7
|
+
data.tar.gz: 61177c2b8d782e83c58d2ba6d4940b2618fc99d96316682c20d466c16c02d11689671bfef602cd18dc2ae596e66d82fdccf615b92fbe39c4746d3b28b5f9f5f4
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/History.txt
ADDED
@@ -0,0 +1,164 @@
|
|
1
|
+
== 0.9.0
|
2
|
+
|
3
|
+
* Relax libxml-ruby version. [hainesr]
|
4
|
+
* Support Ruby 2.2.
|
5
|
+
|
6
|
+
== 0.8.0
|
7
|
+
|
8
|
+
* Add support for custom content types. [xli]
|
9
|
+
* Update libxml-ruby to ~> 2.6
|
10
|
+
|
11
|
+
== 0.7.2
|
12
|
+
|
13
|
+
* Fix UTF handling bug. [carols10cents]
|
14
|
+
|
15
|
+
== 0.7.1
|
16
|
+
|
17
|
+
* 1.8.7 Compat fix [doximity]
|
18
|
+
|
19
|
+
== 0.7.0
|
20
|
+
|
21
|
+
* Atom::VERSION is now a string.
|
22
|
+
* Now works in 1.9.3 without any deprecation warnings. [clnclarinet]
|
23
|
+
* Build system uses bundler and travis and a non-ancient version of Rspec. [clnclarinet]
|
24
|
+
|
25
|
+
== 0.6.10
|
26
|
+
|
27
|
+
* Removed explicit dependency on ActiveSupport. [icambron]
|
28
|
+
* Added support for external content references using the src attribute. [lukfugl]
|
29
|
+
|
30
|
+
== 0.6.9
|
31
|
+
|
32
|
+
* SSL support [kossnocorp]
|
33
|
+
|
34
|
+
== 0.6.8
|
35
|
+
|
36
|
+
* Better auth-hmac detection.
|
37
|
+
* Handles Ruby 1.9 arrays. [wilkie]
|
38
|
+
|
39
|
+
== 0.6.7
|
40
|
+
|
41
|
+
* Handle dashes in extension names.
|
42
|
+
|
43
|
+
== 0.6.6
|
44
|
+
|
45
|
+
* Added support for absoluting relative uris using xml:base. [Greg Campbell]
|
46
|
+
|
47
|
+
== 0.6.5
|
48
|
+
|
49
|
+
* Fixed missing version.rb, now loads version.yml. [Greg Campbell]
|
50
|
+
|
51
|
+
== 0.6.4
|
52
|
+
|
53
|
+
* Remove Hoe dependency and converted to a Jeweler based project build.
|
54
|
+
* Fixed error when assigning nil to node['xml:lang'] [George Guimarães].
|
55
|
+
* Handle link@title. [Brian Dewey]
|
56
|
+
* SimpleExtensions#[] returns a namespace hash if localname is not given. [Daniel Vartanov]
|
57
|
+
|
58
|
+
== 0.6.3 2009-11-19
|
59
|
+
|
60
|
+
* Removed extraneous logging.
|
61
|
+
|
62
|
+
== 0.6.2 2009-06-19
|
63
|
+
|
64
|
+
* Handle href and fixed on service doc categories.
|
65
|
+
* Use request_uri instead of path so that we get any query parameters too. [Wybo Wiersma]
|
66
|
+
* Doc Patches.
|
67
|
+
|
68
|
+
== 0.6.1 2009-03-27
|
69
|
+
|
70
|
+
Some minor exception fixes.
|
71
|
+
|
72
|
+
* Removed Atom::ParseError. Parse errors now will only throw ArgumentError.
|
73
|
+
* ProtocolError has a to string method.
|
74
|
+
|
75
|
+
== 0.6.0 2009-03-19
|
76
|
+
|
77
|
+
* Now depends on libxml-ruby 1.1.2.
|
78
|
+
* Added support for hreflang on links. (David Arango)
|
79
|
+
* Update to work with latest version of libxml-ruby. (oortle & me)
|
80
|
+
* Content::Text and Content::Xhtml can now be created with String's like Content::Html.
|
81
|
+
* Make sure Atom::Generator outputs the generator name as the text of the element.
|
82
|
+
|
83
|
+
== 0.5.2 2008-12-06
|
84
|
+
|
85
|
+
* Remove whitespace modification in content. (dlisboa)
|
86
|
+
|
87
|
+
== 0.5.1 2008-08-05
|
88
|
+
|
89
|
+
* Added optional AuthHMAC support
|
90
|
+
|
91
|
+
== 0.5.0 2008-07-28
|
92
|
+
|
93
|
+
* Fix bug where processing instructions break parsing.
|
94
|
+
* Added Custom extension element classes. (Ignacio Carrera)
|
95
|
+
|
96
|
+
== 0.4.2 2008-07-09
|
97
|
+
|
98
|
+
* Update to libxml-ruby version 0.8.x
|
99
|
+
|
100
|
+
== 0.4.1 2008-07-09
|
101
|
+
|
102
|
+
* Update to libxml-ruby version 0.6.0.
|
103
|
+
|
104
|
+
== 0.4.0 2008-06-26
|
105
|
+
|
106
|
+
* Support for HTTP Basic Authentication.
|
107
|
+
|
108
|
+
== 0.3.7 2008-06-05
|
109
|
+
|
110
|
+
* Support XML in extension elements. (Min Kim)
|
111
|
+
|
112
|
+
== 0.3.6 2008-05-15
|
113
|
+
|
114
|
+
* Added categories to feeds.
|
115
|
+
* Make sure atom:content appears at the end of a atom:entry.
|
116
|
+
* Don't use namespace prefixes on content unless we really have to.
|
117
|
+
|
118
|
+
== 0.3.5 2008-05-03
|
119
|
+
|
120
|
+
* Make sure atom:entries appears last.
|
121
|
+
* Better examples in the documentation. Docs for Feed and Entry list attributes.
|
122
|
+
* Gave Feeds authors and contributors.
|
123
|
+
* Fixed a couple warnings.
|
124
|
+
|
125
|
+
== 0.3.4 2008-04-21
|
126
|
+
|
127
|
+
* Remove useless variable warning. (Sam Roberts)
|
128
|
+
* Support initialization of Atom::Source from Hash and block.
|
129
|
+
* Support initialization of Atom::Generator from Hash and block.
|
130
|
+
|
131
|
+
== 0.3.3 2008-04-09
|
132
|
+
|
133
|
+
* Better serialization of namespaced elements. ratom will now generate prefixes for namespaces and write them as
|
134
|
+
attributes on the root element.
|
135
|
+
* Extensions read as attributes are now written as attributes.
|
136
|
+
* When programmatically setting an extension value you can tell ratom to write it as an attribute using:
|
137
|
+
|
138
|
+
entry['http://example.org', 'extattr'].as_attribute = true
|
139
|
+
|
140
|
+
* Add support for atom:category.
|
141
|
+
* Support extension attributes using the same mechanism as extension elements.
|
142
|
+
|
143
|
+
== 0.3.1 2008-04-02
|
144
|
+
|
145
|
+
* Bunch of fixes to the Atom::Pub classes to make them work like the Atom classes
|
146
|
+
with respect to initializers and to_xml.
|
147
|
+
|
148
|
+
== 0.3.0 2008-04-02
|
149
|
+
|
150
|
+
* Raise Atom::Serialization error when you try and serialize non-utf8 content.
|
151
|
+
* Support reading simple extension elements, see README.txt.
|
152
|
+
* Support writing simple extension elements, see README.txt.
|
153
|
+
|
154
|
+
== 0.2.2 2008-02-10
|
155
|
+
|
156
|
+
* Removed dependency on ActiveSupport.
|
157
|
+
|
158
|
+
== 0.2.1 2008-03-03
|
159
|
+
|
160
|
+
* Initial release to the public.
|
161
|
+
|
162
|
+
== < 0.2.1
|
163
|
+
|
164
|
+
* Internal releases.
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2008 Peerworks
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,309 @@
|
|
1
|
+
= rAtom
|
2
|
+
|
3
|
+
rAtom is a library for working with the Atom Syndication Format and
|
4
|
+
the Atom Publishing Protocol (APP).
|
5
|
+
|
6
|
+
* Built using libxml so it is _much_ faster than a REXML based library.
|
7
|
+
* Uses the libxml pull parser so it has much lighter memory usage.
|
8
|
+
* Supports {RFC 5005}[http://www.ietf.org/rfc/rfc5005.txt] for feed pagination.
|
9
|
+
|
10
|
+
rAtom was originally built to support the communication between a number of applications
|
11
|
+
built by Peerworks[http://peerworks.org], via the Atom Publishing protocol. However, it
|
12
|
+
supports, or aims to support, all the Atom Syndication Format and Publication Protocol
|
13
|
+
and can be used to access Atom feeds or to script publishing entries to a blog supporting APP.
|
14
|
+
|
15
|
+
{<img src="https://secure.travis-ci.org/seangeo/ratom.png?branch=master" alt="Build Status" />}[http://travis-ci.org/seangeo/ratom]
|
16
|
+
|
17
|
+
API docs are {here}[http://rdoc.info/github/seangeo/ratom/frames].
|
18
|
+
|
19
|
+
== Prerequisites
|
20
|
+
|
21
|
+
* nokogiri, >= 1.5.6
|
22
|
+
* rspec (Only required for tests)
|
23
|
+
|
24
|
+
nokogiri in turn requires the libxml2 library to be installed. libxml2 can be downloaded
|
25
|
+
from http://xmlsoft.org/downloads.html or installed using whatever tools are provided by your
|
26
|
+
platform. At least version 2.6.31 is required.
|
27
|
+
|
28
|
+
=== Mac OSX
|
29
|
+
|
30
|
+
Mac OSX by default comes with an old version of libxml2 that will not work with rAtom. You
|
31
|
+
will need to install a more recent version. If you are using Macports:
|
32
|
+
|
33
|
+
port install libxml2
|
34
|
+
|
35
|
+
Alternatively, using Homebrew:
|
36
|
+
|
37
|
+
brew install libxml2
|
38
|
+
|
39
|
+
== Installation
|
40
|
+
|
41
|
+
You can install via gem using:
|
42
|
+
|
43
|
+
gem install ratom
|
44
|
+
|
45
|
+
== Usage
|
46
|
+
|
47
|
+
To fetch a parse an Atom Feed you can simply:
|
48
|
+
|
49
|
+
require 'atom'
|
50
|
+
|
51
|
+
feed = Atom::Feed.load_feed(URI.parse("http://example.com/feed.atom"))
|
52
|
+
|
53
|
+
And then iterate over the entries in the feed using:
|
54
|
+
|
55
|
+
feed.each_entry do |entry|
|
56
|
+
# do cool stuff
|
57
|
+
end
|
58
|
+
|
59
|
+
To construct the following example Feed is from the Atom spec:
|
60
|
+
|
61
|
+
<?xml version="1.0" encoding="utf-8"?>
|
62
|
+
<feed xmlns="http://www.w3.org/2005/Atom">
|
63
|
+
|
64
|
+
<title>Example Feed</title>
|
65
|
+
<link href="http://example.org/"/>
|
66
|
+
<updated>2003-12-13T18:30:02Z</updated>
|
67
|
+
<author>
|
68
|
+
<name>John Doe</name>
|
69
|
+
</author>
|
70
|
+
<id>urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6</id>
|
71
|
+
|
72
|
+
<entry>
|
73
|
+
<title>Atom-Powered Robots Run Amok</title>
|
74
|
+
<link href="http://example.org/2003/12/13/atom03"/>
|
75
|
+
<id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</id>
|
76
|
+
<updated>2003-12-13T18:30:02Z</updated>
|
77
|
+
<summary>Some text.</summary>
|
78
|
+
</entry>
|
79
|
+
|
80
|
+
</feed>
|
81
|
+
|
82
|
+
To build this in rAtom we would do:
|
83
|
+
|
84
|
+
feed = Atom::Feed.new do |f|
|
85
|
+
f.title = "Example Feed"
|
86
|
+
f.links << Atom::Link.new(:href => "http://example.org/")
|
87
|
+
f.updated = Time.parse('2003-12-13T18:30:02Z')
|
88
|
+
f.authors << Atom::Person.new(:name => 'John Doe')
|
89
|
+
f.id = "urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6"
|
90
|
+
f.entries << Atom::Entry.new do |e|
|
91
|
+
e.title = "Atom-Powered Robots Run Amok"
|
92
|
+
e.links << Atom::Link.new(:href => "http://example.org/2003/12/13/atom03")
|
93
|
+
e.id = "urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a"
|
94
|
+
e.updated = Time.parse('2003-12-13T18:30:02Z')
|
95
|
+
e.summary = "Some text."
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
To output the Feed as XML use to_xml
|
100
|
+
|
101
|
+
> puts feed.to_xml
|
102
|
+
<?xml version="1.0"?>
|
103
|
+
<feed xmlns="http://www.w3.org/2005/Atom">
|
104
|
+
<id>urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6</id>
|
105
|
+
<title>Example Feed</title>
|
106
|
+
<updated>2003-12-13T18:30:02Z</updated>
|
107
|
+
<link href="http://example.org/"/>
|
108
|
+
<author>
|
109
|
+
<name>John Doe</name>
|
110
|
+
</author>
|
111
|
+
<entry>
|
112
|
+
<title>Atom-Powered Robots Run Amok</title>
|
113
|
+
<id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</id>
|
114
|
+
<summary>Some text.</summary>
|
115
|
+
<updated>2003-12-13T18:30:02Z</updated>
|
116
|
+
<link href="http://example.org/2003/12/13/atom03"/>
|
117
|
+
</entry>
|
118
|
+
</feed>
|
119
|
+
|
120
|
+
|
121
|
+
See Feed and Entry for details on the methods and attributes of those classes.
|
122
|
+
|
123
|
+
=== Publishing
|
124
|
+
|
125
|
+
To publish to a remote feed using the Atom Publishing Protocol, first you need to create a collection to publish to:
|
126
|
+
|
127
|
+
require 'atom/pub'
|
128
|
+
|
129
|
+
collection = Atom::Pub::Collection.new(:href => 'http://example.org/myblog')
|
130
|
+
|
131
|
+
Then create a new entry
|
132
|
+
|
133
|
+
entry = Atom::Entry.new do |entry|
|
134
|
+
entry.title = "I have discovered rAtom"
|
135
|
+
entry.authors << Atom::Person.new(:name => 'A happy developer')
|
136
|
+
entry.updated = Time.now
|
137
|
+
entry.id = "http://example.org/myblog/newpost"
|
138
|
+
entry.content = Atom::Content::Html.new("<p>rAtom lets me post to my blog using Ruby, how cool!</p>")
|
139
|
+
end
|
140
|
+
|
141
|
+
And publish it to the Collection:
|
142
|
+
|
143
|
+
published_entry = collection.publish(entry)
|
144
|
+
|
145
|
+
Publish returns an updated entry filled out with any attributes to server may have set, including information
|
146
|
+
required to let us update to the entry. For example, lets change the content and republished:
|
147
|
+
|
148
|
+
published_entry.content = Atom::Content::Html.new("<p>rAtom lets me post to and edit my blog using Ruby, how cool!</p>")
|
149
|
+
published_entry.updated = Time.now
|
150
|
+
published_entry.save!
|
151
|
+
|
152
|
+
To update an existing Entry:
|
153
|
+
|
154
|
+
existing_entry = Entry.load_entry(URI.parse("http://example.org/afeedentry.atom"))
|
155
|
+
|
156
|
+
existing_entry.title = "I have discovered rAtom"
|
157
|
+
existing_entry.updated = Time.now
|
158
|
+
existing_entry.save!
|
159
|
+
|
160
|
+
You can also delete an entry using the <tt>destroy!</tt> method, but we won't do that will we?.
|
161
|
+
|
162
|
+
=== Extension elements
|
163
|
+
|
164
|
+
As of version 0.3.0, rAtom support simple extension elements on feeds and entries. As defined in the Atom Syndication Format,
|
165
|
+
simple extension elements consist of XML elements from a non-Atom namespace that have no attributes or child elements, i.e.
|
166
|
+
they are empty or only contain text content. These elements are treated as a name value pair where the element namespace
|
167
|
+
and local name make up the key and the content of the element is the value, empty elements will be treated as an empty string.
|
168
|
+
|
169
|
+
To access extension elements use the [] method on the Feed or Entry. For example, if we are parsing the follow Atom document
|
170
|
+
with extensions:
|
171
|
+
|
172
|
+
<?xml version="1.0"?>
|
173
|
+
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:ex="http://example.org">
|
174
|
+
<title>Feed with extensions</title>
|
175
|
+
<ex:myelement>Something important</ex:myelement>
|
176
|
+
</feed>
|
177
|
+
|
178
|
+
We could then access the extension element on the feed using:
|
179
|
+
|
180
|
+
> feed["http://example.org", "myelement"]
|
181
|
+
=> ["Something important"]
|
182
|
+
|
183
|
+
Note that the return value is an array. This is because XML allows multiple instances of the element.
|
184
|
+
|
185
|
+
To set an extension element you append to the array:
|
186
|
+
|
187
|
+
> feed['http://example.org', 'myelement'] << 'Something less important'
|
188
|
+
=> ["Something important", "Something less important"]
|
189
|
+
|
190
|
+
You can then call to_xml and rAtom will serialize the extension elements into xml.
|
191
|
+
|
192
|
+
> puts feed.to_xml
|
193
|
+
<?xml version="1.0"?>
|
194
|
+
<feed xmlns="http://www.w3.org/2005/Atom">
|
195
|
+
<myelement xmlns="http://example.org">Something important</myelement>
|
196
|
+
<myelement xmlns="http://example.org">Something less important</myelement>
|
197
|
+
</feed>
|
198
|
+
|
199
|
+
Notice that the output repeats the xmlns attribute for each of the extensions, this is semantically the same the input XML, just a bit
|
200
|
+
ugly. It seems to be a limitation of the libxml-Ruby API. But if anyone knows a work around I'd gladly accept a patch (or even advice).
|
201
|
+
|
202
|
+
==== Custom Extension Classes
|
203
|
+
|
204
|
+
As of version 0.5.0 you can also define your own classes for a extension elements. This is done by first creating an alias
|
205
|
+
for the namespace for the class and then using the +element+ method on the Atom::Feed or Atom::Entry class to tell rAtom
|
206
|
+
to use your custom class when it encounters the extension element.
|
207
|
+
|
208
|
+
For example, say we have the following piece Atom XML with a structured extension element:
|
209
|
+
|
210
|
+
<?xml version='1.0' encoding='UTF-8'?>
|
211
|
+
<entry xmlns='http://www.w3.org/2005/Atom' xmlns:custom='http://custom.namespace'>
|
212
|
+
<id>https://custom.namespace/id/1</id>
|
213
|
+
<link rel='self' type='application/atom+xml' href='https://custom.namespace/id/1'/>
|
214
|
+
<custom:property name='foo' value='bar'/>
|
215
|
+
<custom:property name='baz' value='bat'/>
|
216
|
+
</entry>
|
217
|
+
|
218
|
+
And we want the +custom:property+ elements to be parsed as our own custom class called Custom::Property that is
|
219
|
+
defined like this:
|
220
|
+
|
221
|
+
class Custom::Property
|
222
|
+
attr_accessor :name, :value
|
223
|
+
def initialize(xml)
|
224
|
+
# Custom XML handling
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
228
|
+
We can tell rAtom about our custom namespace and custom class using the following method calls:
|
229
|
+
|
230
|
+
Atom::Entry.add_extension_namespace :custom, "http://custom.namespace"
|
231
|
+
Atom::Entry.elements "custom:property", :class => Custom::Property
|
232
|
+
|
233
|
+
The first method call registers an alias for the "http://custom.namespace" namespace and the second method call
|
234
|
+
tell rAtom that when it encounters a custom:property element within a Feed it should create an instance of Custom::Property
|
235
|
+
and pass the XML Reader to the constructor of the instance. It is then up to the constructor to populate the objects attributes
|
236
|
+
from the XML. Note that the alias you create using +add_extension_namespace+ can be anything you want, it doesn't need
|
237
|
+
to match the alias in the actual XML itself.
|
238
|
+
|
239
|
+
The custom property will then be available as a method on the rAtom class. In the above example:
|
240
|
+
|
241
|
+
@feed.custom_property.size == 2
|
242
|
+
@feed.custom_property.first.name == 'foo'
|
243
|
+
@feed.custom_property.first.value == 'bar'
|
244
|
+
|
245
|
+
There is one caveat to this. By using this type of extension support you are permanently modifying the rAtom classes.
|
246
|
+
So if your application process one type of atom extension and you are happy with permanently modified rAtom classes,
|
247
|
+
the extra extensibility might work for you. If on the other hand you process lots of different types of extension you might
|
248
|
+
want to stick with simpler extension mechanism using the [namespace, element] method described above.
|
249
|
+
|
250
|
+
(Thanks to nachokb for this feature!!)
|
251
|
+
|
252
|
+
=== Basic Authentication
|
253
|
+
|
254
|
+
All methods that involve HTTP requests now support HTTP Basic Authentication. Authentication credentials are passed
|
255
|
+
as :user and :pass parameters to the methods that invoke the request. For example you can load a feed with HTTP Basic Authentication using:
|
256
|
+
|
257
|
+
Atom::Feed.load_entry(URI.parse("http://example.org/feed.atom"), :user => 'username', :pass => 'password')
|
258
|
+
|
259
|
+
Likewise all the Atom Pub methods support similar parameters, for example you can publish an Entry to a Feed with authentication
|
260
|
+
using:
|
261
|
+
|
262
|
+
feed.publish(entry, :user => 'username', :pass => 'password')
|
263
|
+
|
264
|
+
Or destroy an entry with:
|
265
|
+
|
266
|
+
entry.destroy!(:user => 'username', :pass => 'password')
|
267
|
+
|
268
|
+
rAtom doesn't store these credentials anywhere within the object model so you will need to pass them as arguments to every
|
269
|
+
method call that requires them. This might be a bit of a pain but it does make things simpler and it means that I'm not responsible
|
270
|
+
for protecting your credentials, although if you are using HTTP Basic Authentication there is a good chance your credentials aren't
|
271
|
+
very well protected anyway.
|
272
|
+
|
273
|
+
=== AuthHMAC authentication
|
274
|
+
|
275
|
+
As of version 0.5.1 rAtom also support authentication via HMAC request signing using the AuthHMAC[http://auth-hmac.rubyforge.org] gem. This is made available using the :hmac_access_id and :hmac_secret_key parameters which can be passed to the same methods as the HTTP Basic credentials support.
|
276
|
+
|
277
|
+
=== SSL
|
278
|
+
|
279
|
+
As of version 0.6.9, rAtom supports fetching feeds via https. This is done by using URLs with the SSL protocol. Publishing support is still limited to http, but patches are welcome.
|
280
|
+
|
281
|
+
== TODO
|
282
|
+
|
283
|
+
* Support partial content responses from the server.
|
284
|
+
* Support batching of protocol operations.
|
285
|
+
* All my tests have been against internal systems, I'd really like feedback from those who have tried rAtom using existing blog software that supports APP.
|
286
|
+
* Handle all base uri tests.
|
287
|
+
* Add slug support.
|
288
|
+
|
289
|
+
== Source Code
|
290
|
+
|
291
|
+
The source repository is accessible via GitHub:
|
292
|
+
|
293
|
+
git clone git://github.com/seangeo/ratom.git
|
294
|
+
|
295
|
+
The project now uses Bundler for dependency management so, just do
|
296
|
+
|
297
|
+
bundle install
|
298
|
+
|
299
|
+
to get going.
|
300
|
+
|
301
|
+
== Contact Information
|
302
|
+
|
303
|
+
The project page is at http://github.com/seangeo/ratom. Please file any bugs or feedback
|
304
|
+
using the trackers and forums there.
|
305
|
+
|
306
|
+
== Authors and Contributors
|
307
|
+
|
308
|
+
rAtom was developed by Peerworks[http://peerworks.org] and written by Sean Geoghegan.
|
309
|
+
|