Class: Atom::Entry
- Inherits:
-
Object
- Object
- Atom::Entry
- Extended by:
- Forwardable
- Includes:
- SimpleExtensions, Xml::Parseable
- Defined in:
- lib/atom.rb,
lib/atom/pub.rb
Overview
Represents an Entry as defined by the Atom Syndication Format specification.
An Entry represents an individual entry within a Feed.
Parsing
An Entry can be parsed using the Entry.load_entry method. This method accepts a String containing a valid atom entry document, an IO object, or an URI to a valid atom entry document. For example:
# Using a File
entry = Entry.load_entry(File.open("/path/to/myfeedentry.atom"))
# Using a URL
Entry = Entry.load_entry(URI.parse("http://example.org/afeedentry.atom"))
The document must contain a stand alone entry element as described in the Atom Syndication Format.
Encoding
A Entry can be converted to XML using, the to_xml method that returns a valid atom entry document in a String.
Attributes
An entry has the following attributes:
id
-
A unique id for the entry.
updated
-
The Time the entry was updated.
published
-
The Time the entry was published.
title
-
The title of the entry.
summary
-
A short textual summary of the item.
authors
-
An array of Atom::Person objects that are authors of this entry.
contributors
-
An array of Atom::Person objects that are contributors to this entry.
rights
-
A string describing the rights associated with this entry.
links
-
An array of Atom:Link objects. (This is actually an Atom::Links array which is an Array with some sugar).
source
-
Metadata of a feed that was the source of this item, for feed aggregators, etc.
categories
-
Array of Atom::Categories.
content
-
The content of the entry. This will be one of Atom::Content::Text, Atom::Content:Html or Atom::Content::Xhtml.
References
See also www.atomenabled.org/developers/syndication/atom-format-spec.php#element.entry for more detailed definitions of the attributes.
Instance Attribute Summary
Attributes included from SimpleExtensions
Instance Method Summary collapse
- #destroy!(opts = {}) ⇒ Object
-
#initialize(o = {}) {|_self| ... } ⇒ Entry
constructor
Initialize an Entry.
-
#reload!(opts = {}) ⇒ Object
Reload the Entry by fetching the self link.
- #save!(opts = {}) ⇒ Object
Methods included from SimpleExtensions
Methods included from Xml::Parseable
#==, #accessor_name, #current_node_is?, included, #next_node_is?, #parse, #to_xml
Constructor Details
#initialize(o = {}) {|_self| ... } ⇒ Entry
Initialize an Entry.
This will also yield itself, so an Entry can be constructed like this:
entry = Entry.new do |entry|
entry.title = "My Cool entry"
end
o
-
An XML Reader or a Hash of attributes.
601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 |
# File 'lib/atom.rb', line 601 def initialize(o = {}) @links = Links.new @authors = [] @contributors = [] @categories = [] case o when XML::Reader if current_node_is?(o, 'entry', Atom::NAMESPACE) || next_node_is?(o, 'entry', Atom::NAMESPACE) o.read parse(o) else raise ArgumentError, "Entry created with node other than atom:entry: #{o.name}" end when Hash o.each do |k,v| send("#{k.to_s}=", v) end else raise ArgumentError, "Got #{o.class} but expected a Hash or XML::Reader" end yield(self) if block_given? end |
Instance Method Details
#destroy!(opts = {}) ⇒ Object
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 |
# File 'lib/atom/pub.rb', line 214 def destroy!(opts = {}) if edit = edit_link uri = URI.parse(edit.href) response = nil Net::HTTP.start(uri.host, uri.port) do |http| request = Net::HTTP::Delete.new(uri.request_uri, {'Accept' => 'application/atom+xml', 'User-Agent' => "rAtom #{Atom::VERSION::STRING}"}) if opts[:user] && opts[:pass] request.basic_auth(opts[:user], opts[:pass]) elsif opts[:hmac_access_id] && opts[:hmac_secret_key] if Atom::Configuration.auth_hmac_enabled? AuthHMAC.sign!(request, opts[:hmac_access_id], opts[:hmac_secret_key]) else raise ArgumentError, "AuthHMAC credentials provides by auth-hmac gem is not installed" end end response = http.request(request) end case response when Net::HTTPSuccess else raise Atom::Pub::ProtocolError, response end else raise Atom::Pub::NotSupported, "Entry does not have an edit link" end end |
#reload!(opts = {}) ⇒ Object
Reload the Entry by fetching the self link.
627 628 629 630 631 |
# File 'lib/atom.rb', line 627 def reload!(opts = {}) if links.self Entry.load_entry(URI.parse(links.self.href), opts) end end |
#save!(opts = {}) ⇒ Object
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 |
# File 'lib/atom/pub.rb', line 185 def save!(opts = {}) if edit = edit_link uri = URI.parse(edit.href) response = nil Net::HTTP.start(uri.host, uri.port) do |http| request = Net::HTTP::Put.new(uri.request_uri, headers) if opts[:user] && opts[:pass] request.basic_auth(opts[:user], opts[:pass]) elsif opts[:hmac_access_id] && opts[:hmac_secret_key] if Atom::Configuration.auth_hmac_enabled? AuthHMAC.sign!(request, opts[:hmac_access_id], opts[:hmac_secret_key]) else raise ArgumentError, "AuthHMAC credentials provides by auth-hmac gem is not installed" end end response = http.request(request, self.to_xml) end case response when Net::HTTPSuccess else raise Atom::Pub::ProtocolError, response end else raise Atom::Pub::NotSupported, "Entry does not have an edit link" end end |