Added "complaints" to TotalResponse (#509)

This commit is contained in:
Tobias Nyholm 2019-01-05 19:56:55 +01:00 committed by GitHub
parent 02e3191bc9
commit 09113482ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 84 additions and 2 deletions

View File

@ -34,6 +34,11 @@ class TotalResponseItem
*/
private $failed;
/**
* @var array
*/
private $complained;
/**
* @param array $data
*
@ -45,7 +50,8 @@ class TotalResponseItem
isset($data['time']) ? new \DateTime($data['time']) : null,
isset($data['accepted']) ? $data['accepted'] : [],
isset($data['delivered']) ? $data['delivered'] : [],
isset($data['failed']) ? $data['failed'] : []
isset($data['failed']) ? $data['failed'] : [],
isset($data['complained']) ? $data['complained'] : []
);
}
@ -54,13 +60,15 @@ class TotalResponseItem
* @param array $accepted
* @param array $delivered
* @param array $failed
* @param array $complained
*/
private function __construct(\DateTime $time, array $accepted, array $delivered, array $failed)
private function __construct(\DateTime $time, array $accepted, array $delivered, array $failed, array $complained)
{
$this->time = $time;
$this->accepted = $accepted;
$this->delivered = $delivered;
$this->failed = $failed;
$this->complained = $complained;
}
/**
@ -94,4 +102,12 @@ class TotalResponseItem
{
return $this->failed;
}
/**
* @return array
*/
public function getComplained()
{
return $this->complained;
}
}

View File

@ -0,0 +1,66 @@
<?php
/*
* Copyright (C) 2013 Mailgun
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
namespace Mailgun\Tests\Model\Stats;
use Mailgun\Model\Stats\TotalResponse;
use Mailgun\Tests\Model\BaseModelTest;
class TotalResponseTest extends BaseModelTest
{
public function testCreate()
{
$json =
<<<'JSON'
{
"end": "Fri, 01 Apr 2012 00:00:00 UTC",
"resolution": "month",
"start": "Tue, 14 Feb 2012 00:00:00 UTC",
"stats": [
{
"time": "Tue, 14 Feb 2012 00:00:00 UTC",
"accepted": {
"outgoing": 10,
"incoming": 5,
"total": 15
},
"delivered": {
"smtp": 15,
"http": 5,
"total": 20
},
"failed": {
"permanent": {
"bounce": 4,
"delayed-bounce": 1,
"suppress-bounce": 1,
"suppress-unsubscribe": 2,
"suppress-complaint": 3,
"total": 10
},
"temporary": {
"espblock": 1
}
},
"complained": {
"total": 1
}
}
]
}
JSON;
$model = TotalResponse::create(json_decode($json, true));
$this->assertEquals('2012-02-14', $model->getStart()->format('Y-m-d'));
$this->assertCount(1, $model->getStats());
$stats = $model->getStats();
$stats = $stats[0];
$this->assertEquals('2012-02-14', $stats->getTime()->format('Y-m-d'));
$this->assertEquals('1', $stats->getComplained()['total']);
}
}