65 lines
1.5 KiB
PHP
65 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace Benharri\MatchplayUtils;
|
|
require __DIR__ . '/../vendor/autoload.php';
|
|
|
|
use GuzzleHttp\Client;
|
|
use Symfony\Component\Dotenv\Dotenv;
|
|
|
|
$dotenv = new Dotenv();
|
|
$dotenv->load( __DIR__ . '/../.env' );
|
|
|
|
$client = new Client( [
|
|
'base_uri' => 'https://next.matchplay.events/api/',
|
|
'headers' => [
|
|
'Authorization' => "Bearer {$_ENV['MATCHPLAY_API_KEY']}",
|
|
'Content-Type' => 'application/json',
|
|
'Accept' => 'application/json',
|
|
],
|
|
] );
|
|
|
|
$playerCounts = [];
|
|
$uri = 'tournaments';
|
|
|
|
while ( true ) {
|
|
$body = $client->get( $uri, [
|
|
'query' => [
|
|
'owner' => '25014',
|
|
'status' => 'completed',
|
|
],
|
|
] )->getBody();
|
|
$tournaments = json_decode( $body );
|
|
|
|
foreach ( $tournaments->data as $tournament ) {
|
|
// skip finals
|
|
if ( $tournament->linkedTournamentId === null ) {
|
|
continue;
|
|
}
|
|
echo PHP_EOL . $tournament->name . PHP_EOL;
|
|
|
|
$tournamentDetails = $client->get( "tournaments/{$tournament->tournamentId}", [
|
|
'query' => [
|
|
'includePlayers' => '1',
|
|
'includeLocation' => '1',
|
|
],
|
|
] )->getBody();
|
|
$details = json_decode( $tournamentDetails );
|
|
|
|
$playerCount = count( $details->data->players );
|
|
echo $playerCount . PHP_EOL;
|
|
|
|
if (!isset($playerCounts[$details->data->location->name]))
|
|
$playerCounts[$details->data->location->name] = 0;
|
|
|
|
$playerCounts[ $details->data->location->name ] += $playerCount;
|
|
}
|
|
|
|
if ( $tournaments->links->next === null ) {
|
|
break;
|
|
} else {
|
|
$uri = $tournaments->links->next;
|
|
}
|
|
}
|
|
|
|
print_r( $playerCounts );
|