Skip to content

Commit 195ea28

Browse files
committed
Added ebay integration and updating tests
1 parent fe52125 commit 195ea28

File tree

10 files changed

+288
-2
lines changed

10 files changed

+288
-2
lines changed

src/DTOs/PushPullJob.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ class PushPullJob extends Data
1616
public function __construct(
1717
#[WithCast(DateTimeInterfaceCast::class, format: ['Y-m-d H:i:s', 'Y-m-d\TH:i:s\+H:i', 'Y-m-d H:i:s.u'])]
1818
public readonly Carbon $created_at,
19-
public readonly string $domain,
2019
public readonly string $id,
21-
public readonly bool $parse,
2220
public readonly string $source,
2321
public readonly string $status,
2422
#[WithCast(DateTimeInterfaceCast::class, format: ['Y-m-d H:i:s', 'Y-m-d\TH:i:s\+H:i', 'Y-m-d H:i:s.u'])]
2523
public readonly Carbon $updated_at,
24+
public readonly ?string $domain = null,
25+
public readonly ?bool $parse = null,
2626
public readonly ?bool $xhr = null,
2727
public readonly ?int $client_id = null,
2828
public readonly ?int $limit = null,

src/DTOs/eBay/ProductRequest.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace AlwaysOpen\OxylabsApi\DTOs\eBay;
4+
5+
use AlwaysOpen\OxylabsApi\Enums\RenderOption;
6+
use Spatie\LaravelData\Data;
7+
8+
class ProductRequest extends Data
9+
{
10+
public function __construct(
11+
public readonly string $product_id,
12+
public readonly ?string $user_agent_type = null,
13+
public readonly ?RenderOption $render = null,
14+
public readonly ?string $domain = null,
15+
// public readonly ?string $callback_url = null,
16+
// public readonly ?string $storage_type = null,
17+
// public readonly ?string $storage_url = null,
18+
) {}
19+
20+
public function toArray(): array
21+
{
22+
return array_filter([
23+
'product_id' => $this->product_id,
24+
'user_agent_type' => $this->user_agent_type,
25+
'render' => $this->render,
26+
'domain' => $this->domain,
27+
]);
28+
}
29+
}

src/DTOs/eBay/SearchRequest.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace AlwaysOpen\OxylabsApi\DTOs\eBay;
4+
5+
use AlwaysOpen\OxylabsApi\Enums\RenderOption;
6+
use Spatie\LaravelData\Data;
7+
8+
class SearchRequest extends Data
9+
{
10+
public function __construct(
11+
public readonly string $query,
12+
public readonly ?int $start_page = null,
13+
public readonly ?string $user_agent_type = null,
14+
public readonly ?RenderOption $render = null,
15+
// public readonly ?string $callback_url = null,
16+
// public readonly ?string $storage_type = null,
17+
// public readonly ?string $storage_url = null,
18+
) {}
19+
20+
public function toArray(): array
21+
{
22+
return array_filter([
23+
'query' => $this->query,
24+
'user_agent_type' => $this->user_agent_type,
25+
'render' => $this->render,
26+
'start_page' => $this->start_page,
27+
]);
28+
}
29+
}

src/DTOs/eBay/eBayResponse.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace AlwaysOpen\OxylabsApi\DTOs\eBay;
4+
5+
use AlwaysOpen\OxylabsApi\DTOs\PushPullJob;
6+
use AlwaysOpen\OxylabsApi\DTOs\Traits\ValidResponse;
7+
use Spatie\LaravelData\Attributes\DataCollectionOf;
8+
use Spatie\LaravelData\Data;
9+
10+
class eBayResponse extends Data
11+
{
12+
use ValidResponse;
13+
14+
public function __construct(
15+
/* @var eBayResult[] $results */
16+
#[DataCollectionOf(eBayResult::class)]
17+
public readonly ?array $results,
18+
public readonly ?PushPullJob $job,
19+
) {}
20+
}

src/DTOs/eBay/eBayResult.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace AlwaysOpen\OxylabsApi\DTOs\eBay;
4+
5+
use AlwaysOpen\OxylabsApi\Traits\Renderable;
6+
use Illuminate\Support\Carbon;
7+
use Spatie\LaravelData\Attributes\WithCast;
8+
use Spatie\LaravelData\Casts\DateTimeInterfaceCast;
9+
use Spatie\LaravelData\Data;
10+
11+
class eBayResult extends Data
12+
{
13+
use Renderable;
14+
15+
public function __construct(
16+
public readonly string $content,
17+
public readonly int $page,
18+
public readonly string $url,
19+
public readonly string $job_id,
20+
public readonly bool $is_render_forced,
21+
public readonly int $status_code,
22+
public readonly ?string $type = null,
23+
public readonly ?string $parser_type = null,
24+
#[WithCast(DateTimeInterfaceCast::class, format: ['Y-m-d H:i:s', 'Y-m-d\TH:i:s\+H:i', 'Y-m-d H:i:s.u'])]
25+
public readonly ?Carbon $created_at = null,
26+
#[WithCast(DateTimeInterfaceCast::class, format: ['Y-m-d H:i:s', 'Y-m-d\TH:i:s\+H:i', 'Y-m-d H:i:s.u'])]
27+
public readonly ?Carbon $updated_at = null,
28+
public readonly ?string $parser_preset = null,
29+
) {}
30+
}

src/OxylabsApi.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ class OxylabsApi
5555

5656
public const string SOURCE_WALMART_SEARCH = 'walmart_search';
5757

58+
public const string SOURCE_EBAY_SEARCH = 'ebay_search';
59+
60+
public const string SOURCE_EBAY_PRODUCT = 'ebay_product';
61+
5862
public const string TARGET_KROGER = 'kroger';
5963

6064
public const string TARGET_BING = 'bing';

src/OxylabsApiClient.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use AlwaysOpen\OxylabsApi\DTOs\Amazon\AmazonSellerResponse;
1313
use AlwaysOpen\OxylabsApi\DTOs\Amazon\AmazonSellersRequest;
1414
use AlwaysOpen\OxylabsApi\DTOs\BatchRequest;
15+
use AlwaysOpen\OxylabsApi\DTOs\eBay\eBayResponse;
1516
use AlwaysOpen\OxylabsApi\DTOs\Google\GoogleShoppingPricingRequest;
1617
use AlwaysOpen\OxylabsApi\DTOs\Google\GoogleShoppingPricingResponse;
1718
use AlwaysOpen\OxylabsApi\DTOs\Google\GoogleShoppingProductRequest;
@@ -534,4 +535,21 @@ public function getGoogleUrlResult(
534535

535536
return GoogleUrlResponse::from($response);
536537
}
538+
539+
/**
540+
* @throws Throwable
541+
* @throws ConnectionException
542+
*/
543+
public function geteBayResult(
544+
string $job_id,
545+
bool $check_status = false,
546+
int $status_check_limit = 5,
547+
int $status_wait_seconds = 3,
548+
?string $type = 'raw',
549+
bool $logResponseBody = true,
550+
): eBayResponse {
551+
$response = $this->getPushPullResults($job_id, $check_status, $status_check_limit, $status_wait_seconds, $type, $logResponseBody);
552+
553+
return eBayResponse::from($response);
554+
}
537555
}

tests/Feature/OxylabsApiClientTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use AlwaysOpen\OxylabsApi\DTOs\Amazon\AmazonProductRequest;
77
use AlwaysOpen\OxylabsApi\DTOs\Amazon\AmazonRequest;
88
use AlwaysOpen\OxylabsApi\DTOs\Amazon\AmazonSellersRequest;
9+
use AlwaysOpen\OxylabsApi\DTOs\eBay\ProductRequest;
910
use AlwaysOpen\OxylabsApi\DTOs\Google\GoogleShoppingPricingRequest;
1011
use AlwaysOpen\OxylabsApi\DTOs\Google\GoogleShoppingProductRequest;
1112
use AlwaysOpen\OxylabsApi\DTOs\Google\Url\GoogleUrlRequest;
@@ -414,4 +415,24 @@ public function test_universal_request()
414415

415416
$this->assertEquals(ParseStatus::FAILURE_COULD_NOT_PARSE->value, $result->results[0]->content->parse_status_code);
416417
}
418+
419+
public function test_ebay_request()
420+
{
421+
Http::fake([
422+
'data.oxylabs.io/v1/queries' => Http::response($this->getFixtureJsonContent('ebay_creation_result.json'), 200),
423+
'data.oxylabs.io/v1/queries/7394841187565211649/results?type=raw' => Http::response($this->getFixtureJsonContent('ebay_search_result.json'), 200),
424+
]);
425+
426+
$client = new OxylabsApiClient(username: 'user', password: 'pass');
427+
428+
$productRequest = new ProductRequest('asdf');
429+
430+
$creationResult = $client->makePostRequest(OxylabsApi::SOURCE_EBAY_SEARCH, $productRequest->toArray());
431+
432+
$this->assertNotEmpty($creationResult->query);
433+
434+
$result = $client->geteBayResult($creationResult->id);
435+
436+
$this->assertTrue($result->results[0]->isRaw());
437+
}
417438
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"source": "ebay_search",
3+
"query": "shoes",
4+
"id": "7394841187565211649",
5+
"status": "pending",
6+
"created_at": "2025-11-13 20:58:48",
7+
"updated_at": "2025-11-13 20:58:48",
8+
"_links": [
9+
{
10+
"rel": "self",
11+
"href": "http://data.oxylabs.io/v1/queries/7394841187565211649",
12+
"method": "GET"
13+
},
14+
{
15+
"rel": "results",
16+
"href": "http://data.oxylabs.io/v1/queries/7394841187565211649/results",
17+
"method": "GET"
18+
},
19+
{
20+
"rel": "results-content",
21+
"href_list": [
22+
"http://data.oxylabs.io/v1/queries/7394841187565211649/results/1/content"
23+
],
24+
"method": "GET"
25+
},
26+
{
27+
"rel": "results-html",
28+
"href": "http://data.oxylabs.io/v1/queries/7394841187565211649/results?type=raw",
29+
"method": "GET"
30+
},
31+
{
32+
"rel": "results-content-html",
33+
"href_list": [
34+
"http://data.oxylabs.io/v1/queries/7394841187565211649/results/1/content?type=raw"
35+
],
36+
"method": "GET"
37+
}
38+
]
39+
}

tests/Fixtures/ebay_search_result.json

Lines changed: 96 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)