Books.php 6.1 KB

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