1 | <?php |
||
16 | class Client |
||
17 | { |
||
18 | |||
19 | protected $httpClient; |
||
20 | |||
21 | protected $token; |
||
22 | |||
23 | public function __construct($token) |
||
27 | |||
28 | /** |
||
29 | * Get full details for specific clan |
||
30 | * |
||
31 | * @param string $tag |
||
32 | * @return Clan |
||
33 | */ |
||
34 | public function getClan($tag) |
||
40 | |||
41 | /** |
||
42 | * Search for clans using parameters |
||
43 | * @see Documentation at https://developer.clashofclans.com/ |
||
44 | * |
||
45 | * @param $params |
||
46 | * @return array |
||
47 | */ |
||
48 | public function getClans($params) |
||
58 | |||
59 | /** |
||
60 | * Get warlog for specific clan |
||
61 | * |
||
62 | * @param string $tag |
||
63 | * @return WarLog |
||
64 | */ |
||
65 | public function getClanWarLog($tag) |
||
74 | |||
75 | /** |
||
76 | * Get player info for specific tag |
||
77 | * |
||
78 | * @param string $tag |
||
79 | * @return PlayerInfo |
||
80 | */ |
||
81 | public function getPlayer($tag) |
||
82 | { |
||
83 | $response = $this->request('players/' . urlencode($tag)); |
||
84 | |||
85 | return FullPlayer::makeFromArray($response); |
||
86 | } |
||
87 | |||
88 | /** |
||
89 | * Get details for specific location |
||
90 | * @param $id |
||
91 | * @return Location |
||
92 | */ |
||
93 | public function getLocation($id) |
||
97 | |||
98 | /** |
||
99 | * Get list of all locations |
||
100 | * |
||
101 | * @return array |
||
102 | */ |
||
103 | public function getLocations() |
||
109 | |||
110 | /** |
||
111 | * Get rankings for specific location |
||
112 | * @param $locationId |
||
113 | * @param $rankingId |
||
114 | * @return array |
||
115 | */ |
||
116 | public function getRankingsForLocation($locationId, $rankingId) |
||
117 | { |
||
118 | $url = 'locations/' . $locationId . '/rankings/' . $rankingId; |
||
119 | |||
120 | if ($rankingId == 'clans') { |
||
121 | return array_map(function ($item) { |
||
122 | return Clan::makeFromArray($item); |
||
123 | }, $this->request($url)['items']); |
||
124 | } |
||
125 | |||
126 | return array_map(function ($item) { |
||
127 | return Player::makeFromArray($item); |
||
128 | }, $this->request($url)['items']); |
||
129 | } |
||
130 | |||
131 | /** |
||
132 | * Get all available leagues |
||
133 | * |
||
134 | * @return array |
||
135 | */ |
||
136 | public function getLeagues() |
||
142 | |||
143 | /** |
||
144 | * @param $url |
||
145 | * @return array |
||
146 | */ |
||
147 | protected function request($url) |
||
154 | |||
155 | /** |
||
156 | * @return GuzzleClient |
||
157 | */ |
||
158 | public function getHttpClient() |
||
159 | { |
||
160 | if ($this->httpClient === null) { |
||
161 | $this->httpClient = new GuzzleClient(['base_uri' => 'https://api.clashofclans.com/v1/']); |
||
162 | } |
||
163 | |||
164 | return $this->httpClient; |
||
165 | } |
||
166 | |||
167 | public function setHttpClient(ClientInterface $client) |
||
173 | |||
174 | /** |
||
175 | * @return string|null |
||
176 | */ |
||
177 | public function getToken() |
||
181 | |||
182 | } |
||
183 |