Example #1
0
 /**
  * Converts a response into a native data type.
  *
  * @param array $array the raw data
  * @param boolean $strictMode whether to throw spec errors
  * @return osapiPerson
  */
 public static function convertArray($array, $strictMode = true)
 {
     $instance = new osapiAlbum();
     $defaults = get_class_vars('osapiAlbum');
     if ($strictMode && sizeof($defaults != sizeof($array))) {
         throw new osapiException("Unexpected fields in people response" . print_r($array, true));
     }
     foreach ($array as $key => $value) {
         $instance->setField($key, $value);
     }
     return self::trimResponse($instance);
 }
    $batch->add($osapi->albums->getSupportedFields(), 'supported_fields');
    // Request the albums of the current user.
    $user_params = array('userId' => '@me', 'groupId' => '@self', 'count' => 2, 'fields' => '@all');
    $batch->add($osapi->albums->get($user_params), 'get_albums');
    // Fetch album by id
    $user_params = array('userId' => '@me', 'groupId' => '@self', 'albumId' => 'myspace.com.album.81886', 'fields' => '@all');
    $batch->add($osapi->albums->get($user_params), 'get_album_for_id');
    // Create album
    $album = new osapiAlbum();
    $album->setField('caption', 'new album caption');
    $album->setField('description', 'new album description');
    $user_params = array('userId' => '@me', 'groupId' => '@self', 'album' => $album);
    // Commented out so that everyone in the world doesn't creat an album =).
    //$batch->add($osapi->albums->create($user_params), 'create_album');
    // Update album
    $album = new osapiAlbum();
    $album->setField('caption', 'caption ' . time());
    $album->setField('description', 'description ' . time());
    $user_params = array('userId' => '@me', 'groupId' => '@self', 'album' => $album, 'albumId' => 'myspace.com.album.81886');
    $batch->add($osapi->albums->update($user_params), 'update_album');
    // Send the batch request.
    $result = $batch->execute();
    ?>

<h1>Albums Example</h1>
<h2>Request:</h2>
<p>This sample fetched supported fields. The albums for the current user. Then gets album details for a specific album. Create a new album. Then update an existing album.</p>

<?php 
    require_once 'response_block.php';
}