Skip to content

Commit b8fa2d7

Browse files
author
Antoine Aflalo
committed
feat(Response): Save raw data in response
1 parent 008ac25 commit b8fa2d7

3 files changed

Lines changed: 36 additions & 0 deletions

File tree

src/Client/Middleware/Error/AuthenticationMiddleware.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use ZEROSPAM\Framework\SDK\Client\IOAuthClient;
1414
use ZEROSPAM\Framework\SDK\Client\Middleware\IMiddleware;
1515
use ZEROSPAM\Framework\SDK\Request\Api\IRequest;
16+
use ZEROSPAM\Framework\SDK\Response\Api\BaseResponse;
1617

1718
/**
1819
* Class AuthenticationMiddleware
@@ -63,6 +64,10 @@ public function handle(IRequest $request, ResponseInterface $httpResponse, array
6364
$this->client->refreshToken();
6465
$response = $this->client->processRequest($request);
6566

67+
if ($response instanceof BaseResponse) {
68+
return $response->getRawData();
69+
}
70+
6671
return $response->data();
6772
}
6873
}

src/Client/OAuthClient.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,10 @@ public function processRequest(IRequest $request): IResponse
320320
*/
321321
$data = $request->processResponse($parsedData);
322322

323+
if ($data instanceof BaseResponse) {
324+
$data->setRawData($parsedData);
325+
}
326+
323327
if ($data instanceof IRateLimitedResponse) {
324328
$this->processThrottleData($response);
325329
$data->setRateLimit($this->rateLimit);

src/Response/Api/BaseResponse.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ abstract class BaseResponse implements IRateLimitedResponse
3535
*/
3636
protected $data;
3737

38+
/**
39+
* Data unprocessed
40+
*
41+
* @var array
42+
*/
43+
protected $rawData;
44+
3845
/**
3946
* Dates to be transTyped from string to Carbon.
4047
*
@@ -52,6 +59,26 @@ public function __construct(array $data)
5259
$this->data = $data;
5360
}
5461

62+
/**
63+
* Used internally
64+
*
65+
* @param array $data
66+
*/
67+
public function setRawData(array $data)
68+
{
69+
$this->rawData = $data;
70+
}
71+
72+
/**
73+
* Used internally
74+
*
75+
* @return array
76+
*/
77+
public function getRawData(): array
78+
{
79+
return $this->rawData;
80+
}
81+
5582
/**
5683
* Data contained in the response.
5784
*

0 commit comments

Comments
 (0)