DateTimeHelper::toSimpleDate($startdate), 'enddate' => DateTimeHelper::toSimpleDate($enddate), 'aggregated_by' => $aggregatedBy, 'offset' => (null != $offset) ? $offset : 1, 'limit' => (null != $limit) ? $limit : 100, )); //validate and preprocess url $_queryUrl = APIHelper::cleanUrl(Configuration::$BASEURI . $_queryBuilder); //prepare headers $_headers = array ( 'user-agent' => BaseController::USER_AGENT, 'api_key' => Configuration::$apiKey ); //call on-before Http callback $_httpRequest = new HttpRequest(HttpMethod::GET, $_headers, $_queryUrl); if ($this->getHttpCallBack() != null) { $this->getHttpCallBack()->callOnBeforeRequest($_httpRequest); } //and invoke the API call request to fetch the response $response = Request::get($_queryUrl, $_headers); $_httpResponse = new HttpResponse($response->code, $response->headers, $response->raw_body); $_httpContext = new HttpContext($_httpRequest, $_httpResponse); //call on-after Http callback if ($this->getHttpCallBack() != null) { $this->getHttpCallBack()->callOnAfterRequest($_httpContext); } //Error handling using HTTP status codes if ($response->code == 400) { throw new APIException('API Response', $_httpContext); } if ($response->code == 401) { throw new APIException('API Response', $_httpContext); } if ($response->code == 403) { throw new APIException('API Response', $_httpContext); } if ($response->code == 405) { throw new APIException('Invalid input', $_httpContext); } //handle errors defined at the API level $this->validateResponse($_httpResponse, $_httpContext); return $response->body; } }