Gbase.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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 Gbase
  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. /**
  22. * @see Zend_Gdata
  23. */
  24. require_once 'Zend/Gdata.php';
  25. /**
  26. * @see Zend_Gdata_Gbase_ItemFeed
  27. */
  28. require_once 'Zend/Gdata/Gbase/ItemFeed.php';
  29. /**
  30. * @see Zend_Gdata_Gbase_ItemEntry
  31. */
  32. require_once 'Zend/Gdata/Gbase/ItemEntry.php';
  33. /**
  34. * @see Zend_Gdata_Gbase_SnippetEntry
  35. */
  36. require_once 'Zend/Gdata/Gbase/SnippetEntry.php';
  37. /**
  38. * @see Zend_Gdata_Gbase_SnippetFeed
  39. */
  40. require_once 'Zend/Gdata/Gbase/SnippetFeed.php';
  41. /**
  42. * Service class for interacting with the Google Base data API
  43. *
  44. * @link http://code.google.com/apis/base
  45. *
  46. * @category Zend
  47. * @package Zend_Gdata
  48. * @subpackage Gbase
  49. * @copyright Copyright (c) 2005-2008 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_Gbase extends Zend_Gdata
  53. {
  54. /**
  55. * Path to the customer items feeds on the Google Base server.
  56. */
  57. const GBASE_ITEM_FEED_URI = 'http://www.google.com/base/feeds/items';
  58. /**
  59. * Path to the snippets feeds on the Google Base server.
  60. */
  61. const GBASE_SNIPPET_FEED_URI = 'http://www.google.com/base/feeds/snippets';
  62. /**
  63. * Authentication service name for Google Base
  64. */
  65. const AUTH_SERVICE_NAME = 'gbase';
  66. /**
  67. * The default URI for POST methods
  68. *
  69. * @var string
  70. */
  71. protected $_defaultPostUri = self::GBASE_ITEM_FEED_URI;
  72. /**
  73. * Namespaces used for Zend_Gdata_Gbase
  74. *
  75. * @var array
  76. */
  77. public static $namespaces = array(
  78. array('g', 'http://base.google.com/ns/1.0', 1, 0),
  79. array('batch', 'http://schemas.google.com/gdata/batch', 1, 0)
  80. );
  81. /**
  82. * Create Zend_Gdata_Gbase object
  83. *
  84. * @param Zend_Http_Client $client (optional) The HTTP client to use when
  85. * when communicating with the Google Apps servers.
  86. * @param string $applicationId The identity of the app in the form of Company-AppName-Version
  87. */
  88. public function __construct($client = null, $applicationId = 'MyCompany-MyApp-1.0')
  89. {
  90. $this->registerPackage('Zend_Gdata_Gbase');
  91. $this->registerPackage('Zend_Gdata_Gbase_Extension');
  92. parent::__construct($client, $applicationId);
  93. $this->_httpClient->setParameterPost('service', self::AUTH_SERVICE_NAME);
  94. }
  95. /**
  96. * Retreive feed object
  97. *
  98. * @param mixed $location The location for the feed, as a URL or Query
  99. * @return Zend_Gdata_Gbase_ItemFeed
  100. */
  101. public function getGbaseItemFeed($location = null)
  102. {
  103. if ($location === null) {
  104. $uri = self::GBASE_ITEM_FEED_URI;
  105. } else if ($location instanceof Zend_Gdata_Query) {
  106. $uri = $location->getQueryUrl();
  107. } else {
  108. $uri = $location;
  109. }
  110. return parent::getFeed($uri, 'Zend_Gdata_Gbase_ItemFeed');
  111. }
  112. /**
  113. * Retreive entry object
  114. *
  115. * @param mixed $location The location for the feed, as a URL or Query
  116. * @return Zend_Gdata_Gbase_ItemEntry
  117. */
  118. public function getGbaseItemEntry($location = null)
  119. {
  120. if ($location === null) {
  121. require_once 'Zend/Gdata/App/InvalidArgumentException.php';
  122. throw new Zend_Gdata_App_InvalidArgumentException(
  123. 'Location must not be null');
  124. } else if ($location instanceof Zend_Gdata_Query) {
  125. $uri = $location->getQueryUrl();
  126. } else {
  127. $uri = $location;
  128. }
  129. return parent::getEntry($uri, 'Zend_Gdata_Gbase_ItemEntry');
  130. }
  131. /**
  132. * Insert an entry
  133. *
  134. * @param Zend_Gdata_Gbase_ItemEntry $entry The Base entry to upload
  135. * @param boolean $dryRun Flag for the 'dry-run' parameter
  136. * @return Zend_Gdata_Gbase_ItemFeed
  137. */
  138. public function insertGbaseItem($entry, $dryRun = false)
  139. {
  140. if ($dryRun == false) {
  141. $uri = $this->_defaultPostUri;
  142. } else {
  143. $uri = $this->_defaultPostUri . '?dry-run=true';
  144. }
  145. $newitem = $this->insertEntry($entry, $uri, 'Zend_Gdata_Gbase_ItemEntry');
  146. return $newitem;
  147. }
  148. /**
  149. * Update an entry
  150. *
  151. * @param Zend_Gdata_Gbase_ItemEntry $entry The Base entry to be updated
  152. * @param boolean $dryRun Flag for the 'dry-run' parameter
  153. * @return Zend_Gdata_Gbase_ItemEntry
  154. */
  155. public function updateGbaseItem($entry, $dryRun = false)
  156. {
  157. $returnedEntry = $entry->save($dryRun);
  158. return $returnedEntry;
  159. }
  160. /**
  161. * Delete an entry
  162. *
  163. * @param Zend_Gdata_Gbase_ItemEntry $entry The Base entry to remove
  164. * @param boolean $dryRun Flag for the 'dry-run' parameter
  165. * @return Zend_Gdata_Gbase_ItemFeed
  166. */
  167. public function deleteGbaseItem($entry, $dryRun = false)
  168. {
  169. $entry->delete($dryRun);
  170. return $this;
  171. }
  172. /**
  173. * Retrieve feed object
  174. *
  175. * @param mixed $location The location for the feed, as a URL or Query
  176. * @return Zend_Gdata_Gbase_SnippetFeed
  177. */
  178. public function getGbaseSnippetFeed($location = null)
  179. {
  180. if ($location === null) {
  181. $uri = self::GBASE_SNIPPET_FEED_URI;
  182. } else if ($location instanceof Zend_Gdata_Query) {
  183. $uri = $location->getQueryUrl();
  184. } else {
  185. $uri = $location;
  186. }
  187. return parent::getFeed($uri, 'Zend_Gdata_Gbase_SnippetFeed');
  188. }
  189. }