dolejska-daniel / riot-api

Riot League of Legends & DataDragon API wrappers for PHP7 and PHP8.
GNU General Public License v3.0
112 stars 25 forks source link

Refactor DataDragonAPI calls from LeagueAPI #31

Closed dolejska-daniel closed 4 years ago

dolejska-daniel commented 5 years ago

DataDragonAPI calls template:

$result = false;
try
{
    // Fetch StaticData from JSON files
    $result = DataDragonAPI::FUNCTION_NAME(...$PARAMETERS);
    if (!$result) throw new ServerException("StaticData failed to be loaded.");

    $this->result_data = $result;
}
catch (DataDragonExceptions\SettingsException $ex)
{
    throw new SettingsException("DataDragon API was not initialized properly! StaticData endpoints cannot be used.");
}
catch (DataDragonExceptions\ArgumentException $ex)
{
    throw new RequestException($ex->getMessage(), $ex->getCode());
}
finally
{
    // Parse array and create instances
    return new ApiObject($result, $this);
}

Should be refactored to "kind of" match up with normal API calls:

$this->setEndpoint("/lol/league/" . self::RESOURCE_LEAGUE_VERSION . "/grandmasterleagues/by-queue/{$game_queue_type}")
    ->setResource(self::RESOURCE_LEAGUE, "/grandmasterleagues/by-queue/%s")
    ->makeCall();

return new Objects\LeagueListDto($this->getResult(), $this);