File indexing completed on 2024-05-12 06:02:40

0001 <?php
0002 
0003 /**
0004  * Zend Framework
0005  *
0006  * LICENSE
0007  *
0008  * This source file is subject to the new BSD license that is bundled
0009  * with this package in the file LICENSE.txt.
0010  * It is also available through the world-wide-web at this URL:
0011  * http://framework.zend.com/license/new-bsd
0012  * If you did not receive a copy of the license and are unable to
0013  * obtain it through the world-wide-web, please send an email
0014  * to license@zend.com so we can send you a copy immediately.
0015  *
0016  * @category   Zend
0017  * @package    Zend_Gdata
0018  * @subpackage Books
0019  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0020  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0021  * @version    $Id$
0022  */
0023 
0024 /**
0025  * @see Zend_Gdata
0026  */
0027 // require_once 'Zend/Gdata.php';
0028 
0029 /**
0030  * @see Zend_Gdata_DublinCore
0031  */
0032 // require_once 'Zend/Gdata/DublinCore.php';
0033 
0034 /**
0035  * @see Zend_Gdata_Books_CollectionEntry
0036  */
0037 // require_once 'Zend/Gdata/Books/CollectionEntry.php';
0038 
0039 /**
0040  * @see Zend_Gdata_Books_CollectionFeed
0041  */
0042 // require_once 'Zend/Gdata/Books/CollectionFeed.php';
0043 
0044 /**
0045  * @see Zend_Gdata_Books_VolumeEntry
0046  */
0047 // require_once 'Zend/Gdata/Books/VolumeEntry.php';
0048 
0049 /**
0050  * @see Zend_Gdata_Books_VolumeFeed
0051  */
0052 // require_once 'Zend/Gdata/Books/VolumeFeed.php';
0053 
0054 /**
0055  * Service class for interacting with the Books service
0056  *
0057  * @category   Zend
0058  * @package    Zend_Gdata
0059  * @subpackage Books
0060  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0061  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0062  */
0063 class Zend_Gdata_Books extends Zend_Gdata
0064 {
0065     const VOLUME_FEED_URI = 'https://books.google.com/books/feeds/volumes';
0066     const MY_LIBRARY_FEED_URI = 'https://books.google.com/books/feeds/users/me/collections/library/volumes';
0067     const MY_ANNOTATION_FEED_URI = 'https://books.google.com/books/feeds/users/me/volumes';
0068     const AUTH_SERVICE_NAME = 'print';
0069 
0070     /**
0071      * Namespaces used for Zend_Gdata_Books
0072      *
0073      * @var array
0074      */
0075     public static $namespaces = array(
0076         array('gbs', 'http://schemas.google.com/books/2008', 1, 0),
0077         array('dc', 'http://purl.org/dc/terms', 1, 0)
0078     );
0079 
0080     /**
0081      * Create Zend_Gdata_Books object
0082      *
0083      * @param Zend_Http_Client $client (optional) The HTTP client to use when
0084      *          when communicating with the Google servers.
0085      * @param string $applicationId The identity of the app in the form of Company-AppName-Version
0086      */
0087     public function __construct($client = null, $applicationId = 'MyCompany-MyApp-1.0')
0088     {
0089         $this->registerPackage('Zend_Gdata_Books');
0090         $this->registerPackage('Zend_Gdata_Books_Extension');
0091         parent::__construct($client, $applicationId);
0092         $this->_httpClient->setParameterPost('service', self::AUTH_SERVICE_NAME);
0093      }
0094 
0095     /**
0096      * Retrieves a feed of volumes.
0097      *
0098      * @param Zend_Gdata_Query|string|null $location (optional) The URL to
0099      *        query or a Zend_Gdata_Query object from which a URL can be
0100      *        determined.
0101      * @return Zend_Gdata_Books_VolumeFeed The feed of volumes found at the
0102      *         specified URL.
0103      */
0104     public function getVolumeFeed($location = null)
0105     {
0106         if ($location == null) {
0107             $uri = self::VOLUME_FEED_URI;
0108         } else if ($location instanceof Zend_Gdata_Query) {
0109             $uri = $location->getQueryUrl();
0110         } else {
0111             $uri = $location;
0112         }
0113         return parent::getFeed($uri, 'Zend_Gdata_Books_VolumeFeed');
0114     }
0115 
0116     /**
0117      * Retrieves a specific volume entry.
0118      *
0119      * @param string|null $volumeId The volumeId of interest.
0120      * @param Zend_Gdata_Query|string|null $location (optional) The URL to
0121      *        query or a Zend_Gdata_Query object from which a URL can be
0122      *        determined.
0123      * @return Zend_Gdata_Books_VolumeEntry The feed of volumes found at the
0124      *         specified URL.
0125      */
0126     public function getVolumeEntry($volumeId = null, $location = null)
0127     {
0128         if ($volumeId !== null) {
0129             $uri = self::VOLUME_FEED_URI . "/" . $volumeId;
0130         } else if ($location instanceof Zend_Gdata_Query) {
0131             $uri = $location->getQueryUrl();
0132         } else {
0133             $uri = $location;
0134         }
0135         return parent::getEntry($uri, 'Zend_Gdata_Books_VolumeEntry');
0136     }
0137 
0138     /**
0139      * Retrieves a feed of volumes, by default the User library feed.
0140      *
0141      * @param Zend_Gdata_Query|string|null $location (optional) The URL to
0142      *        query.
0143      * @return Zend_Gdata_Books_VolumeFeed The feed of volumes found at the
0144      *         specified URL.
0145      */
0146     public function getUserLibraryFeed($location = null)
0147     {
0148         if ($location == null) {
0149             $uri = self::MY_LIBRARY_FEED_URI;
0150         } else {
0151             $uri = $location;
0152         }
0153         return parent::getFeed($uri, 'Zend_Gdata_Books_VolumeFeed');
0154     }
0155 
0156     /**
0157      * Retrieves a feed of volumes, by default the User annotation feed
0158      *
0159      * @param Zend_Gdata_Query|string|null $location (optional) The URL to
0160      *        query.
0161      * @return Zend_Gdata_Books_VolumeFeed The feed of volumes found at the
0162      *         specified URL.
0163      */
0164     public function getUserAnnotationFeed($location = null)
0165     {
0166         if ($location == null) {
0167             $uri = self::MY_ANNOTATION_FEED_URI;
0168         } else {
0169             $uri = $location;
0170         }
0171         return parent::getFeed($uri, 'Zend_Gdata_Books_VolumeFeed');
0172     }
0173 
0174     /**
0175      * Insert a Volume / Annotation
0176      *
0177      * @param Zend_Gdata_Books_VolumeEntry $entry
0178      * @param Zend_Gdata_Query|string|null $location (optional) The URL to
0179      *        query
0180      * @return Zend_Gdata_Books_VolumeEntry The inserted volume entry.
0181      */
0182     public function insertVolume($entry, $location = null)
0183     {
0184         if ($location == null) {
0185             $uri = self::MY_LIBRARY_FEED_URI;
0186         } else {
0187             $uri = $location;
0188         }
0189         return parent::insertEntry(
0190             $entry, $uri, 'Zend_Gdata_Books_VolumeEntry');
0191     }
0192 
0193     /**
0194      * Delete a Volume
0195      *
0196      * @param Zend_Gdata_Books_VolumeEntry $entry
0197      * @return void
0198      */
0199     public function deleteVolume($entry)
0200     {
0201         $entry->delete();
0202     }
0203 
0204 }