Books.php 6.1 KB

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