Skip to content

Commit

Permalink
~ example
Browse files Browse the repository at this point in the history
  • Loading branch information
vantoozz committed Aug 3, 2017
1 parent f23c7e8 commit 6a7e9c4
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 35 deletions.
7 changes: 0 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,21 +74,14 @@ Sometimes things go wrong. This example shows how to handle errors while getting
```php
<?php declare(strict_types = 1);

use GuzzleHttp\Client as GuzzleClient;
use Vantoozz\ProxyScraper\Exceptions\ScraperException;
use Vantoozz\ProxyScraper\HttpClient\GuzzleHttpClient;
use Vantoozz\ProxyScraper\Ipv4;
use Vantoozz\ProxyScraper\Port;
use Vantoozz\ProxyScraper\Proxy;
use Vantoozz\ProxyScraper\Scrapers;

require_once __DIR__ . '/vendor/autoload.php';

$httpClient = new GuzzleHttpClient(new GuzzleClient([
'connect_timeout' => 2,
'timeout' => 3,
]));

$compositeScraper = new Scrapers\CompositeScraper;

// Set exception handler
Expand Down
7 changes: 0 additions & 7 deletions examples/03-composite_scraper_error_hadling.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
<?php declare(strict_types = 1);

use GuzzleHttp\Client as GuzzleClient;
use Vantoozz\ProxyScraper\Exceptions\ScraperException;
use Vantoozz\ProxyScraper\HttpClient\GuzzleHttpClient;
use Vantoozz\ProxyScraper\Ipv4;
use Vantoozz\ProxyScraper\Port;
use Vantoozz\ProxyScraper\Proxy;
use Vantoozz\ProxyScraper\Scrapers;

require_once __DIR__ . '/../vendor/autoload.php';

$httpClient = new GuzzleHttpClient(new GuzzleClient([
'connect_timeout' => 2,
'timeout' => 3,
]));

$compositeScraper = new Scrapers\CompositeScraper;

// Set exception handler
Expand Down
24 changes: 3 additions & 21 deletions examples/04-validation.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
<?php declare(strict_types = 1);

use GuzzleHttp\Client as GuzzleClient;
use Vantoozz\ProxyScraper\Exceptions\ValidationException;
use Vantoozz\ProxyScraper\HttpClient\GuzzleHttpClient;
use Vantoozz\ProxyScraper\Ipv4;
use Vantoozz\ProxyScraper\Port;
use Vantoozz\ProxyScraper\Proxy;
Expand All @@ -11,35 +9,19 @@

require_once __DIR__ . '/../vendor/autoload.php';

$httpClient = new GuzzleHttpClient(new GuzzleClient([
'connect_timeout' => 2,
'timeout' => 3,
]));

$compositeScraper = new Scrapers\CompositeScraper;

// Throws an exception
$compositeScraper->addScraper(new class implements Scrapers\ScraperInterface
$scraper = new class implements Scrapers\ScraperInterface
{
public function get(): \Generator
{
yield new Proxy(new Ipv4('104.202.117.106'), new Port(1234));
}
});

// No exceptions
$compositeScraper->addScraper(new class implements Scrapers\ScraperInterface
{
public function get(): \Generator
{
yield new Proxy(new Ipv4('192.168.0.1'), new Port(8888));
}
});
};

$validator = new Validators\ValidatorPipeline;
$validator->addStep(new Validators\Ipv4RangeValidator);

foreach ($compositeScraper->get() as $proxy) {
foreach ($scraper->get() as $proxy) {

try {
$validator->validate($proxy);
Expand Down

0 comments on commit 6a7e9c4

Please sign in to comment.