示例#1
0
 /**
  * All access to the API is secured by https protocol.
  * All data is expected to be sent via json payloads with header Content-Type: application/json
  * All requests are normally authenticated by passing headers:
  * X-errormator-api-key: APIKEY - server side requests
  *
  * Each endpoint is defined following:
  * https://api.appenlight.com/api/ENDPOINT?protocol_version=0.4
  *
  * @param string $endpoint
  * @return boolean|object
  */
 public function send($endpoint)
 {
     if (!isset($this->_curl)) {
         $this->_curl = curl_init();
     }
     curl_setopt($this->_curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'X-errormator-api-key: ' . $this->_settings->getApiKey()));
     curl_setopt($this->_curl, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($this->_curl, CURLOPT_POST, true);
     curl_setopt($this->_curl, CURLOPT_HEADER, false);
     switch ($endpoint) {
         case self::SEND_LOGS:
             curl_setopt($this->_curl, CURLOPT_URL, $this->buildUrl($this->_logs));
             $jsonData = $this->_logs->toJSON();
             $this->_logs->clearData();
             break;
         case self::SEND_REPORTS:
             curl_setopt($this->_curl, CURLOPT_URL, $this->buildUrl($this->_reports));
             $jsonData = $this->_reports->toJSON();
             $this->_reports->clearData();
             break;
         case self::SEND_REQUEST_STATS:
             curl_setopt($this->_curl, CURLOPT_URL, $this->buildUrl($this->_requestStats));
             $jsonData = $this->_requestStats->toJSON();
             $this->_requestStats->clearData();
             break;
         default:
             $jsonData = null;
     }
     if ($jsonData !== null) {
         curl_setopt($this->_curl, CURLOPT_POSTFIELDS, $this->obfuscateSecureData($jsonData));
         $response = curl_exec($this->_curl);
         if (mb_strlen($response) > 2 && mb_strcut($response, 0, 2) === 'OK') {
             return true;
         } else {
             return json_decode($response);
         }
     } else {
         return false;
     }
 }