Jump to content

Petfinder API - options on shelter.getPets


ang82

Recommended Posts

I've been banging my head against the keyboard trying to figure this out. This is the first time I've used PHP so I'm sure I'm just doing something wrong.

 

The API response that's relevant looks like this:

 

//returns a list of pet records

<xs:complexType name="petfinderPetRecordList">

  <xs:sequence>

    <xs:element name="pet" type="petfinderPetRecord" minOccurs="0"

                maxOccurs="unbounded"/>

  </xs:sequence>

</xs:complexType>

 

//pet record

<xs:complexType name="petfinderPetRecord">

  <xs:sequence>

    <xs:element name="id" type="petIdType"/>

    <xs:element name="shelterId" type="shelterIdType"/>

    <xs:element name="shelterPetId" type="xs:string" minOccurs="0"/>

    <xs:element name="name" type="xs:string"/>

    <xs:element name="animal" type="animalType"/>

    <xs:element name="breeds" type="petfinderBreedList"/>

    <xs:element name="mix">

      <xs:simpleType>

        <xs:restriction base="xs:string">

          <xs:enumeration value="yes"/>

          <xs:enumeration value="no"/>

        </xs:restriction>

      </xs:simpleType>

    </xs:element>

    <xs:element name="age" type="petAgeType"/>

    <xs:element name="sex" type="petGenderType"/>

    <xs:element name="size" type="petSizeType"/>

    <xs:element name="options">

      <xs:complexType>

        <xs:sequence>

          <xs:element name="option" type="petOptionType" minOccurs="0"

                      maxOccurs="unbounded"/>

        </xs:sequence>

      </xs:complexType>

    </xs:element>

    <xs:element name="description" type="xs:string"/>

    <xs:element name="lastUpdate" type="xs:dateTime"/>

    <xs:element name="status" type="petStatusType"/>

    <xs:element name="media">

      <xs:complexType>

        <xs:sequence>

          <xs:element name="photos" minOccurs="0">

            <xs:complexType>

              <xs:sequence>

                <xs:element name="photo" type="petPhotoType" minOccurs="0"

                      maxOccurs="15"/>

              </xs:sequence>

            </xs:complexType>

          </xs:element>

        </xs:sequence>

      </xs:complexType>

    </xs:element>

    <xs:element name="contact" type="petContactType" minOccurs="0"/>

  </xs:sequence>

</xs:complexType>

 

//options

<xs:simpleType name="petOptionType">

  <xs:restriction base="xs:string">

    <xs:enumeration value="specialNeeds"/>

    <xs:enumeration value="noDogs"/>

    <xs:enumeration value="noCats"/>

    <xs:enumeration value="noKids"/>

    <xs:enumeration value="noClaws"/>

    <xs:enumeration value="hasShots"/>

    <xs:enumeration value="housebroken"/>

    <xs:enumeration value="altered"/>

  </xs:restriction>

</xs:simpleType>

 

I want to get the options applicable for that pet.

Here's a code snip:

 

$xml = new SimpleXMLElement($xmlResponse);

$i=0;

foreach($xml->pets->pet as $pet)

{

$data[$i]['id'] = (string)$pet->id;

$data[$i]['name'] = (string)$pet->name;

 

$o=0;

foreach($pet->options->option as $option)

{

$data[$i]['option'][$o] = (string)$option;

$o++;

}

$i++;

}

 

...

 

Name: <?php echo $data[$i]['name'];?><br/> //This works

Number of options: <?php echo count($data[$i]['option']);?><br/> //Only returns 1 if the last option (altered) is true, otherwise returns 0.

 

The weird thing is that I can get the options no problem calling pet.get which returns a single petfinderPetRecord.

 

Code snip of that looks like:

$o=0;

foreach($xml->pet->options->option as $option)

{

$data['option'][$o] = (string)$option;

$o++;

}

 

...

 

Number of options: <?php echo count($data['option']);?><br/>

 

Anyway, sorry to bug, I just have no idea where else to turn. I'm sure it has to be me, because I've seen other sites display the options - such as http://www.petfinder.com/fpm/petlist/petlist.cgi?shelter=NS36&status=A&age=&limit=25&offset=0&animal=Dog&title=&style=10&ref=1I_sKmt3BFyiiTz (no dogs, no kids, etc)

 

In case it helps the API docs are here: http://www.petfinder.com/developers/api-docs

 

and the schemas are here: http://api.petfinder.com/schemas/0.9/petfinder.xsd

Link to comment
https://forums.phpfreaks.com/topic/220386-petfinder-api-options-on-sheltergetpets/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.