| Total Complexity | 96 |
| Total Lines | 787 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
Complex classes like Zend_Gdata_YouTube often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Zend_Gdata_YouTube, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 87 | class Zend_Gdata_YouTube extends Zend_Gdata_Media |
||
| 88 | { |
||
| 89 | |||
| 90 | const AUTH_SERVICE_NAME = 'youtube'; |
||
| 91 | const CLIENTLOGIN_URL = 'https://www.google.com/youtube/accounts/ClientLogin'; |
||
| 92 | |||
| 93 | const STANDARD_TOP_RATED_URI = 'https://gdata.youtube.com/feeds/api/standardfeeds/top_rated'; |
||
| 94 | const STANDARD_MOST_VIEWED_URI = 'https://gdata.youtube.com/feeds/api/standardfeeds/most_viewed'; |
||
| 95 | const STANDARD_RECENTLY_FEATURED_URI = 'https://gdata.youtube.com/feeds/api/standardfeeds/recently_featured'; |
||
| 96 | const STANDARD_WATCH_ON_MOBILE_URI = 'https://gdata.youtube.com/feeds/api/standardfeeds/watch_on_mobile'; |
||
| 97 | |||
| 98 | const STANDARD_TOP_RATED_URI_V2 = |
||
| 99 | 'https://gdata.youtube.com/feeds/api/standardfeeds/top_rated'; |
||
| 100 | const STANDARD_MOST_VIEWED_URI_V2 = |
||
| 101 | 'https://gdata.youtube.com/feeds/api/standardfeeds/most_viewed'; |
||
| 102 | const STANDARD_RECENTLY_FEATURED_URI_V2 = |
||
| 103 | 'https://gdata.youtube.com/feeds/api/standardfeeds/recently_featured'; |
||
| 104 | const STANDARD_WATCH_ON_MOBILE_URI_V2 = |
||
| 105 | 'https://gdata.youtube.com/feeds/api/standardfeeds/watch_on_mobile'; |
||
| 106 | |||
| 107 | const USER_URI = 'https://gdata.youtube.com/feeds/api/users'; |
||
| 108 | const VIDEO_URI = 'https://gdata.youtube.com/feeds/api/videos'; |
||
| 109 | const PLAYLIST_REL = 'http://gdata.youtube.com/schemas/2007#playlist'; |
||
| 110 | const USER_UPLOADS_REL = 'http://gdata.youtube.com/schemas/2007#user.uploads'; |
||
| 111 | const USER_PLAYLISTS_REL = 'http://gdata.youtube.com/schemas/2007#user.playlists'; |
||
| 112 | const USER_SUBSCRIPTIONS_REL = 'http://gdata.youtube.com/schemas/2007#user.subscriptions'; |
||
| 113 | const USER_CONTACTS_REL = 'http://gdata.youtube.com/schemas/2007#user.contacts'; |
||
| 114 | const USER_FAVORITES_REL = 'http://gdata.youtube.com/schemas/2007#user.favorites'; |
||
| 115 | const VIDEO_RESPONSES_REL = 'http://gdata.youtube.com/schemas/2007#video.responses'; |
||
| 116 | const VIDEO_RATINGS_REL = 'http://gdata.youtube.com/schemas/2007#video.ratings'; |
||
| 117 | const VIDEO_COMPLAINTS_REL = 'http://gdata.youtube.com/schemas/2007#video.complaints'; |
||
| 118 | const ACTIVITY_FEED_URI = 'https://gdata.youtube.com/feeds/api/events'; |
||
| 119 | const FRIEND_ACTIVITY_FEED_URI = |
||
| 120 | 'https://gdata.youtube.com/feeds/api/users/default/friendsactivity'; |
||
| 121 | |||
| 122 | /** |
||
| 123 | * The URI of the in-reply-to schema for comments in reply to |
||
| 124 | * other comments. |
||
| 125 | * |
||
| 126 | * @var string |
||
| 127 | */ |
||
| 128 | const IN_REPLY_TO_SCHEME = |
||
| 129 | 'http://gdata.youtube.com/schemas/2007#in-reply-to'; |
||
| 130 | |||
| 131 | /** |
||
| 132 | * The URI of the inbox feed for the currently authenticated user. |
||
| 133 | * |
||
| 134 | * @var string |
||
| 135 | */ |
||
| 136 | const INBOX_FEED_URI = |
||
| 137 | 'https://gdata.youtube.com/feeds/api/users/default/inbox'; |
||
| 138 | |||
| 139 | /** |
||
| 140 | * The maximum number of users for which activity can be requested for, |
||
| 141 | * as enforced by the API. |
||
| 142 | * |
||
| 143 | * @var integer |
||
| 144 | */ |
||
| 145 | const ACTIVITY_FEED_MAX_USERS = 20; |
||
| 146 | |||
| 147 | /** |
||
| 148 | * The suffix for a feed of favorites. |
||
| 149 | * |
||
| 150 | * @var string |
||
| 151 | */ |
||
| 152 | const FAVORITES_URI_SUFFIX = 'favorites'; |
||
| 153 | |||
| 154 | /** |
||
| 155 | * The suffix for the user's upload feed. |
||
| 156 | * |
||
| 157 | * @var string |
||
| 158 | */ |
||
| 159 | const UPLOADS_URI_SUFFIX = 'uploads'; |
||
| 160 | |||
| 161 | /** |
||
| 162 | * The suffix for a feed of video responses. |
||
| 163 | * |
||
| 164 | * @var string |
||
| 165 | */ |
||
| 166 | const RESPONSES_URI_SUFFIX = 'responses'; |
||
| 167 | |||
| 168 | /** |
||
| 169 | * The suffix for a feed of related videos. |
||
| 170 | * |
||
| 171 | * @var string |
||
| 172 | */ |
||
| 173 | const RELATED_URI_SUFFIX = 'related'; |
||
| 174 | |||
| 175 | /** |
||
| 176 | * The suffix for a feed of messages (inbox entries). |
||
| 177 | * |
||
| 178 | * @var string |
||
| 179 | */ |
||
| 180 | const INBOX_URI_SUFFIX = 'inbox'; |
||
| 181 | |||
| 182 | /** |
||
| 183 | * Namespaces used for Zend_Gdata_YouTube |
||
| 184 | * |
||
| 185 | * @var array |
||
| 186 | */ |
||
| 187 | public static $namespaces = array( |
||
| 188 | array('yt', 'http://gdata.youtube.com/schemas/2007', 1, 0), |
||
| 189 | array('georss', 'http://www.georss.org/georss', 1, 0), |
||
| 190 | array('gml', 'http://www.opengis.net/gml', 1, 0), |
||
| 191 | array('media', 'http://search.yahoo.com/mrss/', 1, 0) |
||
| 192 | ); |
||
| 193 | |||
| 194 | /** |
||
| 195 | * Create Zend_Gdata_YouTube object |
||
| 196 | * |
||
| 197 | * @param Zend_Http_Client $client (optional) The HTTP client to use when |
||
| 198 | * when communicating with the Google servers. |
||
| 199 | * @param string $applicationId The identity of the app in the form of |
||
| 200 | * Company-AppName-Version |
||
| 201 | * @param string $clientId The clientId issued by the YouTube dashboard |
||
| 202 | * @param string $developerKey The developerKey issued by the YouTube dashboard |
||
| 203 | */ |
||
| 204 | public function __construct($client = null, |
||
| 215 | } |
||
| 216 | |||
| 217 | /** |
||
| 218 | * Set the Zend_Http_Client object used for communication |
||
| 219 | * |
||
| 220 | * @param Zend_Http_Client $client The client to use for communication |
||
| 221 | * @throws Zend_Gdata_App_HttpException |
||
| 222 | * @return Zend_Gdata_App Provides a fluent interface |
||
| 223 | */ |
||
| 224 | public function setHttpClient($client, |
||
| 225 | $applicationId = 'MyCompany-MyApp-1.0', $clientId = null, |
||
| 226 | $developerKey = null) |
||
| 227 | { |
||
| 228 | if ($client === null) { |
||
| 229 | $client = new Zend_Http_Client(); |
||
| 230 | } |
||
| 231 | if (!$client instanceof Zend_Http_Client) { |
||
|
|
|||
| 232 | require_once 'Zend/Gdata/App/HttpException.php'; |
||
| 233 | throw new Zend_Gdata_App_HttpException( |
||
| 234 | 'Argument is not an instance of Zend_Http_Client.'); |
||
| 235 | } |
||
| 236 | |||
| 237 | if ($clientId != null) { |
||
| 238 | $client->setHeaders('X-GData-Client', $clientId); |
||
| 239 | } |
||
| 240 | |||
| 241 | if ($developerKey != null) { |
||
| 242 | $client->setHeaders('X-GData-Key', 'key='. $developerKey); |
||
| 243 | } |
||
| 244 | |||
| 245 | return parent::setHttpClient($client, $applicationId); |
||
| 246 | } |
||
| 247 | |||
| 248 | /** |
||
| 249 | * Retrieves a feed of videos. |
||
| 250 | * |
||
| 251 | * @param mixed $location (optional) The URL to query or a |
||
| 252 | * Zend_Gdata_Query object from which a URL can be determined |
||
| 253 | * @return Zend_Gdata_YouTube_VideoFeed The feed of videos found at the |
||
| 254 | * specified URL. |
||
| 255 | */ |
||
| 256 | public function getVideoFeed($location = null) |
||
| 257 | { |
||
| 258 | if ($location == null) { |
||
| 259 | $uri = self::VIDEO_URI; |
||
| 260 | } else if ($location instanceof Zend_Gdata_Query) { |
||
| 261 | $uri = $location->getQueryUrl($this->getMajorProtocolVersion()); |
||
| 262 | } else { |
||
| 263 | $uri = $location; |
||
| 264 | } |
||
| 265 | return parent::getFeed($uri, 'Zend_Gdata_YouTube_VideoFeed'); |
||
| 266 | } |
||
| 267 | |||
| 268 | /** |
||
| 269 | * Retrieves a specific video entry. |
||
| 270 | * |
||
| 271 | * @param mixed $videoId The ID of the video to retrieve. |
||
| 272 | * @param mixed $location (optional) The URL to query or a |
||
| 273 | * Zend_Gdata_Query object from which a URL can be determined. |
||
| 274 | * @param boolean $fullEntry (optional) Retrieve the full metadata for the |
||
| 275 | * entry. Only possible if entry belongs to currently authenticated |
||
| 276 | * user. An exception will be thrown otherwise. |
||
| 277 | * @throws Zend_Gdata_App_HttpException |
||
| 278 | * @return Zend_Gdata_YouTube_VideoEntry The video entry found at the |
||
| 279 | * specified URL. |
||
| 280 | */ |
||
| 281 | public function getVideoEntry($videoId = null, $location = null, |
||
| 282 | $fullEntry = false) |
||
| 283 | { |
||
| 284 | if ($videoId !== null) { |
||
| 285 | if ($fullEntry) { |
||
| 286 | return $this->getFullVideoEntry($videoId); |
||
| 287 | } else { |
||
| 288 | $uri = self::VIDEO_URI . "/" . $videoId; |
||
| 289 | } |
||
| 290 | } else if ($location instanceof Zend_Gdata_Query) { |
||
| 291 | $uri = $location->getQueryUrl($this->getMajorProtocolVersion()); |
||
| 292 | } else { |
||
| 293 | $uri = $location; |
||
| 294 | } |
||
| 295 | return parent::getEntry($uri, 'Zend_Gdata_YouTube_VideoEntry'); |
||
| 296 | } |
||
| 297 | |||
| 298 | /** |
||
| 299 | * Retrieves a video entry from the user's upload feed. |
||
| 300 | * |
||
| 301 | * @param mixed $videoID The ID of the video to retrieve. |
||
| 302 | * @throws Zend_Gdata_App_HttpException |
||
| 303 | * @return Zend_Gdata_YouTube_VideoEntry|null The video entry to be |
||
| 304 | * retrieved, or null if it was not found or the user requesting it |
||
| 305 | * did not have the appropriate permissions. |
||
| 306 | */ |
||
| 307 | public function getFullVideoEntry($videoId) |
||
| 308 | { |
||
| 309 | $uri = self::USER_URI . "/default/" . |
||
| 310 | self::UPLOADS_URI_SUFFIX . "/$videoId"; |
||
| 311 | return parent::getEntry($uri, 'Zend_Gdata_YouTube_VideoEntry'); |
||
| 312 | } |
||
| 313 | |||
| 314 | /** |
||
| 315 | * Retrieves a feed of videos related to the specified video ID. |
||
| 316 | * |
||
| 317 | * @param string $videoId The videoId of interest |
||
| 318 | * @param mixed $location (optional) The URL to query or a |
||
| 319 | * Zend_Gdata_Query object from which a URL can be determined |
||
| 320 | * @return Zend_Gdata_YouTube_VideoFeed The feed of videos found at the |
||
| 321 | * specified URL. |
||
| 322 | */ |
||
| 323 | public function getRelatedVideoFeed($videoId = null, $location = null) |
||
| 324 | { |
||
| 325 | if ($videoId !== null) { |
||
| 326 | $uri = self::VIDEO_URI . "/" . $videoId . "/" . |
||
| 327 | self::RELATED_URI_SUFFIX; |
||
| 328 | } else if ($location instanceof Zend_Gdata_Query) { |
||
| 329 | $uri = $location->getQueryUrl($this->getMajorProtocolVersion()); |
||
| 330 | } else { |
||
| 331 | $uri = $location; |
||
| 332 | } |
||
| 333 | return parent::getFeed($uri, 'Zend_Gdata_YouTube_VideoFeed'); |
||
| 334 | } |
||
| 335 | |||
| 336 | /** |
||
| 337 | * Retrieves a feed of video responses related to the specified video ID. |
||
| 338 | * |
||
| 339 | * @param string $videoId The videoId of interest |
||
| 340 | * @param mixed $location (optional) The URL to query or a |
||
| 341 | * Zend_Gdata_Query object from which a URL can be determined |
||
| 342 | * @return Zend_Gdata_YouTube_VideoFeed The feed of videos found at the |
||
| 343 | * specified URL. |
||
| 344 | */ |
||
| 345 | public function getVideoResponseFeed($videoId = null, $location = null) |
||
| 346 | { |
||
| 347 | if ($videoId !== null) { |
||
| 348 | $uri = self::VIDEO_URI . "/" . $videoId . "/" . |
||
| 349 | self::RESPONSES_URI_SUFFIX; |
||
| 350 | } else if ($location instanceof Zend_Gdata_Query) { |
||
| 351 | $uri = $location->getQueryUrl($this->getMajorProtocolVersion()); |
||
| 352 | } else { |
||
| 353 | $uri = $location; |
||
| 354 | } |
||
| 355 | return parent::getFeed($uri, 'Zend_Gdata_YouTube_VideoFeed'); |
||
| 356 | } |
||
| 357 | |||
| 358 | /** |
||
| 359 | * Retrieves a feed of comments related to the specified video ID. |
||
| 360 | * |
||
| 361 | * @param string $videoId The videoId of interest |
||
| 362 | * @param mixed $location (optional) The URL to query or a |
||
| 363 | * Zend_Gdata_Query object from which a URL can be determined |
||
| 364 | * @return Zend_Gdata_YouTube_CommentFeed The feed of videos found at the |
||
| 365 | * specified URL. |
||
| 366 | */ |
||
| 367 | public function getVideoCommentFeed($videoId = null, $location = null) |
||
| 368 | { |
||
| 369 | if ($videoId !== null) { |
||
| 370 | $uri = self::VIDEO_URI . "/" . $videoId . "/comments"; |
||
| 371 | } else if ($location instanceof Zend_Gdata_Query) { |
||
| 372 | $uri = $location->getQueryUrl($this->getMajorProtocolVersion()); |
||
| 373 | } else { |
||
| 374 | $uri = $location; |
||
| 375 | } |
||
| 376 | return parent::getFeed($uri, 'Zend_Gdata_YouTube_CommentFeed'); |
||
| 377 | } |
||
| 378 | |||
| 379 | /** |
||
| 380 | * Retrieves a feed of comments related to the specified video ID. |
||
| 381 | * |
||
| 382 | * @param mixed $location (optional) The URL to query or a |
||
| 383 | * Zend_Gdata_Query object from which a URL can be determined |
||
| 384 | * @return Zend_Gdata_YouTube_CommentFeed The feed of videos found at the |
||
| 385 | * specified URL. |
||
| 386 | */ |
||
| 387 | public function getTopRatedVideoFeed($location = null) |
||
| 388 | { |
||
| 389 | $standardFeedUri = self::STANDARD_TOP_RATED_URI; |
||
| 390 | |||
| 391 | if ($this->getMajorProtocolVersion() == 2) { |
||
| 392 | $standardFeedUri = self::STANDARD_TOP_RATED_URI_V2; |
||
| 393 | } |
||
| 394 | |||
| 395 | if ($location == null) { |
||
| 396 | $uri = $standardFeedUri; |
||
| 397 | } else if ($location instanceof Zend_Gdata_Query) { |
||
| 398 | if ($location instanceof Zend_Gdata_YouTube_VideoQuery) { |
||
| 399 | if (!isset($location->url)) { |
||
| 400 | $location->setFeedType('top rated'); |
||
| 401 | } |
||
| 402 | } |
||
| 403 | $uri = $location->getQueryUrl($this->getMajorProtocolVersion()); |
||
| 404 | } else { |
||
| 405 | $uri = $location; |
||
| 406 | } |
||
| 407 | return parent::getFeed($uri, 'Zend_Gdata_YouTube_VideoFeed'); |
||
| 408 | } |
||
| 409 | |||
| 410 | |||
| 411 | /** |
||
| 412 | * Retrieves a feed of the most viewed videos. |
||
| 413 | * |
||
| 414 | * @param mixed $location (optional) The URL to query or a |
||
| 415 | * Zend_Gdata_Query object from which a URL can be determined |
||
| 416 | * @return Zend_Gdata_YouTube_VideoFeed The feed of videos found at the |
||
| 417 | * specified URL. |
||
| 418 | */ |
||
| 419 | public function getMostViewedVideoFeed($location = null) |
||
| 420 | { |
||
| 421 | $standardFeedUri = self::STANDARD_MOST_VIEWED_URI; |
||
| 422 | |||
| 423 | if ($this->getMajorProtocolVersion() == 2) { |
||
| 424 | $standardFeedUri = self::STANDARD_MOST_VIEWED_URI_V2; |
||
| 425 | } |
||
| 426 | |||
| 427 | if ($location == null) { |
||
| 428 | $uri = $standardFeedUri; |
||
| 429 | } else if ($location instanceof Zend_Gdata_Query) { |
||
| 430 | if ($location instanceof Zend_Gdata_YouTube_VideoQuery) { |
||
| 431 | if (!isset($location->url)) { |
||
| 432 | $location->setFeedType('most viewed'); |
||
| 433 | } |
||
| 434 | } |
||
| 435 | $uri = $location->getQueryUrl($this->getMajorProtocolVersion()); |
||
| 436 | } else { |
||
| 437 | $uri = $location; |
||
| 438 | } |
||
| 439 | return parent::getFeed($uri, 'Zend_Gdata_YouTube_VideoFeed'); |
||
| 440 | } |
||
| 441 | |||
| 442 | /** |
||
| 443 | * Retrieves a feed of recently featured videos. |
||
| 444 | * |
||
| 445 | * @param mixed $location (optional) The URL to query or a |
||
| 446 | * Zend_Gdata_Query object from which a URL can be determined |
||
| 447 | * @return Zend_Gdata_YouTube_VideoFeed The feed of videos found at the |
||
| 448 | * specified URL. |
||
| 449 | */ |
||
| 450 | public function getRecentlyFeaturedVideoFeed($location = null) |
||
| 451 | { |
||
| 452 | $standardFeedUri = self::STANDARD_RECENTLY_FEATURED_URI; |
||
| 453 | |||
| 454 | if ($this->getMajorProtocolVersion() == 2) { |
||
| 455 | $standardFeedUri = self::STANDARD_RECENTLY_FEATURED_URI_V2; |
||
| 456 | } |
||
| 457 | |||
| 458 | if ($location == null) { |
||
| 459 | $uri = $standardFeedUri; |
||
| 460 | } else if ($location instanceof Zend_Gdata_Query) { |
||
| 461 | if ($location instanceof Zend_Gdata_YouTube_VideoQuery) { |
||
| 462 | if (!isset($location->url)) { |
||
| 463 | $location->setFeedType('recently featured'); |
||
| 464 | } |
||
| 465 | } |
||
| 466 | $uri = $location->getQueryUrl($this->getMajorProtocolVersion()); |
||
| 467 | } else { |
||
| 468 | $uri = $location; |
||
| 469 | } |
||
| 470 | return parent::getFeed($uri, 'Zend_Gdata_YouTube_VideoFeed'); |
||
| 471 | } |
||
| 472 | |||
| 473 | /** |
||
| 474 | * Retrieves a feed of videos recently featured for mobile devices. |
||
| 475 | * These videos will have RTSP links in the $entry->mediaGroup->content |
||
| 476 | * |
||
| 477 | * @param mixed $location (optional) The URL to query or a |
||
| 478 | * Zend_Gdata_Query object from which a URL can be determined |
||
| 479 | * @return Zend_Gdata_YouTube_VideoFeed The feed of videos found at the |
||
| 480 | * specified URL. |
||
| 481 | */ |
||
| 482 | public function getWatchOnMobileVideoFeed($location = null) |
||
| 483 | { |
||
| 484 | $standardFeedUri = self::STANDARD_WATCH_ON_MOBILE_URI; |
||
| 485 | |||
| 486 | if ($this->getMajorProtocolVersion() == 2) { |
||
| 487 | $standardFeedUri = self::STANDARD_WATCH_ON_MOBILE_URI_V2; |
||
| 488 | } |
||
| 489 | |||
| 490 | if ($location == null) { |
||
| 491 | $uri = $standardFeedUri; |
||
| 492 | } else if ($location instanceof Zend_Gdata_Query) { |
||
| 493 | if ($location instanceof Zend_Gdata_YouTube_VideoQuery) { |
||
| 494 | if (!isset($location->url)) { |
||
| 495 | $location->setFeedType('watch on mobile'); |
||
| 496 | } |
||
| 497 | } |
||
| 498 | $uri = $location->getQueryUrl($this->getMajorProtocolVersion()); |
||
| 499 | } else { |
||
| 500 | $uri = $location; |
||
| 501 | } |
||
| 502 | return parent::getFeed($uri, 'Zend_Gdata_YouTube_VideoFeed'); |
||
| 503 | } |
||
| 504 | |||
| 505 | /** |
||
| 506 | * Retrieves a feed which lists a user's playlist |
||
| 507 | * |
||
| 508 | * @param string $user (optional) The username of interest |
||
| 509 | * @param mixed $location (optional) The URL to query or a |
||
| 510 | * Zend_Gdata_Query object from which a URL can be determined |
||
| 511 | * @return Zend_Gdata_YouTube_PlaylistListFeed The feed of playlists |
||
| 512 | */ |
||
| 513 | public function getPlaylistListFeed($user = null, $location = null) |
||
| 514 | { |
||
| 515 | if ($user !== null) { |
||
| 516 | $uri = self::USER_URI . '/' . $user . '/playlists'; |
||
| 517 | } else if ($location instanceof Zend_Gdata_Query) { |
||
| 518 | $uri = $location->getQueryUrl($this->getMajorProtocolVersion()); |
||
| 519 | } else { |
||
| 520 | $uri = $location; |
||
| 521 | } |
||
| 522 | return parent::getFeed($uri, 'Zend_Gdata_YouTube_PlaylistListFeed'); |
||
| 523 | } |
||
| 524 | |||
| 525 | /** |
||
| 526 | * Retrieves a feed of videos in a particular playlist |
||
| 527 | * |
||
| 528 | * @param mixed $location (optional) The URL to query or a |
||
| 529 | * Zend_Gdata_Query object from which a URL can be determined |
||
| 530 | * @return Zend_Gdata_YouTube_PlaylistVideoFeed The feed of videos found at |
||
| 531 | * the specified URL. |
||
| 532 | */ |
||
| 533 | public function getPlaylistVideoFeed($location) |
||
| 534 | { |
||
| 535 | if ($location instanceof Zend_Gdata_Query) { |
||
| 536 | $uri = $location->getQueryUrl($this->getMajorProtocolVersion()); |
||
| 537 | } else { |
||
| 538 | $uri = $location; |
||
| 539 | } |
||
| 540 | return parent::getFeed($uri, 'Zend_Gdata_YouTube_PlaylistVideoFeed'); |
||
| 541 | } |
||
| 542 | |||
| 543 | /** |
||
| 544 | * Retrieves a feed of a user's subscriptions |
||
| 545 | * |
||
| 546 | * @param string $user (optional) The username of interest |
||
| 547 | * @param mixed $location (optional) The URL to query or a |
||
| 548 | * Zend_Gdata_Query object from which a URL can be determined |
||
| 549 | * @return Zend_Gdata_YouTube_SubscriptionListFeed The feed of subscriptions |
||
| 550 | */ |
||
| 551 | public function getSubscriptionFeed($user = null, $location = null) |
||
| 561 | } |
||
| 562 | |||
| 563 | /** |
||
| 564 | * Retrieves a feed of a user's contacts |
||
| 565 | * |
||
| 566 | * @param string $user (optional) The username of interest |
||
| 567 | * @param mixed $location (optional) The URL to query or a |
||
| 568 | * Zend_Gdata_Query object from which a URL can be determined |
||
| 569 | * @return Zend_Gdata_YouTube_ContactFeed The feed of contacts |
||
| 570 | */ |
||
| 571 | public function getContactFeed($user = null, $location = null) |
||
| 572 | { |
||
| 573 | if ($user !== null) { |
||
| 574 | $uri = self::USER_URI . '/' . $user . '/contacts'; |
||
| 575 | } else if ($location instanceof Zend_Gdata_Query) { |
||
| 576 | $uri = $location->getQueryUrl($this->getMajorProtocolVersion()); |
||
| 577 | } else { |
||
| 578 | $uri = $location; |
||
| 579 | } |
||
| 580 | return parent::getFeed($uri, 'Zend_Gdata_YouTube_ContactFeed'); |
||
| 581 | } |
||
| 582 | |||
| 583 | /** |
||
| 584 | * Retrieves a user's uploads |
||
| 585 | * |
||
| 586 | * @param string $user (optional) The username of interest |
||
| 587 | * @param mixed $location (optional) The URL to query or a |
||
| 588 | * Zend_Gdata_Query object from which a URL can be determined |
||
| 589 | * @return Zend_Gdata_YouTube_VideoFeed The videos uploaded by the user |
||
| 590 | */ |
||
| 591 | public function getUserUploads($user = null, $location = null) |
||
| 592 | { |
||
| 593 | if ($user !== null) { |
||
| 594 | $uri = self::USER_URI . '/' . $user . '/' . |
||
| 595 | self::UPLOADS_URI_SUFFIX; |
||
| 596 | } else if ($location instanceof Zend_Gdata_Query) { |
||
| 597 | $uri = $location->getQueryUrl($this->getMajorProtocolVersion()); |
||
| 598 | } else { |
||
| 599 | $uri = $location; |
||
| 600 | } |
||
| 601 | return parent::getFeed($uri, 'Zend_Gdata_YouTube_VideoFeed'); |
||
| 602 | } |
||
| 603 | |||
| 604 | /** |
||
| 605 | * Retrieves a user's favorites |
||
| 606 | * |
||
| 607 | * @param string $user (optional) The username of interest |
||
| 608 | * @param mixed $location (optional) The URL to query or a |
||
| 609 | * Zend_Gdata_Query object from which a URL can be determined |
||
| 610 | * @return Zend_Gdata_YouTube_VideoFeed The videos favorited by the user |
||
| 611 | */ |
||
| 612 | public function getUserFavorites($user = null, $location = null) |
||
| 613 | { |
||
| 614 | if ($user !== null) { |
||
| 615 | $uri = self::USER_URI . '/' . $user . '/' . |
||
| 616 | self::FAVORITES_URI_SUFFIX; |
||
| 617 | } else if ($location instanceof Zend_Gdata_Query) { |
||
| 618 | $uri = $location->getQueryUrl($this->getMajorProtocolVersion()); |
||
| 619 | } else { |
||
| 620 | $uri = $location; |
||
| 621 | } |
||
| 622 | return parent::getFeed($uri, 'Zend_Gdata_YouTube_VideoFeed'); |
||
| 623 | } |
||
| 624 | |||
| 625 | /** |
||
| 626 | * Retrieves a user's profile as an entry |
||
| 627 | * |
||
| 628 | * @param string $user (optional) The username of interest |
||
| 629 | * @param mixed $location (optional) The URL to query or a |
||
| 630 | * Zend_Gdata_Query object from which a URL can be determined |
||
| 631 | * @return Zend_Gdata_YouTube_UserProfileEntry The user profile entry |
||
| 632 | */ |
||
| 633 | public function getUserProfile($user = null, $location = null) |
||
| 634 | { |
||
| 635 | if ($user !== null) { |
||
| 636 | $uri = self::USER_URI . '/' . $user; |
||
| 637 | } else if ($location instanceof Zend_Gdata_Query) { |
||
| 638 | $uri = $location->getQueryUrl($this->getMajorProtocolVersion()); |
||
| 639 | } else { |
||
| 640 | $uri = $location; |
||
| 641 | } |
||
| 642 | return parent::getEntry($uri, 'Zend_Gdata_YouTube_UserProfileEntry'); |
||
| 643 | } |
||
| 644 | |||
| 645 | /** |
||
| 646 | * Helper function for parsing a YouTube token response |
||
| 647 | * |
||
| 648 | * @param string $response The service response |
||
| 649 | * @throws Zend_Gdata_App_Exception |
||
| 650 | * @return array An array containing the token and URL |
||
| 651 | */ |
||
| 652 | public static function parseFormUploadTokenResponse($response) |
||
| 653 | { |
||
| 654 | // Load the feed as an XML DOMDocument object |
||
| 655 | @ini_set('track_errors', 1); |
||
| 656 | $doc = new DOMDocument(); |
||
| 657 | $doc = @Zend_Xml_Security::scan($response, $doc); |
||
| 658 | @ini_restore('track_errors'); |
||
| 659 | |||
| 660 | if (!$doc) { |
||
| 661 | require_once 'Zend/Gdata/App/Exception.php'; |
||
| 662 | throw new Zend_Gdata_App_Exception( |
||
| 663 | "Zend_Gdata_YouTube::parseFormUploadTokenResponse - " . |
||
| 664 | "DOMDocument cannot parse XML: $php_errormsg"); |
||
| 665 | } |
||
| 666 | $responseElement = $doc->getElementsByTagName('response')->item(0); |
||
| 667 | |||
| 668 | $urlText = null; |
||
| 669 | $tokenText = null; |
||
| 670 | if ($responseElement != null) { |
||
| 671 | $urlElement = |
||
| 672 | $responseElement->getElementsByTagName('url')->item(0); |
||
| 673 | $tokenElement = |
||
| 674 | $responseElement->getElementsByTagName('token')->item(0); |
||
| 675 | |||
| 676 | if ($urlElement && $urlElement->hasChildNodes() && |
||
| 677 | $tokenElement && $tokenElement->hasChildNodes()) { |
||
| 678 | |||
| 679 | $urlText = $urlElement->firstChild->nodeValue; |
||
| 680 | $tokenText = $tokenElement->firstChild->nodeValue; |
||
| 681 | } |
||
| 682 | } |
||
| 683 | |||
| 684 | if ($tokenText != null && $urlText != null) { |
||
| 685 | return array('token' => $tokenText, 'url' => $urlText); |
||
| 686 | } else { |
||
| 687 | require_once 'Zend/Gdata/App/Exception.php'; |
||
| 688 | throw new Zend_Gdata_App_Exception( |
||
| 689 | 'Form upload token not found in response'); |
||
| 690 | } |
||
| 691 | } |
||
| 692 | |||
| 693 | /** |
||
| 694 | * Retrieves a YouTube token |
||
| 695 | * |
||
| 696 | * @param Zend_Gdata_YouTube_VideoEntry $videoEntry The video entry |
||
| 697 | * @param string $url The location as a string URL |
||
| 698 | * @throws Zend_Gdata_App_Exception |
||
| 699 | * @return array An array containing a token and URL |
||
| 700 | */ |
||
| 701 | public function getFormUploadToken($videoEntry, |
||
| 702 | $url='https://gdata.youtube.com/action/GetUploadToken') |
||
| 703 | { |
||
| 704 | if ($url != null && is_string($url)) { |
||
| 705 | // $response is a Zend_Http_response object |
||
| 706 | $response = $this->post($videoEntry, $url); |
||
| 707 | return self::parseFormUploadTokenResponse($response->getBody()); |
||
| 708 | } else { |
||
| 709 | require_once 'Zend/Gdata/App/Exception.php'; |
||
| 710 | throw new Zend_Gdata_App_Exception( |
||
| 711 | 'Url must be provided as a string URL'); |
||
| 712 | } |
||
| 713 | } |
||
| 714 | |||
| 715 | /** |
||
| 716 | * Retrieves the activity feed for users |
||
| 717 | * |
||
| 718 | * @param mixed $usernames A string identifying the usernames for which to |
||
| 719 | * retrieve activity for. This can also be a Zend_Gdata_Query |
||
| 720 | * object from which a URL can be determined. |
||
| 721 | * @throws Zend_Gdata_App_VersionException if using version less than 2. |
||
| 722 | * @return Zend_Gdata_YouTube_ActivityFeed |
||
| 723 | */ |
||
| 724 | public function getActivityForUser($username) |
||
| 747 | } |
||
| 748 | |||
| 749 | /** |
||
| 750 | * Retrieve the activity of the currently authenticated users friend. |
||
| 751 | * |
||
| 752 | * @throws Zend_Gdata_App_Exception if not logged in. |
||
| 753 | * @return Zend_Gdata_YouTube_ActivityFeed |
||
| 754 | */ |
||
| 755 | public function getFriendActivityForCurrentUser() |
||
| 756 | { |
||
| 757 | if (!$this->isAuthenticated()) { |
||
| 758 | require_once 'Zend/Gdata/App/Exception.php'; |
||
| 759 | throw new Zend_Gdata_App_Exception('You must be authenticated to ' . |
||
| 760 | 'use the getFriendActivityForCurrentUser function in Zend_' . |
||
| 761 | 'Gdata_YouTube.'); |
||
| 762 | } |
||
| 763 | return parent::getFeed(self::FRIEND_ACTIVITY_FEED_URI, |
||
| 764 | 'Zend_Gdata_YouTube_ActivityFeed'); |
||
| 765 | } |
||
| 766 | |||
| 767 | /** |
||
| 768 | * Retrieve a feed of messages in the currently authenticated user's inbox. |
||
| 769 | * |
||
| 770 | * @throws Zend_Gdata_App_Exception if not logged in. |
||
| 771 | * @return Zend_Gdata_YouTube_InboxFeed|null |
||
| 772 | */ |
||
| 773 | public function getInboxFeedForCurrentUser() |
||
| 784 | } |
||
| 785 | |||
| 786 | /** |
||
| 787 | * Send a video message. |
||
| 788 | * |
||
| 789 | * Note: Either a Zend_Gdata_YouTube_VideoEntry or a valid video ID must |
||
| 790 | * be provided. |
||
| 791 | * |
||
| 792 | * @param string $body The body of the message |
||
| 793 | * @param Zend_Gdata_YouTube_VideoEntry (optional) The video entry to send |
||
| 794 | * @param string $videoId The id of the video to send |
||
| 795 | * @param string $recipientUserName The username of the recipient |
||
| 796 | * @throws Zend_Gdata_App_InvalidArgumentException if no valid |
||
| 797 | * Zend_Gdata_YouTube_VideoEntry or videoId were provided |
||
| 798 | * @return Zend_Gdata_YouTube_InboxEntry|null The |
||
| 799 | * Zend_Gdata_YouTube_Inbox_Entry representing the sent message. |
||
| 800 | * |
||
| 801 | */ |
||
| 802 | public function sendVideoMessage($body, $videoEntry = null, |
||
| 844 | } |
||
| 845 | |||
| 846 | /** |
||
| 847 | * Post a comment in reply to an existing comment |
||
| 848 | * |
||
| 849 | * @param Zend_Gdata_YouTube_CommentEntry $commentEntry The comment entry |
||
| 850 | * to reply to |
||
| 851 | * @param string $commentText The text of the |
||
| 852 | * comment to post |
||
| 853 | * @return Zend_Gdata_YouTube_CommentEntry the posted comment |
||
| 854 | */ |
||
| 855 | public function replyToCommentEntry($commentEntry, $commentText) |
||
| 874 | } |
||
| 875 | |||
| 876 | } |
||
| 877 |