From 84a5c5dd4a910ff4879e222ab1ad26931df25628 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Wed, 22 Mar 2017 07:44:08 +0100 Subject: [PATCH] Rename deserializer to hydrator (#296) * Renamed "deserializer" to "hydrator" * Make sure we use singlular in namespaces Also did some cleanups. * Fixed typo * cs * minor fix --- README.md | 8 ++--- src/Mailgun/Api/Domain.php | 20 +++++------ src/Mailgun/Api/Event.php | 2 +- src/Mailgun/Api/HttpApi.php | 29 ++++++++++------ src/Mailgun/Api/Message.php | 4 +-- src/Mailgun/Api/Pagination.php | 4 +-- src/Mailgun/Api/Routes.php | 10 +++--- src/Mailgun/Api/Stats.php | 4 +-- .../Api/{Suppressions.php => Suppression.php} | 33 ++++++++++-------- .../{Suppressions => Suppression}/Bounce.php | 22 ++++++------ .../Complaint.php | 22 ++++++------ .../Unsubscribe.php | 22 ++++++------ src/Mailgun/Api/Tag.php | 10 +++--- src/Mailgun/Api/Webhook.php | 10 +++--- .../ArrayHydrator.php} | 6 ++-- .../Hydrator.php} | 4 +-- .../ModelHydrator.php} | 6 ++-- .../NoopHydrator.php} | 8 ++--- src/Mailgun/Mailgun.php | 34 +++++++++---------- .../BaseResponse.php | 4 +-- .../Bounce/CreateResponse.php | 4 +-- .../Bounce/DeleteResponse.php | 2 +- .../Bounce/IndexResponse.php | 2 +- .../Bounce/ShowResponse.php | 8 ++--- .../Complaint/CreateResponse.php | 4 +-- .../Complaint/DeleteResponse.php | 4 +-- .../Complaint/IndexResponse.php | 2 +- .../Complaint/ShowResponse.php | 4 +-- .../Unsubscribe/CreateResponse.php | 4 +-- .../Unsubscribe/DeleteResponse.php | 4 +-- .../Unsubscribe/IndexResponse.php | 2 +- .../Unsubscribe/ShowResponse.php | 6 ++-- tests/Api/TestCase.php | 4 +-- 33 files changed, 164 insertions(+), 148 deletions(-) rename src/Mailgun/Api/{Suppressions.php => Suppression.php} (52%) rename src/Mailgun/Api/{Suppressions => Suppression}/Bounce.php (79%) rename src/Mailgun/Api/{Suppressions => Suppression}/Complaint.php (79%) rename src/Mailgun/Api/{Suppressions => Suppression}/Unsubscribe.php (78%) rename src/Mailgun/{Deserializer/ArrayDeserializer.php => Hydrator/ArrayHydrator.php} (80%) rename src/Mailgun/{Deserializer/ResponseDeserializer.php => Hydrator/Hydrator.php} (88%) rename src/Mailgun/{Deserializer/ModelDeserializer.php => Hydrator/ModelHydrator.php} (85%) rename src/Mailgun/{Deserializer/PSR7Deserializer.php => Hydrator/NoopHydrator.php} (74%) rename src/Mailgun/Model/{Suppressions => Suppression}/BaseResponse.php (92%) rename src/Mailgun/Model/{Suppressions => Suppression}/Bounce/CreateResponse.php (75%) rename src/Mailgun/Model/{Suppressions => Suppression}/Bounce/DeleteResponse.php (87%) rename src/Mailgun/Model/{Suppressions => Suppression}/Bounce/IndexResponse.php (96%) rename src/Mailgun/Model/{Suppressions => Suppression}/Bounce/ShowResponse.php (90%) rename src/Mailgun/Model/{Suppressions => Suppression}/Complaint/CreateResponse.php (75%) rename src/Mailgun/Model/{Suppressions => Suppression}/Complaint/DeleteResponse.php (75%) rename src/Mailgun/Model/{Suppressions => Suppression}/Complaint/IndexResponse.php (96%) rename src/Mailgun/Model/{Suppressions => Suppression}/Complaint/ShowResponse.php (91%) rename src/Mailgun/Model/{Suppressions => Suppression}/Unsubscribe/CreateResponse.php (74%) rename src/Mailgun/Model/{Suppressions => Suppression}/Unsubscribe/DeleteResponse.php (74%) rename src/Mailgun/Model/{Suppressions => Suppression}/Unsubscribe/IndexResponse.php (96%) rename src/Mailgun/Model/{Suppressions => Suppression}/Unsubscribe/ShowResponse.php (90%) diff --git a/README.md b/README.md index 1454898..15c6aad 100644 --- a/README.md +++ b/README.md @@ -94,13 +94,13 @@ foreach ($dns as $record) { } ``` -If you rather be working with array then object you can inject the `ArrayDeserializer` +If you rather be working with array then object you can inject the `ArrayHydrator` to the Mailgun class. ```php -use Mailgun\Deserializer\ArrayDeserializer; +use Mailgun\Hydrator\ArrayHydator; -$mg = new Mailgun("key-example", null, null, new ArrayDeserializer()); +$mg = new Mailgun("key-example", null, null, new ArrayHydator()); $data = $mg->domains()->show('example.com'); foreach ($data['receiving_dns_records'] as $record) { @@ -108,7 +108,7 @@ foreach ($data['receiving_dns_records'] as $record) { } ``` -You could also use the `PSR7Deserializer` to get a PSR7 Response returned from +You could also use the `NoopHydrator` to get a PSR7 Response returned from the API calls. ### Debugging diff --git a/src/Mailgun/Api/Domain.php b/src/Mailgun/Api/Domain.php index d145e3d..77e7cc1 100644 --- a/src/Mailgun/Api/Domain.php +++ b/src/Mailgun/Api/Domain.php @@ -49,7 +49,7 @@ class Domain extends HttpApi $response = $this->httpGet('/v3/domains', $params); - return $this->safeDeserialize($response, IndexResponse::class); + return $this->safeHydrate($response, IndexResponse::class); } /** @@ -65,7 +65,7 @@ class Domain extends HttpApi $response = $this->httpGet(sprintf('/v3/domains/%s', $domain)); - return $this->safeDeserialize($response, ShowResponse::class); + return $this->safeHydrate($response, ShowResponse::class); } /** @@ -97,7 +97,7 @@ class Domain extends HttpApi $response = $this->httpPost('/v3/domains', $params); - return $this->safeDeserialize($response, CreateResponse::class); + return $this->safeHydrate($response, CreateResponse::class); } /** @@ -114,7 +114,7 @@ class Domain extends HttpApi $response = $this->httpDelete(sprintf('/v3/domains/%s', $domain)); - return $this->safeDeserialize($response, DeleteResponse::class); + return $this->safeHydrate($response, DeleteResponse::class); } /** @@ -139,7 +139,7 @@ class Domain extends HttpApi $response = $this->httpGet(sprintf('/v3/domains/%s/credentials', $domain), $params); - return $this->safeDeserialize($response, CredentialResponse::class); + return $this->safeHydrate($response, CredentialResponse::class); } /** @@ -165,7 +165,7 @@ class Domain extends HttpApi $response = $this->httpPost(sprintf('/v3/domains/%s/credentials', $domain), $params); - return $this->safeDeserialize($response, CreateCredentialResponse::class); + return $this->safeHydrate($response, CreateCredentialResponse::class); } /** @@ -190,7 +190,7 @@ class Domain extends HttpApi $response = $this->httpPut(sprintf('/v3/domains/%s/credentials/%s', $domain, $login), $params); - return $this->safeDeserialize($response, UpdateCredentialResponse::class); + return $this->safeHydrate($response, UpdateCredentialResponse::class); } /** @@ -214,7 +214,7 @@ class Domain extends HttpApi ) ); - return $this->safeDeserialize($response, DeleteCredentialResponse::class); + return $this->safeHydrate($response, DeleteCredentialResponse::class); } /** @@ -230,7 +230,7 @@ class Domain extends HttpApi $response = $this->httpGet(sprintf('/v3/domains/%s/connection', $domain)); - return $this->safeDeserialize($response, ConnectionResponse::class); + return $this->safeHydrate($response, ConnectionResponse::class); } /** @@ -261,6 +261,6 @@ class Domain extends HttpApi $response = $this->httpPut(sprintf('/v3/domains/%s/connection', $domain), $params); - return $this->safeDeserialize($response, UpdateConnectionResponse::class); + return $this->safeHydrate($response, UpdateConnectionResponse::class); } } diff --git a/src/Mailgun/Api/Event.php b/src/Mailgun/Api/Event.php index da80265..6014fc9 100644 --- a/src/Mailgun/Api/Event.php +++ b/src/Mailgun/Api/Event.php @@ -33,7 +33,7 @@ class Event extends HttpApi $response = $this->httpGet(sprintf('/v3/%s/events', $domain), $params); - return $this->safeDeserialize($response, EventResponse::class); + return $this->safeHydrate($response, EventResponse::class); } /** diff --git a/src/Mailgun/Api/HttpApi.php b/src/Mailgun/Api/HttpApi.php index ce31090..bf58cb5 100644 --- a/src/Mailgun/Api/HttpApi.php +++ b/src/Mailgun/Api/HttpApi.php @@ -11,7 +11,8 @@ namespace Mailgun\Api; use Http\Client\Exception as HttplugException; use Http\Client\HttpClient; -use Mailgun\Deserializer\ResponseDeserializer; +use Mailgun\Hydrator\Hydrator; +use Mailgun\Hydrator\NoopHydrator; use Mailgun\Exception\HttpClientException; use Mailgun\Exception\HttpServerException; use Mailgun\RequestBuilder; @@ -31,9 +32,9 @@ abstract class HttpApi private $httpClient; /** - * @var ResponseDeserializer + * @var Hydrator */ - protected $deserializer; + protected $hydrator; /** * @var RequestBuilder @@ -41,15 +42,17 @@ abstract class HttpApi protected $requestBuilder; /** - * @param HttpClient $httpClient - * @param RequestBuilder $requestBuilder - * @param ResponseDeserializer $deserializer + * @param HttpClient $httpClient + * @param RequestBuilder $requestBuilder + * @param Hydrator $hydrator */ - public function __construct(HttpClient $httpClient, RequestBuilder $requestBuilder, ResponseDeserializer $deserializer) + public function __construct(HttpClient $httpClient, RequestBuilder $requestBuilder, Hydrator $hydrator) { $this->httpClient = $httpClient; $this->requestBuilder = $requestBuilder; - $this->deserializer = $deserializer; + if (!$hydrator instanceof NoopHydrator) { + $this->hydrator = $hydrator; + } } /** @@ -64,14 +67,18 @@ abstract class HttpApi * * @return object $class */ - protected function safeDeserialize(ResponseInterface $response, $className) + protected function safeHydrate(ResponseInterface $response, $className) { + if (!$this->hydrator) { + return $response; + } + if ($response->getStatusCode() === 200) { - return $this->deserializer->deserialize($response, $className); + return $this->hydrator->deserialize($response, $className); } elseif ($response->getStatusCode() === 401) { throw HttpClientException::unauthorized(); } else { - return $this->deserializer->deserialize($response, ErrorResponse::class); + return $this->hydrator->deserialize($response, ErrorResponse::class); } } diff --git a/src/Mailgun/Api/Message.php b/src/Mailgun/Api/Message.php index d5b9c22..4508190 100644 --- a/src/Mailgun/Api/Message.php +++ b/src/Mailgun/Api/Message.php @@ -68,7 +68,7 @@ class Message extends HttpApi $response = $this->httpPostRaw(sprintf('/v3/%s/messages', $domain), $postDataMultipart); - return $this->safeDeserialize($response, SendResponse::class); + return $this->safeHydrate($response, SendResponse::class); } /** @@ -90,7 +90,7 @@ class Message extends HttpApi $response = $this->httpGet($url, [], $headers); - return $this->safeDeserialize($response, ShowResponse::class); + return $this->safeHydrate($response, ShowResponse::class); } /** diff --git a/src/Mailgun/Api/Pagination.php b/src/Mailgun/Api/Pagination.php index a80b8c7..d881a6c 100644 --- a/src/Mailgun/Api/Pagination.php +++ b/src/Mailgun/Api/Pagination.php @@ -20,7 +20,7 @@ trait Pagination { abstract protected function httpGet($path, array $parameters = [], array $requestHeaders = []); - abstract protected function safeDeserialize(ResponseInterface $response, $className); + abstract protected function safeHydrate(ResponseInterface $response, $className); /** * @param PagingProvider $response @@ -78,6 +78,6 @@ trait Pagination $response = $this->httpGet($url); - return $this->safeDeserialize($response, $class); + return $this->safeHydrate($response, $class); } } diff --git a/src/Mailgun/Api/Routes.php b/src/Mailgun/Api/Routes.php index 9c52798..289f5ab 100644 --- a/src/Mailgun/Api/Routes.php +++ b/src/Mailgun/Api/Routes.php @@ -45,7 +45,7 @@ class Routes extends HttpApi $response = $this->httpGet('/v3/routes', $params); - return $this->safeDeserialize($response, IndexResponse::class); + return $this->safeHydrate($response, IndexResponse::class); } /** @@ -61,7 +61,7 @@ class Routes extends HttpApi $response = $this->httpGet(sprintf('/v3/routes/%s', $routeId)); - return $this->safeDeserialize($response, ShowResponse::class); + return $this->safeHydrate($response, ShowResponse::class); } /** @@ -90,7 +90,7 @@ class Routes extends HttpApi $response = $this->httpPost('/v3/routes', $params); - return $this->safeDeserialize($response, CreateResponse::class); + return $this->safeHydrate($response, CreateResponse::class); } /** @@ -136,7 +136,7 @@ class Routes extends HttpApi $response = $this->httpPut(sprintf('/v3/routes/%s', $routeId), $params); - return $this->safeDeserialize($response, UpdateResponse::class); + return $this->safeHydrate($response, UpdateResponse::class); } /** @@ -152,6 +152,6 @@ class Routes extends HttpApi $response = $this->httpDelete(sprintf('/v3/routes/%s', $routeId)); - return $this->safeDeserialize($response, DeleteResponse::class); + return $this->safeHydrate($response, DeleteResponse::class); } } diff --git a/src/Mailgun/Api/Stats.php b/src/Mailgun/Api/Stats.php index c336007..9b9d6b8 100644 --- a/src/Mailgun/Api/Stats.php +++ b/src/Mailgun/Api/Stats.php @@ -32,7 +32,7 @@ class Stats extends HttpApi $response = $this->httpGet(sprintf('/v3/%s/stats/total', rawurlencode($domain)), $params); - return $this->safeDeserialize($response, TotalResponse::class); + return $this->safeHydrate($response, TotalResponse::class); } /** @@ -47,6 +47,6 @@ class Stats extends HttpApi $response = $this->httpGet(sprintf('/v3/%s/stats', rawurlencode($domain)), $params); - return $this->safeDeserialize($response, AllResponse::class); + return $this->safeHydrate($response, AllResponse::class); } } diff --git a/src/Mailgun/Api/Suppressions.php b/src/Mailgun/Api/Suppression.php similarity index 52% rename from src/Mailgun/Api/Suppressions.php rename to src/Mailgun/Api/Suppression.php index 8ed73eb..3357482 100644 --- a/src/Mailgun/Api/Suppressions.php +++ b/src/Mailgun/Api/Suppression.php @@ -10,7 +10,10 @@ namespace Mailgun\Api; use Http\Client\HttpClient; -use Mailgun\Deserializer\ResponseDeserializer; +use Mailgun\Api\Supression\Bounce; +use Mailgun\Api\Supression\Complaint; +use Mailgun\Api\Supression\Unsubscribe; +use Mailgun\Hydrator\Hydrator; use Mailgun\RequestBuilder; /** @@ -18,7 +21,7 @@ use Mailgun\RequestBuilder; * * @author Sean Johnson */ -class Suppressions +class Suppression { /** * @var HttpClient @@ -31,43 +34,43 @@ class Suppressions private $requestBuilder; /** - * @var ResponseDeserializer + * @var Hydrator */ - private $deserializer; + private $hydrator; /** - * @param HttpClient $httpClient - * @param RequestBuilder $requestBuilder - * @param ResponseDeserializer $deserializer + * @param HttpClient $httpClient + * @param RequestBuilder $requestBuilder + * @param Hydrator $hydrator */ - public function __construct(HttpClient $httpClient, RequestBuilder $requestBuilder, ResponseDeserializer $deserializer) + public function __construct(HttpClient $httpClient, RequestBuilder $requestBuilder, Hydrator $hydrator) { $this->httpClient = $httpClient; $this->requestBuilder = $requestBuilder; - $this->deserializer = $deserializer; + $this->hydrator = $hydrator; } /** - * @return Suppressions\Bounce + * @return Bounce */ public function bounces() { - return new Suppressions\Bounce($this->httpClient, $this->requestBuilder, $this->deserializer); + return new Bounce($this->httpClient, $this->requestBuilder, $this->hydrator); } /** - * @return Suppressions\Complaint + * @return Complaint */ public function complaints() { - return new Suppressions\Complaint($this->httpClient, $this->requestBuilder, $this->deserializer); + return new Complaint($this->httpClient, $this->requestBuilder, $this->hydrator); } /** - * @return Suppressions\Unsubscribe + * @return Unsubscribe */ public function unsubscribes() { - return new Suppressions\Unsubscribe($this->httpClient, $this->requestBuilder, $this->deserializer); + return new Unsubscribe($this->httpClient, $this->requestBuilder, $this->hydrator); } } diff --git a/src/Mailgun/Api/Suppressions/Bounce.php b/src/Mailgun/Api/Suppression/Bounce.php similarity index 79% rename from src/Mailgun/Api/Suppressions/Bounce.php rename to src/Mailgun/Api/Suppression/Bounce.php index 205041b..4055bee 100644 --- a/src/Mailgun/Api/Suppressions/Bounce.php +++ b/src/Mailgun/Api/Suppression/Bounce.php @@ -7,13 +7,15 @@ * of the MIT license. See the LICENSE file for details. */ -namespace Mailgun\Api; +namespace Mailgun\Api\Supression; +use Mailgun\Api\HttpApi; +use Mailgun\Api\Pagination; use Mailgun\Assert; -use Mailgun\Model\Suppressions\Bounce\CreateResponse; -use Mailgun\Model\Suppressions\Bounce\DeleteResponse; -use Mailgun\Model\Suppressions\Bounce\IndexResponse; -use Mailgun\Model\Suppressions\Bounce\ShowResponse; +use Mailgun\Model\Suppression\Bounce\CreateResponse; +use Mailgun\Model\Suppression\Bounce\DeleteResponse; +use Mailgun\Model\Suppression\Bounce\IndexResponse; +use Mailgun\Model\Suppression\Bounce\ShowResponse; /** * @see https://documentation.mailgun.com/api-suppressions.html#bounces @@ -41,7 +43,7 @@ class Bounce extends HttpApi $response = $this->httpGet(sprintf('/v3/%s/bounces', $domain), $params); - return $this->safeDeserialize($response, IndexResponse::class); + return $this->safeHydrate($response, IndexResponse::class); } /** @@ -57,7 +59,7 @@ class Bounce extends HttpApi $response = $this->httpGet(sprintf('/v3/%s/bounces/%s', $domain, $address)); - return $this->safeDeserialize($response, ShowResponse::class); + return $this->safeHydrate($response, ShowResponse::class); } /** @@ -76,7 +78,7 @@ class Bounce extends HttpApi $response = $this->httpPost(sprintf('/v3/%s/bounces', $domain), $params); - return $this->safeDeserialize($response, CreateResponse::class); + return $this->safeHydrate($response, CreateResponse::class); } /** @@ -92,7 +94,7 @@ class Bounce extends HttpApi $response = $this->httpDelete(sprintf('/v3/%s/bounces/%s', $domain, $address)); - return $this->safeDeserialize($response, DeleteResponse::class); + return $this->safeHydrate($response, DeleteResponse::class); } /** @@ -106,6 +108,6 @@ class Bounce extends HttpApi $response = $this->httpDelete(sprintf('/v3/%s/bounces', $domain)); - return $this->safeDeserialize($response, DeleteResponse::class); + return $this->safeHydrate($response, DeleteResponse::class); } } diff --git a/src/Mailgun/Api/Suppressions/Complaint.php b/src/Mailgun/Api/Suppression/Complaint.php similarity index 79% rename from src/Mailgun/Api/Suppressions/Complaint.php rename to src/Mailgun/Api/Suppression/Complaint.php index 283cfad..9475913 100644 --- a/src/Mailgun/Api/Suppressions/Complaint.php +++ b/src/Mailgun/Api/Suppression/Complaint.php @@ -7,13 +7,15 @@ * of the MIT license. See the LICENSE file for details. */ -namespace Mailgun\Api; +namespace Mailgun\Api\Supression; +use Mailgun\Api\HttpApi; +use Mailgun\Api\Pagination; use Mailgun\Assert; -use Mailgun\Model\Suppressions\Complaint\CreateResponse; -use Mailgun\Model\Suppressions\Complaint\DeleteResponse; -use Mailgun\Model\Suppressions\Complaint\IndexResponse; -use Mailgun\Model\Suppressions\Complaint\ShowResponse; +use Mailgun\Model\Suppression\Complaint\CreateResponse; +use Mailgun\Model\Suppression\Complaint\DeleteResponse; +use Mailgun\Model\Suppression\Complaint\IndexResponse; +use Mailgun\Model\Suppression\Complaint\ShowResponse; /** * @see https://documentation.mailgun.com/api-suppressions.html#complaints @@ -41,7 +43,7 @@ class Complaint extends HttpApi $response = $this->httpGet(sprintf('/v3/%s/complaints', $domain), $params); - return $this->safeDeserialize($response, IndexResponse::class); + return $this->safeHydrate($response, IndexResponse::class); } /** @@ -56,7 +58,7 @@ class Complaint extends HttpApi Assert::stringNotEmpty($address); $response = $this->httpGet(sprintf('/v3/%s/complaints/%s', $domain, $address)); - return $this->safeDeserialize($response, ShowResponse::class); + return $this->safeHydrate($response, ShowResponse::class); } /** @@ -75,7 +77,7 @@ class Complaint extends HttpApi $response = $this->httpPost(sprintf('/v3/%s/complaints', $domain), $params); - return $this->safeDeserialize($response, CreateResponse::class); + return $this->safeHydrate($response, CreateResponse::class); } /** @@ -91,7 +93,7 @@ class Complaint extends HttpApi $response = $this->httpDelete(sprintf('/v3/%s/complaints/%s', $domain, $address)); - return $this->safeDeserialize($response, DeleteResponse::class); + return $this->safeHydrate($response, DeleteResponse::class); } /** @@ -105,6 +107,6 @@ class Complaint extends HttpApi $response = $this->httpDelete(sprintf('/v3/%s/complaints', $domain)); - return $this->safeDeserialize($response, DeleteResponse::class); + return $this->safeHydrate($response, DeleteResponse::class); } } diff --git a/src/Mailgun/Api/Suppressions/Unsubscribe.php b/src/Mailgun/Api/Suppression/Unsubscribe.php similarity index 78% rename from src/Mailgun/Api/Suppressions/Unsubscribe.php rename to src/Mailgun/Api/Suppression/Unsubscribe.php index 01775fc..fde6c2f 100644 --- a/src/Mailgun/Api/Suppressions/Unsubscribe.php +++ b/src/Mailgun/Api/Suppression/Unsubscribe.php @@ -7,13 +7,15 @@ * of the MIT license. See the LICENSE file for details. */ -namespace Mailgun\Api; +namespace Mailgun\Api\Supression; +use Mailgun\Api\HttpApi; +use Mailgun\Api\Pagination; use Mailgun\Assert; -use Mailgun\Model\Suppressions\Unsubscribe\CreateResponse; -use Mailgun\Model\Suppressions\Unsubscribe\DeleteResponse; -use Mailgun\Model\Suppressions\Unsubscribe\IndexResponse; -use Mailgun\Model\Suppressions\Unsubscribe\ShowResponse; +use Mailgun\Model\Suppression\Unsubscribe\CreateResponse; +use Mailgun\Model\Suppression\Unsubscribe\DeleteResponse; +use Mailgun\Model\Suppression\Unsubscribe\IndexResponse; +use Mailgun\Model\Suppression\Unsubscribe\ShowResponse; /** * @see https://documentation.mailgun.com/api-suppressions.html#unsubscribes @@ -41,7 +43,7 @@ class Unsubscribe extends HttpApi $response = $this->httpGet(sprintf('/v3/%s/unsubscribes', $domain), $params); - return $this->safeDeserialize($response, IndexResponse::class); + return $this->safeHydrate($response, IndexResponse::class); } /** @@ -57,7 +59,7 @@ class Unsubscribe extends HttpApi $response = $this->httpGet(sprintf('/v3/%s/unsubscribes/%s', $domain, $address)); - return $this->safeDeserialize($response, ShowResponse::class); + return $this->safeHydrate($response, ShowResponse::class); } /** @@ -76,7 +78,7 @@ class Unsubscribe extends HttpApi $response = $this->httpPost(sprintf('/v3/%s/unsubscribes', $domain), $params); - return $this->safeDeserialize($response, CreateResponse::class); + return $this->safeHydrate($response, CreateResponse::class); } /** @@ -92,7 +94,7 @@ class Unsubscribe extends HttpApi $response = $this->httpDelete(sprintf('/v3/%s/unsubscribes/%s', $domain, $address)); - return $this->safeDeserialize($response, DeleteResponse::class); + return $this->safeHydrate($response, DeleteResponse::class); } /** @@ -106,6 +108,6 @@ class Unsubscribe extends HttpApi $response = $this->httpDelete(sprintf('/v3/%s/unsubscribes', $domain)); - return $this->safeDeserialize($response, DeleteResponse::class); + return $this->safeHydrate($response, DeleteResponse::class); } } diff --git a/src/Mailgun/Api/Tag.php b/src/Mailgun/Api/Tag.php index 984568e..65cedd0 100644 --- a/src/Mailgun/Api/Tag.php +++ b/src/Mailgun/Api/Tag.php @@ -43,7 +43,7 @@ class Tag extends HttpApi $response = $this->httpGet(sprintf('/v3/%s/tags', $domain), $params); - return $this->safeDeserialize($response, IndexResponse::class); + return $this->safeHydrate($response, IndexResponse::class); } /** @@ -61,7 +61,7 @@ class Tag extends HttpApi $response = $this->httpGet(sprintf('/v3/%s/tags/%s', $domain, $tag)); - return $this->safeDeserialize($response, ShowResponse::class); + return $this->safeHydrate($response, ShowResponse::class); } /** @@ -85,7 +85,7 @@ class Tag extends HttpApi $response = $this->httpPut(sprintf('/v3/%s/tags/%s', $domain, $tag), $params); - return $this->safeDeserialize($response, UpdateResponse::class); + return $this->safeHydrate($response, UpdateResponse::class); } /** @@ -105,7 +105,7 @@ class Tag extends HttpApi $response = $this->httpGet(sprintf('/v3/%s/tags/%s/stats', $domain, $tag), $params); - return $this->safeDeserialize($response, StatisticsResponse::class); + return $this->safeHydrate($response, StatisticsResponse::class); } /** @@ -123,6 +123,6 @@ class Tag extends HttpApi $response = $this->httpDelete(sprintf('/v3/%s/tags/%s', $domain, $tag)); - return $this->safeDeserialize($response, DeleteResponse::class); + return $this->safeHydrate($response, DeleteResponse::class); } } diff --git a/src/Mailgun/Api/Webhook.php b/src/Mailgun/Api/Webhook.php index 41545c4..c4256f7 100644 --- a/src/Mailgun/Api/Webhook.php +++ b/src/Mailgun/Api/Webhook.php @@ -31,7 +31,7 @@ class Webhook extends HttpApi Assert::notEmpty($domain); $response = $this->httpGet(sprintf('/v3/domains/%s/webhooks', $domain)); - return $this->safeDeserialize($response, IndexResponse::class); + return $this->safeHydrate($response, IndexResponse::class); } /** @@ -46,7 +46,7 @@ class Webhook extends HttpApi Assert::notEmpty($webhook); $response = $this->httpGet(sprintf('/v3/domains/%s/webhooks/%s', $domain, $webhook)); - return $this->safeDeserialize($response, ShowResponse::class); + return $this->safeHydrate($response, ShowResponse::class); } /** @@ -69,7 +69,7 @@ class Webhook extends HttpApi $response = $this->httpPost(sprintf('/v3/domains/%s/webhooks', $domain), $params); - return $this->safeDeserialize($response, CreateResponse::class); + return $this->safeHydrate($response, CreateResponse::class); } /** @@ -91,7 +91,7 @@ class Webhook extends HttpApi $response = $this->httpPut(sprintf('/v3/domains/%s/webhooks/%s', $domain, $id), $params); - return $this->safeDeserialize($response, UpdateResponse::class); + return $this->safeHydrate($response, UpdateResponse::class); } /** @@ -107,6 +107,6 @@ class Webhook extends HttpApi $response = $this->httpDelete(sprintf('/v3/domains/%s/webhooks/%s', $domain, $id)); - return $this->safeDeserialize($response, DeleteResponse::class); + return $this->safeHydrate($response, DeleteResponse::class); } } diff --git a/src/Mailgun/Deserializer/ArrayDeserializer.php b/src/Mailgun/Hydrator/ArrayHydrator.php similarity index 80% rename from src/Mailgun/Deserializer/ArrayDeserializer.php rename to src/Mailgun/Hydrator/ArrayHydrator.php index b9fe028..548e636 100644 --- a/src/Mailgun/Deserializer/ArrayDeserializer.php +++ b/src/Mailgun/Hydrator/ArrayHydrator.php @@ -7,7 +7,7 @@ * of the MIT license. See the LICENSE file for details. */ -namespace Mailgun\Deserializer; +namespace Mailgun\Hydrator; use Mailgun\Exception\DeserializeException; use Psr\Http\Message\ResponseInterface; @@ -17,7 +17,7 @@ use Psr\Http\Message\ResponseInterface; * * @author Tobias Nyholm */ -class ArrayDeserializer implements ResponseDeserializer +class ArrayHydrator implements Hydrator { /** * @param ResponseInterface $response @@ -29,7 +29,7 @@ class ArrayDeserializer implements ResponseDeserializer { $body = $response->getBody()->__toString(); if (strpos($response->getHeaderLine('Content-Type'), 'application/json') !== 0) { - throw new DeserializeException('The ArrayDeserializer cannot deserialize response with Content-Type:'.$response->getHeaderLine('Content-Type')); + throw new DeserializeException('The ArrayHydrator cannot hydrate response with Content-Type:'.$response->getHeaderLine('Content-Type')); } $content = json_decode($body, true); diff --git a/src/Mailgun/Deserializer/ResponseDeserializer.php b/src/Mailgun/Hydrator/Hydrator.php similarity index 88% rename from src/Mailgun/Deserializer/ResponseDeserializer.php rename to src/Mailgun/Hydrator/Hydrator.php index e361559..68cb3c7 100644 --- a/src/Mailgun/Deserializer/ResponseDeserializer.php +++ b/src/Mailgun/Hydrator/Hydrator.php @@ -7,14 +7,14 @@ * of the MIT license. See the LICENSE file for details. */ -namespace Mailgun\Deserializer; +namespace Mailgun\Hydrator; use Psr\Http\Message\ResponseInterface; /** * Deserialize a PSR-7 response to something else. */ -interface ResponseDeserializer +interface Hydrator { /** * @param ResponseInterface $response diff --git a/src/Mailgun/Deserializer/ModelDeserializer.php b/src/Mailgun/Hydrator/ModelHydrator.php similarity index 85% rename from src/Mailgun/Deserializer/ModelDeserializer.php rename to src/Mailgun/Hydrator/ModelHydrator.php index 82b2d34..e16ef32 100644 --- a/src/Mailgun/Deserializer/ModelDeserializer.php +++ b/src/Mailgun/Hydrator/ModelHydrator.php @@ -7,7 +7,7 @@ * of the MIT license. See the LICENSE file for details. */ -namespace Mailgun\Deserializer; +namespace Mailgun\Hydrator; use Mailgun\Exception\DeserializeException; use Mailgun\Model\ApiResponse; @@ -18,7 +18,7 @@ use Psr\Http\Message\ResponseInterface; * * @author Tobias Nyholm */ -class ModelDeserializer implements ResponseDeserializer +class ModelHydrator implements Hydrator { /** * @param ResponseInterface $response @@ -31,7 +31,7 @@ class ModelDeserializer implements ResponseDeserializer $body = $response->getBody()->__toString(); $contentType = $response->getHeaderLine('Content-Type'); if (strpos($contentType, 'application/json') !== 0 && strpos($contentType, 'application/octet-stream') !== 0) { - throw new DeserializeException('The ModelDeserializer cannot deserialize response with Content-Type: '.$contentType); + throw new DeserializeException('The ModelHydrator cannot hydrate response with Content-Type: '.$contentType); } $data = json_decode($body, true); diff --git a/src/Mailgun/Deserializer/PSR7Deserializer.php b/src/Mailgun/Hydrator/NoopHydrator.php similarity index 74% rename from src/Mailgun/Deserializer/PSR7Deserializer.php rename to src/Mailgun/Hydrator/NoopHydrator.php index 859c093..9f2cb02 100644 --- a/src/Mailgun/Deserializer/PSR7Deserializer.php +++ b/src/Mailgun/Hydrator/NoopHydrator.php @@ -7,7 +7,7 @@ * of the MIT license. See the LICENSE file for details. */ -namespace Mailgun\Deserializer; +namespace Mailgun\Hydrator; use Psr\Http\Message\ResponseInterface; @@ -16,16 +16,16 @@ use Psr\Http\Message\ResponseInterface; * * @author Tobias Nyholm */ -class PSR7Deserializer implements ResponseDeserializer +class NoopHydrator implements Hydrator { /** * @param ResponseInterface $response * @param string $class * - * @return ResponseInterface + * @throws \LogicException */ public function deserialize(ResponseInterface $response, $class) { - return $response; + throw new \LogicException('The NoopHydrator should never be called'); } } diff --git a/src/Mailgun/Mailgun.php b/src/Mailgun/Mailgun.php index 9468778..9cd56c1 100644 --- a/src/Mailgun/Mailgun.php +++ b/src/Mailgun/Mailgun.php @@ -17,8 +17,8 @@ use Mailgun\Lists\OptInHandler; use Mailgun\Messages\BatchMessage; use Mailgun\Messages\Exceptions; use Mailgun\Messages\MessageBuilder; -use Mailgun\Deserializer\ModelDeserializer; -use Mailgun\Deserializer\ResponseDeserializer; +use Mailgun\Hydrator\ModelHydrator; +use Mailgun\Hydrator\Hydrator; /** * This class is the base class for the Mailgun SDK. @@ -43,9 +43,9 @@ class Mailgun private $httpClient; /** - * @var ResponseDeserializer + * @var Hydrator */ - private $deserializer; + private $hydrator; /** * @var RequestBuilder @@ -56,7 +56,7 @@ class Mailgun * @param string|null $apiKey * @param HttpClient|null $httpClient * @param string $apiEndpoint - * @param ResponseDeserializer|null $deserializer + * @param Hydrator|null $hydrator * @param HttpClientConfigurator|null $clientConfigurator * @param RequestBuilder|null $requestBuilder */ @@ -64,7 +64,7 @@ class Mailgun $apiKey = null, HttpClient $httpClient = null, /* Deprecated, will be removed in 3.0 */ $apiEndpoint = 'api.mailgun.net', /* Deprecated, will be removed in 3.0 */ - ResponseDeserializer $deserializer = null, + Hydrator $hydrator = null, HttpClientConfigurator $clientConfigurator = null, RequestBuilder $requestBuilder = null ) { @@ -89,7 +89,7 @@ class Mailgun $this->httpClient = $clientConfigurator->createConfiguredClient(); $this->requestBuilder = $requestBuilder ?: new RequestBuilder(); - $this->deserializer = $deserializer ?: new ModelDeserializer(); + $this->hydrator = $hydrator ?: new ModelHydrator(); } /** @@ -290,7 +290,7 @@ class Mailgun */ public function stats() { - return new Api\Stats($this->httpClient, $this->requestBuilder, $this->deserializer); + return new Api\Stats($this->httpClient, $this->requestBuilder, $this->hydrator); } /** @@ -298,15 +298,15 @@ class Mailgun */ public function domains() { - return new Api\Domain($this->httpClient, $this->requestBuilder, $this->deserializer); + return new Api\Domain($this->httpClient, $this->requestBuilder, $this->hydrator); } /** * @return Api\Tag */ - public function tag() + public function tags() { - return new Api\Tag($this->httpClient, $this->requestBuilder, $this->deserializer); + return new Api\Tag($this->httpClient, $this->requestBuilder, $this->hydrator); } /** @@ -314,7 +314,7 @@ class Mailgun */ public function events() { - return new Api\Event($this->httpClient, $this->requestBuilder, $this->deserializer); + return new Api\Event($this->httpClient, $this->requestBuilder, $this->hydrator); } /** @@ -322,7 +322,7 @@ class Mailgun */ public function routes() { - return new Api\Routes($this->httpClient, $this->requestBuilder, $this->deserializer); + return new Api\Routes($this->httpClient, $this->requestBuilder, $this->hydrator); } /** @@ -330,7 +330,7 @@ class Mailgun */ public function webhooks() { - return new Api\Webhook($this->httpClient, $this->requestBuilder, $this->deserializer); + return new Api\Webhook($this->httpClient, $this->requestBuilder, $this->hydrator); } /** @@ -338,14 +338,14 @@ class Mailgun */ public function messages() { - return new Api\Message($this->httpClient, $this->requestBuilder, $this->deserializer); + return new Api\Message($this->httpClient, $this->requestBuilder, $this->hydrator); } /** - * @return Api\Suppressions + * @return Api\Suppression */ public function suppressions() { - return new Api\Suppressions($this->httpClient, $this->requestBuilder, $this->deserializer); + return new Api\Suppression($this->httpClient, $this->requestBuilder, $this->hydrator); } } diff --git a/src/Mailgun/Model/Suppressions/BaseResponse.php b/src/Mailgun/Model/Suppression/BaseResponse.php similarity index 92% rename from src/Mailgun/Model/Suppressions/BaseResponse.php rename to src/Mailgun/Model/Suppression/BaseResponse.php index 7902932..413bee9 100644 --- a/src/Mailgun/Model/Suppressions/BaseResponse.php +++ b/src/Mailgun/Model/Suppression/BaseResponse.php @@ -7,12 +7,12 @@ * of the MIT license. See the LICENSE file for details. */ -namespace Mailgun\Model\Suppressions; +namespace Mailgun\Model\Suppression; use Mailgun\Model\ApiResponse; /** - * Serves only as an abstract base for suppressions API code. + * Serves only as an abstract base for Suppression API code. * * @author Sean Johnson */ diff --git a/src/Mailgun/Model/Suppressions/Bounce/CreateResponse.php b/src/Mailgun/Model/Suppression/Bounce/CreateResponse.php similarity index 75% rename from src/Mailgun/Model/Suppressions/Bounce/CreateResponse.php rename to src/Mailgun/Model/Suppression/Bounce/CreateResponse.php index 4b80b3b..e91d5e8 100644 --- a/src/Mailgun/Model/Suppressions/Bounce/CreateResponse.php +++ b/src/Mailgun/Model/Suppression/Bounce/CreateResponse.php @@ -7,9 +7,9 @@ * of the MIT license. See the LICENSE file for details. */ -namespace Mailgun\Model\Suppressions\Bounce; +namespace Mailgun\Model\Suppression\Bounce; -use Mailgun\Model\Suppressions\BaseResponse; +use Mailgun\Model\Suppression\BaseResponse; /** * @author Sean Johnson diff --git a/src/Mailgun/Model/Suppressions/Bounce/DeleteResponse.php b/src/Mailgun/Model/Suppression/Bounce/DeleteResponse.php similarity index 87% rename from src/Mailgun/Model/Suppressions/Bounce/DeleteResponse.php rename to src/Mailgun/Model/Suppression/Bounce/DeleteResponse.php index df93cab..92dac6a 100644 --- a/src/Mailgun/Model/Suppressions/Bounce/DeleteResponse.php +++ b/src/Mailgun/Model/Suppression/Bounce/DeleteResponse.php @@ -9,7 +9,7 @@ namespace Mailgun\Model\Suppression\Bounce; -use Mailgun\Model\Suppressions\BaseResponse; +use Mailgun\Model\Suppression\BaseResponse; /** * @author Sean Johnson diff --git a/src/Mailgun/Model/Suppressions/Bounce/IndexResponse.php b/src/Mailgun/Model/Suppression/Bounce/IndexResponse.php similarity index 96% rename from src/Mailgun/Model/Suppressions/Bounce/IndexResponse.php rename to src/Mailgun/Model/Suppression/Bounce/IndexResponse.php index 9c8f65c..cbf7658 100644 --- a/src/Mailgun/Model/Suppressions/Bounce/IndexResponse.php +++ b/src/Mailgun/Model/Suppression/Bounce/IndexResponse.php @@ -7,7 +7,7 @@ * of the MIT license. See the LICENSE file for details. */ -namespace Mailgun\Model\Suppressions\Bounce; +namespace Mailgun\Model\Suppression\Bounce; use Mailgun\Model\ApiResponse; use Mailgun\Model\PaginationResponse; diff --git a/src/Mailgun/Model/Suppressions/Bounce/ShowResponse.php b/src/Mailgun/Model/Suppression/Bounce/ShowResponse.php similarity index 90% rename from src/Mailgun/Model/Suppressions/Bounce/ShowResponse.php rename to src/Mailgun/Model/Suppression/Bounce/ShowResponse.php index 6f57865..e062490 100644 --- a/src/Mailgun/Model/Suppressions/Bounce/ShowResponse.php +++ b/src/Mailgun/Model/Suppression/Bounce/ShowResponse.php @@ -7,7 +7,7 @@ * of the MIT license. See the LICENSE file for details. */ -namespace Mailgun\Model\Suppressions\Bounce; +namespace Mailgun\Model\Suppression\Bounce; use Mailgun\Model\ApiResponse; @@ -55,13 +55,13 @@ final class ShowResponse implements ApiResponse $bounce = new self($data['address']); if (isset($data['code'])) { - $this->setCode($data['code']); + $bounce->setCode($data['code']); } if (isset($data['error'])) { - $this->setError($data['error']); + $bounce->setError($data['error']); } if (isset($data['created_at'])) { - $this->setCreatedAt(new \DateTime($data['created_at'])); + $bounce->setCreatedAt(new \DateTime($data['created_at'])); } return $bounce; diff --git a/src/Mailgun/Model/Suppressions/Complaint/CreateResponse.php b/src/Mailgun/Model/Suppression/Complaint/CreateResponse.php similarity index 75% rename from src/Mailgun/Model/Suppressions/Complaint/CreateResponse.php rename to src/Mailgun/Model/Suppression/Complaint/CreateResponse.php index d390638..78e3dde 100644 --- a/src/Mailgun/Model/Suppressions/Complaint/CreateResponse.php +++ b/src/Mailgun/Model/Suppression/Complaint/CreateResponse.php @@ -7,9 +7,9 @@ * of the MIT license. See the LICENSE file for details. */ -namespace Mailgun\Model\Suppressions\Complaint; +namespace Mailgun\Model\Suppression\Complaint; -use Mailgun\Model\Suppressions\BaseResponse; +use Mailgun\Model\Suppression\BaseResponse; /** * @author Sean Johnson diff --git a/src/Mailgun/Model/Suppressions/Complaint/DeleteResponse.php b/src/Mailgun/Model/Suppression/Complaint/DeleteResponse.php similarity index 75% rename from src/Mailgun/Model/Suppressions/Complaint/DeleteResponse.php rename to src/Mailgun/Model/Suppression/Complaint/DeleteResponse.php index eb950fe..9c8ce93 100644 --- a/src/Mailgun/Model/Suppressions/Complaint/DeleteResponse.php +++ b/src/Mailgun/Model/Suppression/Complaint/DeleteResponse.php @@ -7,9 +7,9 @@ * of the MIT license. See the LICENSE file for details. */ -namespace Mailgun\Model\Suppressions\Complaint; +namespace Mailgun\Model\Suppression\Complaint; -use Mailgun\Model\Suppressions\BaseResponse; +use Mailgun\Model\Suppression\BaseResponse; /** * @author Sean Johnson diff --git a/src/Mailgun/Model/Suppressions/Complaint/IndexResponse.php b/src/Mailgun/Model/Suppression/Complaint/IndexResponse.php similarity index 96% rename from src/Mailgun/Model/Suppressions/Complaint/IndexResponse.php rename to src/Mailgun/Model/Suppression/Complaint/IndexResponse.php index 39ec88c..6f96b4f 100644 --- a/src/Mailgun/Model/Suppressions/Complaint/IndexResponse.php +++ b/src/Mailgun/Model/Suppression/Complaint/IndexResponse.php @@ -7,7 +7,7 @@ * of the MIT license. See the LICENSE file for details. */ -namespace Mailgun\Model\Suppressions\Complaint; +namespace Mailgun\Model\Suppression\Complaint; use Mailgun\Model\ApiResponse; use Mailgun\Model\PaginationResponse; diff --git a/src/Mailgun/Model/Suppressions/Complaint/ShowResponse.php b/src/Mailgun/Model/Suppression/Complaint/ShowResponse.php similarity index 91% rename from src/Mailgun/Model/Suppressions/Complaint/ShowResponse.php rename to src/Mailgun/Model/Suppression/Complaint/ShowResponse.php index 291c133..79da797 100644 --- a/src/Mailgun/Model/Suppressions/Complaint/ShowResponse.php +++ b/src/Mailgun/Model/Suppression/Complaint/ShowResponse.php @@ -7,7 +7,7 @@ * of the MIT license. See the LICENSE file for details. */ -namespace Mailgun\Model\Suppressions\Complaint; +namespace Mailgun\Model\Suppression\Complaint; use Mailgun\Model\ApiResponse; @@ -45,7 +45,7 @@ final class ShowResponse implements ApiResponse $bounce = new self($data['address']); if (isset($data['created_at'])) { - $this->setCreatedAt(new \DateTime($data['created_at'])); + $bounce->setCreatedAt(new \DateTime($data['created_at'])); } return $bounce; diff --git a/src/Mailgun/Model/Suppressions/Unsubscribe/CreateResponse.php b/src/Mailgun/Model/Suppression/Unsubscribe/CreateResponse.php similarity index 74% rename from src/Mailgun/Model/Suppressions/Unsubscribe/CreateResponse.php rename to src/Mailgun/Model/Suppression/Unsubscribe/CreateResponse.php index 05c6438..8d398f3 100644 --- a/src/Mailgun/Model/Suppressions/Unsubscribe/CreateResponse.php +++ b/src/Mailgun/Model/Suppression/Unsubscribe/CreateResponse.php @@ -7,9 +7,9 @@ * of the MIT license. See the LICENSE file for details. */ -namespace Mailgun\Model\Suppressions\Unsubscribe; +namespace Mailgun\Model\Suppression\Unsubscribe; -use Mailgun\Model\Suppressions\BaseResponse; +use Mailgun\Model\Suppression\BaseResponse; /** * @author Sean Johnson diff --git a/src/Mailgun/Model/Suppressions/Unsubscribe/DeleteResponse.php b/src/Mailgun/Model/Suppression/Unsubscribe/DeleteResponse.php similarity index 74% rename from src/Mailgun/Model/Suppressions/Unsubscribe/DeleteResponse.php rename to src/Mailgun/Model/Suppression/Unsubscribe/DeleteResponse.php index 76b0e65..c873026 100644 --- a/src/Mailgun/Model/Suppressions/Unsubscribe/DeleteResponse.php +++ b/src/Mailgun/Model/Suppression/Unsubscribe/DeleteResponse.php @@ -7,9 +7,9 @@ * of the MIT license. See the LICENSE file for details. */ -namespace Mailgun\Model\Suppressions\Unsubscribe; +namespace Mailgun\Model\Suppression\Unsubscribe; -use Mailgun\Model\Suppressions\BaseResponse; +use Mailgun\Model\Suppression\BaseResponse; /** * @author Sean Johnson diff --git a/src/Mailgun/Model/Suppressions/Unsubscribe/IndexResponse.php b/src/Mailgun/Model/Suppression/Unsubscribe/IndexResponse.php similarity index 96% rename from src/Mailgun/Model/Suppressions/Unsubscribe/IndexResponse.php rename to src/Mailgun/Model/Suppression/Unsubscribe/IndexResponse.php index aeccd7e..2774a5b 100644 --- a/src/Mailgun/Model/Suppressions/Unsubscribe/IndexResponse.php +++ b/src/Mailgun/Model/Suppression/Unsubscribe/IndexResponse.php @@ -7,7 +7,7 @@ * of the MIT license. See the LICENSE file for details. */ -namespace Mailgun\Model\Suppressions\Unsubscribe; +namespace Mailgun\Model\Suppression\Unsubscribe; use Mailgun\Model\ApiResponse; use Mailgun\Model\PaginationResponse; diff --git a/src/Mailgun/Model/Suppressions/Unsubscribe/ShowResponse.php b/src/Mailgun/Model/Suppression/Unsubscribe/ShowResponse.php similarity index 90% rename from src/Mailgun/Model/Suppressions/Unsubscribe/ShowResponse.php rename to src/Mailgun/Model/Suppression/Unsubscribe/ShowResponse.php index 3073667..5df9426 100644 --- a/src/Mailgun/Model/Suppressions/Unsubscribe/ShowResponse.php +++ b/src/Mailgun/Model/Suppression/Unsubscribe/ShowResponse.php @@ -7,7 +7,7 @@ * of the MIT license. See the LICENSE file for details. */ -namespace Mailgun\Model\Suppressions\Unsubscribe; +namespace Mailgun\Model\Suppression\Unsubscribe; use Mailgun\Model\ApiResponse; @@ -50,10 +50,10 @@ final class ShowResponse implements ApiResponse $unsubscribe = new self($data['address']); if (isset($data['tag'])) { - $this->setTag($data['tag']); + $unsubscribe->setTag($data['tag']); } if (isset($data['created_at'])) { - $this->setCreatedAt(new \DateTime($data['created_at'])); + $unsubscribe->setCreatedAt(new \DateTime($data['created_at'])); } return $unsubscribe; diff --git a/tests/Api/TestCase.php b/tests/Api/TestCase.php index ae5bb6c..bf59b36 100644 --- a/tests/Api/TestCase.php +++ b/tests/Api/TestCase.php @@ -58,13 +58,13 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase ->setMethods(['create']) ->getMock(); - $deserializer = $this->getMockBuilder('Mailgun\Deserializer\ResponseDeserializer') + $hydrator = $this->getMockBuilder('Mailgun\Hydrator\Hydrator') ->setMethods(['deserialize']) ->getMock(); return $this->getMockBuilder($this->getApiClass()) ->setMethods(['httpGet', 'httpPost', 'httpPostRaw', 'httpDelete', 'httpPut']) - ->setConstructorArgs([$httpClient, $requestClient, $deserializer]) + ->setConstructorArgs([$httpClient, $requestClient, $hydrator]) ->getMock(); }