|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Riot\API\Version4; |
| 6 | + |
| 7 | +use Riot\API\AbstractApi; |
| 8 | +use Riot\DTO\LobbyEventDTOWrapperDTO; |
| 9 | +use Riot\DTO\TournamentCodeDTO; |
| 10 | +use Riot\Enum\GeoRegionEnum; |
| 11 | +use Riot\Enum\MapTypeEnum; |
| 12 | +use Riot\Enum\PickTypeEnum; |
| 13 | +use Riot\Enum\SpectatorTypeEnum; |
| 14 | +use Riot\Enum\TournamentRegionEnum; |
| 15 | +use Webmozart\Assert\Assert; |
| 16 | + |
| 17 | +final class Tournament extends AbstractApi |
| 18 | +{ |
| 19 | + /** |
| 20 | + * @param array<string> $allowedSummonerIds |
| 21 | + * |
| 22 | + * @return array<string> |
| 23 | + */ |
| 24 | + public function createCode( |
| 25 | + int $tournamentId, |
| 26 | + int $count, |
| 27 | + array $allowedSummonerIds, |
| 28 | + int $teamSize, |
| 29 | + PickTypeEnum $pickType, |
| 30 | + MapTypeEnum $mapType, |
| 31 | + SpectatorTypeEnum $spectatorType, |
| 32 | + ?string $metadata |
| 33 | + ): array { |
| 34 | + Assert::isList($allowedSummonerIds); |
| 35 | + Assert::allString($allowedSummonerIds); |
| 36 | + Assert::range($teamSize, 1, 5); |
| 37 | + |
| 38 | + $response = $this->riotConnection->post( |
| 39 | + GeoRegionEnum::AMERICAS()->getValue(), |
| 40 | + sprintf('lol/tournament/v4/codes?count=%d&tournamentId=%d', $count, $tournamentId), |
| 41 | + [ |
| 42 | + 'allowedSummonerIds' => $allowedSummonerIds, |
| 43 | + 'metadata' => $metadata, |
| 44 | + 'teamSize' => $teamSize, |
| 45 | + 'pickType' => $pickType->getValue(), |
| 46 | + 'mapType' => $mapType->getValue(), |
| 47 | + 'spectatorType' => $spectatorType->getValue(), |
| 48 | + ], |
| 49 | + ); |
| 50 | + |
| 51 | + return $response->getBodyContentsDecodedAsArray(); |
| 52 | + } |
| 53 | + |
| 54 | + /** |
| 55 | + * @param array<string> $allowedSummonerIds |
| 56 | + */ |
| 57 | + public function updateCode( |
| 58 | + string $tournamentCode, |
| 59 | + array $allowedSummonerIds, |
| 60 | + PickTypeEnum $pickType, |
| 61 | + MapTypeEnum $mapType, |
| 62 | + SpectatorTypeEnum $spectatorType |
| 63 | + ): bool { |
| 64 | + Assert::isList($allowedSummonerIds); |
| 65 | + Assert::allString($allowedSummonerIds); |
| 66 | + |
| 67 | + $this->riotConnection->put( |
| 68 | + GeoRegionEnum::AMERICAS()->getValue(), |
| 69 | + sprintf('lol/tournament/v4/codes/%s', $tournamentCode), |
| 70 | + [ |
| 71 | + 'allowedSummonerIds' => $allowedSummonerIds, |
| 72 | + 'pickType' => $pickType->getValue(), |
| 73 | + 'mapType' => $mapType->getValue(), |
| 74 | + 'spectatorType' => $spectatorType->getValue(), |
| 75 | + ], |
| 76 | + ); |
| 77 | + |
| 78 | + return true; |
| 79 | + } |
| 80 | + |
| 81 | + public function getCodeByTournamentCode(string $tournamentCode): TournamentCodeDTO |
| 82 | + { |
| 83 | + $response = $this->riotConnection->get( |
| 84 | + GeoRegionEnum::AMERICAS()->getValue(), |
| 85 | + sprintf('lol/tournament/v4/codes/%s', $tournamentCode), |
| 86 | + ); |
| 87 | + |
| 88 | + return TournamentCodeDTO::createFromArray($response->getBodyContentsDecodedAsArray()); |
| 89 | + } |
| 90 | + |
| 91 | + public function getLobbyEventsByTournamentCode(string $tournamentCode): LobbyEventDTOWrapperDTO |
| 92 | + { |
| 93 | + $response = $this->riotConnection->get( |
| 94 | + GeoRegionEnum::AMERICAS()->getValue(), |
| 95 | + sprintf('lol/tournament/v4/lobby-events/by-code/%s', $tournamentCode), |
| 96 | + ); |
| 97 | + |
| 98 | + return LobbyEventDTOWrapperDTO::createFromArray($response->getBodyContentsDecodedAsArray()); |
| 99 | + } |
| 100 | + |
| 101 | + public function createProvider(TournamentRegionEnum $region, string $url): int |
| 102 | + { |
| 103 | + $response = $this->riotConnection->post( |
| 104 | + GeoRegionEnum::AMERICAS()->getValue(), |
| 105 | + 'lol/tournament/v4/providers', |
| 106 | + [ |
| 107 | + 'region' => $region->getValue(), |
| 108 | + 'url' => $url, |
| 109 | + ], |
| 110 | + ); |
| 111 | + |
| 112 | + return $response->getBodyContentsDecodedAsInt(); |
| 113 | + } |
| 114 | + |
| 115 | + public function createTournament(int $providerId, string $name): int |
| 116 | + { |
| 117 | + $response = $this->riotConnection->post( |
| 118 | + GeoRegionEnum::AMERICAS()->getValue(), |
| 119 | + 'lol/tournament/v4/tournaments', |
| 120 | + [ |
| 121 | + 'providerId' => $providerId, |
| 122 | + 'name' => $name, |
| 123 | + ], |
| 124 | + ); |
| 125 | + |
| 126 | + return $response->getBodyContentsDecodedAsInt(); |
| 127 | + } |
| 128 | +} |
0 commit comments