Skip to content

Commit

Permalink
Merge upstream changes to docs and HTTP Status Code handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
atheken committed Oct 26, 2016
2 parents 0a0904d + bdd1815 commit bd36391
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 26 deletions.
18 changes: 9 additions & 9 deletions src/Postmark/PostmarkClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function __construct($serverToken, $timeout = 30) {
* @param array $headers Headers to be included with the sent email message.
* @param array $attachments An array of PostmarkAttachment objects.
* @param string $trackLinks Can be any of "None", "HtmlAndText", "HtmlOnly", "TextOnly" to enable link tracking.
* @return DyanamicResponseModel
* @return DynamicResponseModel
*/
function sendEmail($from, $to, $subject, $htmlBody = NULL, $textBody = NULL,
$tag = NULL, $trackOpens = true, $replyTo = NULL, $cc = NULL, $bcc = NULL,
Expand Down Expand Up @@ -85,7 +85,7 @@ function sendEmail($from, $to, $subject, $htmlBody = NULL, $textBody = NULL,
* @param array $headers Headers to be included with the sent email message.
* @param array $attachments An array of PostmarkAttachment objects.
* @param string $trackLinks Can be any of "None", "HtmlAndText", "HtmlOnly", "TextOnly" to enable link tracking.
* @return DyanamicResponseModel
* @return DynamicResponseModel
*/
function sendEmailWithTemplate($from, $to, $templateId, $templateModel, $inlineCss = true,
$tag = NULL, $trackOpens = true, $replyTo = NULL,
Expand Down Expand Up @@ -143,7 +143,7 @@ private function fixHeaders($headers) {
*
* @param array $emailBatch An array of emails to be sent in one batch.
*
* @return DyanamicResponseModel
* @return DynamicResponseModel
*/
function sendEmailBatch($emailBatch = array()) {

Expand All @@ -164,7 +164,7 @@ function sendEmailBatch($emailBatch = array()) {
/**
* Get an overview of the delivery statistics for all email that has been sent through this Server.
*
* @return DyanamicResponseModel
* @return DynamicResponseModel
*/
function getDeliveryStatistics() {
return new DynamicResponseModel($this->processRestRequest('GET', '/deliverystats'));
Expand Down Expand Up @@ -201,7 +201,7 @@ function getBounces($count = 100, $offset = 0, $type = NULL,
* Locate information on a specific email bounce.
*
* @param integer $id The ID of the bounce to get.
* @return DyanamicResponseModel
* @return DynamicResponseModel
*/
function getBounce($id) {
return new DynamicResponseModel($this->processRestRequest('GET', "/bounces/$id"));
Expand All @@ -221,7 +221,7 @@ function getBounceDump($id) {
* Cause the email address associated with a Bounce to be reactivated.
*
* @param integer $id The bounce which has a deactivated email address.
* @return DyanamicResponseModel
* @return DynamicResponseModel
*/
function activateBounce($id) {
return new DynamicResponseModel($this->processRestRequest('PUT', "/bounces/$id/activate"));
Expand All @@ -242,7 +242,7 @@ function getBounceTags() {
* Get the settings for the server associated with this PostmarkClient instance
* (defined by the $server_token you passed when instantiating this client)
*
* @return DyanamicResponseModel
* @return DynamicResponseModel
*/
function getServer() {
return new DynamicResponseModel($this->processRestRequest('GET', '/server'));
Expand All @@ -263,7 +263,7 @@ function getServer() {
* @param bool $trackOpens Indicates if all emails being sent through this server have open tracking enabled.
* @param string $inboundDomain Inbound domain for MX setup.
* @param integer $inboundSpamThreshold The maximum spam score for an inbound message before it's blocked (range from 0-30).
* @return DyanamicResponseModel
* @return DynamicResponseModel
*/
function editServer($name = NULL, $color = NULL, $rawEmailEnabled = NULL,
$smtpApiActivated = NULL, $inboundHookUrl = NULL, $bounceHookUrl = NULL,
Expand Down Expand Up @@ -298,7 +298,7 @@ function editServer($name = NULL, $color = NULL, $rawEmailEnabled = NULL,
* @param string $status The current status for the outbound messages to return defaults to 'sent'
* @param string $fromdate Filter to messages on or after YYYY-MM-DD
* @param string $todate Filter to messages on or before YYYY-MM-DD
* @return DyanamicResponseModel
* @return DynamicResponseModel
*/
function getOutboundMessages($count = 100, $offset = 0, $recipient = NULL,
$fromEmail = NULL, $tag = NULL, $subject = NULL, $status = NULL,
Expand Down
28 changes: 11 additions & 17 deletions src/Postmark/PostmarkClientBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,42 +139,36 @@ protected function processRestRequest($method = NULL, $path = NULL, array $body

$response = $client->request($method, $path, $options);

$result = NULL;

switch ($response->getStatusCode()) {
case 200:
$result = json_decode($response->getBody(), true);
break;
return json_decode($response->getBody(), true);
case 401:
$ex = new PostmarkException();
$ex->message = 'Unauthorized: Missing or incorrect API token in header. ' .
'Please verify that you used the correct token when you constructed your client.';
$ex->httpStatusCode = 401;
throw $ex;
break;
case 422:
$ex = new PostmarkException();
$body = json_decode($response->getBody(), true);
$ex->httpStatusCode = 422;
$ex->postmarkApiErrorCode = $body['ErrorCode'];
$ex->message = $body['Message'];
throw $ex;
break;
case 500:
$ex = new PostmarkException();
$ex->httpStatusCode = 500;
$ex->message = 'Internal Server Error: This is an issue with Postmark’s servers processing your request. ' .
'In most cases the message is lost during the process, ' .
'and Postmark is notified so that we can investigate the issue.';
throw $ex;
break;
case 503:
$ex = new PostmarkException();
$ex->httpStatusCode = 503;
$ex->message = 'The Postmark API is currently unavailable due to scheduled downtime. Please try your request again, later.';
$ex->message = 'The Postmark API is currently unavailable, please try your request later.';
throw $ex;
// This should cover case 422, and any others that are possible:
default:
$ex = new PostmarkException();
$body = json_decode($response->getBody(), true);
$ex->httpStatusCode = $response->getStatusCode();
$ex->postmarkApiErrorCode = $body['ErrorCode'];
$ex->message = $body['Message'];
throw $ex;
break;
}
return $result;

}
}

0 comments on commit bd36391

Please sign in to comment.