Pergunta

I am completely confounded by HTTParty's XML parsing of seemingly identical XML. I am making the same GET call (get function parameters) to a web service, but to a different resource (/channels/3/functions/58/ vs. /channels/6/functions/106/). I am using HTTParty to make the call. The problem is that it is interpreting the results differently and I cannot find any differences in the returned XML that would explain the difference.

Here is what is happening in my first call to /channels/3/functions/58/

XML response:

<functionsResult xmlns="http://www.w3.org/2005/Atom">
<function>
    <id>58</id>
    <name>API: movies</name>
    <type>trigger</type>
    <description></description>
    <tags></tags>
    <status>active</status>
    <parameters>
        <parameter name="movie_query" label="Movie Query" type="xsd:string" required="false" default=""/>
        <parameter name="critics-pick" label="Critics Pick" type="xsd:string" required="false" default=""/>
        <parameter name="thousand-best" label="Thousand Best" type="xsd:string" required="false" default=""/>
        <parameter name="dvds" label="Dvds" type="xsd:string" required="false" default=""/>
        <parameter name="reviewer" label="Reviewer" type="xsd:string" required="false" default=""/>
        <parameter name="publication-date" label="Publication Date" type="xsd:date" required="false" default=""/>
        <parameter name="opening-date" label="Opening Date" type="xsd:date"      required="false" default=""/>
    </parameters>
    <link rel="self" title="This Function" method="GET" type="application/xml" href="/channels/3/functions/58/"/>
    <link rel="related" title="Function Channel" method="GET" type="application/xml" href="/channels/3/"/>
</function>
</functionsResult>

The hash that HTTParty gives me back is fine and looks like this (debug output):

functionsResult:
  function:
    id: '58'
    name: ! 'API: movies'
    type: trigger
    description: !!null 
    tags: !!null 
    status: active
    parameters:
      parameter:
      - name: movie_query
        label: Movie Query
        type: xsd:string
        required: 'false'
        default: ''
      - name: critics-pick
        label: Critics Pick
        type: xsd:string
        required: 'false'
        default: ''
      - name: thousand-best
        label: Thousand Best
        type: xsd:string
        required: 'false'
        default: ''
      - name: dvds
        label: Dvds
        type: xsd:string
        required: 'false'
        default: ''
      - name: reviewer
        label: Reviewer
        type: xsd:string
        required: 'false'
        default: ''
      - name: publication-date
        label: Publication Date
        type: xsd:date
        required: 'false'
        default: ''
      - name: opening-date
        label: Opening Date
        type: xsd:date
        required: 'false'
        default: ''
    link:
    - rel: self
      title: This Function
      method: GET
      type: application/xml
      href: /channels/3/functions/58/
    - rel: related
      title: Function Channel
      method: GET
      type: application/xml
      href: /channels/3/

The XML for the other resource is almost identical in its structure:

<functionsResult xmlns="http://www.w3.org/2005/Atom">
<function>
    <id>106</id>
    <name>search</name>
    <type>trigger</type>
    <description/>
    <tags/>
    <status>active</status>
    <parameters>
        <parameter name="callback" label="Callback" type="string" required="false" default=""/>
        <parameter name="geocode" label="Geocode" type="string" required="false" default=""/>
        <parameter name="lang" label="Lang" type="string" required="false" default=""/>
        <parameter name="locale" label="Locale" type="string" required="false" default=""/>
        <parameter name="page" label="Page" type="string" required="false" default=""/>
        <parameter name="result_type" label="Result Type" type="string" required="false" default=""/>
        <parameter name="rpp" label="Rpp" type="string" required="false" default=""/>
        <parameter name="show_user" label="Show User" type="string" required="false" default=""/>
        <parameter name="until" label="Until" type="string" required="false" default=""/>
        <parameter name="since_id" label="Since Id" type="string" required="false" default=""/>
        <parameter name="include_entities" label="Include Entities" type="string" required="false" default=""/>
    </parameters>
    <link rel="self" title="This Function" method="GET" type="application/xml" href="/channels/6/functions/106/"/>
    <link rel="related" title="Function Channel" method="GET" type="application/xml" href="/channels/6/"/>
</function>
</functionsResult>

However the hash that gets returned returns an empty array for 'Parameters' (debug output)!

functionsResult:
  function:
    id: '106'
    name: ! 'search'
    type: trigger
    description: !!null 
    tags: !!null 
    status: active
    parameters:
      parameter:
      - ''
      - ''
      - ''
      - ''
      - ''
      - ''
      - ''
      - ''
      - ''
      - ''
      - ''
    link:
    - rel: self
      title: This Function
      method: GET
      type: application/xml
      href: /channels/6/functions/106/
    - rel: related
      title: Function Channel
      method: GET
      type: application/xml
      href: /channels/6/

The only thing I can think of is that the parameters in the second GET call have underscores in some attributes??? That seems an unlikely explanation. Any help is much appreciated.

Foi útil?

Solução

i assume that it might be a problem with xml namespaces. the first response seems to have a valid type attribute, while the latter misses the xsd:string namespace.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top