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

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

@ -266,7 +266,7 @@ class EmailValidationV4 extends HttpApi
/**
* @param string $previewId
*
*
* @return mixed|ResponseInterface
*
* @throws Exception

View File

@ -95,6 +95,8 @@ abstract class HttpApi
throw HttpClientException::forbidden($response);
case 404:
throw HttpClientException::notFound($response);
case 409:
throw HttpClientException::conflict($response);
case 413:
throw HttpClientException::payloadTooLarge($response);
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);
}
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)
{
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;
/**
* @var JobDownloadUrl
* @var JobDownloadUrl|null
*/
private $downloadUrl;
@ -47,7 +47,7 @@ class Job implements ApiResponse
private $status;
/**
* @var Summary
* @var Summary|null
*/
private $summary;
@ -59,13 +59,13 @@ class Job implements ApiResponse
{
$model = new static();
$model->createdAt = isset($data['created_at']) ? new DateTimeImmutable($data['created_at']) : null;
$model->downloadUrl = JobDownloadUrl::create($data['download_url']);
$model->createdAt = isset($data['created_at']) ? (DateTimeImmutable::createFromFormat('U', (string) ($data['created_at'])) ?: null) : null;
$model->downloadUrl = $data['download_url'] ? JobDownloadUrl::create($data['download_url']) : null;
$model->id = $data['id'] ?? null;
$model->quantity = $data['quantity'] ?? null;
$model->recordsProcessed = $data['records_processed'] ?? null;
$model->status = $data['status'] ?? null;
$model->summary = Summary::create($data['summary']);
$model->summary = $data['summary'] ? Summary::create($data['summary']) : null;
return $model;
}
@ -75,7 +75,7 @@ class Job implements ApiResponse
return $this->createdAt;
}
public function getDownloadUrl(): JobDownloadUrl
public function getDownloadUrl(): ?JobDownloadUrl
{
return $this->downloadUrl;
}
@ -100,7 +100,7 @@ class Job implements ApiResponse
return $this->status;
}
public function getSummary(): Summary
public function getSummary(): ?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;
/**
* @var Summary
* @var Summary|null
*/
private $summary;
@ -58,8 +58,8 @@ class Preview implements ApiResponse
$model->valid = $data['valid'] ?? null;
$model->status = $data['status'] ?? null;
$model->quantity = $data['quantity'] ?? null;
$model->createdAt = isset($data['created_at']) ? DateTimeImmutable::createFromFormat('U', (string) ($data['created_at'])) : null;
$model->summary = Summary::create($data['summary']);
$model->createdAt = isset($data['created_at']) ? (DateTimeImmutable::createFromFormat('U', (string) ($data['created_at'])) ?: null) : null;
$model->summary = $data['summary'] ? Summary::create($data['summary']) : null;
return $model;
}
@ -89,7 +89,7 @@ class Preview implements ApiResponse
return $this->createdAt;
}
public function getSummary(): Summary
public function getSummary(): ?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": [
{
"created_at": "Tue, 26 Feb 2019 21:30:03 GMT",
"created_at": 1590080191,
"download_url": {
"csv": "<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": {
"csv": "<download_link>",
"json": "<download_link>"
@ -200,7 +200,7 @@ JSON
$this->setRequestUri('/v4/address/validate/bulk/listId123');
$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": {
"csv": "<download_link>",
"json": "<download_link>"
@ -236,7 +236,7 @@ JSON
$this->assertInstanceOf(GetBulkJobResponse::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->assertEquals('bulk_validations_sandbox_mailgun_org', $response->getId());
$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'
{
"created_at": "Sat, 23 Feb 2019 21:30:03 GMT",
"created_at": 1590080191,
"download_url": {
"csv": "<download_link>",
"json": "<download_link>"
@ -50,7 +50,7 @@ class JobTest extends BaseModelTest
}
JSON;
$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->assertEquals('bulk_validations_sandbox_mailgun_org', $model->getId());
$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