private function getAuthToken() { /* * We default to asking our own cache for an token, because * if we find one, this saves us one expensive HTTP call. * * The chance we find an auth token is slim though as it expires * after a few seconds */ $svcPrvHttp = new Services_Providers_Http(null); $translaterToken = $this->_cacheDao->getCachedTranslaterToken($this->_clientId . $this->_clientSecret); if ($translaterToken != false) { return $translaterToken['content']; } # if # Don't even try if no tokens are available if (!$this->isAvailable()) { return false; } # if # create the request array $paramArr = array('grant_type' => Services_Translation_Microsoft::grantType, 'scope' => Services_Translation_Microsoft::scopeUrl, 'client_id' => $this->_clientId, 'client_secret' => $this->_clientSecret); $svcPrvHttp->setMethod('POST'); $svcPrvHttp->setPostContent($paramArr); $tmpResult = $svcPrvHttp->perform(Services_Translation_Microsoft::authUrl, null); if (!$tmpResult['successful']) { $tmpResult = @json_decode($tmpResult['data']); if (!empty($tmpResult->error)) { throw new Exception($tmpResult->error_description); } # if return false; } # if $result = json_decode($tmpResult['data']); /* * throw any exception if one happens because else we get sometimes * failing translations which suck even more. */ if (!empty($result->error)) { throw new Exception($result->error_description); } # if /* * store the translation token into the cache */ $translaterToken = $result->access_token; $this->_cacheDao->saveTranslaterTokenCache($this->_clientId . $this->_clientSecret, time() + ($result->expires_in - 2), $translaterToken); return $translaterToken; }
/** * * Execute a POST to the given url and return the body. * @param String $url * @param array $postdata * @return bool|mixed */ protected function postAndDownloadNzb($url, array $postdata) { // Initialize download retrieval class $svcHttp = new Services_Providers_Http($this->_cacheDao); $svcHttp->setPostContent($postdata); $svcHttp->setMethod('POST'); $result = $svcHttp->perform($url); // Check if any error occured if (!$result['successful']) { SpotDebug::msg(SpotDebug::DEBUG, __CLASS__ . '->postAndDownloadNzb(), not succesful=' . $result['errorstr']); return false; } # if // Load the body into simplexml. // If the xml is well formed this will result in true thus returning the xml. // Suppress errors if the string is not well formed, where testing here. if (@simplexml_load_string($result['data'])) { return $result['data']; } else { return false; } # else }