/** * @param $call * @param array $params * @param string $method * @return array|null|\stdClass|mixed * @throws \RuntimeException */ protected function callApi($call, array $params = array(), $method = self::CALL_GET) { if (!isset($params['api_user'])) { $params['api_user'] = $this->config->getUser(); } if (!isset($params['api_key'])) { $params['api_key'] = $this->config->getPass(); } $options = array(\CURLOPT_RETURNTRANSFER => true, \CURLOPT_HEADER => false, \CURLOPT_ENCODING => '', \CURLOPT_SSL_VERIFYPEER => $this->config->getVerifySSL(), \CURLOPT_USERPWD => sprintf('%s:%s', $params['api_user'], $params['api_key'])); $output = $this->config->getOutput(); if (substr($call, -1 * strlen($output)) !== $output) { $call .= $output; } $url = $this->config->getBaseUrl() . $call; if ($method === self::CALL_GET) { $url .= '?' . http_build_query($params); } else { $options[\CURLOPT_HTTPHEADER] = array('expect:', 'user-agent: evodelavega-sendgrid/1.0;php'); $options[\CURLOPT_POST] = true; $options[\CURLOPT_POSTFIELDS] = $params; } $ch = $this->initCurl($url, $options); //we've set CURL_RETURNTRANSFER, curl_exec returns the result, or false $response = curl_exec($ch); return $this->processResult($response, $ch); }