Skip to content
This repository was archived by the owner on Mar 20, 2025. It is now read-only.

Commit 0e34850

Browse files
authored
Merge pull request #9 from elbgoods/laravel-guzzle-v2
upgrade laravel-guzzle:2.0.0
2 parents 2a22d51 + 02182c4 commit 0e34850

10 files changed

+82
-37
lines changed

.github/workflows/run-tests.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ jobs:
3939
4040
- name: phpunit
4141
run: vendor/bin/phpunit
42+
env:
43+
VERIFIER_API_KEY: ${{ secrets.VERIFIER_API_KEY }}
4244

4345
- name: php-cs-test
4446
run: vendor/bin/php-cs-test

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
All notable changes to this package will be documented in this file.
44

5+
## v0.5.0
6+
7+
* upgrade `astrotomic/laravel-guzzle` to v2.0.0
8+
59
## v0.4.0
610

711
* add https://verifier.meetchopra.com provider `\Elbgoods\TrashmailRule\Providers\VerifierProvider`

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
],
2020
"require": {
2121
"php": "^7.4",
22-
"astrotomic/laravel-guzzle": "^1.0.1",
22+
"astrotomic/laravel-guzzle": "^2.0",
2323
"illuminate/cache": "^6.0",
2424
"illuminate/support": "^6.0"
2525
},

config/trashmail.php

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
<?php
22

3-
use GuzzleHttp\RequestOptions;
4-
53
return [
64
/*
75
* The list of providers that should run to decide whether an email is disposable or not.
@@ -25,30 +23,21 @@
2523
'key' => 'elbgoods.trashmail.dead_letter',
2624
'ttl' => 60 * 60 * 24, // one day
2725
],
28-
'guzzle' => [
29-
RequestOptions::TIMEOUT => 10,
30-
],
3126
],
3227

3328
/*
3429
* This package can do a request to https://www.disposable-email-detector.com
3530
*/
3631
'disposable_email_detector' => [
3732
'enabled' => false,
38-
'guzzle' => [
39-
RequestOptions::TIMEOUT => 5,
40-
],
4133
],
4234

4335
/*
4436
* This package can do a request to https://verifier.meetchopra.com
4537
*/
4638
'verifier' => [
4739
'enabled' => false,
48-
'api_key' => null,
49-
'guzzle' => [
50-
RequestOptions::TIMEOUT => 5,
51-
],
40+
'api_key' => env('VERIFIER_API_KEY'),
5241
],
5342

5443
/*

src/Providers/DeadLetterProvider.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@
22

33
namespace Elbgoods\TrashmailRule\Providers;
44

5+
use Astrotomic\LaravelGuzzle\Facades\Guzzle;
56
use Elbgoods\TrashmailRule\Contracts\ProviderContract;
67
use Illuminate\Contracts\Cache\Factory as CacheFactory;
78
use Illuminate\Contracts\Cache\Repository as CacheRepository;
89

910
class DeadLetterProvider implements ProviderContract
1011
{
11-
protected const BLACKLIST_URL = 'https://www.dead-letter.email/blacklist_flat.json';
12-
1312
protected array $config;
1413
protected CacheFactory $cache;
1514

@@ -59,10 +58,8 @@ protected function getBlacklist(): array
5958

6059
protected function loadDeadLetter(): array
6160
{
62-
$response = guzzle(
63-
self::BLACKLIST_URL,
64-
$this->config['guzzle']
65-
)->request('GET', '');
61+
$response = Guzzle::client('dead-letter.email')
62+
->request('GET', 'blacklist_flat.json');
6663

6764
$body = $response->getBody()->getContents();
6865

src/Providers/DisposableEmailDetectorProvider.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22

33
namespace Elbgoods\TrashmailRule\Providers;
44

5+
use Astrotomic\LaravelGuzzle\Facades\Guzzle;
56
use Elbgoods\TrashmailRule\Contracts\ProviderContract;
67

78
class DisposableEmailDetectorProvider implements ProviderContract
89
{
9-
protected const BASE_URL = 'https://api.disposable-email-detector.com/api/dea/v1/check/';
10-
1110
protected array $config;
1211

1312
public function __construct(array $config)
@@ -21,10 +20,8 @@ public function isDisposable(string $domain): ?bool
2120
return null;
2221
}
2322

24-
$response = guzzle(
25-
self::BASE_URL,
26-
$this->config['guzzle']
27-
)->request('GET', $domain);
23+
$response = Guzzle::client('api.disposable-email-detector.com')
24+
->request('GET', 'api/dea/v1/check/'.urlencode($domain));
2825

2926
$body = $response->getBody()->getContents();
3027

src/Providers/VerifierProvider.php

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22

33
namespace Elbgoods\TrashmailRule\Providers;
44

5+
use Astrotomic\LaravelGuzzle\Facades\Guzzle;
56
use Elbgoods\TrashmailRule\Contracts\ProviderContract;
67

78
class VerifierProvider implements ProviderContract
89
{
9-
protected const BASE_URL = 'https://verifier.meetchopra.com/verify/';
10-
1110
protected array $config;
1211

1312
public function __construct(array $config)
@@ -25,14 +24,12 @@ public function isDisposable(string $domain): ?bool
2524
return null;
2625
}
2726

28-
$response = guzzle(
29-
self::BASE_URL,
30-
$this->config['guzzle']
31-
)->request('GET', $domain, [
32-
'query' => [
33-
'token' => $this->config['api_key'],
34-
],
35-
]);
27+
$response = Guzzle::client('verifier.meetchopra.com')
28+
->request('GET', 'verify/'.urlencode($domain), [
29+
'query' => [
30+
'token' => $this->config['api_key'],
31+
],
32+
]);
3633

3734
$body = $response->getBody()->getContents();
3835

src/TrashmailRuleServiceProvider.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Elbgoods\TrashmailRule;
44

5+
use Astrotomic\LaravelGuzzle\Facades\Guzzle;
6+
use GuzzleHttp\RequestOptions;
57
use Illuminate\Support\ServiceProvider;
68

79
class TrashmailRuleServiceProvider extends ServiceProvider
@@ -12,6 +14,27 @@ public function boot(): void
1214
$this->bootConfig();
1315
$this->bootLang();
1416
}
17+
18+
Guzzle::register('dead-letter.email', [
19+
'base_uri' => 'https://www.dead-letter.email',
20+
RequestOptions::TIMEOUT => 10,
21+
RequestOptions::ALLOW_REDIRECTS => true,
22+
RequestOptions::HTTP_ERRORS => true,
23+
]);
24+
25+
Guzzle::register('api.disposable-email-detector.com', [
26+
'base_uri' => 'https://api.disposable-email-detector.com',
27+
RequestOptions::TIMEOUT => 5,
28+
RequestOptions::ALLOW_REDIRECTS => true,
29+
RequestOptions::HTTP_ERRORS => true,
30+
]);
31+
32+
Guzzle::register('verifier.meetchopra.com', [
33+
'base_uri' => 'https://verifier.meetchopra.com',
34+
RequestOptions::TIMEOUT => 5,
35+
RequestOptions::ALLOW_REDIRECTS => true,
36+
RequestOptions::HTTP_ERRORS => true,
37+
]);
1538
}
1639

1740
public function register(): void

tests/Rules/TrashmailRuleTest.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,42 @@ public function it_passes_whitelist_addresses(): void
4747
$this->assertTrue($rule->passes('email', 'example@'.$domain));
4848
}
4949

50+
/** @test */
51+
public function dead_letter_fails_with_disposable_email(): void
52+
{
53+
$this->app['config']->set('trashmail.dead_letter.enabled', true);
54+
55+
$rule = new TrashmailRule();
56+
57+
$this->assertFalse($rule->passes('email', 'example@0815.ru'));
58+
}
59+
60+
/** @test */
61+
public function disposable_email_fails_with_disposable_email(): void
62+
{
63+
$this->app['config']->set('trashmail.disposable_email_detector.enabled', true);
64+
65+
$rule = new TrashmailRule();
66+
67+
$this->assertFalse($rule->passes('email', 'example@0815.ru'));
68+
}
69+
70+
/** @test */
71+
public function verifier_fails_with_disposable_email(): void
72+
{
73+
if ($this->app['config']->get('trashmail.verifier.api_key') === null) {
74+
$this->markTestSkipped('Verifier requires an API-Key');
75+
76+
return;
77+
}
78+
79+
$this->app['config']->set('trashmail.verifier.enabled', true);
80+
81+
$rule = new TrashmailRule();
82+
83+
$this->assertFalse($rule->passes('email', 'example@0815.ru'));
84+
}
85+
5086
public function provideTrashMailDomain(): array
5187
{
5288
return array_map(static function (string $domain): array {

tests/TestCase.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Elbgoods\TrashmailRule\Tests;
44

5-
use Astrotomic\LaravelGuzzle\LaravelGuzzleServiceProvider;
5+
use Astrotomic\LaravelGuzzle\GuzzleServiceProvider;
66
use Elbgoods\TrashmailRule\TrashmailRuleServiceProvider;
77
use Orchestra\Testbench\TestCase as Orchestra;
88

@@ -11,7 +11,7 @@ abstract class TestCase extends Orchestra
1111
protected function getPackageProviders($app)
1212
{
1313
return [
14-
LaravelGuzzleServiceProvider::class,
14+
GuzzleServiceProvider::class,
1515
TrashmailRuleServiceProvider::class,
1616
];
1717
}

0 commit comments

Comments
 (0)