public final function onRequest(ehough_tickertape_GenericEvent $event) { /** * @var $request ehough_shortstop_api_HttpRequest */ $request = $event->getSubject(); if ($request->getUrl()->getHost() !== 'vimeo.com') { //not a Vimeo request return; } $clientId = $this->_executionContext->get(tubepress_addons_vimeo_api_const_options_names_Feed::VIMEO_KEY); $clientSecret = $this->_executionContext->get(tubepress_addons_vimeo_api_const_options_names_Feed::VIMEO_SECRET); $clientCredentials = new ehough_coauthor_api_v1_Credentials($clientId, $clientSecret); $this->_oauthClient->signRequest($request, $clientCredentials); }
private function _getFromCache($url, tubepress_spi_context_ExecutionContext $context, $isDebugEnabled) { /** * @var $cache ehough_stash_interfaces_PoolInterface */ $cache = tubepress_impl_patterns_sl_ServiceLocator::getCacheService(); if ($isDebugEnabled) { $this->_logger->debug(sprintf('First asking cache for <a href="%s">URL</a>', $url)); } $cacheKey = $this->_urlToCacheKey($url); $result = $cache->getItem($cacheKey); if ($result && !$result->isMiss()) { if ($isDebugEnabled) { $this->_logger->debug(sprintf('Cache has <a href="%s">URL</a>. Sweet.', $url)); } } else { if ($isDebugEnabled) { $this->_logger->debug(sprintf('Cache does not have <a href="%s">URL</a>. We\'ll have to get it from the network.', $url)); } $data = $this->_getFromNetwork($url); $storedSuccessfully = $result->set($data, $context->get(tubepress_api_const_options_names_Cache::CACHE_LIFETIME_SECONDS)); if (!$storedSuccessfully) { if ($isDebugEnabled) { $this->_logger->debug('Unable to store data to cache'); } return $data; } } return $result->get(); }
private function _findPlayerLocation(tubepress_spi_context_ExecutionContext $context) { $requestedPlayerName = $context->get(tubepress_api_const_options_names_Embedded::PLAYER_LOCATION); /** * @var $playerLocation tubepress_spi_player_PluggablePlayerLocationService */ foreach ($this->_playerLocations as $playerLocation) { if ($playerLocation->getName() === $requestedPlayerName) { return $playerLocation; } } return null; }
private function _urlProcessingOrderBy(tubepress_spi_context_ExecutionContext $execContext, ehough_curly_Url $url) { /* * In a request for a video feed, the following values are valid for this parameter: * * relevance – Entries are ordered by their relevance to a search query. This is the default setting for video search results feeds. * published – Entries are returned in reverse chronological order. This is the default value for video feeds other than search results feeds. * viewCount – Entries are ordered from most views to least views. * rating – Entries are ordered from highest rating to lowest rating. * * In a request for a playlist feed, the following values are valid for this parameter: * * position – Entries are ordered by their position in the playlist. This is the default setting. * commentCount – Entries are ordered by number of comments from most comments to least comments. * duration – Entries are ordered by length of each playlist video from longest video to shortest video. * published – Entries are returned in reverse chronological order. * reversedPosition – Entries are ordered in reverse of their position in the playlist. * title – Entries are ordered alphabetically by title. * viewCount – Entries are ordered from most views to least views. */ $requestedSortOrder = $execContext->get(tubepress_api_const_options_names_Feed::ORDER_BY); $currentGallerySource = $execContext->get(tubepress_api_const_options_names_Output::GALLERY_SOURCE); if ($requestedSortOrder === tubepress_api_const_options_values_OrderByValue::DEFAULTT) { $url->setQueryVariable(self::$_URL_PARAM_ORDER, $this->_calculateDefaultSearchOrder($currentGallerySource)); return; } if ($requestedSortOrder === tubepress_api_const_options_values_OrderByValue::NEWEST) { $url->setQueryVariable(self::$_URL_PARAM_ORDER, 'published'); return; } if ($requestedSortOrder == tubepress_api_const_options_values_OrderByValue::VIEW_COUNT) { $url->setQueryVariable(self::$_URL_PARAM_ORDER, $requestedSortOrder); return; } if ($currentGallerySource == tubepress_addons_youtube_api_const_options_values_GallerySourceValue::YOUTUBE_PLAYLIST) { if (in_array($requestedSortOrder, array(tubepress_api_const_options_values_OrderByValue::POSITION, tubepress_api_const_options_values_OrderByValue::COMMENT_COUNT, tubepress_api_const_options_values_OrderByValue::DURATION, tubepress_api_const_options_values_OrderByValue::REV_POSITION, tubepress_api_const_options_values_OrderByValue::TITLE))) { $url->setQueryVariable(self::$_URL_PARAM_ORDER, $requestedSortOrder); return; } } else { if (in_array($requestedSortOrder, array(tubepress_api_const_options_values_OrderByValue::RELEVANCE, tubepress_api_const_options_values_OrderByValue::RATING))) { $url->setQueryVariable(self::$_URL_PARAM_ORDER, $requestedSortOrder); } } }
private function _verifyKeyAndSecretExists(tubepress_spi_context_ExecutionContext $execContext) { if ($execContext->get(tubepress_addons_vimeo_api_const_options_names_Feed::VIMEO_KEY) === '') { throw new RuntimeException('Missing Vimeo API Consumer Key.'); } if ($execContext->get(tubepress_addons_vimeo_api_const_options_names_Feed::VIMEO_SECRET) === '') { throw new RuntimeException('Missing Vimeo API Consumer Secret.'); } }