2
0

Gbase.php 6.0 KB

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