public function mailgunRequest($type, $domain, $apiKey, $data, $method = Zend_Http_Client::GET, $uriOveride = false)
{
$client = new Zend_Http_Client();
$client->setAuth("api", $apiKey);
$client->setMethod($method);
if ($uriOveride) {
$client->setUri($uriOveride);
} else {
$client->setUri($this->apiUrl . $domain . "/" . $type);
}
if ($method == Zend_Http_Client::POST) {
foreach ($data as $key => $value) {
$client->setParameterPost($key, $value);
}
} else {
foreach ($data as $key => $value) {
$client->setParameterGet($key, $value);
}
}
try {
$response = $client->request();
if ($response->getStatus() == 200) {
return json_decode($response->getBody());
} else {
throw new Zend_Http_Exception("Error connecting to MailGun API. Returned error code: " . $response->getStatus() . " --- " . $response->getBody());
}
} catch (Exception $e) {
Mage::logException($e);
return false;
}
}