2009-05-06 03:14:55 -04:00
|
|
|
require 'active_support/core_ext/hash/conversions'
|
|
|
|
|
2007-09-20 19:18:05 -04:00
|
|
|
module ActiveResource
|
|
|
|
module Formats
|
|
|
|
module XmlFormat
|
|
|
|
extend self
|
2008-08-29 21:19:18 -04:00
|
|
|
|
2007-09-20 19:18:05 -04:00
|
|
|
def extension
|
|
|
|
"xml"
|
|
|
|
end
|
2008-08-29 21:19:18 -04:00
|
|
|
|
2007-09-20 19:18:05 -04:00
|
|
|
def mime_type
|
|
|
|
"application/xml"
|
|
|
|
end
|
2008-08-29 21:19:18 -04:00
|
|
|
|
|
|
|
def encode(hash, options={})
|
|
|
|
hash.to_xml(options)
|
2007-09-20 19:18:05 -04:00
|
|
|
end
|
2008-08-29 21:19:18 -04:00
|
|
|
|
2007-09-20 19:18:05 -04:00
|
|
|
def decode(xml)
|
|
|
|
from_xml_data(Hash.from_xml(xml))
|
|
|
|
end
|
2008-08-29 21:19:18 -04:00
|
|
|
|
2007-09-20 19:18:05 -04:00
|
|
|
private
|
|
|
|
# Manipulate from_xml Hash, because xml_simple is not exactly what we
|
2008-05-25 07:29:00 -04:00
|
|
|
# want for Active Resource.
|
2007-09-20 19:18:05 -04:00
|
|
|
def from_xml_data(data)
|
|
|
|
if data.is_a?(Hash) && data.keys.size == 1
|
|
|
|
data.values.first
|
|
|
|
else
|
|
|
|
data
|
|
|
|
end
|
2008-08-29 21:19:18 -04:00
|
|
|
end
|
2007-09-20 19:18:05 -04:00
|
|
|
end
|
|
|
|
end
|
2008-08-29 21:19:18 -04:00
|
|
|
end
|