Skip to content

Commit b93e780

Browse files
committed
Use the new ParsedContentsInterface
1 parent 06ff9b1 commit b93e780

File tree

4 files changed

+177
-6
lines changed

4 files changed

+177
-6
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"php": "^7.0",
1212
"api-clients/json": "^1.0",
1313
"api-clients/middleware": "^4.0",
14+
"api-clients/transport": "^3.1",
1415
"clue/buzz-react": "^2.0 || ^1.4",
1516
"psr/http-message": "^1.0",
1617
"ringcentral/psr7": "^1.2",

composer.lock

Lines changed: 169 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/JsonEncodeMiddleware.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use ApiClients\Foundation\Middleware\ErrorTrait;
77
use ApiClients\Foundation\Middleware\MiddlewareInterface;
88
use ApiClients\Foundation\Middleware\PostTrait;
9+
use ApiClients\Foundation\Transport\ParsedContentsInterface;
910
use ApiClients\Tools\Json\JsonEncodeService;
1011
use Psr\Http\Message\RequestInterface;
1112
use React\Promise\CancellablePromiseInterface;
@@ -42,11 +43,12 @@ public function pre(
4243
string $transactionId,
4344
array $options = []
4445
): CancellablePromiseInterface {
45-
if (!($request->getBody() instanceof JsonStream)) {
46+
$body = $request->getBody();
47+
if (!($body instanceof ParsedContentsInterface)) {
4648
return resolve($request);
4749
}
4850

49-
return $this->jsonEncodeService->encode($request->getBody()->getJson())->then(function ($json) use ($request) {
51+
return $this->jsonEncodeService->encode($body->getParsedContents())->then(function ($json) use ($request) {
5052
$body = new BufferStream(strlen($json));
5153
$body->write($json);
5254
return resolve($request->withBody($body)->withAddedHeader('Content-Type', 'application/json'));

src/JsonStream.php

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

33
namespace ApiClients\Middleware\Json;
44

5+
use ApiClients\Foundation\Transport\ParsedContentsInterface;
56
use Psr\Http\Message\StreamInterface;
67
use RingCentral\Psr7\BufferStream;
78

8-
class JsonStream implements StreamInterface
9+
class JsonStream implements StreamInterface, ParsedContentsInterface
910
{
1011
/**
1112
* @var array
@@ -28,7 +29,7 @@ public function __construct(array $json)
2829
/**
2930
* @return array
3031
*/
31-
public function getJson()
32+
public function getParsedContents(): array
3233
{
3334
return $this->json;
3435
}

0 commit comments

Comments
 (0)