Class: Atom::Pub::Collection
- Inherits:
-
Object
- Object
- Atom::Pub::Collection
- Includes:
- Xml::Parseable
- Defined in:
- lib/atom/pub.rb
Instance Method Summary collapse
- #feed ⇒ Object
-
#initialize(o = nil) {|_self| ... } ⇒ Collection
constructor
A new instance of Collection.
- #publish(entry) ⇒ Object
Methods included from Xml::Parseable
#==, #current_node_is?, included, #next_node_is?, #parse, #to_xml
Constructor Details
#initialize(o = nil) {|_self| ... } ⇒ Collection
Returns a new instance of Collection.
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/atom/pub.rb', line 98 def initialize(o = nil) @accepts = [] case o when XML::Reader # do it once to get the attributes parse(o, :once => true) # now step into the element and the sub tree o.read parse(o) when Hash o.each do |k, v| self.send("#{k}=", v) end end yield(self) if block_given? end |
Instance Method Details
#feed ⇒ Object
116 117 118 119 120 |
# File 'lib/atom/pub.rb', line 116 def feed if href Atom::Feed.load_feed(URI.parse(href)) end end |
#publish(entry) ⇒ Object
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/atom/pub.rb', line 122 def publish(entry) uri = URI.parse(href) response = nil Net::HTTP.start(uri.host, uri.port) do |http| response = http.post(uri.path, entry.to_xml.to_s, headers) end case response when Net::HTTPCreated published = begin Atom::Entry.load_entry(response.body) rescue Atom::ParseError entry end if response['Location'] if published.edit_link published.edit_link.href = response['Location'] else published.links << Atom::Link.new(:rel => 'edit', :href => response['Location']) end end published else raise Atom::Pub::ProtocolError, response end end |