diff --git a/src/Api/EmailValidationV4.php b/src/Api/EmailValidationV4.php old mode 100644 new mode 100755 index 54170bc..71663ff --- a/src/Api/EmailValidationV4.php +++ b/src/Api/EmailValidationV4.php @@ -266,7 +266,7 @@ class EmailValidationV4 extends HttpApi /** * @param string $previewId - * + * * @return mixed|ResponseInterface * * @throws Exception diff --git a/src/Api/HttpApi.php b/src/Api/HttpApi.php index 4e71506..2b11be7 100644 --- a/src/Api/HttpApi.php +++ b/src/Api/HttpApi.php @@ -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: diff --git a/src/Exception/HttpClientException.php b/src/Exception/HttpClientException.php index 261d451..8067e44 100644 --- a/src/Exception/HttpClientException.php +++ b/src/Exception/HttpClientException.php @@ -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); diff --git a/src/Model/EmailValidationV4/CreateBulkJobResponse.php b/src/Model/EmailValidationV4/CreateBulkJobResponse.php old mode 100644 new mode 100755 diff --git a/src/Model/EmailValidationV4/DeleteBulkJobResponse.php b/src/Model/EmailValidationV4/DeleteBulkJobResponse.php old mode 100644 new mode 100755 diff --git a/src/Model/EmailValidationV4/GetBulkJobResponse.php b/src/Model/EmailValidationV4/GetBulkJobResponse.php old mode 100644 new mode 100755 diff --git a/src/Model/EmailValidationV4/GetBulkJobsResponse.php b/src/Model/EmailValidationV4/GetBulkJobsResponse.php old mode 100644 new mode 100755 diff --git a/src/Model/EmailValidationV4/GetBulkPreviewResponse.php b/src/Model/EmailValidationV4/GetBulkPreviewResponse.php old mode 100644 new mode 100755 diff --git a/src/Model/EmailValidationV4/GetBulkPreviewsResponse.php b/src/Model/EmailValidationV4/GetBulkPreviewsResponse.php old mode 100644 new mode 100755 diff --git a/src/Model/EmailValidationV4/Job.php b/src/Model/EmailValidationV4/Job.php old mode 100644 new mode 100755 index a2dc4c2..84918e2 --- a/src/Model/EmailValidationV4/Job.php +++ b/src/Model/EmailValidationV4/Job.php @@ -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; } diff --git a/src/Model/EmailValidationV4/JobDownloadUrl.php b/src/Model/EmailValidationV4/JobDownloadUrl.php old mode 100644 new mode 100755 diff --git a/src/Model/EmailValidationV4/Preview.php b/src/Model/EmailValidationV4/Preview.php old mode 100644 new mode 100755 index 02fb74f..a3f6b46 --- a/src/Model/EmailValidationV4/Preview.php +++ b/src/Model/EmailValidationV4/Preview.php @@ -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; } diff --git a/src/Model/EmailValidationV4/PromoteBulkPreviewResponse.php b/src/Model/EmailValidationV4/PromoteBulkPreviewResponse.php old mode 100644 new mode 100755 diff --git a/src/Model/EmailValidationV4/Summary.php b/src/Model/EmailValidationV4/Summary.php old mode 100644 new mode 100755 diff --git a/src/Model/EmailValidationV4/SummaryResult.php b/src/Model/EmailValidationV4/SummaryResult.php old mode 100644 new mode 100755 diff --git a/src/Model/EmailValidationV4/SummaryRisk.php b/src/Model/EmailValidationV4/SummaryRisk.php old mode 100644 new mode 100755 diff --git a/src/Model/EmailValidationV4/ValidateResponse.php b/src/Model/EmailValidationV4/ValidateResponse.php old mode 100644 new mode 100755 diff --git a/tests/Api/EmailValidationV4Test.php b/tests/Api/EmailValidationV4Test.php old mode 100644 new mode 100755 index 147c020..aa8842f --- a/tests/Api/EmailValidationV4Test.php +++ b/tests/Api/EmailValidationV4Test.php @@ -116,7 +116,7 @@ JSON { "jobs": [ { - "created_at": "Tue, 26 Feb 2019 21:30:03 GMT", + "created_at": 1590080191, "download_url": { "csv": "", "json": "" @@ -142,7 +142,7 @@ JSON } }, { - "created_at": "Tue, 23 Feb 2019 21:30:03 GMT", + "created_at": 1590080191, "download_url": { "csv": "", "json": "" @@ -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": "", "json": "" @@ -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()); diff --git a/tests/Model/EmailValidationV4/JobDownloadUrlTest.php b/tests/Model/EmailValidationV4/JobDownloadUrlTest.php old mode 100644 new mode 100755 diff --git a/tests/Model/EmailValidationV4/JobTest.php b/tests/Model/EmailValidationV4/JobTest.php old mode 100644 new mode 100755 index 2d65dbc..3a37283 --- a/tests/Model/EmailValidationV4/JobTest.php +++ b/tests/Model/EmailValidationV4/JobTest.php @@ -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": "", "json": "" @@ -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()); diff --git a/tests/Model/EmailValidationV4/PreviewTest.php b/tests/Model/EmailValidationV4/PreviewTest.php old mode 100644 new mode 100755 diff --git a/tests/Model/EmailValidationV4/SummaryResultTest.php b/tests/Model/EmailValidationV4/SummaryResultTest.php old mode 100644 new mode 100755 diff --git a/tests/Model/EmailValidationV4/SummaryRiskTest.php b/tests/Model/EmailValidationV4/SummaryRiskTest.php old mode 100644 new mode 100755 diff --git a/tests/Model/EmailValidationV4/SummaryTest.php b/tests/Model/EmailValidationV4/SummaryTest.php old mode 100644 new mode 100755