Skip to content

Commit

Permalink
Merge pull request #57 from pgraham3/master
Browse files Browse the repository at this point in the history
Adds template alias support
  • Loading branch information
Andrew Theken authored Jul 29, 2019
2 parents 70162fe + 923fc63 commit f11540d
Showing 1 changed file with 29 additions and 18 deletions.
47 changes: 29 additions & 18 deletions src/Postmark/PostmarkClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function sendEmail($from, $to, $subject, $htmlBody = NULL, $textBody = NULL,
$body['TrackOpens'] = $trackOpens;
$body['Attachments'] = $attachments;
$body['Metadata'] = $metadata;

// Since this parameter can override a per-server setting
// we have to check whether it was actually set.
// And only include it in the API call if that is the case.
Expand All @@ -76,7 +76,7 @@ function sendEmail($from, $to, $subject, $htmlBody = NULL, $textBody = NULL,
*
* @param string $from The sender of the email. (Your account must have an associated Sender Signature for the address used.)
* @param string $to The recipient of the email.
* @param integer $templateId The ID of the template to use to generate the content of this message.
* @param integer|string $templateIdOrAlias The ID or alias of the template to use to generate the content of this message.
* @param array $templateModel The values to combine with the Templated content.
* @param boolean $inlineCss If the template contains an HTMLBody, CSS is automatically inlined, you may opt-out of this by passing 'false' for this parameter.
* @param string $tag A tag associated with this message, useful for classifying sent messages.
Expand All @@ -90,9 +90,9 @@ function sendEmail($from, $to, $subject, $htmlBody = NULL, $textBody = NULL,
* @param array $metadata Add metadata to the message. The metadata is an associative array , and values will be evaluated as strings by Postmark.
* @return DynamicResponseModel
*/
function sendEmailWithTemplate($from, $to, $templateId, $templateModel, $inlineCss = true,
function sendEmailWithTemplate($from, $to, $templateIdOrAlias, $templateModel, $inlineCss = true,
$tag = NULL, $trackOpens = true, $replyTo = NULL,
$cc = NULL, $bcc = NULL, $headers = NULL, $attachments = NULL,
$cc = NULL, $bcc = NULL, $headers = NULL, $attachments = NULL,
$trackLinks = NULL, $metadata = NULL) {

$body = array();
Expand All @@ -106,18 +106,25 @@ function sendEmailWithTemplate($from, $to, $templateId, $templateModel, $inlineC
$body['TrackOpens'] = $trackOpens;
$body['Attachments'] = $attachments;
$body['TemplateModel'] = $templateModel;
$body['TemplateId'] = $templateId;
$body['InlineCss'] = $inlineCss;
$body['Metadata'] = $metadata;


// Since this parameter can override a per-server setting
// we have to check whether it was actually set.
// And only include it in the API call if that is the case.
if ($trackLinks !== NULL) {
$body['TrackLinks'] = $trackLinks;
}

if ( is_int( $templateIdOrAlias ) ) {
$body['TemplateId'] = $templateIdOrAlias;

// Uses the Template Alias if specified instead of Template ID.
} else {
$body['TemplateAlias'] = $templateIdOrAlias;
}


return new DynamicResponseModel($this->processRestRequest('POST', '/email/withTemplate', $body));
}
Expand Down Expand Up @@ -190,7 +197,7 @@ function getDeliveryStatistics() {
* @return DynamicResponseModel
*/
function getBounces($count = 100, $offset = 0, $type = NULL,
$inactive = NULL, $emailFilter = NULL, $tag = NULL, $messageID = NULL,
$inactive = NULL, $emailFilter = NULL, $tag = NULL, $messageID = NULL,
$fromdate = NULL, $todate = NULL) {

$query = array();
Expand Down Expand Up @@ -313,13 +320,13 @@ function editServer($name = NULL, $color = NULL, $rawEmailEnabled = NULL,
* @param string $tag Filter by tag.
* @param string $subject Filter by subject.
* @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 $fromdate Filter to messages on or after YYYY-MM-DD
* @param string $todate Filter to messages on or before YYYY-MM-DD
* @param string $metadata An associatative array of key-values that must all match values included in the metadata of matching sent messages.
* @return DynamicResponseModel
*/
function getOutboundMessages($count = 100, $offset = 0, $recipient = NULL,
$fromEmail = NULL, $tag = NULL, $subject = NULL, $status = NULL,
$fromEmail = NULL, $tag = NULL, $subject = NULL, $status = NULL,
$fromdate = NULL, $todate = NULL, $metadata = NULL) {

$query = array();
Expand Down Expand Up @@ -373,7 +380,7 @@ function getOutboundMessageDump($id) {
* @param string $subject Filter by the message subject
* @param string $mailboxHash Filter by the mailboxHash
* @param string $status Filter by status ('blocked' or 'processed')
* @param string $fromdate Filter to messages on or after YYYY-MM-DD
* @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 DynamicResponseModel
*/
Expand Down Expand Up @@ -757,7 +764,7 @@ function getOutboundClickBrowserFamilyStatistics($tag = NULL, $fromdate = NULL,
}

/**
* Get information about which browsers platforms (Desktop, Mobile, etc.) were used to open
* Get information about which browsers platforms (Desktop, Mobile, etc.) were used to open
* tracked links for the messages sent using this Server,
* optionally filtering on message tag, and a to and from date.
*
Expand All @@ -777,7 +784,7 @@ function getOutboundClickBrowserPlatformStatistics($tag = NULL, $fromdate = NULL
}

/**
* Get information about part of the message (HTML or Text)
* Get information about part of the message (HTML or Text)
* tracked links were clicked from in messages sent using this Server,
* optionally filtering on message tag, and a to and from date.
*
Expand Down Expand Up @@ -907,7 +914,7 @@ function deleteInboundRuleTrigger($id) {
/**
* Delete a template.
*
* @param integer $id The ID of the template to delete.
* @param string $id The ID or alias of the template to delete.
* @return DynamicResponseModel
*/
function deleteTemplate($id) {
Expand All @@ -921,43 +928,47 @@ function deleteTemplate($id) {
* @param string $subject The template to be used for the 'subject' of emails sent using this template.
* @param string $htmlBody The template to be used for the 'htmlBody' of emails sent using this template, optional if 'textBody' is not NULL.
* @param string $textBody The template to be used for the 'textBody' of emails sent using this template, optional if 'htmlBody' is not NULL.
* @param string $alias An optional string you can provide to identify this Template. Allowed characters are numbers, ASCII letters, and ‘.’, ‘-’, ‘_’ characters, and the string has to start with a letter.
*
* @return DynamicResponseModel
*/
function createTemplate($name, $subject, $htmlBody, $textBody) {
function createTemplate($name, $subject, $htmlBody, $textBody, $alias = NULL) {
$template = array();
$template["name"] = $name;
$template["subject"] = $subject;
$template["htmlBody"] = $htmlBody;
$template["textBody"] = $textBody;
$template["alias"] = $alias;
return new DynamicResponseModel($this->processRestRequest('POST', "/templates", $template));
}

/**
* Edit a template
*
* @param integer $id The ID of the template you wish to update.
* @param string $id The ID or alias of the template you wish to update.
* @param string $name The friendly name for this template.
* @param string $subject The template to be used for the 'subject' of emails sent using this template.
* @param string $htmlBody The template to be used for the 'htmlBody' of emails sent using this template.
* @param string $textBody The template to be used for the 'textBody' of emails sent using this template.
* @param string $alias An optional string you can provide to identify this Template. Allowed characters are numbers, ASCII letters, and ‘.’, ‘-’, ‘_’ characters, and the string has to start with a letter.
*
* @return DynamicResponseModel
*/
function editTemplate($id, $name = NULL, $subject = NULL, $htmlBody = NULL, $textBody = NULL) {
function editTemplate($id, $name = NULL, $subject = NULL, $htmlBody = NULL, $textBody = NULL, $alias = NULL) {
$template = array();
$template["name"] = $name;
$template["subject"] = $subject;
$template["htmlBody"] = $htmlBody;
$template["textBody"] = $textBody;
$template["alias"] = $alias;

return new DynamicResponseModel($this->processRestRequest('PUT', "/templates/$id", $template));
}

/**
* Get the current information for a specific template.
*
* @param integer $id the Id for the template info you wish to retrieve.
* @param string $id the Id or alias for the template info you wish to retrieve.
* @return DynamicResponseModel
*/
function getTemplate($id) {
Expand Down

0 comments on commit f11540d

Please sign in to comment.