Beispiel #1
0
 /**
  * @param tubepress_api_url_UrlInterface $url
  * @param array                          $requestOpts
  *
  * @return array
  */
 public function getDecodedApiResponse(tubepress_api_url_UrlInterface $url, $requestOpts = array())
 {
     $httpRequest = $this->_httpClient->createRequest('GET', $url, $requestOpts);
     $finalConfig = array_merge($httpRequest->getConfig(), array('tubepress-remote-api-call' => true));
     $httpRequest->setConfig($finalConfig);
     $urlAsString = $url->toString();
     if (!isset($this->_memoryCache[$urlAsString])) {
         $httpResponse = $this->_httpClient->send($httpRequest);
         $rawFeed = $httpResponse->getBody()->toString();
         $decoded = json_decode($rawFeed, true);
         if ($decoded === null) {
             throw new RuntimeException('Unable to decode JSON from Dailymotion');
         }
         $this->checkForApiResponseError($decoded);
         $this->_memoryCache[$urlAsString] = $decoded;
     } else {
         if ($this->_shouldLog) {
             $this->_logger->debug(sprintf('Response for <code>%s</code> found in the in-memory cache.', $urlAsString));
         }
     }
     return $this->_memoryCache[$urlAsString];
 }
Beispiel #2
0
 private function _fetchFeedAndPrepareForAnalysis($url, tubepress_spi_media_HttpFeedHandlerInterface $feedHandler)
 {
     try {
         $httpRequest = $this->_httpClient->createRequest('GET', $url);
         /*
          * Allows the cache to recognize this as an API call.
          */
         $httpRequest->setConfig(array_merge($httpRequest->getConfig(), array('tubepress-remote-api-call' => true)));
         $httpResponse = $this->_httpClient->send($httpRequest);
     } catch (tubepress_api_http_exception_RequestException $e) {
         throw $e;
     }
     $rawFeed = $httpResponse->getBody()->toString();
     $feedHandler->onAnalysisStart($rawFeed, $url);
     return $rawFeed;
 }
 private function _fetchAndBuildToken(tubepress_api_http_message_RequestInterface $request, tubepress_spi_http_oauth2_Oauth2ProviderInterface $provider)
 {
     $response = $this->_httpClient->send($request);
     $this->_checkResponseForError($provider, $response);
     return $this->_buildTokenFromResponse($provider, $response);
 }