function getRankedStats() { global $apiKey, $playerID, $playerServer; $url = 'https://' . $playerServer . '.api.pvp.net/api/lol/' . $playerServer . '/v1.3/stats/by-summoner/' . $playerID . '/ranked?season=SEASON2015&api_key=' . $apiKey; $response = file_get_contents($url); if (requestFailed($response, $url)) { $error = error_get_last(); $error = $error['message']; $errorCode = substr($error, strpos($error, "/1.1") + 5, 3); handleError($errorCode, $url, "champions on ranked"); return; } $rankedStats = json_decode($response); $championsPlayed = $rankedStats->champions; $url = 'https://global.api.pvp.net/api/lol/static-data/' . $playerServer . '/v1.2/champion?champData=image&api_key=' . $apiKey; $response = file_get_contents($url); if (requestFailed($response, $url)) { $error = error_get_last(); $error = $error['message']; $errorCode = substr($error, strpos($error, "/1.1") + 5, 3); handleError($errorCode, $url, "champions"); return; } $champions = json_decode($response)->data; $playerChampions = array(); foreach ($champions as $key => $champion) { foreach ($championsPlayed as $key => $championPlayed) { if ($championPlayed->id == $champion->id) { $champ = new Champion(); $champ->name = $champion->name; $champ->id = $champion->id; $champ->title = $champion->title; $champ->image = $champion->image->full; $champ->stats = $championPlayed->stats; array_push($playerChampions, $champ); break; } } } usort($playerChampions, "sortChamps"); echo json_encode($playerChampions); }
function setSummoner($summonerName, $server) { global $apiKey, $playerID, $name, $iconID, $level, $playerServer, $rankedLeague, $rankedTier; $playerServer = $server; $summonerName = str_replace(' ', '', $summonerName); // So if the user has spaces in it, it works. $url = 'https://' . $server . '.api.pvp.net/api/lol/' . $server . '/v1.4/summoner/by-name/' . $summonerName . '?api_key=' . $apiKey; $response = @file_get_contents($url); if (requestFailed($response, $url)) { $error = error_get_last(); $error = $error['message']; $errorCode = substr($error, strpos($error, "/1.1") + 5, 3); handleError($errorCode, $url, "name and playerID"); return; } $stats = json_decode($response)->{$summonerName}; $playerID = $stats->id; $name = $stats->name; $iconID = $stats->profileIconId; $level = $stats->summonerLevel; $url = 'https://' . $playerServer . '.api.pvp.net/api/lol/' . $playerServer . '/v2.5/league/by-summoner/' . $playerID . '?api_key=' . $apiKey; $response = @file_get_contents($url); if (requestFailed($response, $url)) { $error = error_get_last(); $error = $error['message']; $errorCode = substr($error, strpos($error, "/1.1") + 5, 3); if ($errorCode == "404" || $errorCode == "503") { handleError(405, $url, "league and tier"); } else { handleError($errorCode, $url, "league and tier"); } return; } $league = json_decode($response)->{$playerID}; $rankedLeague = $league[0]->name; $rankedTier = $league[0]->tier; }