Class: Atom::Collection
Instance Attribute Summary collapse
-
#feed ⇒ Object
readonly
Returns the value of attribute feed.
-
#http ⇒ Object
readonly
Returns the value of attribute http.
Attributes inherited from Element
Class Method Summary collapse
Instance Method Summary collapse
- #accepts ⇒ Object
- #accepts=(array) ⇒ Object
-
#delete!(entry, url = entry.edit_url) ⇒ Object
DELETE an entry from the collection.
-
#initialize(href = nil, http = Atom::HTTP.new) ⇒ Collection
constructor
A new instance of Collection.
-
#post!(entry, slug = nil) ⇒ Object
POST an entry to the collection, with an optional slug.
-
#post_media!(data, content_type, slug = nil) ⇒ Object
POST a media item to the collection.
-
#put!(entry, url = entry.edit_url) ⇒ Object
PUT an updated version of an entry to the collection.
-
#put_media!(data, content_type, slug = nil) ⇒ Object
PUT a media item to the collection.
- #title ⇒ Object
Methods inherited from Element
#append_elem, attributes, #build, builders, def_get, def_set, do_parsing, #get, #get_atom_attrb, #get_atom_elem, #get_atom_elems, #get_elem, #get_elems, is_atom_element, is_element, on_build, on_init, run_initters, #set, #set_atom_attrb, #to_s, #to_xml
Methods included from Parsers
#on_parse, #on_parse_attr, #on_parse_many, #on_parse_root, #parse_plain
Methods included from Converters
#atom_attrb, #atom_element, #atom_elements, #atom_link, #atom_string, #atom_time, #attrb, #build_plain, #element, #elements, #strings, #time
Constructor Details
#initialize(href = nil, http = Atom::HTTP.new) ⇒ Collection
Returns a new instance of Collection.
70 71 72 73 74 75 76 77 78 |
# File 'lib/atom/collection.rb', line 70 def initialize(href = nil, http = Atom::HTTP.new) super() @http = http if href self.href = href end end |
Instance Attribute Details
#feed ⇒ Object (readonly)
Returns the value of attribute feed.
68 69 70 |
# File 'lib/atom/collection.rb', line 68 def feed @feed end |
#http ⇒ Object (readonly)
Returns the value of attribute http.
66 67 68 |
# File 'lib/atom/collection.rb', line 66 def http @http end |
Class Method Details
.parse(xml, base = '') ⇒ Object
80 81 82 83 84 85 86 87 88 89 |
# File 'lib/atom/collection.rb', line 80 def self.parse xml, base = '' e = super # URL absolutization if !e.base.empty? and e.href e.href = (e.base.to_uri + e.href).to_s end e end |
Instance Method Details
#accepts ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/atom/collection.rb', line 54 def accepts if @accepts.empty? ['application/atom+xml;type=entry'] else @accepts end end |
#accepts=(array) ⇒ Object
62 63 64 |
# File 'lib/atom/collection.rb', line 62 def accepts= array @accepts = array end |
#delete!(entry, url = entry.edit_url) ⇒ Object
DELETE an entry from the collection
106 107 108 |
# File 'lib/atom/collection.rb', line 106 def delete!(entry, url = entry.edit_url) @http.delete(url) end |
#post!(entry, slug = nil) ⇒ Object
POST an entry to the collection, with an optional slug
92 93 94 95 96 97 98 |
# File 'lib/atom/collection.rb', line 92 def post!(entry, slug = nil) raise "Cowardly refusing to POST a non-Atom::Entry" unless entry.is_a? Atom::Entry headers = {"Content-Type" => "application/atom+xml" } headers["Slug"] = slug if slug @http.post(@href, entry.to_s, headers) end |
#post_media!(data, content_type, slug = nil) ⇒ Object
POST a media item to the collection
111 112 113 114 115 116 |
# File 'lib/atom/collection.rb', line 111 def post_media!(data, content_type, slug = nil) headers = {"Content-Type" => content_type} headers["Slug"] = slug if slug @http.post(@href, data, headers) end |
#put!(entry, url = entry.edit_url) ⇒ Object
PUT an updated version of an entry to the collection
101 102 103 |
# File 'lib/atom/collection.rb', line 101 def put!(entry, url = entry.edit_url) @http.put_atom_entry(entry, url) end |
#put_media!(data, content_type, slug = nil) ⇒ Object
PUT a media item to the collection
119 120 121 122 123 |
# File 'lib/atom/collection.rb', line 119 def put_media!(data, content_type, slug = nil) headers = {"Content-Type" => content_type} @http.put(url, data, headers) end |
#title ⇒ Object
50 51 52 |
# File 'lib/atom/collection.rb', line 50 def title @title or @feed.title end |