response.rb revision bed075ca5886f9d5a0010cd6da54c6f3b839ea09
module Oops
class Response
Element = Struct.new(:type, :code, :name, :description, :affects)
# Returns a list of Oops::Response::Element elements
def self.parse(data)
doc = Nokogiri::XML(data)
if doc.root.name == 'RDF'
raise Error, "got RDF response, expected XML"
end
doc.root.elements.map do |node|
Element.new \
node.name,
node.xpath("oops:Code").text,
node.xpath("oops:Name").text,
node.xpath("oops:Description").text,
node.xpath("//oops:AffectedElement").map(&:text)
end
end
end
end