diff --git a/src/Riot/API/AbstractApi.php b/src/Riot/API/AbstractApi.php index 92af994..282d0be 100644 --- a/src/Riot/API/AbstractApi.php +++ b/src/Riot/API/AbstractApi.php @@ -5,13 +5,73 @@ namespace Riot\API; use Riot\ConnectionInterface; +use Riot\Enum\GeoRegionEnum; +use Riot\Enum\RegionEnum; abstract class AbstractApi { - protected ConnectionInterface $riotConnection; + private ConnectionInterface $riotConnection; public function __construct(ConnectionInterface $riotConnection) { $this->riotConnection = $riotConnection; } + + /** + * @param string|RegionEnum|GeoRegionEnum $unionRegion + */ + private function getData($unionRegion, string $path): ResponseDecoderInterface + { + /** @var string $region * */ + $region = $unionRegion; + if ($unionRegion instanceof RegionEnum) { + $region = $unionRegion->getValue(); + } elseif ($unionRegion instanceof GeoRegionEnum) { + $region = $unionRegion->__toString(); + } + + return $this->riotConnection->get($region, $path); + } + + /** + * @param array $data + */ + public function post(string $region, string $path, array $data): ResponseDecoderInterface + { + return $this->riotConnection->post($region, $path, $data); + } + + /** + * @param array $data + */ + public function put(string $region, string $path, array $data): ResponseDecoderInterface + { + return $this->riotConnection->put($region, $path, $data); + } + + /** + * @param string|RegionEnum|GeoRegionEnum $region + * + * @return array + */ + protected function get($region, string $path): array + { + return $this->getData($region, $path)->getBodyContentsDecodedAsArray(); + } + + /** + * @param string|RegionEnum|GeoRegionEnum $region + */ + protected function getInt($region, string $path): int + { + return $this->getData($region, $path)->getBodyContentsDecodedAsInt(); + } + + /** + * @param string|RegionEnum|GeoRegionEnum $region + */ + protected function getString($region, string $path): string + { + return $this->getData($region, $path)->getBodyContentsDecodedAsString(); + } } diff --git a/src/Riot/API/Version1/Account.php b/src/Riot/API/Version1/Account.php index 55433dc..4374427 100644 --- a/src/Riot/API/Version1/Account.php +++ b/src/Riot/API/Version1/Account.php @@ -31,12 +31,9 @@ final class Account extends AbstractApi */ public function getByPuuid(string $puuid, GeoRegionEnum $geoRegion): AccountDTO { - $response = $this->riotConnection->get( - $geoRegion->__toString(), - sprintf('riot/account/v1/accounts/by-puuid/%s', $puuid), + return AccountDTO::createFromArray( + $this->get($geoRegion->__toString(), sprintf('riot/account/v1/accounts/by-puuid/%s', $puuid)) ); - - return AccountDTO::createFromArray($response->getBodyContentsDecodedAsArray()); } /** @@ -56,12 +53,9 @@ public function getByPuuid(string $puuid, GeoRegionEnum $geoRegion): AccountDTO */ public function getByGameNameAndTagLine(string $gameName, string $tagLine, GeoRegionEnum $geoRegion): AccountDTO { - $response = $this->riotConnection->get( - $geoRegion->__toString(), - sprintf('riot/account/v1/accounts/by-riot-id/%s/%s', $gameName, $tagLine), + return AccountDTO::createFromArray( + $this->get($geoRegion, sprintf('riot/account/v1/accounts/by-riot-id/%s/%s', $gameName, $tagLine)) ); - - return AccountDTO::createFromArray($response->getBodyContentsDecodedAsArray()); } /** @@ -81,11 +75,8 @@ public function getByGameNameAndTagLine(string $gameName, string $tagLine, GeoRe */ public function getByGameAndPuuid(string $game, string $puuid, GeoRegionEnum $geoRegion): ActiveShardDTO { - $response = $this->riotConnection->get( - $geoRegion->__toString(), - sprintf('riot/account/v1/active-shards/by-game/%s/by-puuid/%s', $game, $puuid), + return ActiveShardDTO::createFromArray( + $this->get($geoRegion, sprintf('riot/account/v1/active-shards/by-game/%s/by-puuid/%s', $game, $puuid)) ); - - return ActiveShardDTO::createFromArray($response->getBodyContentsDecodedAsArray()); } } diff --git a/src/Riot/API/Version1/Clash.php b/src/Riot/API/Version1/Clash.php index ee2f012..1dfe657 100644 --- a/src/Riot/API/Version1/Clash.php +++ b/src/Riot/API/Version1/Clash.php @@ -15,51 +15,36 @@ final class Clash extends AbstractApi { public function getPlayersBySummonerId(string $encryptedSummonerId, RegionEnum $region): PlayerDTOCollection { - $response = $this->riotConnection->get( - $region->getValue(), - sprintf('lol/clash/v1/players/by-summoner/%s', $encryptedSummonerId), + return PlayerDTOCollection::createFromArray( + $this->get($region, sprintf('lol/clash/v1/players/by-summoner/%s', $encryptedSummonerId)) ); - - return PlayerDTOCollection::createFromArray($response->getBodyContentsDecodedAsArray()); } public function getTeamById(string $teamid, RegionEnum $region): TeamDTO { - $response = $this->riotConnection->get( - $region->getValue(), - sprintf('lol/clash/v1/teams/%s', $teamid), + return TeamDTO::createFromArray( + $this->get($region, sprintf('lol/clash/v1/teams/%s', $teamid)) ); - - return TeamDTO::createFromArray($response->getBodyContentsDecodedAsArray()); } public function getTournaments(RegionEnum $region): TournamentDTOCollection { - $response = $this->riotConnection->get( - $region->getValue(), - 'lol/clash/v1/tournaments', + return TournamentDTOCollection::createFromArray( + $this->get($region, 'lol/clash/v1/tournaments') ); - - return TournamentDTOCollection::createFromArray($response->getBodyContentsDecodedAsArray()); } public function getTournamentByTeamId(string $teamId, RegionEnum $region): TournamentDTO { - $response = $this->riotConnection->get( - $region->getValue(), - sprintf('lol/clash/v1/tournaments/by-team/%s', $teamId), + return TournamentDTO::createFromArray( + $this->get($region, sprintf('lol/clash/v1/tournaments/by-team/%s', $teamId)) ); - - return TournamentDTO::createFromArray($response->getBodyContentsDecodedAsArray()); } public function getTournamentById(string $tournamentId, RegionEnum $region): TournamentDTO { - $response = $this->riotConnection->get( - $region->getValue(), - sprintf('lol/clash/v1/tournaments/%s', $tournamentId), + return TournamentDTO::createFromArray( + $this->get($region, sprintf('lol/clash/v1/tournaments/%s', $tournamentId)) ); - - return TournamentDTO::createFromArray($response->getBodyContentsDecodedAsArray()); } } diff --git a/src/Riot/API/Version1/LorMatch.php b/src/Riot/API/Version1/LorMatch.php index 0f63363..a736159 100644 --- a/src/Riot/API/Version1/LorMatch.php +++ b/src/Riot/API/Version1/LorMatch.php @@ -32,12 +32,7 @@ final class LorMatch extends AbstractApi */ public function getIdsByPuuid(string $puuid, GeoRegionEnum $geoRegion): array { - $response = $this->riotConnection->get( - $geoRegion->__toString(), - sprintf('lor/match/v1/matches/by-puuid/%s/ids', $puuid), - ); - - return $response->getBodyContentsDecodedAsArray(); + return $this->get($geoRegion, sprintf('lor/match/v1/matches/by-puuid/%s/ids', $puuid)); } /** @@ -57,11 +52,8 @@ public function getIdsByPuuid(string $puuid, GeoRegionEnum $geoRegion): array */ public function getById(string $matchId, GeoRegionEnum $geoRegion): MatchDTO { - $response = $this->riotConnection->get( - $geoRegion->__toString(), - sprintf('lor/match/v1/matches/%s', $matchId), + return MatchDTO::createFromArray( + $this->get($geoRegion, sprintf('lor/match/v1/matches/%s', $matchId)) ); - - return MatchDTO::createFromArray($response->getBodyContentsDecodedAsArray()); } } diff --git a/src/Riot/API/Version1/LorRanked.php b/src/Riot/API/Version1/LorRanked.php index 09ac13c..3971d65 100644 --- a/src/Riot/API/Version1/LorRanked.php +++ b/src/Riot/API/Version1/LorRanked.php @@ -30,11 +30,8 @@ final class LorRanked extends AbstractApi */ public function getLeaderboards(GeoRegionEnum $geoRegion): LeaderboardDTO { - $response = $this->riotConnection->get( - $geoRegion->__toString(), - 'lor/ranked/v1/leaderboards', + return LeaderboardDTO::createFromArray( + $this->get($geoRegion, 'lor/ranked/v1/leaderboards') ); - - return LeaderboardDTO::createFromArray($response->getBodyContentsDecodedAsArray()); } } diff --git a/src/Riot/API/Version3/Champion.php b/src/Riot/API/Version3/Champion.php index 178d5a0..5734c2f 100644 --- a/src/Riot/API/Version3/Champion.php +++ b/src/Riot/API/Version3/Champion.php @@ -30,11 +30,8 @@ final class Champion extends AbstractApi */ public function getChampionRotations(RegionEnum $region): ChampionInfoDTO { - $response = $this->riotConnection->get( - $region->__toString(), - 'lol/platform/v3/champion-rotations', + return ChampionInfoDTO::createFromArray( + $this->get($region, 'lol/platform/v3/champion-rotations') ); - - return ChampionInfoDTO::createFromArray($response->getBodyContentsDecodedAsArray()); } } diff --git a/src/Riot/API/Version3/LolStatus.php b/src/Riot/API/Version3/LolStatus.php index edf7cf5..4ac641d 100644 --- a/src/Riot/API/Version3/LolStatus.php +++ b/src/Riot/API/Version3/LolStatus.php @@ -30,11 +30,8 @@ final class LolStatus extends AbstractApi */ public function getShardData(RegionEnum $region): ShardStatusDTO { - $response = $this->riotConnection->get( - $region->__toString(), - 'lol/status/v3/shard-data', + return ShardStatusDTO::createFromArray( + $this->get($region, 'lol/status/v3/shard-data') ); - - return ShardStatusDTO::createFromArray($response->getBodyContentsDecodedAsArray()); } } diff --git a/src/Riot/API/Version4/ChampionMastery.php b/src/Riot/API/Version4/ChampionMastery.php index 3d8a297..acb03c4 100644 --- a/src/Riot/API/Version4/ChampionMastery.php +++ b/src/Riot/API/Version4/ChampionMastery.php @@ -33,12 +33,10 @@ final class ChampionMastery extends AbstractApi */ public function getBySummonerId(string $encryptedSummonerId, RegionEnum $region): ChampionMasteryDTOCollection { - $response = $this->riotConnection->get( - $region->__toString(), - sprintf('lol/champion-mastery/v4/champion-masteries/by-summoner/%s', $encryptedSummonerId), + $championMasteries = $this->get( + $region, sprintf('lol/champion-mastery/v4/champion-masteries/by-summoner/%s', $encryptedSummonerId) ); - $championMasteries = $response->getBodyContentsDecodedAsArray(); $collection = new ChampionMasteryDTOCollection(); foreach ($championMasteries as $championMastery) { $collection->add(ChampionMasteryDTO::createFromArray($championMastery)); @@ -67,16 +65,14 @@ public function getBySummonerIdAndChampionId( int $championId, RegionEnum $region ): ChampionMasteryDTO { - $response = $this->riotConnection->get( - $region->__toString(), + return ChampionMasteryDTO::createFromArray($this->get( + $region, sprintf( 'lol/champion-mastery/v4/champion-masteries/by-summoner/%s/by-champion/%s', $encryptedSummonerId, $championId, ), - ); - - return ChampionMasteryDTO::createFromArray($response->getBodyContentsDecodedAsArray()); + )); } /** @@ -96,14 +92,6 @@ public function getBySummonerIdAndChampionId( */ public function getScoreBySummonerId(string $encryptedSummonerId, RegionEnum $region): int { - $response = $this->riotConnection->get( - $region->__toString(), - sprintf( - 'lol/champion-mastery/v4/scores/by-summoner/%s', - $encryptedSummonerId, - ), - ); - - return $response->getBodyContentsDecodedAsInt(); + return $this->getInt($region, sprintf('lol/champion-mastery/v4/scores/by-summoner/%s', $encryptedSummonerId)); } } diff --git a/src/Riot/API/Version4/League.php b/src/Riot/API/Version4/League.php index 4479cb8..3ae8031 100644 --- a/src/Riot/API/Version4/League.php +++ b/src/Riot/API/Version4/League.php @@ -16,22 +16,16 @@ final class League extends AbstractApi { public function getChallengerLeaguesByQueue(QueueEnum $queue, RegionEnum $region): LeagueListDTO { - $response = $this->riotConnection->get( - $region->__toString(), - sprintf('lol/league/v4/challengerleagues/by-queue/%s', $queue->__toString()), + return LeagueListDTO::createFromArray( + $this->get($region, sprintf('lol/league/v4/challengerleagues/by-queue/%s', $queue)) ); - - return LeagueListDTO::createFromArray($response->getBodyContentsDecodedAsArray()); } public function getBySummonerId(string $encryptedSummonerId, RegionEnum $region): LeagueEntryDTOCollection { - $response = $this->riotConnection->get( - $region->__toString(), - sprintf('lol/league/v4/entries/by-summoner/%s', $encryptedSummonerId), + return LeagueEntryDTOCollection::createFromArray( + $this->get($region, sprintf('lol/league/v4/entries/by-summoner/%s', $encryptedSummonerId)) ); - - return LeagueEntryDTOCollection::createFromArray($response->getBodyContentsDecodedAsArray()); } public function getByQueueAndTierAndDivision( @@ -41,47 +35,29 @@ public function getByQueueAndTierAndDivision( RegionEnum $region, int $page = 1 ): LeagueEntryDTOCollection { - $response = $this->riotConnection->get( - $region->__toString(), - sprintf( - 'lol/league/v4/entries/%s/%s/%s?page=%d', - $queue->__toString(), - $tier->__toString(), - $division->__toString(), - $page - ), + return LeagueEntryDTOCollection::createFromArray( + $this->get($region, sprintf('lol/league/v4/entries/%s/%s/%s?page=%d', $queue, $tier, $division, $page)) ); - - return LeagueEntryDTOCollection::createFromArray($response->getBodyContentsDecodedAsArray()); } public function getGrandmasterLeaguesByQueue(QueueEnum $queue, RegionEnum $region): LeagueListDTO { - $response = $this->riotConnection->get( - $region->__toString(), - sprintf('lol/league/v4/grandmasterleagues/by-queue/%s', $queue->__toString()), + return LeagueListDTO::createFromArray( + $this->get($region, sprintf('lol/league/v4/grandmasterleagues/by-queue/%s', $queue)) ); - - return LeagueListDTO::createFromArray($response->getBodyContentsDecodedAsArray()); } public function getById(string $leagueId, RegionEnum $region): LeagueListDTO { - $response = $this->riotConnection->get( - $region->__toString(), - sprintf('lol/league/v4/leagues/%s', $leagueId), + return LeagueListDTO::createFromArray( + $this->get($region, sprintf('lol/league/v4/leagues/%s', $leagueId)) ); - - return LeagueListDTO::createFromArray($response->getBodyContentsDecodedAsArray()); } public function getMasterLeaguesByQueue(QueueEnum $queue, RegionEnum $region): LeagueListDTO { - $response = $this->riotConnection->get( - $region->__toString(), - sprintf('lol/league/v4/masterleagues/by-queue/%s', $queue->__toString()), + return LeagueListDTO::createFromArray( + $this->get($region, sprintf('lol/league/v4/masterleagues/by-queue/%s', $queue)) ); - - return LeagueListDTO::createFromArray($response->getBodyContentsDecodedAsArray()); } } diff --git a/src/Riot/API/Version4/LeagueExp.php b/src/Riot/API/Version4/LeagueExp.php index ce8bdec..ea77e44 100644 --- a/src/Riot/API/Version4/LeagueExp.php +++ b/src/Riot/API/Version4/LeagueExp.php @@ -20,17 +20,8 @@ public function getByQueueAndTierAndDivision( RegionEnum $region, int $page = 1 ): LeagueEntryDTOCollection { - $response = $this->riotConnection->get( - $region->__toString(), - sprintf( - 'lol/league/v4/entries/%s/%s/%s?page=%d', - $queue->__toString(), - $tier->__toString(), - $division->__toString(), - $page - ), + return LeagueEntryDTOCollection::createFromArray( + $this->get($region, sprintf('lol/league/v4/entries/%s/%s/%s?page=%d', $queue, $tier, $division, $page)) ); - - return LeagueEntryDTOCollection::createFromArray($response->getBodyContentsDecodedAsArray()); } } diff --git a/src/Riot/API/Version4/Matches.php b/src/Riot/API/Version4/Matches.php index 52793e6..e3a9d9c 100644 --- a/src/Riot/API/Version4/Matches.php +++ b/src/Riot/API/Version4/Matches.php @@ -18,12 +18,9 @@ final class Matches extends AbstractApi { public function getByMatchId(int $matchId, RegionEnum $region): MatchDTO { - $response = $this->riotConnection->get( - $region->__toString(), - sprintf('lol/match/v4/matches/%s', $matchId), + return MatchDTO::createFromArray( + $this->get($region, sprintf('lol/match/v4/matches/%s', $matchId)) ); - - return MatchDTO::createFromArray($response->getBodyContentsDecodedAsArray()); } public function getMatchlistByAccountId( @@ -31,26 +28,21 @@ public function getMatchlistByAccountId( RegionEnum $region, ?MatchlistFilter $filter = null ): MatchlistDTO { - $response = $this->riotConnection->get( - $region->getValue(), + return MatchlistDTO::createFromArray($this->get( + $region, sprintf( 'lol/match/v4/matchlists/by-account/%s?%s', $encryptedAccountId, $filter ? $filter->getAsHttpQuery() : '', ), - ); - - return MatchlistDTO::createFromArray($response->getBodyContentsDecodedAsArray()); + )); } public function getTimelineByMatchId(int $matchId, RegionEnum $region): MatchTimelineDTO { - $response = $this->riotConnection->get( - $region->__toString(), - sprintf('lol/match/v4/timelines/by-match/%s', $matchId), + return MatchTimelineDTO::createFromArray( + $this->get($region, sprintf('lol/match/v4/timelines/by-match/%s', $matchId)) ); - - return MatchTimelineDTO::createFromArray($response->getBodyContentsDecodedAsArray()); } /** @@ -72,21 +64,13 @@ public function getTimelineByMatchId(int $matchId, RegionEnum $region): MatchTim */ public function getIdsByTournamentCode(string $tournamentCode, RegionEnum $region): array { - $response = $this->riotConnection->get( - $region->__toString(), - sprintf('lol/match/v4/matches/by-tournament-code/%s/ids', $tournamentCode), - ); - - return $response->getBodyContentsDecodedAsArray(); + return $this->get($region, sprintf('lol/match/v4/matches/by-tournament-code/%s/ids', $tournamentCode)); } public function getByMatchIdAndTournamentCode(int $matchId, string $tournamentCode, RegionEnum $region): MatchDTO { - $response = $this->riotConnection->get( - $region->__toString(), - sprintf('lol/match/v4/matches/%s/by-tournament-code/%s', $matchId, $tournamentCode), + return MatchDTO::createFromArray( + $this->get($region, sprintf('lol/match/v4/matches/%s/by-tournament-code/%s', $matchId, $tournamentCode)) ); - - return MatchDTO::createFromArray($response->getBodyContentsDecodedAsArray()); } } diff --git a/src/Riot/API/Version4/Spectator.php b/src/Riot/API/Version4/Spectator.php index 47fed49..1ab7308 100644 --- a/src/Riot/API/Version4/Spectator.php +++ b/src/Riot/API/Version4/Spectator.php @@ -31,12 +31,9 @@ final class Spectator extends AbstractApi */ public function getActiveGamesBySummonerId(string $encryptedSummonerId, RegionEnum $region): CurrentGameInfoDTO { - $response = $this->riotConnection->get( - $region->__toString(), - sprintf('lol/spectator/v4/active-games/by-summoner/%s', $encryptedSummonerId), + return CurrentGameInfoDTO::createFromArray( + $this->get($region, sprintf('lol/spectator/v4/active-games/by-summoner/%s', $encryptedSummonerId)) ); - - return CurrentGameInfoDTO::createFromArray($response->getBodyContentsDecodedAsArray()); } /** @@ -56,11 +53,8 @@ public function getActiveGamesBySummonerId(string $encryptedSummonerId, RegionEn */ public function getFeaturedGames(RegionEnum $region): FeaturedGamesDTO { - $response = $this->riotConnection->get( - $region->__toString(), - 'lol/spectator/v4/featured-games', + return FeaturedGamesDTO::createFromArray( + $this->get($region, 'lol/spectator/v4/featured-games') ); - - return FeaturedGamesDTO::createFromArray($response->getBodyContentsDecodedAsArray()); } } diff --git a/src/Riot/API/Version4/Summoner.php b/src/Riot/API/Version4/Summoner.php index fa52c86..150d4f2 100644 --- a/src/Riot/API/Version4/Summoner.php +++ b/src/Riot/API/Version4/Summoner.php @@ -30,12 +30,9 @@ final class Summoner extends AbstractApi */ public function getByName(string $summonerName, RegionEnum $region): SummonerDTO { - $response = $this->riotConnection->get( - $region->__toString(), - sprintf('lol/summoner/v4/summoners/by-name/%s', $summonerName), + return SummonerDTO::createFromArray( + $this->get($region, sprintf('lol/summoner/v4/summoners/by-name/%s', $summonerName)) ); - - return SummonerDTO::createFromArray($response->getBodyContentsDecodedAsArray()); } /** @@ -55,12 +52,9 @@ public function getByName(string $summonerName, RegionEnum $region): SummonerDTO */ public function getByAccountId(string $encryptedAccountId, RegionEnum $region): SummonerDTO { - $response = $this->riotConnection->get( - $region->__toString(), - sprintf('lol/summoner/v4/summoners/by-account/%s', $encryptedAccountId), + return SummonerDTO::createFromArray( + $this->get($region, sprintf('lol/summoner/v4/summoners/by-account/%s', $encryptedAccountId)) ); - - return SummonerDTO::createFromArray($response->getBodyContentsDecodedAsArray()); } /** @@ -80,12 +74,9 @@ public function getByAccountId(string $encryptedAccountId, RegionEnum $region): */ public function getByPuuid(string $encryptedPuuid, RegionEnum $region): SummonerDTO { - $response = $this->riotConnection->get( - $region->__toString(), - sprintf('lol/summoner/v4/summoners/by-puuid/%s', $encryptedPuuid), + return SummonerDTO::createFromArray( + $this->get($region, sprintf('lol/summoner/v4/summoners/by-puuid/%s', $encryptedPuuid)) ); - - return SummonerDTO::createFromArray($response->getBodyContentsDecodedAsArray()); } /** @@ -105,11 +96,8 @@ public function getByPuuid(string $encryptedPuuid, RegionEnum $region): Summoner */ public function getById(string $id, RegionEnum $region): SummonerDTO { - $response = $this->riotConnection->get( - $region->__toString(), - sprintf('lol/summoner/v4/summoners/%s', $id), + return SummonerDTO::createFromArray( + $this->get($region, sprintf('lol/summoner/v4/summoners/%s', $id)) ); - - return SummonerDTO::createFromArray($response->getBodyContentsDecodedAsArray()); } } diff --git a/src/Riot/API/Version4/ThirdPartyCode.php b/src/Riot/API/Version4/ThirdPartyCode.php index 416d97f..e89899c 100644 --- a/src/Riot/API/Version4/ThirdPartyCode.php +++ b/src/Riot/API/Version4/ThirdPartyCode.php @@ -29,11 +29,8 @@ final class ThirdPartyCode extends AbstractApi */ public function getBySummonerId(string $encryptedSummonerId, RegionEnum $region): string { - $response = $this->riotConnection->get( - $region->__toString(), - sprintf('lol/platform/v4/third-party-code/by-summoner/%s', $encryptedSummonerId), + return $this->getString( + $region, sprintf('lol/platform/v4/third-party-code/by-summoner/%s', $encryptedSummonerId), ); - - return $response->getBodyContentsDecodedAsString(); } } diff --git a/src/Riot/API/Version4/Tournament.php b/src/Riot/API/Version4/Tournament.php index dbae6c1..7aad349 100644 --- a/src/Riot/API/Version4/Tournament.php +++ b/src/Riot/API/Version4/Tournament.php @@ -35,7 +35,7 @@ public function createCode( Assert::allString($allowedSummonerIds); Assert::range($teamSize, 1, 5); - $response = $this->riotConnection->post( + $response = $this->post( GeoRegionEnum::AMERICAS()->getValue(), sprintf('lol/tournament/v4/codes?count=%d&tournamentId=%d', $count, $tournamentId), [ @@ -64,7 +64,7 @@ public function updateCode( Assert::isList($allowedSummonerIds); Assert::allString($allowedSummonerIds); - $this->riotConnection->put( + $this->put( GeoRegionEnum::AMERICAS()->getValue(), sprintf('lol/tournament/v4/codes/%s', $tournamentCode), [ @@ -80,27 +80,22 @@ public function updateCode( public function getCodeByTournamentCode(string $tournamentCode): TournamentCodeDTO { - $response = $this->riotConnection->get( - GeoRegionEnum::AMERICAS()->getValue(), - sprintf('lol/tournament/v4/codes/%s', $tournamentCode), + return TournamentCodeDTO::createFromArray( + $this->get(GeoRegionEnum::AMERICAS()->getValue(), sprintf('lol/tournament/v4/codes/%s', $tournamentCode)) ); - - return TournamentCodeDTO::createFromArray($response->getBodyContentsDecodedAsArray()); } public function getLobbyEventsByTournamentCode(string $tournamentCode): LobbyEventDTOWrapperDTO { - $response = $this->riotConnection->get( + return LobbyEventDTOWrapperDTO::createFromArray($this->get( GeoRegionEnum::AMERICAS()->getValue(), sprintf('lol/tournament/v4/lobby-events/by-code/%s', $tournamentCode), - ); - - return LobbyEventDTOWrapperDTO::createFromArray($response->getBodyContentsDecodedAsArray()); + )); } public function createProvider(TournamentRegionEnum $region, string $url): int { - $response = $this->riotConnection->post( + $response = $this->post( GeoRegionEnum::AMERICAS()->getValue(), 'lol/tournament/v4/providers', [ @@ -114,7 +109,7 @@ public function createProvider(TournamentRegionEnum $region, string $url): int public function createTournament(int $providerId, string $name): int { - $response = $this->riotConnection->post( + $response = $this->post( GeoRegionEnum::AMERICAS()->getValue(), 'lol/tournament/v4/tournaments', [ diff --git a/src/Riot/API/Version4/TournamentStub.php b/src/Riot/API/Version4/TournamentStub.php index 9b102d6..1a667a0 100644 --- a/src/Riot/API/Version4/TournamentStub.php +++ b/src/Riot/API/Version4/TournamentStub.php @@ -34,7 +34,7 @@ public function createCode( Assert::allString($allowedSummonerIds); Assert::range($teamSize, 1, 5); - $response = $this->riotConnection->post( + $response = $this->post( GeoRegionEnum::AMERICAS()->getValue(), sprintf('lol/tournament-stub/v4/codes?count=%d&tournamentId=%d', $count, $tournamentId), [ @@ -52,17 +52,15 @@ public function createCode( public function getLobbyEventsByTournamentCode(string $tournamentCode): LobbyEventDTOWrapperDTO { - $response = $this->riotConnection->get( + return LobbyEventDTOWrapperDTO::createFromArray($this->get( GeoRegionEnum::AMERICAS()->getValue(), sprintf('lol/tournament-stub/v4/lobby-events/by-code/%s', $tournamentCode), - ); - - return LobbyEventDTOWrapperDTO::createFromArray($response->getBodyContentsDecodedAsArray()); + )); } public function createProvider(TournamentRegionEnum $region, string $url): int { - $response = $this->riotConnection->post( + $response = $this->post( GeoRegionEnum::AMERICAS()->getValue(), 'lol/tournament-stub/v4/providers', [ @@ -76,7 +74,7 @@ public function createProvider(TournamentRegionEnum $region, string $url): int public function createTournament(int $providerId, string $name): int { - $response = $this->riotConnection->post( + $response = $this->post( GeoRegionEnum::AMERICAS()->getValue(), 'lol/tournament-stub/v4/tournaments', [