| @@ 11-40 (lines=30) @@ | ||
| 8 | use ApiClients\Tools\Services\Client\FetchAndHydrateService; |
|
| 9 | use React\Promise\PromiseInterface; |
|
| 10 | ||
| 11 | final class AstronomyHandler |
|
| 12 | { |
|
| 13 | /** |
|
| 14 | * @var FetchAndHydrateService |
|
| 15 | */ |
|
| 16 | private $service; |
|
| 17 | ||
| 18 | /** |
|
| 19 | * @param FetchAndHydrateService $service |
|
| 20 | */ |
|
| 21 | public function __construct(FetchAndHydrateService $service) |
|
| 22 | { |
|
| 23 | $this->service = $service; |
|
| 24 | } |
|
| 25 | ||
| 26 | /** |
|
| 27 | * Fetch the given repository and hydrate it |
|
| 28 | * |
|
| 29 | * @param AstronomyCommand $command |
|
| 30 | * @return PromiseInterface |
|
| 31 | */ |
|
| 32 | public function handle(AstronomyCommand $command): PromiseInterface |
|
| 33 | { |
|
| 34 | return $this->service->fetch( |
|
| 35 | 'astronomy/q/' . $command->getLocation() . '.json', |
|
| 36 | '', |
|
| 37 | AstronomyInterface::HYDRATE_CLASS |
|
| 38 | ); |
|
| 39 | } |
|
| 40 | } |
|
| 41 | ||
| @@ 12-41 (lines=30) @@ | ||
| 9 | use function React\Promise\resolve; |
|
| 10 | use function WyriHaximus\React\futureFunctionPromise; |
|
| 11 | ||
| 12 | final class ConditionsHandler |
|
| 13 | { |
|
| 14 | /** |
|
| 15 | * @var FetchAndHydrateService |
|
| 16 | */ |
|
| 17 | private $service; |
|
| 18 | ||
| 19 | /** |
|
| 20 | * @param FetchAndHydrateService $service |
|
| 21 | */ |
|
| 22 | public function __construct(FetchAndHydrateService $service) |
|
| 23 | { |
|
| 24 | $this->service = $service; |
|
| 25 | } |
|
| 26 | ||
| 27 | /** |
|
| 28 | * Fetch the given repository and hydrate it |
|
| 29 | * |
|
| 30 | * @param ConditionsCommand $command |
|
| 31 | * @return PromiseInterface |
|
| 32 | */ |
|
| 33 | public function handle(ConditionsCommand $command): PromiseInterface |
|
| 34 | { |
|
| 35 | return $this->service->fetch( |
|
| 36 | 'conditions/q/' . $command->getLocation() . '.json', |
|
| 37 | 'current_observation', |
|
| 38 | ConditionInterface::HYDRATE_CLASS |
|
| 39 | ); |
|
| 40 | } |
|
| 41 | } |
|
| 42 | ||