Books.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Gdata
  17. * @subpackage Books
  18. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. require_once 'Zend/Gdata.php';
  23. /**
  24. * @see Zend_Gdata_DublinCore
  25. */
  26. require_once 'Zend/Gdata/DublinCore.php';
  27. /**
  28. * @see Zend_Gdata_Books_CollectionEntry
  29. */
  30. require_once 'Zend/Gdata/Books/CollectionEntry.php';
  31. /**
  32. * @see Zend_Gdata_Books_CollectionFeed
  33. */
  34. require_once 'Zend/Gdata/Books/CollectionFeed.php';
  35. /**
  36. * @see Zend_Gdata_Books_VolumeEntry
  37. */
  38. require_once 'Zend/Gdata/Books/VolumeEntry.php';
  39. /**
  40. * @see Zend_Gdata_Books_VolumeFeed
  41. */
  42. require_once 'Zend/Gdata/Books/VolumeFeed.php';
  43. /**
  44. * Service class for interacting with the Books service
  45. *
  46. * @category Zend
  47. * @package Zend_Gdata
  48. * @subpackage Books
  49. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  50. * @license http://framework.zend.com/license/new-bsd New BSD License
  51. */
  52. class Zend_Gdata_Books extends Zend_Gdata
  53. {
  54. const VOLUME_FEED_URI = 'http://books.google.com/books/feeds/volumes';
  55. const MY_LIBRARY_FEED_URI = 'http://books.google.com/books/feeds/users/me/collections/library/volumes';
  56. const MY_ANNOTATION_FEED_URI = 'http://books.google.com/books/feeds/users/me/volumes';
  57. const AUTH_SERVICE_NAME = 'print';
  58. /**
  59. * Namespaces used for Zend_Gdata_Books
  60. *
  61. * @var array
  62. */
  63. public static $namespaces = array(
  64. array('gbs', 'http://schemas.google.com/books/2008', 1, 0),
  65. array('dc', 'http://purl.org/dc/terms', 1, 0)
  66. );
  67. /**
  68. * Create Zend_Gdata_Books object
  69. *
  70. * @param Zend_Http_Client $client (optional) The HTTP client to use when
  71. * when communicating with the Google servers.
  72. * @param string $applicationId The identity of the app in the form of Company-AppName-Version
  73. */
  74. public function __construct($client = null, $applicationId = 'MyCompany-MyApp-1.0')
  75. {
  76. $this->registerPackage('Zend_Gdata_Books');
  77. $this->registerPackage('Zend_Gdata_Books_Extension');
  78. parent::__construct($client, $applicationId);
  79. $this->_httpClient->setParameterPost('service', self::AUTH_SERVICE_NAME);
  80. }
  81. /**
  82. * Retrieves a feed of volumes.
  83. *
  84. * @param Zend_Gdata_Query|string|null $location (optional) The URL to
  85. * query or a Zend_Gdata_Query object from which a URL can be
  86. * determined.
  87. * @return Zend_Gdata_Books_VolumeFeed The feed of volumes found at the
  88. * specified URL.
  89. */
  90. public function getVolumeFeed($location = null)
  91. {
  92. if ($location == null) {
  93. $uri = self::VOLUME_FEED_URI;
  94. } else if ($location instanceof Zend_Gdata_Query) {
  95. $uri = $location->getQueryUrl();
  96. } else {
  97. $uri = $location;
  98. }
  99. return parent::getFeed($uri, 'Zend_Gdata_Books_VolumeFeed');
  100. }
  101. /**
  102. * Retrieves a specific volume entry.
  103. *
  104. * @param string|null $volumeId The volumeId of interest.
  105. * @param Zend_Gdata_Query|string|null $location (optional) The URL to
  106. * query or a Zend_Gdata_Query object from which a URL can be
  107. * determined.
  108. * @return Zend_Gdata_Books_VolumeEntry The feed of volumes found at the
  109. * specified URL.
  110. */
  111. public function getVolumeEntry($volumeId = null, $location = null)
  112. {
  113. if ($volumeId !== null) {
  114. $uri = self::VOLUME_FEED_URI . "/" . $volumeId;
  115. } else if ($location instanceof Zend_Gdata_Query) {
  116. $uri = $location->getQueryUrl();
  117. } else {
  118. $uri = $location;
  119. }
  120. return parent::getEntry($uri, 'Zend_Gdata_Books_VolumeEntry');
  121. }
  122. /**
  123. * Retrieves a feed of volumes, by default the User library feed.
  124. *
  125. * @param Zend_Gdata_Query|string|null $location (optional) The URL to
  126. * query.
  127. * @return Zend_Gdata_Books_VolumeFeed The feed of volumes found at the
  128. * specified URL.
  129. */
  130. public function getUserLibraryFeed($location = null)
  131. {
  132. if ($location == null) {
  133. $uri = self::MY_LIBRARY_FEED_URI;
  134. } else {
  135. $uri = $location;
  136. }
  137. return parent::getFeed($uri, 'Zend_Gdata_Books_VolumeFeed');
  138. }
  139. /**
  140. * Retrieves a feed of volumes, by default the User annotation feed
  141. *
  142. * @param Zend_Gdata_Query|string|null $location (optional) The URL to
  143. * query.
  144. * @return Zend_Gdata_Books_VolumeFeed The feed of volumes found at the
  145. * specified URL.
  146. */
  147. public function getUserAnnotationFeed($location = null)
  148. {
  149. if ($location == null) {
  150. $uri = self::MY_ANNOTATION_FEED_URI;
  151. } else {
  152. $uri = $location;
  153. }
  154. return parent::getFeed($uri, 'Zend_Gdata_Books_VolumeFeed');
  155. }
  156. /**
  157. * Insert a Volume / Annotation
  158. *
  159. * @param Zend_Gdata_Books_VolumeEntry $entry
  160. * @param Zend_Gdata_Query|string|null $location (optional) The URL to
  161. * query
  162. * @return Zend_Gdata_Books_VolumeEntry The inserted volume entry.
  163. */
  164. public function insertVolume($entry, $location = null)
  165. {
  166. if ($location == null) {
  167. $uri = self::MY_LIBRARY_FEED_URI;
  168. } else {
  169. $uri = $location;
  170. }
  171. return parent::insertEntry(
  172. $entry, $uri, 'Zend_Gdata_Books_VolumeEntry');
  173. }
  174. /**
  175. * Delete a Volume
  176. *
  177. * @param Zend_Gdata_Books_VolumeEntry $entry
  178. * @return void
  179. */
  180. public function deleteVolume($entry)
  181. {
  182. $entry->delete();
  183. }
  184. }