mirror of
https://github.com/retailcrm/mailgun-php.git
synced 2024-11-26 06:46:08 +03:00
PHPDoc typos fixed, minor performance changes
This commit is contained in:
parent
976a76a3b5
commit
2d9cd57d2e
@ -197,22 +197,30 @@ class RestClient
|
|||||||
*/
|
*/
|
||||||
public function responseHandler(ResponseInterface $responseObj)
|
public function responseHandler(ResponseInterface $responseObj)
|
||||||
{
|
{
|
||||||
$httpResponseCode = $responseObj->getStatusCode();
|
$httpResponseCode = (int)$responseObj->getStatusCode();
|
||||||
if ($httpResponseCode === 200) {
|
|
||||||
$data = (string) $responseObj->getBody();
|
switch ($httpResponseCode) {
|
||||||
|
case 200:
|
||||||
|
$data = (string)$responseObj->getBody();
|
||||||
$jsonResponseData = json_decode($data, false);
|
$jsonResponseData = json_decode($data, false);
|
||||||
$result = new \stdClass();
|
$result = new \stdClass();
|
||||||
// return response data as json if possible, raw if not
|
// return response data as json if possible, raw if not
|
||||||
$result->http_response_body = $data && $jsonResponseData === null ? $data : $jsonResponseData;
|
$result->http_response_body = $data && $jsonResponseData === null ? $data : $jsonResponseData;
|
||||||
} elseif ($httpResponseCode == 400) {
|
break;
|
||||||
throw new MissingRequiredParameters(ExceptionMessages::EXCEPTION_MISSING_REQUIRED_PARAMETERS.$this->getResponseExceptionMessage($responseObj));
|
case 400:
|
||||||
} elseif ($httpResponseCode == 401) {
|
throw new MissingRequiredParameters(ExceptionMessages::EXCEPTION_MISSING_REQUIRED_PARAMETERS . $this->getResponseExceptionMessage($responseObj));
|
||||||
|
break;
|
||||||
|
case 401:
|
||||||
throw new InvalidCredentials(ExceptionMessages::EXCEPTION_INVALID_CREDENTIALS);
|
throw new InvalidCredentials(ExceptionMessages::EXCEPTION_INVALID_CREDENTIALS);
|
||||||
} elseif ($httpResponseCode == 404) {
|
break;
|
||||||
throw new MissingEndpoint(ExceptionMessages::EXCEPTION_MISSING_ENDPOINT.$this->getResponseExceptionMessage($responseObj));
|
case 404:
|
||||||
} else {
|
throw new MissingEndpoint(ExceptionMessages::EXCEPTION_MISSING_ENDPOINT . $this->getResponseExceptionMessage($responseObj));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
throw new GenericHTTPError(ExceptionMessages::EXCEPTION_GENERIC_HTTP_ERROR, $httpResponseCode, $responseObj->getBody());
|
throw new GenericHTTPError(ExceptionMessages::EXCEPTION_GENERIC_HTTP_ERROR, $httpResponseCode, $responseObj->getBody());
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
$result->http_response_code = $httpResponseCode;
|
$result->http_response_code = $httpResponseCode;
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
@ -230,6 +238,8 @@ class RestClient
|
|||||||
if (json_last_error() == JSON_ERROR_NONE && isset($response->message)) {
|
if (json_last_error() == JSON_ERROR_NONE && isset($response->message)) {
|
||||||
return ' '.$response->message;
|
return ' '.$response->message;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -237,6 +247,8 @@ class RestClient
|
|||||||
*
|
*
|
||||||
* @param string $fieldName
|
* @param string $fieldName
|
||||||
* @param string|array $filePath
|
* @param string|array $filePath
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
*/
|
*/
|
||||||
protected function prepareFile($fieldName, $filePath)
|
protected function prepareFile($fieldName, $filePath)
|
||||||
{
|
{
|
||||||
@ -293,11 +305,7 @@ class RestClient
|
|||||||
*/
|
*/
|
||||||
private function generateEndpoint($apiEndpoint, $apiVersion, $ssl)
|
private function generateEndpoint($apiEndpoint, $apiVersion, $ssl)
|
||||||
{
|
{
|
||||||
if (!$ssl) {
|
return ($ssl ? 'https://' : 'http://') . $apiEndpoint . '/' . $apiVersion . '/';
|
||||||
return 'http://'.$apiEndpoint.'/'.$apiVersion.'/';
|
|
||||||
} else {
|
|
||||||
return 'https://'.$apiEndpoint.'/'.$apiVersion.'/';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -50,6 +50,8 @@ class Mailgun{
|
|||||||
* @param string $workingDomain
|
* @param string $workingDomain
|
||||||
* @param array $postData
|
* @param array $postData
|
||||||
* @param array $postFiles
|
* @param array $postFiles
|
||||||
|
*
|
||||||
|
* @return \stdClass
|
||||||
* @throws Exceptions\MissingRequiredMIMEParameters
|
* @throws Exceptions\MissingRequiredMIMEParameters
|
||||||
*/
|
*/
|
||||||
public function sendMessage($workingDomain, $postData, $postFiles = array()){
|
public function sendMessage($workingDomain, $postData, $postFiles = array()){
|
||||||
@ -86,7 +88,7 @@ class Mailgun{
|
|||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function verifyWebhookSignature($postData = NULL) {
|
public function verifyWebhookSignature($postData = NULL) {
|
||||||
if(is_null($postData)) {
|
if($postData === null) {
|
||||||
$postData = $_POST;
|
$postData = $_POST;
|
||||||
}
|
}
|
||||||
$hmac = hash_hmac('sha256', "{$postData["timestamp"]}{$postData["token"]}", $this->apiKey);
|
$hmac = hash_hmac('sha256', "{$postData["timestamp"]}{$postData["token"]}", $this->apiKey);
|
||||||
|
@ -276,11 +276,13 @@ class MessageBuilder
|
|||||||
/**
|
/**
|
||||||
* @param string $inlineImagePath
|
* @param string $inlineImagePath
|
||||||
* @param string|null $inlineImageName
|
* @param string|null $inlineImageName
|
||||||
|
*
|
||||||
|
* @return bool|true
|
||||||
* @throws InvalidParameter
|
* @throws InvalidParameter
|
||||||
*/
|
*/
|
||||||
public function addInlineImage($inlineImagePath, $inlineImageName = null)
|
public function addInlineImage($inlineImagePath, $inlineImageName = null)
|
||||||
{
|
{
|
||||||
if (preg_match("/^@/", $inlineImagePath)) {
|
if (strpos($inlineImagePath, '@') === 0) {
|
||||||
if (isset($this->files['inline'])) {
|
if (isset($this->files['inline'])) {
|
||||||
$inlineAttachment = array(
|
$inlineAttachment = array(
|
||||||
'filePath' => $inlineImagePath,
|
'filePath' => $inlineImagePath,
|
||||||
|
Loading…
Reference in New Issue
Block a user