[DOCS] fixed code comment in one programlisting
[zend/radio.git] / library / Zend / Gdata.php
blob0445c6a5f14e7346f9cb14aec62a945c73c8255b
1 <?php
3 /**
4 * Zend Framework
6 * LICENSE
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.
16 * @category Zend
17 * @package Zend_Gdata
18 * @subpackage Gdata
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
21 * @version $Id$
24 /**
25 * Zend_Gdata_App
27 require_once 'Zend/Gdata/App.php';
29 /**
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
38 * @category Zend
39 * @package Zend_Gdata
40 * @subpackage Gdata
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
47 /**
48 * Service name for use with Google's authentication mechanisms
50 * @var string
52 const AUTH_SERVICE_NAME = 'xapi';
54 /**
55 * Default URI to which to POST.
57 * @var string
59 protected $_defaultPostUri = null;
61 /**
62 * Packages to search for classes when using magic __call method, in order.
64 * @var array
66 protected $_registeredPackages = array(
67 'Zend_Gdata_Kind',
68 'Zend_Gdata_Extension',
69 'Zend_Gdata',
70 'Zend_Gdata_App_Extension',
71 'Zend_Gdata_App');
73 /**
74 * Namespaces used for Gdata data
76 * @var array
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)
85 /**
86 * Client object used to communicate
88 * @var Zend_Gdata_HttpClient
90 protected $_httpClient;
92 /**
93 * Client object used to communicate in static context
95 * @var Zend_Gdata_HttpClient
97 protected static $_staticHttpClient = null;
99 /**
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.
114 * @param string $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);
136 return $feed;
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)) {
153 $uri = $location;
154 } elseif ($location instanceof Zend_Gdata_Query) {
155 $uri = $location->getQueryUrl();
156 } else {
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)) {
178 $uri = $location;
179 } elseif ($location instanceof Zend_Gdata_Query) {
180 $uri = $location->getQueryUrl();
181 } else {
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
202 * for this request
203 * @param string $body The body of the HTTP request
204 * @param string $contentType The value for the content type of the
205 * request body
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));
220 } else {
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()) {
235 return true;
238 return false;