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