Skip to content

Commit

Permalink
Introduced deliverability reporting request/models
Browse files Browse the repository at this point in the history
  • Loading branch information
ey-mailosaur authored and jm-mailosaur committed Sep 30, 2024
1 parent c2ec6a1 commit f109783
Show file tree
Hide file tree
Showing 9 changed files with 344 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/Models/BlockListResult.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace Mailosaur\Models;


class BlockListResult
{
/** @var string */
public $id;

/** @var string */
public $name;

/** @var \Mailosaur\Models\ResultEnum */
public $result;

public function __construct(\stdClass $data)
{
if (property_exists($data, 'id')) {
$this->id = $data->id;
}

if (property_exists($data, 'name')) {
$this->name = $data->name;
}

if (property_exists($data, 'result')) {
$this->result = ResultEnum::from($data->result);
}
}
}
73 changes: 73 additions & 0 deletions src/Models/Content.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php

namespace Mailosaur\Models;


class Content
{
/** @var bool */
public $embed;

/** @var bool */
public $iframe;

/** @var bool */
public $object;

/** @var bool */
public $script;

/** @var bool */
public $shortUrls;

/** @var int */
public $textSize;

/** @var int */
public $totalSize;

/** @var bool */
public $missingAlt;

/** @var bool */
public $missingListUnsubscribe;

public function __construct(\stdClass $data)
{
if (property_exists($data, 'embed')) {
$this->embed = $data->embed;
}

if (property_exists($data, 'iframe')) {
$this->iframe = $data->iframe;
}

if (property_exists($data, 'object')) {
$this->object = $data->object;
}

if (property_exists($data, 'script')) {
$this->script = $data->script;
}

if (property_exists($data, 'shortUrls')) {
$this->shortUrls = $data->shortUrls;
}

if (property_exists($data, 'textSize')) {
$this->textSize = $data->textSize;
}

if (property_exists($data, 'totalSize')) {
$this->totalSize = $data->totalSize;
}

if (property_exists($data, 'missingAlt')) {
$this->missingAlt = $data->missingAlt;
}

if (property_exists($data, 'missingListUnsubscribe')) {
$this->missingListUnsubscribe = $data->missingListUnsubscribe;
}
}
}
63 changes: 63 additions & 0 deletions src/Models/DeliverabilityReport.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

namespace Mailosaur\Models;


class DeliverabilityReport
{
/** @var \Mailosaur\Models\EmailAuthenticationResult */
public $spf;

/** @var \Mailosaur\Models\EmailAuthenticationResult[] */
public $dkim;

/** @var \Mailosaur\Models\EmailAuthenticationResult */
public $dmarc;

/** @var \Mailosaur\Models\BlockListResult[] */
public $blockLists = array();

/** @var \Mailosaur\Models\Content */
public $content;

/** @var \Mailosaur\Models\DnsRecords */
public $dnsRecords;

/** @var \Mailosaur\Models\SpamAssassinResult */
public $spamAssassin;

public function __construct(\stdClass $data)
{
if (property_exists($data, 'spf')) {
$this->spf = new EmailAuthenticationResult($data->spf);
}

if (property_exists($data, 'dkim') && is_array($data->dkim)) {
foreach ($data->dkim as $dkimResult) {
$this->dkim[] = new EmailAuthenticationResult($dkimResult);
}
}

if (property_exists($data, 'dmarc')) {
$this->dmarc = new EmailAuthenticationResult($data->dmarc);
}

if (property_exists($data, 'blockLists') && is_array($data->blockLists)) {
foreach ($data->blockLists as $blockList) {
$this->blockLists[] = new BlockListResult($blockList);
}
}

if (property_exists($data, 'content')) {
$this->content = new Content($data->content);
}

if (property_exists($data, 'dnsRecords')) {
$this->dnsRecords = new DnsRecords($data->dnsRecords);
}

if (property_exists($data, 'spamAssassin')) {
$this->spamAssassin = new SpamAssassinResult($data->spamAssassin);
}
}
}
31 changes: 31 additions & 0 deletions src/Models/DnsRecords.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace Mailosaur\Models;


class DnsRecords
{
/** @var string[] */
public $a;

/** @var string[] */
public $mx;

/** @var string[] */
public $ptr;

public function __construct(\stdClass $data)
{
if (property_exists($data, 'a') && is_array($data->a)) {
$this->a = $data->a;
}

if (property_exists($data, 'mx') && is_array($data->mx)) {
$this->mx = $data->mx;
}

if (property_exists($data, 'ptr') && is_array($data->ptr)) {
$this->ptr = $data->ptr;
}
}
}
44 changes: 44 additions & 0 deletions src/Models/EmailAuthenticationResult.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace Mailosaur\Models;


class EmailAuthenticationResult
{
/** @var \Mailosaur\Models\ResultEnum */
public $result;

/** @var string */
public $description;

/** @var string */
public $rawValue;

/** @var [] */
public $tags;

public function __construct(\stdClass $data)
{
if (property_exists($data, 'result')) {
$this->result = ResultEnum::from($data->result);
}

if (property_exists($data, 'description')) {
$this->description = $data->description;
}

if (property_exists($data, 'rawValue')) {
$this->rawValue = $data->rawValue;
}

if (property_exists($data, 'tags') && is_array($data->tags)) {
foreach ($data->tags as $tag) {
if (is_object($tag)) {
foreach ($tag as $key => $value) {
$this->tags[$key] = $value;
}
}
}
}
}
}
12 changes: 12 additions & 0 deletions src/Models/ResultEnum.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace Mailosaur\Models;


enum ResultEnum: string
{
case Pass = "Pass";
case Warning = "Warning";
case Fail = "Fail";
case Timeout = "Timeout";
}
33 changes: 33 additions & 0 deletions src/Models/SpamAssassinResult.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace Mailosaur\Models;


class SpamAssassinResult
{
/** @var double */
public $score;

/** @var \Mailosaur\Models\ResultEnum */
public $result;

/** @var \Mailosaur\Models\SpamAssassinRule[] */
public $rules = array();

public function __construct(\stdClass $data)
{
if (property_exists($data, 'score')) {
$this->score = $data->score;
}

if (property_exists($data, 'result')) {
$this->result = ResultEnum::from($data->result);
}

if (property_exists($data, 'rules') && is_array($data->rules)) {
foreach ($data->rules as $rule) {
$this->rules[] = new SpamAssassinRule($rule);
}
}
}
}
19 changes: 19 additions & 0 deletions src/Operations/Analysis.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@


use Mailosaur\Models\SpamAnalysisResult;
use Mailosaur\Models\DeliverabilityReport;

class Analysis extends AOperation
{
Expand All @@ -31,4 +32,22 @@ public function spam($email)

return new SpamAnalysisResult($response);
}

/**
* <strong>Perform a deliverability report</strong>
*
* @param string $email The identifier of the email to be analyzed.
*
* @return DeliverabilityReport
* @throws \Mailosaur\Models\MailosaurException
* @see https://mailosaur.com/docs/api/analysis Perform a deliverability test docs
* @example https://mailosaur.com/docs/api/analysis
*/
public function deliverability($email)
{
$response = $this->request('api/analysis/deliverability/' . urlencode($email));

$response = json_decode($response);
return new DeliverabilityReport($response);
}
}
38 changes: 38 additions & 0 deletions tests/EmailsTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,44 @@ public function testSpamAnalysis()
}
}

public function testDeliverabilityReport()
{
$targetId = self::$emails[0]->id;

$result = self::$client->analysis->deliverability($targetId);

$this->assertNotNull($result);

$this->assertNotNull($result->spf);

$this->assertNotNull($result->dkim);
foreach ($result->dkim as $dkim) {
$this->assertNotNull($dkim);
}

$this->assertNotNull($result->dmarc);

$this->assertNotNull($result->blockLists);
foreach ($result->blockLists as $blockList) {
$this->assertNotNull($blockList);
$this->assertNotNull($blockList->id);
$this->assertNotNull($blockList->name);
}

$this->assertNotNull($result->content);

$this->assertNotNull($result->dnsRecords);
$this->assertNotNull($result->dnsRecords->a);
$this->assertNotNull($result->dnsRecords->mx);
$this->assertNotNull($result->dnsRecords->ptr);

$this->assertNotNull($result->spamAssassin);
foreach ($result->spamAssassin->rules as $rule) {
$this->assertNotEmpty($rule->rule);
$this->assertNotEmpty($rule->description);
}
}

public function testDelete()
{
$targetEmailId = self::$emails[4]->id;
Expand Down

0 comments on commit f109783

Please sign in to comment.