/** * Make a call to a DataSift API endpoint. * * @param DataSift_User $user The user's username. * @param string $endPoint The endpoint of the API call. * @param array $headers The headers to be sent. * @param array $successCode The codes defined as a success for the call. * @param array $params The parameters to be passed along with the request. * @param string $userAgent The HTTP User-Agent header. * * @return array The response from the server. * @throws DataSift_Exception_APIError * @throws DataSift_Exception_RateLimitExceeded * @throws DataSift_Exception_NotYetImplemented */ public static function call(DataSift_User $user, $endPoint, $method, $params = array(), $headers = array(), $userAgent = DataSift_User::USER_AGENT, $qs = array(), $ingest = false) { $decodeCode = array(self::HTTP_OK, self::HTTP_NO_CONTENT); // Curl is required if (!function_exists('curl_init')) { throw new DataSift_Exception_NotYetImplemented('Curl is required for DataSift_ApiClient'); } if (empty($headers)) { $headers = array('Auth: ' . $user->getUsername() . ':' . $user->getAPIKey(), 'Expect:', 'Content-Type: application/json'); } $ssl = $user->useSSL(); // Build the full endpoint URL if ($ingest) { $url = 'http' . ($ssl ? 's' : '') . '://' . $user->getIngestUrl() . $endPoint; } else { $url = 'http' . ($ssl ? 's' : '') . '://' . $user->getApiUrl() . $user->getApiVersion() . '/' . $endPoint; } $ch = self::initialize($method, $ssl, $url, $headers, $params, $userAgent, $qs, $ingest); $res = curl_exec($ch); $info = curl_getinfo($ch); curl_close($ch); $res = self::parseHTTPResponse($res); if ($user->getDebug()) { $log['headers'] = $res['headers']; $log['status'] = $info['http_code']; $log['body'] = self::decodeBody($res); $user->setLastResponse($log); } $retval = array('response_code' => $info['http_code'], 'data' => strlen($res['body']) == 0 ? array() : self::decodeBody($res), 'rate_limit' => isset($res['headers']['x-ratelimit-limit']) ? $res['headers']['x-ratelimit-limit'] : -1, 'rate_limit_remaining' => isset($res['headers']['x-ratelimit-remaining']) ? $res['headers']['x-ratelimit-remaining'] : -1); return $retval; }