Fixing broken suppression API (#332)

* Fixing broken suppression API

* cs
This commit is contained in:
Tobias Nyholm 2017-04-07 22:09:59 +02:00 committed by GitHub
parent 27d13d85fd
commit ae9ee585a2
8 changed files with 308 additions and 250 deletions

View File

@ -0,0 +1,123 @@
<?php
/*
* Copyright (C) 2013-2016 Mailgun
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
namespace Mailgun\Model\Suppression\Bounce;
/**
* @author Sean Johnson <sean@mailgun.com>
*/
class Bounce
{
/**
* @var string
*/
private $address;
/**
* @var string
*/
private $code;
/**
* @var string
*/
private $error;
/**
* @var \DateTime
*/
private $createdAt;
/**
* @param string $address
*/
private function __construct($address)
{
$this->address = $address;
$this->createdAt = new \DateTime();
}
/**
* @param array $data
*
* @return Bounce
*/
public static function create(array $data)
{
$bounce = new self($data['address']);
if (isset($data['code'])) {
$bounce->setCode($data['code']);
}
if (isset($data['error'])) {
$bounce->setError($data['error']);
}
if (isset($data['created_at'])) {
$bounce->setCreatedAt(new \DateTime($data['created_at']));
}
return $bounce;
}
/**
* @return string
*/
public function getAddress()
{
return $this->address;
}
/**
* @return string
*/
public function getCode()
{
return $this->code;
}
/**
* @param string $code
*/
private function setCode($code)
{
$this->code = $code;
}
/**
* @return string
*/
public function getError()
{
return $this->error;
}
/**
* @param string $error
*/
private function setError($error)
{
$this->error = $error;
}
/**
* @return \DateTime
*/
public function getCreatedAt()
{
return $this->createdAt;
}
/**
* @param \DateTime $createdAt
*/
private function setCreatedAt(\DateTime $createdAt)
{
$this->createdAt = $createdAt;
}
}

View File

@ -14,112 +14,6 @@ use Mailgun\Model\ApiResponse;
/** /**
* @author Sean Johnson <sean@mailgun.com> * @author Sean Johnson <sean@mailgun.com>
*/ */
final class ShowResponse implements ApiResponse final class ShowResponse extends Bounce implements ApiResponse
{ {
/**
* @var string
*/
private $address;
/**
* @var string
*/
private $code;
/**
* @var string
*/
private $error;
/**
* @var \DateTime
*/
private $createdAt;
/**
* @param string $address
*/
private function __construct($address)
{
$this->address = $address;
$this->createdAt = new \DateTime();
}
/**
* @param array $data
*
* @return ShowResponse
*/
public static function create(array $data)
{
$bounce = new self($data['address']);
if (isset($data['code'])) {
$bounce->setCode($data['code']);
}
if (isset($data['error'])) {
$bounce->setError($data['error']);
}
if (isset($data['created_at'])) {
$bounce->setCreatedAt(new \DateTime($data['created_at']));
}
return $bounce;
}
/**
* @return string
*/
public function getAddress()
{
return $this->address;
}
/**
* @return string
*/
public function getCode()
{
return $this->code;
}
/**
* @param string $code
*/
private function setCode($code)
{
$this->code = $code;
}
/**
* @return string
*/
public function getError()
{
return $this->error;
}
/**
* @param string $error
*/
private function setError($error)
{
$this->error = $error;
}
/**
* @return \DateTime
*/
public function getCreatedAt()
{
return $this->createdAt;
}
/**
* @param \DateTime $createdAt
*/
private function setCreatedAt(\DateTime $createdAt)
{
$this->createdAt = $createdAt;
}
} }

View File

@ -0,0 +1,75 @@
<?php
/*
* Copyright (C) 2013-2016 Mailgun
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
namespace Mailgun\Model\Suppression\Complaint;
/**
* @author Sean Johnson <sean@mailgun.com>
*/
class Complaint
{
/**
* @var string
*/
private $address;
/**
* @var \DateTime
*/
private $createdAt;
/**
* @param string $address
*/
private function __construct($address)
{
$this->address = $address;
$this->createdAt = new \DateTime();
}
/**
* @param array $data
*
* @return Complaint
*/
public static function create(array $data)
{
$complaint = new self($data['address']);
if (isset($data['created_at'])) {
$complaint->setCreatedAt(new \DateTime($data['created_at']));
}
return $complaint;
}
/**
* @return string
*/
public function getAddress()
{
return $this->address;
}
/**
* @return \DateTime
*/
public function getCreatedAt()
{
return $this->createdAt;
}
/**
* @param \DateTime $createdAt
*/
private function setCreatedAt(\DateTime $createdAt)
{
$this->createdAt = $createdAt;
}
}

View File

@ -14,64 +14,6 @@ use Mailgun\Model\ApiResponse;
/** /**
* @author Sean Johnson <sean@mailgun.com> * @author Sean Johnson <sean@mailgun.com>
*/ */
final class ShowResponse implements ApiResponse final class ShowResponse extends Complaint implements ApiResponse
{ {
/**
* @var string
*/
private $address;
/**
* @var \DateTime
*/
private $createdAt;
/**
* @param string $address
*/
private function __construct($address)
{
$this->address = $address;
$this->createdAt = new \DateTime();
}
/**
* @param array $data
*
* @return ShowResponse
*/
public static function create(array $data)
{
$bounce = new self($data['address']);
if (isset($data['created_at'])) {
$bounce->setCreatedAt(new \DateTime($data['created_at']));
}
return $bounce;
}
/**
* @return string
*/
public function getAddress()
{
return $this->address;
}
/**
* @return \DateTime
*/
public function getCreatedAt()
{
return $this->createdAt;
}
/**
* @param \DateTime $createdAt
*/
private function setCreatedAt(\DateTime $createdAt)
{
$this->createdAt = $createdAt;
}
} }

View File

@ -45,7 +45,7 @@ final class IndexResponse implements ApiResponse, PagingProvider
$unsubscribes = []; $unsubscribes = [];
if (isset($data['items'])) { if (isset($data['items'])) {
foreach ($data['items'] as $item) { foreach ($data['items'] as $item) {
$unsubscribes[] = Unsubscribes::create($item); $unsubscribes[] = Unsubscribe::create($item);
} }
} }

View File

@ -14,88 +14,6 @@ use Mailgun\Model\ApiResponse;
/** /**
* @author Sean Johnson <sean@mailgun.com> * @author Sean Johnson <sean@mailgun.com>
*/ */
final class ShowResponse implements ApiResponse final class ShowResponse extends Unsubscribe implements ApiResponse
{ {
/**
* @var string
*/
private $address;
/**
* @var string
*/
private $tag;
/**
* @var \DateTime
*/
private $createdAt;
/**
* @param string $address
*/
private function __construct($address)
{
$this->address = $address;
$this->createdAt = new \DateTime();
}
/**
* @param array $data
*
* @return ShowResponse
*/
public static function create(array $data)
{
$unsubscribe = new self($data['address']);
if (isset($data['tag'])) {
$unsubscribe->setTag($data['tag']);
}
if (isset($data['created_at'])) {
$unsubscribe->setCreatedAt(new \DateTime($data['created_at']));
}
return $unsubscribe;
}
/**
* @return string
*/
public function getAddress()
{
return $this->address;
}
/**
* @return string
*/
public function getTag()
{
return $this->tag;
}
/**
* @param string $tag
*/
private function setTag($tag)
{
$this->tag = $tag;
}
/**
* @return \DateTime
*/
public function getCreatedAt()
{
return $this->createdAt;
}
/**
* @param \DateTime $createdAt
*/
private function setCreatedAt(\DateTime $createdAt)
{
$this->createdAt = $createdAt;
}
} }

View File

@ -0,0 +1,99 @@
<?php
/*
* Copyright (C) 2013-2016 Mailgun
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
namespace Mailgun\Model\Suppression\Unsubscribe;
/**
* @author Sean Johnson <sean@mailgun.com>
*/
class Unsubscribe
{
/**
* @var string
*/
private $address;
/**
* @var string
*/
private $tag;
/**
* @var \DateTime
*/
private $createdAt;
/**
* @param string $address
*/
private function __construct($address)
{
$this->address = $address;
$this->createdAt = new \DateTime();
}
/**
* @param array $data
*
* @return Unsubscribe
*/
public static function create(array $data)
{
$unsubscribe = new self($data['address']);
if (isset($data['tag'])) {
$unsubscribe->setTag($data['tag']);
}
if (isset($data['created_at'])) {
$unsubscribe->setCreatedAt(new \DateTime($data['created_at']));
}
return $unsubscribe;
}
/**
* @return string
*/
public function getAddress()
{
return $this->address;
}
/**
* @return string
*/
public function getTag()
{
return $this->tag;
}
/**
* @param string $tag
*/
private function setTag($tag)
{
$this->tag = $tag;
}
/**
* @return \DateTime
*/
public function getCreatedAt()
{
return $this->createdAt;
}
/**
* @param \DateTime $createdAt
*/
private function setCreatedAt(\DateTime $createdAt)
{
$this->createdAt = $createdAt;
}
}

7
test.php Normal file
View File

@ -0,0 +1,7 @@
<?php
include "vendor/autoload.php";
$mailgun = \Mailgun\Mailgun::create('key-f22961235cdf7aaef78a9228c710f12c');
$bounces = $mailgun->suppressions()->bounces()->index('sandbox40c4b0745b8a4461959950ccf9c0a1ea.mailgun.org');
$x = 2;