Extra pagination keys included in XML responses from API?

Leigh Caplan's Avatar

Leigh Caplan

29 Jan, 2013 02:40 AM

Hi guys,

I'm not sure if this is a recent change, or if something has changed on my end, but I'm having issues parsing XML responses using the Lighthouse gem. I've tracked the issue down to the fact that the tickets now take the following form:

<?xml version="1.0" encoding="UTF-8"?>`
<tickets type="array">
  <total_pages>1</total_pages>
  <current_page>1</current_page>
  <ticket>
  ...
  </ticket>
</tickets>

It seems that ActiveSupport parsing (Hash.to_xml) chokes on the extra keys (it's expecting <ticket/> to be the only element type inside <tickets/>. Sometimes it will parse correctly, but it fails intermittently because I'm running 1.8.7 still, and the hashes that get slurped out of the raw XML have keys in random order.

So I guess I'd like to know a few things from you guys:
1. Is including the pagination information in the XML a new thing?
2. Is it essential that it be left in?
3. Is anyone else running into this issue, or am I just Doing It Wrong™?

If it's not going to change, I'll probably just end up updating the Lighthouse gem to use your JSON API, because XML sucks anyway :)

Thanks for your help!
Leigh

  1. Support Staff 1 Posted by Tiger Team on 29 Jan, 2013 03:57 AM

    Tiger Team's Avatar
    1. The pagination keys are not a new thing
    2. It's important because people complain about missing tickets in their list when really it's just on page 2.
    3. It's probably related to your recent upgrade because of the rails xml/yaml security thing.

    Try this: (sigh)

    class Hash
      def self.from_xml(xml)
        xml_parsed = ActiveSupport::XmlMini.parse(xml)
        if xml_parsed["tickets"]
          xml_parsed["tickets"].delete "current_page"
          xml_parsed["tickets"].delete "total_pages"
        end
        typecast_xml_value(unrename_keys(xml_parsed))
      end
    end
    
  2. 2 Posted by Leigh Caplan on 29 Jan, 2013 06:03 PM

    Leigh Caplan's Avatar

    Thanks for getting back so quickly Courtenay. That's quite an ugly hack, but it'll work for the time being. In the medium term, I'll update the Lighthouse gem to use JSON.

  3. brandi closed this discussion on 30 Jan, 2013 07:49 PM.

Discussions are closed to public comments.
If you need help with Lighthouse please start a new discussion.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac