Пример #1
0
 public static function callApi($url, $auth_token, $method = 'POST', $data = null)
 {
     $headers = array("Accept: application/json", "Content-Type: application/json");
     if ($auth_token) {
         $headers[] = "Authorization: OAuth oauth_token={$auth_token}";
     }
     $json_data = false;
     if (is_array($data)) {
         $json_data = json_encode($data);
         $headers[] = "Content-Length: " . strlen($json_data);
     }
     $request = HttpRequest::request($url, $method, $json_data, $headers);
     if ($request) {
         $results = json_decode($request);
         if (isset($results->int_err_code)) {
             throw new \ErrorException('There was an error returned from the API: ' . $results->msg . ' (' . $results->int_err_code . ')', 160);
         } elseif (isset($results->err)) {
             throw new \ErrorException('There was an error returned from the API: ' . $results->message . ' (' . $results->err . ')', 160);
         } else {
             return $results;
         }
     } else {
         $error = "API call returned an HTTP status code of " . curl_errno($ch);
         throw new \ErrorException($error, 107);
     }
 }
Пример #2
0
 public static function callApi($baseUrl, $queryParams, $command, $salt, $method = 'GET', $data = null, $returnUrl = false)
 {
     $queryString = '';
     if (is_array($queryParams)) {
         $first = true;
         foreach ($queryParams as $name => $value) {
             if ($first) {
                 $first = false;
             } else {
                 $queryString .= '&';
             }
             $queryString .= $name . '=' . urlencode($value);
         }
     }
     $checksum = sha1($command . $queryString . $salt);
     $url = $baseUrl . $command . '/?' . $queryString . '&checksum=' . $checksum;
     if ($returnUrl) {
         return $url;
     }
     $request = HttpRequest::request($url, $method);
     if ($request) {
         $xml = new \SimpleXMLElement($request);
         if ($xml) {
             if ($xml->returncode == 'SUCCESS') {
                 return $xml;
             } else {
                 throw new \ErrorException('An API error occured (' . $xml->messageKey . ') ' . $xml->message);
             }
         }
     } else {
         $error = "API call returned an HTTP status code of " . curl_errno($ch);
         throw new \ErrorException($error, 107);
     }
 }
Пример #3
0
 /**
  * Performs API call to WebEx XML API
  * 
  * @param String|SimpleXMLElement $xml Either the full XML to be sent or a SimpleXMLElement object
  * @return SimpleXMLElement The bodyContent section of successful API response
  * @throws ErrorException when the API call fails or it is unable to parse response.
  */
 public static function callApi($xml, $sitename)
 {
     if (is_object($xml)) {
         $xml = $xml->asXML();
     }
     $apiUrl = "https://{$sitename}.webex.com/WBXService/XMLService";
     $body = HttpRequest::request($apiUrl, 'POST', $xml);
     if ($body) {
         /*
          * Clear out unnecessary namespaces from returned XML
          */
         $body = preg_replace('/<[a-z]{1,}:/', '<', $body);
         $body = preg_replace('/<\\/[a-z]{1,}:/', '</', $body);
         libxml_use_internal_errors(true);
         $results = new \SimpleXMLElement($body);
         if ($results) {
             if ($results->header->response->result == 'SUCCESS') {
                 return $results->body->bodyContent;
             } else {
                 $error = "An error was returned from the API: " . $results->header->response->reason->__toString() . ' (' . $results->header->response->exceptionID->__toString() . ')';
                 throw new \ErrorException($error, 108);
             }
         } else {
             $errors = '';
             foreach (libxml_get_errors() as $error) {
                 $errors .= ",\t" . $error->message;
             }
             $error = "Unable to parse XML response, errors occured: {$errors}";
             throw new \ErrorException($error, 106);
         }
     } else {
         $error = "API call returned an HTTP status code of " . curl_errno($ch);
         throw new \ErrorException($error, 107);
     }
 }
Пример #4
0
 public static function callApi($url)
 {
     $request = HttpRequest::request($url);
     $success = preg_match('/^OK\\n(.*)/ms', $request, $success_matches);
     if ($success) {
         return $success_matches[1];
     } else {
         $error = preg_match('/^ERROR: (\\d+); (.*)$/', $request, $matches);
         if ($error) {
             throw new \ErrorException($matches[2], $matches[1]);
         } else {
             throw new \ErrorException('An API Error Occured: ' . $request, '300');
         }
     }
 }