public function fetchWithClientCredentials(tubepress_spi_http_oauth2_Oauth2ProviderInterface $provider) { $tokenUrl = $provider->getTokenEndpoint(); $clientId = $this->_persistenceHelper->getClientId($provider); $clientSecret = $this->_persistenceHelper->getClientSecret($provider); $request = $this->_httpClient->createRequest('POST', $tokenUrl, array('body' => array('grant_type' => 'client_credentials'))); $provider->onAccessTokenRequest($request, $clientId, $clientSecret); return $this->_fetchAndBuildToken($request, $provider); }
/** * @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]; }
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; }