-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
1,002 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<phpunit xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" | ||
bootstrap = "vendor/autoload.php" | ||
backupGlobals = "false" | ||
backupStaticAttributes = "false" | ||
colors = "true" | ||
convertErrorsToExceptions = "true" | ||
convertNoticesToExceptions = "true" | ||
convertWarningsToExceptions = "true" | ||
processIsolation = "false" | ||
stopOnFailure = "false"> | ||
|
||
<testsuites> | ||
<testsuite name="MailerSend PHP SDK"> | ||
<directory>tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
<php> | ||
<env name="APP_ENV" value="testing"/> | ||
</php> | ||
|
||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<?php | ||
|
||
namespace MailerSend\Endpoints; | ||
|
||
use Assert\Assertion; | ||
use MailerSend\Exceptions\MailerSendAssertException; | ||
use MailerSend\Helpers\Builder\Attachment; | ||
use MailerSend\Helpers\Builder\EmailParams; | ||
use MailerSend\Helpers\Builder\Personalization; | ||
use MailerSend\Helpers\Builder\Recipient; | ||
use MailerSend\Helpers\Builder\Variable; | ||
use MailerSend\Helpers\GeneralHelpers; | ||
use Tightenco\Collect\Support\Collection; | ||
|
||
class BulkEmail extends AbstractEndpoint | ||
{ | ||
protected string $endpoint = 'bulk-email'; | ||
|
||
/** | ||
* @throws \JsonException | ||
* @throws \MailerSend\Exceptions\MailerSendAssertException | ||
* @throws \Psr\Http\Client\ClientExceptionInterface | ||
*/ | ||
public function send(array $bulkParams): array | ||
{ | ||
GeneralHelpers::assert(fn () => Assertion::minCount($bulkParams, 1, 'Bulk params should contain at least 1 email')); | ||
|
||
$requestData = []; | ||
|
||
foreach ($bulkParams as $params) { | ||
GeneralHelpers::validateEmailParams($params); | ||
|
||
$recipients_mapped = GeneralHelpers::mapToArray($params->getRecipients(), Recipient::class); | ||
$cc_mapped = GeneralHelpers::mapToArray($params->getCc(), Recipient::class); | ||
$bcc_mapped = GeneralHelpers::mapToArray($params->getBcc(), Recipient::class); | ||
$attachments_mapped = GeneralHelpers::mapToArray($params->getAttachments(), Attachment::class); | ||
$variables_mapped = GeneralHelpers::mapToArray($params->getVariables(), Variable::class); | ||
$personalization_mapped = GeneralHelpers::mapToArray($params->getPersonalization(), Personalization::class); | ||
|
||
$requestData[] = array_filter( | ||
[ | ||
'from' => [ | ||
'email' => $params->getFrom(), | ||
'name' => $params->getFromName(), | ||
], | ||
'reply_to' => [ | ||
'email' => $params->getReplyTo(), | ||
'name' => $params->getReplyToName(), | ||
], | ||
'to' => $recipients_mapped, | ||
'cc' => $cc_mapped, | ||
'bcc' => $bcc_mapped, | ||
'subject' => $params->getSubject(), | ||
'template_id' => $params->getTemplateId(), | ||
'text' => $params->getText(), | ||
'html' => $params->getHtml(), | ||
'tags' => $params->getTags(), | ||
'attachments' => $attachments_mapped, | ||
'variables' => $variables_mapped, | ||
'personalization' => $personalization_mapped | ||
], | ||
fn ($v) => is_array($v) ? array_filter($v, fn ($v) => $v !== null) : $v !== null | ||
); | ||
} | ||
|
||
return $this->httpLayer->post( | ||
$this->buildUri($this->endpoint), | ||
$requestData | ||
); | ||
} | ||
|
||
/** | ||
* @param string $bulkEmailId | ||
* @return array | ||
* @throws \JsonException | ||
* @throws \Psr\Http\Client\ClientExceptionInterface | ||
*/ | ||
public function getStatus(string $bulkEmailId): array | ||
{ | ||
GeneralHelpers::assert( | ||
fn () => Assertion::minLength($bulkEmailId, 1, 'Bulk email id is required.') | ||
); | ||
|
||
return $this->httpLayer->get( | ||
$this->buildUri("$this->endpoint/$bulkEmailId") | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.