email validation v4 fixes

This commit is contained in:
Artem Bondarenko 2020-12-01 20:42:04 +02:00 committed by David Garcia
parent 2a35fcb077
commit b454618229
24 changed files with 25 additions and 18 deletions

0
src/Api/EmailValidationV4.php Normal file → Executable file
View File

View File

@ -95,6 +95,8 @@ abstract class HttpApi
throw HttpClientException::forbidden($response); throw HttpClientException::forbidden($response);
case 404: case 404:
throw HttpClientException::notFound($response); throw HttpClientException::notFound($response);
case 409:
throw HttpClientException::conflict($response);
case 413: case 413:
throw HttpClientException::payloadTooLarge($response); throw HttpClientException::payloadTooLarge($response);
case 500 <= $statusCode: case 500 <= $statusCode:

View File

@ -78,6 +78,11 @@ final class HttpClientException extends \RuntimeException implements Exception
return new self('The endpoint you have tried to access does not exist. Check if the domain matches the domain you have configure on Mailgun.', 404, $response); return new self('The endpoint you have tried to access does not exist. Check if the domain matches the domain you have configure on Mailgun.', 404, $response);
} }
public static function conflict(ResponseInterface $response)
{
return new self('Request conflicts with current state of the target resource.', 409, $response);
}
public static function payloadTooLarge(ResponseInterface $response) public static function payloadTooLarge(ResponseInterface $response)
{ {
return new self('Payload too large, your total attachment size is too big.', 413, $response); return new self('Payload too large, your total attachment size is too big.', 413, $response);

0
src/Model/EmailValidationV4/CreateBulkJobResponse.php Normal file → Executable file
View File

0
src/Model/EmailValidationV4/DeleteBulkJobResponse.php Normal file → Executable file
View File

0
src/Model/EmailValidationV4/GetBulkJobResponse.php Normal file → Executable file
View File

0
src/Model/EmailValidationV4/GetBulkJobsResponse.php Normal file → Executable file
View File

0
src/Model/EmailValidationV4/GetBulkPreviewResponse.php Normal file → Executable file
View File

View File

14
src/Model/EmailValidationV4/Job.php Normal file → Executable file
View File

@ -22,7 +22,7 @@ class Job implements ApiResponse
private $createdAt; private $createdAt;
/** /**
* @var JobDownloadUrl * @var JobDownloadUrl|null
*/ */
private $downloadUrl; private $downloadUrl;
@ -47,7 +47,7 @@ class Job implements ApiResponse
private $status; private $status;
/** /**
* @var Summary * @var Summary|null
*/ */
private $summary; private $summary;
@ -59,13 +59,13 @@ class Job implements ApiResponse
{ {
$model = new static(); $model = new static();
$model->createdAt = isset($data['created_at']) ? new DateTimeImmutable($data['created_at']) : null; $model->createdAt = isset($data['created_at']) ? (DateTimeImmutable::createFromFormat('U', (string) ($data['created_at'])) ?: null) : null;
$model->downloadUrl = JobDownloadUrl::create($data['download_url']); $model->downloadUrl = $data['download_url'] ? JobDownloadUrl::create($data['download_url']) : null;
$model->id = $data['id'] ?? null; $model->id = $data['id'] ?? null;
$model->quantity = $data['quantity'] ?? null; $model->quantity = $data['quantity'] ?? null;
$model->recordsProcessed = $data['records_processed'] ?? null; $model->recordsProcessed = $data['records_processed'] ?? null;
$model->status = $data['status'] ?? null; $model->status = $data['status'] ?? null;
$model->summary = Summary::create($data['summary']); $model->summary = $data['summary'] ? Summary::create($data['summary']) : null;
return $model; return $model;
} }
@ -75,7 +75,7 @@ class Job implements ApiResponse
return $this->createdAt; return $this->createdAt;
} }
public function getDownloadUrl(): JobDownloadUrl public function getDownloadUrl(): ?JobDownloadUrl
{ {
return $this->downloadUrl; return $this->downloadUrl;
} }
@ -100,7 +100,7 @@ class Job implements ApiResponse
return $this->status; return $this->status;
} }
public function getSummary(): Summary public function getSummary(): ?Summary
{ {
return $this->summary; return $this->summary;
} }

0
src/Model/EmailValidationV4/JobDownloadUrl.php Normal file → Executable file
View File

8
src/Model/EmailValidationV4/Preview.php Normal file → Executable file
View File

@ -42,7 +42,7 @@ class Preview implements ApiResponse
private $createdAt; private $createdAt;
/** /**
* @var Summary * @var Summary|null
*/ */
private $summary; private $summary;
@ -58,8 +58,8 @@ class Preview implements ApiResponse
$model->valid = $data['valid'] ?? null; $model->valid = $data['valid'] ?? null;
$model->status = $data['status'] ?? null; $model->status = $data['status'] ?? null;
$model->quantity = $data['quantity'] ?? null; $model->quantity = $data['quantity'] ?? null;
$model->createdAt = isset($data['created_at']) ? DateTimeImmutable::createFromFormat('U', (string) ($data['created_at'])) : null; $model->createdAt = isset($data['created_at']) ? (DateTimeImmutable::createFromFormat('U', (string) ($data['created_at'])) ?: null) : null;
$model->summary = Summary::create($data['summary']); $model->summary = $data['summary'] ? Summary::create($data['summary']) : null;
return $model; return $model;
} }
@ -89,7 +89,7 @@ class Preview implements ApiResponse
return $this->createdAt; return $this->createdAt;
} }
public function getSummary(): Summary public function getSummary(): ?Summary
{ {
return $this->summary; return $this->summary;
} }

View File

0
src/Model/EmailValidationV4/Summary.php Normal file → Executable file
View File

0
src/Model/EmailValidationV4/SummaryResult.php Normal file → Executable file
View File

0
src/Model/EmailValidationV4/SummaryRisk.php Normal file → Executable file
View File

0
src/Model/EmailValidationV4/ValidateResponse.php Normal file → Executable file
View File

8
tests/Api/EmailValidationV4Test.php Normal file → Executable file
View File

@ -116,7 +116,7 @@ JSON
{ {
"jobs": [ "jobs": [
{ {
"created_at": "Tue, 26 Feb 2019 21:30:03 GMT", "created_at": 1590080191,
"download_url": { "download_url": {
"csv": "<download_link>", "csv": "<download_link>",
"json": "<download_link>" "json": "<download_link>"
@ -142,7 +142,7 @@ JSON
} }
}, },
{ {
"created_at": "Tue, 23 Feb 2019 21:30:03 GMT", "created_at": 1590080191,
"download_url": { "download_url": {
"csv": "<download_link>", "csv": "<download_link>",
"json": "<download_link>" "json": "<download_link>"
@ -200,7 +200,7 @@ JSON
$this->setRequestUri('/v4/address/validate/bulk/listId123'); $this->setRequestUri('/v4/address/validate/bulk/listId123');
$this->setHttpResponse(new Response(200, ['Content-Type' => 'application/json'], <<<'JSON' $this->setHttpResponse(new Response(200, ['Content-Type' => 'application/json'], <<<'JSON'
{ {
"created_at": "Sat, 23 Feb 2019 21:30:03 GMT", "created_at": 1590080191,
"download_url": { "download_url": {
"csv": "<download_link>", "csv": "<download_link>",
"json": "<download_link>" "json": "<download_link>"
@ -236,7 +236,7 @@ JSON
$this->assertInstanceOf(GetBulkJobResponse::class, $response); $this->assertInstanceOf(GetBulkJobResponse::class, $response);
$this->assertInstanceOf(Job::class, $response); $this->assertInstanceOf(Job::class, $response);
$this->assertEquals('2019-02-23 21:30:03', $response->getCreatedAt()->format('Y-m-d H:i:s')); $this->assertEquals('2020-05-21 16:56:31', $response->getCreatedAt()->format('Y-m-d H:i:s'));
$this->assertInstanceOf(JobDownloadUrl::class, $response->getDownloadUrl()); $this->assertInstanceOf(JobDownloadUrl::class, $response->getDownloadUrl());
$this->assertEquals('bulk_validations_sandbox_mailgun_org', $response->getId()); $this->assertEquals('bulk_validations_sandbox_mailgun_org', $response->getId());
$this->assertEquals(207, $response->getQuantity()); $this->assertEquals(207, $response->getQuantity());

0
tests/Model/EmailValidationV4/JobDownloadUrlTest.php Normal file → Executable file
View File

4
tests/Model/EmailValidationV4/JobTest.php Normal file → Executable file
View File

@ -23,7 +23,7 @@ class JobTest extends BaseModelTest
$json = $json =
<<<'JSON' <<<'JSON'
{ {
"created_at": "Sat, 23 Feb 2019 21:30:03 GMT", "created_at": 1590080191,
"download_url": { "download_url": {
"csv": "<download_link>", "csv": "<download_link>",
"json": "<download_link>" "json": "<download_link>"
@ -50,7 +50,7 @@ class JobTest extends BaseModelTest
} }
JSON; JSON;
$model = Job::create(json_decode($json, true)); $model = Job::create(json_decode($json, true));
$this->assertEquals('2019-02-23 21:30:03', $model->getCreatedAt()->format('Y-m-d H:i:s')); $this->assertEquals('2020-05-21 16:56:31', $model->getCreatedAt()->format('Y-m-d H:i:s'));
$this->assertInstanceOf(JobDownloadUrl::class, $model->getDownloadUrl()); $this->assertInstanceOf(JobDownloadUrl::class, $model->getDownloadUrl());
$this->assertEquals('bulk_validations_sandbox_mailgun_org', $model->getId()); $this->assertEquals('bulk_validations_sandbox_mailgun_org', $model->getId());
$this->assertEquals(207, $model->getQuantity()); $this->assertEquals(207, $model->getQuantity());

0
tests/Model/EmailValidationV4/PreviewTest.php Normal file → Executable file
View File

0
tests/Model/EmailValidationV4/SummaryResultTest.php Normal file → Executable file
View File

0
tests/Model/EmailValidationV4/SummaryRiskTest.php Normal file → Executable file
View File

0
tests/Model/EmailValidationV4/SummaryTest.php Normal file → Executable file
View File