|
6 | 6 | use ApiClients\Client\Travis\Resource\HookInterface; |
7 | 7 | use ApiClients\Foundation\ClientInterface; |
8 | 8 | use ApiClients\Foundation\Factory; |
| 9 | +use ApiClients\Foundation\Hydrator\CommandBus\Command\ExtractFQCNCommand; |
| 10 | +use ApiClients\Foundation\Hydrator\CommandBus\Command\HydrateFQCNCommand; |
| 11 | +use ApiClients\Foundation\Resource\ResourceInterface; |
9 | 12 | use React\EventLoop\LoopInterface; |
10 | 13 | use React\Promise\CancellablePromiseInterface; |
11 | 14 | use React\Promise\PromiseInterface; |
12 | 15 | use Rx\ObservableInterface; |
13 | 16 | use Rx\React\Promise; |
14 | 17 | use Rx\Scheduler; |
15 | 18 | use function ApiClients\Tools\Rx\unwrapObservableFromPromise; |
| 19 | +use function React\Promise\resolve; |
16 | 20 |
|
17 | 21 | final class AsyncClient implements AsyncClientInterface |
18 | 22 | { |
@@ -55,6 +59,26 @@ public static function create( |
55 | 59 | return new self($client); |
56 | 60 | } |
57 | 61 |
|
| 62 | + public function hydrate(array $resource) |
| 63 | + { |
| 64 | + $class = $resource['class']; |
| 65 | + $json = $resource['json']; |
| 66 | + return $this->client->handle(new HydrateFQCNCommand($class, $json)); |
| 67 | + } |
| 68 | + |
| 69 | + public function extract(ResourceInterface $resource) |
| 70 | + { |
| 71 | + $class = get_class($resource); |
| 72 | + return $this->client->handle( |
| 73 | + new ExtractFQCNCommand($class, $resource) |
| 74 | + )->then(function ($json) use ($class) { |
| 75 | + return resolve([ |
| 76 | + 'class' => $class, |
| 77 | + 'json' => $json, |
| 78 | + ]); |
| 79 | + }); |
| 80 | + } |
| 81 | + |
58 | 82 | /** |
59 | 83 | * Create an AsyncClient from a ApiClients\Foundation\ClientInterface. |
60 | 84 | * Be sure to pass in a client with the options from ApiSettings and the Async namespace suffix. |
|
0 commit comments