dolejska-daniel/riot-api

getStaticChampion not working without version

Closed this issue · 2 comments

Describe the bug
LeagueAPI::getStaticChampion not working without version.

To Reproduce
Steps to reproduce the behavior:

  1. Run code:
$api = new LeagueAPI([
    LeagueAPI::SET_KEY => 'MY_KEY',
    LeagueAPI::SET_REGION => Region::EUROPE_EAST
]);
$api->getStaticChampion(203, false, 'en_US');
  1. See error:
    Argument 1 passed to RiotAPI\LeagueAPI\Objects\ApiObject::__construct() must be of the type array, boolean given, called in /var/www/thekingeagle/public/vendor/dolejska-daniel/riot-api/src/LeagueAPI/LeagueAPI.php on line 1809

Expected behavior
The function should return the same result as the:
$api->getStaticChampion(203, false, 'en_US', '9.3.1');
This result contains data about Kinder champion

Server:

  • PHP version: 7.2

Additional context
After small investigation, I found that there is a validation for version parameter:
File: RiotAPI\DataDragonAPI\DataDragonAPI::getStaticDataFileUrl

If we do not specify the version for getStaticChampion method, then the version in getStaticDataFileUrl will be null (default method parameter).

We can't just remove this validation because the URL will be generated wrong:
https://ddragon.leagueoflegends.com/cdn//data/en_US/champion.json#by-key
The correct URL will be:
https://ddragon.leagueoflegends.com/cdn/9.3.1/data/en_US/champion.json#by-key

Hi, I had the same issue. I tried the getting started example which has the default set to null. It seems that the null eventually leads to a thrown error:

	public static function checkInit()
	{
		if (!self::$initialized)
			throw new SettingsException('DataDragon class was not initialized - version is potentially unknown.');
	}

Maybe there is a way to retrieve the latest version number? If not I may create some functionality since I am creating a project and my intent is to have as little necessary maintenance as possible.

Adding on: I have found this in Riot Documentation:

Data Dragon versions aren't always equivalent to the League of Legends client version. You can determine which version of Data Dragon each region is on by using the realms endpoint within the Static Data API. You can also find all valid Data Dragon versions by using the versions endpoint. Both the realm and versions endpoints draw their information from the corresponding Data Dragon files which can be found in the table below.

-https://developer.riotgames.com/static-data.html

I think this may help resolve your issue. I think the getting started documentation should reflect this functionality.

Hello, the library needs DataDragonAPI to be initialized for static data calls to work. You can either initialize it by yourself:

DataDragonAPI::initByCdn();
$api = new LeagueAPI(...);
$api->getStaticChampion(203, false, 'en_US');

or let the library initialize DataDragonAPI on its own by specifying option LeagueAPI::SET_DATADRAGON_INIT:

$api = new LeagueAPI([
    LeagueAPI::SET_DATADRAGON_INIT => true,
    ...
]);
$api->getStaticChampion(203, false, 'en_US');

Let me know if this works and close the issue,
Daniel