Skip to content

Commit 7135820

Browse files
feat(refactor)!: clean up pagination, errors, as well as request methods
1 parent 2516566 commit 7135820

28 files changed

+100
-110
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ When the library is unable to connect to the API, or if the API returns a non-su
7272
```php
7373
<?php
7474

75-
use Scrapegraphai\Errors\APIConnectionError;
75+
use Scrapegraphai\Core\Errors\APIConnectionError;
7676

7777
try {
7878
$completedSmartscraper = $client->smartscraper->create(

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"$schema": "https://getcomposer.org/schema.json",
33
"autoload": {
44
"files": [
5-
"src/Core/Omit.php",
5+
"src/Core.php",
66
"src/Client.php"
77
],
88
"psr-4": {

src/Core/Omittable.php renamed to src/Core.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@ enum Omittable
1111
{
1212
case OMIT;
1313
}
14+
15+
const OMIT = Omittable::OMIT;

src/Core/BaseClient.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
use Psr\Http\Message\StreamFactoryInterface;
1414
use Psr\Http\Message\UriFactoryInterface;
1515
use Psr\Http\Message\UriInterface;
16-
use Scrapegraphai\Errors\APIStatusError;
16+
use Scrapegraphai\Core\Errors\APIStatusError;
1717
use Scrapegraphai\RequestOptions;
1818

1919
class BaseClient

src/Core/Concerns/SdkParams.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Scrapegraphai\Core\Conversion;
88
use Scrapegraphai\Core\Conversion\DumpState;
9+
use Scrapegraphai\Core\Util;
910
use Scrapegraphai\RequestOptions;
1011

1112
/**
@@ -29,9 +30,10 @@ trait SdkParams
2930
*/
3031
public static function parseRequest(array|self|null $params, array|RequestOptions|null $options): array
3132
{
33+
$value = is_array($params) ? Util::array_filter_omit($params) : $params;
3234
$converter = self::converter();
3335
$state = new DumpState;
34-
$dumped = (array) Conversion::dump($converter, value: $params, state: $state);
36+
$dumped = (array) Conversion::dump($converter, value: $value, state: $state);
3537
$opts = RequestOptions::parse($options); // @phpstan-ignore-line
3638

3739
if (!$state->canRetry) {

src/Core/Contracts/BasePage.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,31 @@
99
use Scrapegraphai\Core\Pagination\PageRequestOptions;
1010

1111
/**
12-
* @internal
12+
* @template Item
13+
*
14+
* @extends \IteratorAggregate<int, static>
1315
*/
14-
interface BasePage
16+
interface BasePage extends \IteratorAggregate
1517
{
18+
/**
19+
* @internal
20+
*/
1621
public function __construct(
1722
BaseClient $client,
1823
PageRequestOptions $options,
1924
ResponseInterface $response,
2025
mixed $body,
2126
);
27+
28+
public function hasNextPage(): bool;
29+
30+
/**
31+
* @return list<Item>
32+
*/
33+
public function getPaginatedItems(): array;
34+
35+
/**
36+
* @return static<Item>
37+
*/
38+
public function getNextPage(): static;
2239
}

src/Errors/APIConnectionError.php renamed to src/Core/Errors/APIConnectionError.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Scrapegraphai\Errors;
3+
namespace Scrapegraphai\Core\Errors;
44

55
class APIConnectionError extends APIError
66
{

src/Errors/APIError.php renamed to src/Core/Errors/APIError.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<?php
22

3-
namespace Scrapegraphai\Errors;
3+
namespace Scrapegraphai\Core\Errors;
44

55
use Psr\Http\Message\RequestInterface;
66
use Psr\Http\Message\ResponseInterface;
77

8-
class APIError extends Error
8+
class APIError extends ScrapegraphaiError
99
{
1010
public ?int $status = null;
1111

src/Errors/APIStatusError.php renamed to src/Core/Errors/APIStatusError.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Scrapegraphai\Errors;
3+
namespace Scrapegraphai\Core\Errors;
44

55
use Psr\Http\Message\RequestInterface;
66
use Psr\Http\Message\ResponseInterface;

src/Errors/APITimeoutError.php renamed to src/Core/Errors/APITimeoutError.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Scrapegraphai\Errors;
3+
namespace Scrapegraphai\Core\Errors;
44

55
use Psr\Http\Message\RequestInterface;
66

0 commit comments

Comments
 (0)