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.
19 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
20 * @license http://framework.zend.com/license/new-bsd New BSD License
27 require_once 'Zend/Gdata/App.php';
30 * Provides functionality to interact with Google data APIs
31 * Subclasses exist to implement service-specific features
33 * As the Google data API protocol is based upon the Atom Publishing Protocol
34 * (APP), Gdata functionality extends the appropriate Zend_Gdata_App classes
36 * @link http://code.google.com/apis/gdata/overview.html
41 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
42 * @license http://framework.zend.com/license/new-bsd New BSD License
44 class Zend_Gdata
extends Zend_Gdata_App
48 * Service name for use with Google's authentication mechanisms
52 const AUTH_SERVICE_NAME
= 'xapi';
55 * Default URI to which to POST.
59 protected $_defaultPostUri = null;
62 * Packages to search for classes when using magic __call method, in order.
66 protected $_registeredPackages = array(
68 'Zend_Gdata_Extension',
70 'Zend_Gdata_App_Extension',
74 * Namespaces used for Gdata data
78 public static $namespaces = array(
79 array('gd', 'http://schemas.google.com/g/2005', 1, 0),
80 array('openSearch', 'http://a9.com/-/spec/opensearchrss/1.0/', 1, 0),
81 array('openSearch', 'http://a9.com/-/spec/opensearch/1.1/', 2, 0),
82 array('rss', 'http://blogs.law.harvard.edu/tech/rss', 1, 0)
86 * Client object used to communicate
88 * @var Zend_Gdata_HttpClient
90 protected $_httpClient;
93 * Client object used to communicate in static context
95 * @var Zend_Gdata_HttpClient
97 protected static $_staticHttpClient = null;
100 * Create Gdata object
102 * @param Zend_Http_Client $client
103 * @param string $applicationId The identity of the app in the form of
104 * Company-AppName-Version
106 public function __construct($client = null, $applicationId = 'MyCompany-MyApp-1.0')
108 parent
::__construct($client, $applicationId);
112 * Imports a feed located at $uri.
115 * @param Zend_Http_Client $client The client used for communication
116 * @param string $className The class which is used as the return type
117 * @throws Zend_Gdata_App_Exception
118 * @return string|Zend_Gdata_App_Feed Returns string only if the object
119 * mapping has been disabled explicitly
120 * by passing false to the
121 * useObjectMapping() function.
123 public static function import($uri, $client = null,
124 $className='Zend_Gdata_Feed')
126 $app = new Zend_Gdata($client);
127 $requestData = $app->decodeRequest('GET', $uri);
128 $response = $app->performHttpRequest($requestData['method'], $requestData['url']);
130 $feedContent = $response->getBody();
132 $feed = self
::importString($feedContent, $className);
133 if ($client != null) {
134 $feed->setHttpClient($client);
140 * Retrieve feed as string or object
142 * @param mixed $location The location as string or Zend_Gdata_Query
143 * @param string $className The class type to use for returning the feed
144 * @throws Zend_Gdata_App_InvalidArgumentException
145 * @return string|Zend_Gdata_App_Feed Returns string only if the object
146 * mapping has been disabled explicitly
147 * by passing false to the
148 * useObjectMapping() function.
150 public function getFeed($location, $className='Zend_Gdata_Feed')
152 if (is_string($location)) {
154 } elseif ($location instanceof Zend_Gdata_Query
) {
155 $uri = $location->getQueryUrl();
157 require_once 'Zend/Gdata/App/InvalidArgumentException.php';
158 throw new Zend_Gdata_App_InvalidArgumentException(
159 'You must specify the location as either a string URI ' .
160 'or a child of Zend_Gdata_Query');
162 return parent
::getFeed($uri, $className);
166 * Retrieve entry as string or object
168 * @param mixed $location The location as string or Zend_Gdata_Query
169 * @throws Zend_Gdata_App_InvalidArgumentException
170 * @return string|Zend_Gdata_App_Entry Returns string only if the object
171 * mapping has been disabled explicitly
172 * by passing false to the
173 * useObjectMapping() function.
175 public function getEntry($location, $className='Zend_Gdata_Entry')
177 if (is_string($location)) {
179 } elseif ($location instanceof Zend_Gdata_Query
) {
180 $uri = $location->getQueryUrl();
182 require_once 'Zend/Gdata/App/InvalidArgumentException.php';
183 throw new Zend_Gdata_App_InvalidArgumentException(
184 'You must specify the location as either a string URI ' .
185 'or a child of Zend_Gdata_Query');
187 return parent
::getEntry($uri, $className);
191 * Performs a HTTP request using the specified method.
193 * Overrides the definition in the parent (Zend_Gdata_App)
194 * and uses the Zend_Gdata_HttpClient functionality
195 * to filter the HTTP requests and responses.
197 * @param string $method The HTTP method for the request -
198 * 'GET', 'POST', 'PUT', 'DELETE'
199 * @param string $url The URL to which this request is being performed,
200 * or null if found in $data
201 * @param array $headers An associative array of HTTP headers
203 * @param string $body The body of the HTTP request
204 * @param string $contentType The value for the content type of the
206 * @param int $remainingRedirects Number of redirects to follow
207 * if requests results in one
208 * @return Zend_Http_Response The response object
210 public function performHttpRequest($method, $url, $headers = array(), $body = null, $contentType = null, $remainingRedirects = null)
212 if ($this->_httpClient
instanceof Zend_Gdata_HttpClient
) {
213 $filterResult = $this->_httpClient
->filterHttpRequest($method, $url, $headers, $body, $contentType);
214 $method = $filterResult['method'];
215 $url = $filterResult['url'];
216 $body = $filterResult['body'];
217 $headers = $filterResult['headers'];
218 $contentType = $filterResult['contentType'];
219 return $this->_httpClient
->filterHttpResponse(parent
::performHttpRequest($method, $url, $headers, $body, $contentType, $remainingRedirects));
221 return parent
::performHttpRequest($method, $url, $headers, $body, $contentType, $remainingRedirects);
226 * Determines whether service object is authenticated.
228 * @return boolean True if service object is authenticated, false otherwise.
230 public function isAuthenticated()
232 $client = parent
::getHttpClient();
233 if ($client->getClientLoginToken() ||
234 $client->getAuthSubToken()) {