Skip to content

Commit 16714bf

Browse files
committed
Updated to store headers
1 parent bf84019 commit 16714bf

File tree

4 files changed

+37
-2
lines changed

4 files changed

+37
-2
lines changed

src/DTOs/PushPullBatchJobResponse.php

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

33
namespace AlwaysOpen\OxylabsApi\DTOs;
44

5+
use AlwaysOpen\OxylabsApi\Traits\Headers;
56
use Spatie\LaravelData\Attributes\DataCollectionOf;
67
use Spatie\LaravelData\Data;
78

89
class PushPullBatchJobResponse extends Data
910
{
11+
use Headers;
12+
1013
public function __construct(
1114
/* @var PushPullJobResponse[] $queries */
1215
#[DataCollectionOf(PushPullJobResponse::class)]

src/DTOs/PushPullJob.php

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

33
namespace AlwaysOpen\OxylabsApi\DTOs;
44

5+
use AlwaysOpen\OxylabsApi\Traits\Headers;
56
use Illuminate\Support\Carbon;
67
use Spatie\LaravelData\Attributes\DataCollectionOf;
78
use Spatie\LaravelData\Attributes\WithCast;
@@ -10,6 +11,8 @@
1011

1112
class PushPullJob extends Data
1213
{
14+
use Headers;
15+
1316
public function __construct(
1417
#[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'])]
1518
public readonly Carbon $created_at,

src/OxylabsApiClient.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public function makePostRequest(
101101
throw new RuntimeException('API request failed: '.$response->body(), $response->getStatusCode());
102102
}
103103

104-
return PushPullJob::from($response->json());
104+
return PushPullJob::from($response->json())->setHeaders($response->getHeaders());
105105
} catch (Throwable $e) {
106106
throw new RuntimeException('API request failed: '.$e->getMessage(), $e->getCode(), $e);
107107
}
@@ -342,7 +342,7 @@ public function makeBatchRequest(
342342
throw new RuntimeException('API request failed: '.$response->body());
343343
}
344344

345-
return PushPullBatchJobResponse::from($response->json());
345+
return PushPullBatchJobResponse::from($response->json())->setHeaders($response->getHeaders());
346346
}
347347

348348
/**

src/Traits/Headers.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\Traits;
4+
5+
trait Headers
6+
{
7+
protected ?array $__headers = null;
8+
9+
public function getHeaderValue(string $key): mixed
10+
{
11+
if ($this->__headers) {
12+
return $this->__headers[$key] ?? null;
13+
}
14+
15+
return null;
16+
}
17+
18+
public function getHeaders(): ?array
19+
{
20+
return $this->__headers;
21+
}
22+
23+
public function setHeaders(?array $headers = null): self
24+
{
25+
$this->__headers = $headers;
26+
27+
return $this;
28+
}
29+
}

0 commit comments

Comments
 (0)