-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from elbgoods/ft-verifier-provider
add verifier provider
- Loading branch information
Showing
6 changed files
with
80 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
namespace Elbgoods\TrashmailRule\Providers; | ||
|
||
use Elbgoods\TrashmailRule\Contracts\ProviderContract; | ||
|
||
class VerifierProvider implements ProviderContract | ||
{ | ||
protected const BASE_URL = 'https://verifier.meetchopra.com/verify/'; | ||
|
||
protected array $config; | ||
|
||
public function __construct(array $config) | ||
{ | ||
$this->config = $config; | ||
} | ||
|
||
public function isDisposable(string $domain): ?bool | ||
{ | ||
if (! $this->config['enabled']) { | ||
return null; | ||
} | ||
|
||
if (empty($this->config['api_key'])) { | ||
return null; | ||
} | ||
|
||
$response = guzzle( | ||
self::BASE_URL, | ||
$this->config['guzzle'] | ||
)->request('GET', $domain, [ | ||
'query' => [ | ||
'token' => $this->config['api_key'], | ||
], | ||
]); | ||
|
||
$body = $response->getBody()->getContents(); | ||
|
||
return (! json_decode($body, true)['status']) ?? null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,9 @@ final class TrashmailRuleTest extends TestCase | |
/** @test */ | ||
public function it_validates_the_email_domain(): void | ||
{ | ||
$this->app['config']->set('trashmail.disposable_email_detector.enabled', true); | ||
$this->app['config']->set('trashmail.dead_letter.enabled', true); | ||
|
||
$rule = new TrashmailRule(); | ||
|
||
$this->assertFalse($rule->passes('email', '[email protected]')); | ||
|
@@ -23,6 +26,8 @@ public function it_validates_the_email_domain(): void | |
*/ | ||
public function it_fails_known_trashmail_providers(string $domain): void | ||
{ | ||
$this->app['config']->set('trashmail.disposable_email_detector.enabled', true); | ||
$this->app['config']->set('trashmail.dead_letter.enabled', true); | ||
$this->app['config']->set('trashmail.blacklist', $this->trashMailDomains()); | ||
|
||
$rule = new TrashmailRule(); | ||
|