private function sendRequest($method, $args) { SpotTiming::start(__CLASS__ . '::' . __FUNCTION__); $reqarr = array('version' => '1.1', 'method' => $method, 'params' => $args); $content = json_encode($reqarr); /* * Actually perform the HTTP POST */ $svcProvHttp = new Services_Providers_Http(null); $svcProvHttp->setUsername($this->_username); $svcProvHttp->setPassword($this->_password); $svcProvHttp->setMethod('POST'); $svcProvHttp->setContentType('application/json'); $svcProvHttp->setRawPostData($content); $output = $svcProvHttp->perform($this->_url, null); if ($output['successful'] === false) { $errorStr = "ERROR: Could not decode json-data for NZBGet method '" . $method . "', " . $output['errorstr']; error_log($errorStr); throw new Exception($errorStr); } # if $response = json_decode($output['data'], true); if (is_array($response) && isset($response['error']) && isset($response['error']['code'])) { error_log("NZBGet RPC: Method '" . $method . "', " . $response['error']['message'] . " (" . $response['error']['code'] . ")"); throw new Exception("NZBGet RPC: Method '" . $method . "', " . $response['error']['message'] . " (" . $response['error']['code'] . ")"); } elseif (is_array($response) && isset($response['result'])) { $response = $response['result']; } SpotTiming::stop(__CLASS__ . '::' . __FUNCTION__, array($method, $args)); return $response; }
private function querySabnzbd($request) { $url = $this->_sabnzbd['url'] . "api?" . $request . '&apikey=' . $this->_sabnzbd['apikey'] . '&output=json'; $svcProvHttp = new Services_Providers_Http(null); $svcProvHttp->setUsername($this->_username); $svcProvHttp->setPassword($this->_password); $tmpData = $svcProvHttp->perform($url, null); return $tmpData['data']; }
/** * * Curl GET return xml or false if not well formed. * @param String $url * @return bool|mixed */ protected function getAndDownloadNzb($url) { // Initialize download retrieval class $svcHttp = new Services_Providers_Http($this->_cacheDao); $result = $svcHttp->perform($url); // Check if any error occured if (!$result['successful']) { trigger_error($result['errorstr']); return false; } // 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. $body = $result['data']; if (@simplexml_load_string($body)) { return $body; } else { return false; } return false; }
public function translateMultiple($dstLanguage, $list, $field) { /* * Try to obtain an translator token */ $translaterToken = $this->getAuthToken(); if ($translaterToken === false) { return false; } # if /* * Actually start translating our message */ $doc = new DOMDocument('1.0', 'utf-8'); $doc->formatOutput = true; $tar = $doc->createElement('TranslateArrayRequest'); $tar->appendChild($doc->createElement('AppId', '')); $tar->appendChild($doc->createElement('From', '')); $texts = $doc->createElement('Texts'); foreach ($list as $v) { $str = $doc->createElement('string'); $str->appendChild($doc->createTextNode($v[$field])); $str->setAttribute('xmlns', 'http://schemas.microsoft.com/2003/10/Serialization/Arrays'); $texts->appendChild($str); } # foreach $tar->appendChild($texts); $tar->appendChild($doc->createElement('To', $dstLanguage)); $doc->appendChild($tar); $svcPrvHttp = new Services_Providers_Http(null); $svcPrvHttp->setBearerAuth($translaterToken); $svcPrvHttp->setMethod('POST'); $svcPrvHttp->setRawPostData($doc->saveXML()); $svcPrvHttp->setContentType('text/xml'); $httpResult = $svcPrvHttp->perform(Services_Translation_Microsoft::translateUrl, false); /* * and use the result */ if ($httpResult['successful']) { /* * Loop through all results, and actually translate the * information */ $translated = simplexml_load_string($httpResult['data']); $listCounter = 0; foreach ($translated->TranslateArrayResponse as $tar) { $list[$listCounter][$field . '_translated'] = (string) $tar->TranslatedText; $listCounter++; } # foreach return $list; } else { return false; } # else }