1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace ApiClients\Client\AppVeyor\CommandBus\Handler\Project; |
4
|
|
|
|
5
|
|
|
use ApiClients\Client\AppVeyor\CommandBus\Command\Project\HistoryCommand; |
6
|
|
|
use ApiClients\Client\AppVeyor\Resource\BuildInterface; |
7
|
|
|
use ApiClients\Client\AppVeyor\Service\IteratePagesService; |
8
|
|
|
use ApiClients\Foundation\Hydrator\Hydrator; |
9
|
|
|
use React\Promise\PromiseInterface; |
10
|
|
|
use function ApiClients\Tools\Rx\observableFromArray; |
11
|
|
|
use function React\Promise\resolve; |
12
|
|
|
|
13
|
|
|
final class HistoryHandler |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @var IteratePagesService |
17
|
|
|
*/ |
18
|
|
|
private $service; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var Hydrator |
22
|
|
|
*/ |
23
|
|
|
private $hydrator; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @param IteratePagesService $service |
27
|
|
|
* @param Hydrator $hydrator |
28
|
|
|
*/ |
29
|
1 |
|
public function __construct(IteratePagesService $service, Hydrator $hydrator) |
30
|
|
|
{ |
31
|
1 |
|
$this->service = $service; |
32
|
1 |
|
$this->hydrator = $hydrator; |
33
|
1 |
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @param HistoryCommand $command |
37
|
|
|
* @return PromiseInterface |
38
|
|
|
*/ |
39
|
1 |
|
public function handle(HistoryCommand $command): PromiseInterface |
40
|
|
|
{ |
41
|
1 |
|
return resolve( |
42
|
1 |
|
$this->service->iterate( |
43
|
|
|
'projects/' . |
44
|
1 |
|
$command->getAccountName() . |
45
|
1 |
|
'/' . |
46
|
1 |
|
$command->getProjectSlug() . |
47
|
1 |
|
'/history?recordsNumber=25', |
48
|
1 |
|
'builds', |
49
|
1 |
|
'buildId', |
50
|
1 |
|
'startBuildId' |
51
|
1 |
|
)->flatMap(function ($builds) { |
52
|
1 |
|
return observableFromArray($builds['builds']); |
53
|
|
|
})->map(function ($build) { |
54
|
1 |
|
return $this->hydrator->hydrate(BuildInterface::HYDRATE_CLASS, $build); |
55
|
1 |
|
}) |
56
|
|
|
); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|