1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace ApiClients\Client\AppVeyor; |
4
|
|
|
|
5
|
|
|
use ApiClients\Client\AppVeyor\Resource\Sync\Project; |
6
|
|
|
use ApiClients\Foundation\Factory as FoundationClientFactory; |
7
|
|
|
use ApiClients\Foundation\Transport\Client as Transport; |
8
|
|
|
use ApiClients\Foundation\Transport\Factory; |
9
|
|
|
use React\EventLoop\Factory as LoopFactory; |
10
|
|
|
use React\EventLoop\LoopInterface; |
11
|
|
|
use Rx\React\Promise; |
12
|
|
|
use function Clue\React\Block\await; |
13
|
|
|
use Rx\Scheduler; |
14
|
|
|
|
15
|
|
|
class Client |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @var LoopInterface |
19
|
|
|
*/ |
20
|
|
|
private $loop; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var AsyncClient |
24
|
|
|
*/ |
25
|
|
|
private $client; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @param string $token |
29
|
|
|
* @param array $options |
30
|
|
|
* @return Client |
31
|
|
|
*/ |
32
|
|
|
public static function create( |
33
|
|
|
string $token, |
34
|
|
|
array $options = [] |
35
|
|
|
): self { |
36
|
|
|
$loop = LoopFactory::create(); |
37
|
|
|
$options = ApiSettings::getOptions($token,$options, 'Sync'); |
38
|
|
|
$client = FoundationClientFactory::create($loop, $options); |
39
|
|
|
|
40
|
|
|
try { |
41
|
|
|
Scheduler::setAsyncFactory(function () use ($loop) { |
42
|
|
|
return new Scheduler\EventLoopScheduler($loop); |
43
|
|
|
}); |
44
|
|
|
} catch (\Throwable $t) { |
|
|
|
|
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
$asyncClient = AsyncClient::createFromClient($client); |
48
|
|
|
|
49
|
|
|
return new self($loop, $asyncClient); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param LoopInterface $loop |
54
|
|
|
* @param AsyncClient $client |
55
|
|
|
*/ |
56
|
|
|
private function __construct(LoopInterface $loop, AsyncClient $client) |
57
|
|
|
{ |
58
|
|
|
$this->loop = $loop; |
59
|
|
|
$this->client = $client; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function projects(): array |
63
|
|
|
{ |
64
|
|
|
return await( |
65
|
|
|
Promise::fromObservable( |
66
|
|
|
$this->client->projects()->toArray() |
67
|
|
|
), |
68
|
|
|
$this->loop |
69
|
|
|
); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function project(string $repository): Project |
73
|
|
|
{ |
74
|
|
|
return await( |
75
|
|
|
$this->client->project($repository), |
76
|
|
|
$this->loop |
77
|
|
|
); |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|