2

Using Rails and ActiveResource i am getting non-rails style of XML response form third-party API. Object which i like to map is basically wrapped in prestahop element. What should i override to get rid of that element to map the object correctly?

<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">
<order>
    <id></id> 
Jakub Kuchar
  • 1,665
  • 2
  • 23
  • 39

2 Answers2

3

You should use custom formatter for your needs, something like this may be good solution.

class PrestaXMLFormatter
  include ActiveResource::Formats::XmlFormat

  def decode(xml)
    ActiveResource::Formats::XmlFormat.decode(xml)['prestashop']
  end
end

class Order < ActiveResource::Base
  self.format = PrestaXMLFormatter.new
end  
Fivell
  • 11,829
  • 3
  • 61
  • 99
0

I have a few external services where I have to talk non-rails style api. I'm using combination of Savon gem to make SOAP requests and parse SOAP responses, and Roxml gem to map actual XML into ruby objects.

konung
  • 6,908
  • 6
  • 54
  • 79