mirror of
https://github.com/retailcrm/mailgun-php.git
synced 2024-11-22 04:26:02 +03:00
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
This commit is contained in:
parent
b3f24e9d7a
commit
84a5c5dd4a
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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 <sean@mailgun.com>
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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 <tobias.nyholm@gmail.com>
|
||||
*/
|
||||
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);
|
@ -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
|
@ -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 <tobias.nyholm@gmail.com>
|
||||
*/
|
||||
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);
|
@ -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 <tobias.nyholm@gmail.com>
|
||||
*/
|
||||
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');
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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 <sean@mailgun.com>
|
||||
*/
|
@ -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 <sean@mailgun.com>
|
@ -9,7 +9,7 @@
|
||||
|
||||
namespace Mailgun\Model\Suppression\Bounce;
|
||||
|
||||
use Mailgun\Model\Suppressions\BaseResponse;
|
||||
use Mailgun\Model\Suppression\BaseResponse;
|
||||
|
||||
/**
|
||||
* @author Sean Johnson <sean@mailgun.com>
|
@ -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;
|
@ -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;
|
@ -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 <sean@mailgun.com>
|
@ -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 <sean@mailgun.com>
|
@ -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;
|
@ -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;
|
@ -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 <sean@mailgun.com>
|
@ -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 <sean@mailgun.com>
|
@ -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;
|
@ -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;
|
@ -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();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user