Skip to content

Commit

Permalink
Fixed TFT implementation from PR #87
Browse files Browse the repository at this point in the history
  • Loading branch information
dolejska-daniel committed Oct 19, 2020
1 parent 6b16029 commit f2b65d0
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 63 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ Please refer to [wiki pages](https://github.com/dolejska-daniel/riot-api/wiki/Le
| [Status](https://github.com/dolejska-daniel/riot-api/wiki/LeagueAPI:-Resources-and-endpoints#status-) | ![Status resource implemented version](https://img.shields.io/badge/implemented_version-v3-brightgreen.svg) |
| [Summoner](https://github.com/dolejska-daniel/riot-api/wiki/LeagueAPI:-Resources-and-endpoints#summoner-) | ![Summoner resource implemented version](https://img.shields.io/badge/implemented_version-v4-brightgreen.svg) |
| [TFT League](#) | ![TFT League resource implemented version](https://img.shields.io/badge/implemented_version-v1_(untested)-yellow.svg) |
| [TFT Match](#) | ![TFT Match resource implemented version](https://img.shields.io/badge/implemented_version-not_yet_implemented-orange.svg) |
| [TFT Summoner](#) | ![TFT Summoner resource implemented version](https://img.shields.io/badge/implemented_version-not_yet_implemented-orange.svg) |
| [TFT Match](#) | ![TFT Match resource implemented version](https://img.shields.io/badge/implemented_version-v1_(untested)-yellow.svg) |
| [TFT Summoner](#) | ![TFT Summoner resource implemented version](https://img.shields.io/badge/implemented_version-v1_(untested)-yellow.svg) |
| [Third Party Code](https://github.com/dolejska-daniel/riot-api/wiki/LeagueAPI%3A-Resources-and-endpoints#third-party-code-) | ![Third Party Code endpoint implemented version](https://img.shields.io/badge/implemented_version-v4-brightgreen.svg) |
| [Tournament](https://github.com/dolejska-daniel/riot-api/wiki/LeagueAPI:-Resources-and-endpoints#tournament---tournament-stub-) | ![Tournament resource implemented version](https://img.shields.io/badge/implemented_version-v4-brightgreen.svg) |
| [Tournament Stub](https://github.com/dolejska-daniel/riot-api/wiki/LeagueAPI:-Resources-and-endpoints#tournament---tournament-stub-) | ![Tournament Stub resource implemented version](https://img.shields.io/badge/implemented_version-v4-brightgreen.svg) |
Expand Down
123 changes: 62 additions & 61 deletions src/LeagueAPI/LeagueAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ class LeagueAPI
SET_VERIFY_SSL = 'SET_VERIFY_SSL', /** Specifies whether or not to verify SSL (verification often fails on localhost) **/
SET_KEY = 'SET_KEY', /** API key used by default **/
SET_TFT_KEY = 'SET_TFT_KEY', /** API TFT key used by default **/
SET_KEY_INCLUDE_TYPE = 'SET_KEY_INCLUDE_TYPE', /** API key request include type (header, query) **/
SET_TOURNAMENT_KEY = 'SET_TOURNAMENT_KEY', /** API key used when working with tournaments **/
SET_KEY_INCLUDE_TYPE = 'SET_KEY_INCLUDE_TYPE', /** API key request include type (header, query) **/
SET_INTERIM = 'SET_INTERIM', /** Used to set whether or not is your application in Interim mode (Tournament STUB endpoints) **/
SET_CACHE_PROVIDER = 'SET_CACHE_PROVIDER', /** Specifies CacheProvider class name **/
SET_CACHE_PROVIDER_PARAMS = 'SET_CACHE_PROVIDER_PARAMS', /** Specifies parameters passed to CacheProvider class when initializing **/
Expand Down Expand Up @@ -913,6 +913,45 @@ public function unsetTemporaryRegion(): self
return $this;
}

/**
* The AMERICAS routing value serves NA, BR, LAN, LAS, and OCE.
* The ASIA routing value serves KR and JP.
* The EUROPE routing value serves EUNE, EUW, TR, and RU.
*
* @param string $platform
*
* @throws GeneralException
* @throws SettingsException
*/
public function setTemporaryContinentRegionForPlatform(string $platform)
{
switch (strtolower($platform))
{
case Platform::EUROPE_WEST:
case Platform::EUROPE_EAST:
case Platform::TURKEY:
case Platform::RUSSIA:
$this->setTemporaryRegion(Region::EUROPE);
break;

case Platform::NORTH_AMERICA:
case Platform::LAMERICA_NORTH:
case Platform::LAMERICA_SOUTH:
case Platform::BRASIL:
case Platform::OCEANIA:
$this->setTemporaryRegion(Region::AMERICAS);
break;

case Platform::KOREA:
case Platform::JAPAN:
$this->setTemporaryRegion(Region::ASIA);
break;

default:
throw new GeneralException("Unable to convert provided platform ID to corresponding continent region.");
}
}

/**
* Sets API key type for next API call.
*
Expand Down Expand Up @@ -2716,49 +2755,6 @@ public function getSummonerByPUUID( string $encrypted_puuid )
return new Objects\SummonerDto($result, $this);
});
}
/**
The AMERICAS routing value serves NA, BR, LAN, LAS, and OCE. The ASIA routing value serves KR and JP. The EUROPE routing value serves EUNE, EUW, TR, and RU.
*/
public function _ReverseRegion($region){
switch (strtoupper($region)) {
case 'EUW1':
$this->setTemporaryRegion("europe");
break;
case 'EUN1':
$this->setTemporaryRegion("europe");
break;
case 'TR1':
$this->setTemporaryRegion("europe");
break;
case 'RU':
$this->setTemporaryRegion("europe");
break;
case 'NA1':
$this->setTemporaryRegion("americas");
break;
case 'BR1':
$this->setTemporaryRegion("americas");
break;
case 'LA1':
$this->setTemporaryRegion("americas");
break;
case 'LA2':
$this->setTemporaryRegion("americas");
break;
case 'OC1':
$this->setTemporaryRegion("americas");
break;
case 'KR':
$this->setTemporaryRegion("asia");
break;
case 'JP1':
$this->setTemporaryRegion("asia");
break;
default:
# code...
break;
}
}

/**
* ==================================================================dd=
Expand Down Expand Up @@ -2961,13 +2957,14 @@ public function getTFTMasterLeague()
**/
const RESOURCE_TFT_MATCH = '1481:tft-match';
const RESOURCE_TFT_MATCH_VERSION = 'v1';

/**
* Retrieve match by match ID.
*
* @cli-name get
* @cli-namespace match
* @cli-namespace tft-match
*
* @param int $match_id
* @param string $match_id
*
* @return Objects\MatchDto
*
Expand All @@ -2979,25 +2976,27 @@ public function getTFTMasterLeague()
*
* @link https://developer.riotgames.com/apis#tft-match-v1/GET_getMatch
*/
public function getTFTMatch( $match_id )
public function getTFTMatch( string $match_id )
{
$this->_ReverseRegion(explode("_", $match_id)[0]);
$this->setTemporaryContinentRegionForPlatform(explode("_", $match_id)[0]);
$resultPromise = $this->setEndpoint("/tft/match/" . self::RESOURCE_TFT_MATCH_VERSION . "/matches/{$match_id}")
->setResource(self::RESOURCE_TFT_MATCH, "/matches/%i")
->useKey(self::SET_TFT_KEY)
->makeCall();

$this->unsetTemporaryRegion();
return $this->resolveOrEnqueuePromise($resultPromise, function(array $result) {
return new Objects\MatchDto($result, $this);
});
}
/**
* Get matchs with Puuid
*
* @cli-name get
* @cli-namespace match
* @cli-name get-by-puuid
* @cli-namespace tft-match
*
* @param string $encrypted_puuid
* @param int $page
* @param int $count
*
* @return Objects\MatchDto
*
Expand All @@ -3009,14 +3008,16 @@ public function getTFTMatch( $match_id )
*
* @link https://developer.riotgames.com/apis#tft-match-v1/GET_getMatchIdsByPUUID
*/
public function getTFTMatchByPuuid( $encrypted_puuid, $count = 20)
public function getTFTMatchByPuuid( string $encrypted_puuid, int $count = 20 )
{
$this->_ReverseRegion($this->getSetting(self::SET_PLATFORM));
$this->setTemporaryContinentRegionForPlatform($this->getSetting(self::SET_PLATFORM));
$resultPromise = $this->setEndpoint("/tft/match/" . self::RESOURCE_TFT_MATCH_VERSION . "/matches/by-puuid/{$encrypted_puuid}/ids")
->setResource(self::RESOURCE_TFT_MATCH, "/matches/%i")
->addQuery('count', $count)
->useKey(self::SET_TFT_KEY)
->makeCall();

$this->unsetTemporaryRegion();
return $this->resolveOrEnqueuePromise($resultPromise, function(array $result) {
return new Objects\MatchDto($result, $this);
});
Expand All @@ -3035,7 +3036,7 @@ public function getTFTMatchByPuuid( $encrypted_puuid, $count = 20)
* Get TFT single summoner object for a given summoner ID.
*
* @cli-name get
* @cli-namespace summoner
* @cli-namespace tft-summoner
*
* @param string $encrypted_summoner_id
*
Expand All @@ -3051,7 +3052,7 @@ public function getTFTMatchByPuuid( $encrypted_puuid, $count = 20)
*/
public function getTFTSummoner( string $encrypted_summoner_id )
{
$resultPromise = $this->setEndpoint("/tft/lol/summoner/".self::RESOURCE_TFT_LEAGUE_VERSION."/summoners/{$encrypted_summoner_id}")
$resultPromise = $this->setEndpoint("/tft/lol/summoner/" . self::RESOURCE_TFT_SUMMONER_VERSION . "/summoners/{$encrypted_summoner_id}")
->setResource(self::RESOURCE_TFT_SUMMONER, "/summoners/%s")
->useKey(self::SET_TFT_KEY)
->makeCall();
Expand All @@ -3065,7 +3066,7 @@ public function getTFTSummoner( string $encrypted_summoner_id )
* Get TFT summoner for a given summoner name.
*
* @cli-name get-by-name
* @cli-namespace summoner
* @cli-namespace tft-summoner
*
* @param string $summoner_name
*
Expand All @@ -3082,7 +3083,7 @@ public function getTFTSummoner( string $encrypted_summoner_id )
public function getTFTSummonerByName( string $summoner_name )
{
$summoner_name = str_replace(' ', '', $summoner_name);
$resultPromise = $this->setEndpoint("/tft/summoner/" . self::RESOURCE_TFT_LEAGUE_VERSION . "/summoners/by-name/{$summoner_name}")
$resultPromise = $this->setEndpoint("/tft/summoner/" . self::RESOURCE_TFT_SUMMONER_VERSION . "/summoners/by-name/{$summoner_name}")
->setResource(self::RESOURCE_TFT_SUMMONER, "/summoners/by-name/%s")
->useKey(self::SET_TFT_KEY)
->makeCall();
Expand All @@ -3096,7 +3097,7 @@ public function getTFTSummonerByName( string $summoner_name )
* Get TFT single summoner object for a given summoner's account ID.
*
* @cli-name get-by-account-id
* @cli-namespace summoner
* @cli-namespace tft-summoner
*
* @param string $encrypted_account_id
*
Expand All @@ -3112,7 +3113,7 @@ public function getTFTSummonerByName( string $summoner_name )
*/
public function getTFTSummonerByAccountId( string $encrypted_account_id )
{
$resultPromise = $this->setEndpoint("/tft/lol/summoner/" . self::RESOURCE_TFT_LEAGUE_VERSION . "/summoners/by-account/{$encrypted_account_id}")
$resultPromise = $this->setEndpoint("/tft/lol/summoner/" . self::RESOURCE_TFT_SUMMONER_VERSION . "/summoners/by-account/{$encrypted_account_id}")
->setResource(self::RESOURCE_TFT_SUMMONER, "/summoners/by-account/%s")
->useKey(self::SET_TFT_KEY)
->makeCall();
Expand All @@ -3126,7 +3127,7 @@ public function getTFTSummonerByAccountId( string $encrypted_account_id )
* Get TFT single summoner object for a given summoner's PUUID.
*
* @cli-name get-by-puuid
* @cli-namespace summoner
* @cli-namespace tft-summoner
*
* @param string $encrypted_puuid
*
Expand All @@ -3142,7 +3143,7 @@ public function getTFTSummonerByAccountId( string $encrypted_account_id )
*/
public function getTFTSummonerByPUUID( string $encrypted_puuid )
{
$resultPromise = $this->setEndpoint("/tft/lol/summoner/" . self::RESOURCE_TFT_LEAGUE_VERSION . "/summoners/by-puuid/{$encrypted_puuid}")
$resultPromise = $this->setEndpoint("/tft/lol/summoner/" . self::RESOURCE_TFT_SUMMONER_VERSION . "/summoners/by-puuid/{$encrypted_puuid}")
->setResource(self::RESOURCE_TFT_SUMMONER, "/summoners/by-puuid/%s")
->useKey(self::SET_TFT_KEY)
->makeCall();
Expand Down

0 comments on commit f2b65d0

Please sign in to comment.