private function call($decode) { // Prep headers curl_setopt($this->curl, CURLOPT_HTTPHEADER, array_merge($this->curl_headers, TraackrApi::getExtraHeaders())); // Make the call! $curl_exec = curl_exec($this->curl); $logger = TraackrAPI::getLogger(); if ($curl_exec === false) { $logger->error('cUrl error: ' . curl_error($this->curl)); $info = curl_getinfo($this->curl); throw new TraackrApiException('API call failed (' . $info['url'] . '): ' . curl_error($this->curl)); } if (is_null($curl_exec)) { $logger->error('cUrl error: Return was null'); throw new TraackrApiException('API call failed. Response was null.'); } $httpcode = curl_getinfo($this->curl, CURLINFO_HTTP_CODE); if ($httpcode != "200") { $info = curl_getinfo($this->curl); $logger->error('cUrl HTTP error: ' . $httpcode); if ($httpcode == "400") { // Let's try to see if it's a bad customer key if ($curl_exec === "Customer key not found") { throw new InvalidCustomerKeyException('Invalid Customer Key (HTTP 400): ' . $curl_exec, $httpcode); } else { throw new MissingParameterException('Missing or Invalid argument/parameter (HTTP 400): ' . $curl_exec, $httpcode); } } elseif ($httpcode == "403") { throw new InvalidApiKeyException('Invalid API key (HTTP 403): ' . $curl_exec, $httpcode); } elseif ($httpcode == "404") { throw new NotFoundException('API resource not found (HTTP 404): ' . $info['url'], $httpcode); } else { throw new TraackrApiException('API HTTP Error (HTTP ' . $httpcode . '): ' . $curl_exec, $httpcode); } return false; } // API MUST return UTF8 if ($decode) { $rez = json_decode($curl_exec, true); } else { $rez = $curl_exec; } return is_null($rez) ? false : $rez; }