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