1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PtrTn\Battlerite; |
4
|
|
|
|
5
|
|
|
use GuzzleHttp\Client as GuzzleClient; |
6
|
|
|
use PtrTn\Battlerite\Dto\Match\DetailedMatch; |
7
|
|
|
use PtrTn\Battlerite\Dto\Matches\Matches; |
8
|
|
|
use PtrTn\Battlerite\Dto\Player\DetailedPlayer; |
9
|
|
|
use PtrTn\Battlerite\Dto\Players\Players; |
10
|
|
|
use PtrTn\Battlerite\Dto\Status\Status; |
11
|
|
|
use PtrTn\Battlerite\Dto\Teams\Teams; |
12
|
|
|
use PtrTn\Battlerite\Query\Matches\MatchesQuery; |
13
|
|
|
use PtrTn\Battlerite\Query\Players\PlayersQuery; |
14
|
|
|
use PtrTn\Battlerite\Query\Teams\TeamsQuery; |
15
|
|
|
|
16
|
|
|
class Client |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @var ApiClient |
20
|
|
|
*/ |
21
|
|
|
private $apiClient; |
22
|
|
|
|
23
|
30 |
|
public function __construct(ApiClient $apiClient) |
24
|
|
|
{ |
25
|
30 |
|
$this->apiClient = $apiClient; |
26
|
30 |
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Create default API client setup |
30
|
|
|
*/ |
31
|
1 |
|
public static function create(string $apiKey): self |
32
|
|
|
{ |
33
|
1 |
|
return new self( |
34
|
1 |
|
new ApiClient( |
35
|
1 |
|
$apiKey, |
36
|
1 |
|
new GuzzleClient() |
37
|
|
|
) |
38
|
|
|
); |
39
|
|
|
} |
40
|
|
|
|
41
|
1 |
|
public function getStatus(): Status |
42
|
|
|
{ |
43
|
1 |
|
$responseData = $this->apiClient->sendRequestToEndPoint( |
44
|
1 |
|
'/status' |
45
|
|
|
); |
46
|
1 |
|
return Status::createFromArray($responseData['data']); |
47
|
|
|
} |
48
|
|
|
|
49
|
8 |
|
public function getMatches(MatchesQuery $query = null): Matches |
50
|
|
|
{ |
51
|
8 |
|
$responseData = $this->apiClient->sendRequestToEndPoint( |
52
|
8 |
|
'/shards/global/matches', |
53
|
8 |
|
$query |
54
|
|
|
); |
55
|
8 |
|
return Matches::createFromArray($responseData['data']); |
56
|
|
|
} |
57
|
|
|
|
58
|
7 |
|
public function getMatch(string $matchId): DetailedMatch |
59
|
|
|
{ |
60
|
7 |
|
$responseData = $this->apiClient->sendRequestToEndPoint( |
61
|
7 |
|
'/shards/global/matches/' . $matchId |
62
|
|
|
); |
63
|
7 |
|
return DetailedMatch::createFromArray($responseData); |
64
|
|
|
} |
65
|
|
|
|
66
|
5 |
|
public function getPlayers(PlayersQuery $query = null): Players |
67
|
|
|
{ |
68
|
5 |
|
$responseData = $this->apiClient->sendRequestToEndPoint( |
69
|
5 |
|
'/shards/global/players', |
70
|
5 |
|
$query |
71
|
|
|
); |
72
|
5 |
|
return Players::createFromArray($responseData['data']); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function getPlayer(string $playerId): DetailedPlayer |
76
|
|
|
{ |
77
|
|
|
$responseData = $this->apiClient->sendRequestToEndPoint( |
78
|
|
|
'/shards/global/players/' . $playerId |
79
|
|
|
); |
80
|
|
|
return DetailedPlayer::createFromArray($responseData['data']); |
81
|
|
|
} |
82
|
|
|
|
83
|
6 |
|
public function getTeams(TeamsQuery $query = null): Teams |
84
|
|
|
{ |
85
|
6 |
|
$responseData = $this->apiClient->sendRequestToEndPoint( |
86
|
6 |
|
'/shards/global/teams', |
87
|
6 |
|
$query |
88
|
|
|
); |
89
|
6 |
|
return Teams::createFromArray($responseData['data']); |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|