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\Factory\DetailedPlayerFactory; |
13
|
|
|
use PtrTn\Battlerite\Query\Matches\MatchesQuery; |
14
|
|
|
use PtrTn\Battlerite\Query\Players\PlayersQuery; |
15
|
|
|
use PtrTn\Battlerite\Query\Teams\TeamsQuery; |
16
|
|
|
use PtrTn\Battlerite\Repository\DataMappingRepository; |
17
|
|
|
|
18
|
|
|
class Client |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @var ApiClient |
22
|
|
|
*/ |
23
|
|
|
private $apiClient; |
24
|
|
|
/** |
25
|
|
|
* @var DetailedPlayerFactory |
26
|
|
|
*/ |
27
|
|
|
private $detailedPlayerFactory; |
28
|
|
|
|
29
|
30 |
|
public function __construct( |
30
|
|
|
ApiClient $apiClient, |
31
|
|
|
DetailedPlayerFactory $detailedPlayerFactory |
32
|
|
|
) { |
33
|
30 |
|
$this->apiClient = $apiClient; |
34
|
30 |
|
$this->detailedPlayerFactory = $detailedPlayerFactory; |
35
|
30 |
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Create default API client setup |
39
|
|
|
* @todo, move this method to a factory or possibly a builder class. |
40
|
|
|
*/ |
41
|
1 |
|
public static function create(string $apiKey): self |
42
|
|
|
{ |
43
|
1 |
|
return new self( |
44
|
1 |
|
new ApiClient( |
45
|
1 |
|
$apiKey, |
46
|
1 |
|
new GuzzleClient() |
47
|
|
|
), |
48
|
1 |
|
new DetailedPlayerFactory( |
49
|
1 |
|
new DataMappingRepository() |
50
|
|
|
) |
51
|
|
|
); |
52
|
|
|
} |
53
|
|
|
|
54
|
1 |
|
public function getStatus(): Status |
55
|
|
|
{ |
56
|
1 |
|
$responseData = $this->apiClient->sendRequestToEndPoint( |
57
|
1 |
|
'/status' |
58
|
|
|
); |
59
|
1 |
|
return Status::createFromArray($responseData['data']); |
60
|
|
|
} |
61
|
|
|
|
62
|
8 |
|
public function getMatches(MatchesQuery $query = null): Matches |
63
|
|
|
{ |
64
|
8 |
|
$responseData = $this->apiClient->sendRequestToEndPoint( |
65
|
8 |
|
'/shards/global/matches', |
66
|
8 |
|
$query |
67
|
|
|
); |
68
|
8 |
|
return Matches::createFromArray($responseData['data']); |
69
|
|
|
} |
70
|
|
|
|
71
|
7 |
|
public function getMatch(string $matchId): DetailedMatch |
72
|
|
|
{ |
73
|
7 |
|
$responseData = $this->apiClient->sendRequestToEndPoint( |
74
|
7 |
|
'/shards/global/matches/' . $matchId |
75
|
|
|
); |
76
|
7 |
|
return DetailedMatch::createFromArray($responseData); |
77
|
|
|
} |
78
|
|
|
|
79
|
5 |
|
public function getPlayers(PlayersQuery $query = null): Players |
80
|
|
|
{ |
81
|
5 |
|
$responseData = $this->apiClient->sendRequestToEndPoint( |
82
|
5 |
|
'/shards/global/players', |
83
|
5 |
|
$query |
84
|
|
|
); |
85
|
5 |
|
return Players::createFromArray($responseData['data']); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
public function getPlayer(string $playerId): DetailedPlayer |
89
|
|
|
{ |
90
|
|
|
$responseData = $this->apiClient->sendRequestToEndPoint( |
91
|
|
|
'/shards/global/players/' . $playerId |
92
|
|
|
); |
93
|
|
|
return $this->detailedPlayerFactory->createFromArray($responseData['data']); |
94
|
|
|
} |
95
|
|
|
|
96
|
6 |
|
public function getTeams(TeamsQuery $query = null): Teams |
97
|
|
|
{ |
98
|
6 |
|
$responseData = $this->apiClient->sendRequestToEndPoint( |
99
|
6 |
|
'/shards/global/teams', |
100
|
6 |
|
$query |
101
|
|
|
); |
102
|
6 |
|
return Teams::createFromArray($responseData['data']); |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|