Class: Partigirb::Handlers::AtomHandler

Inherits:
XMLHandler show all
Defined in:
lib/partigirb/handlers/atom_handler.rb

Instance Method Summary collapse

Instance Method Details

#decode_response(body) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/partigirb/handlers/atom_handler.rb', line 4

def decode_response(body)
  return REXML::Document.new if body.blank?
  xml = REXML::Document.new(body.gsub(/>\s+</,'><'))
  
  if xml.root.name == 'feed'
    entries = xml.root.get_elements('entry')
    
    # Depending on whether we have one or more entries we return an PartigiStruct or an array of PartigiStruct
    if entries.size == 1
      load_recursive(entries.first)
    else
      entries.map{|e| load_recursive(e)}
    end
  else
    # We just parse as a common XML
    load_recursive(xml.root)
  end
end