Last active
November 9, 2016 13:39
-
-
Save exyjerome/2c6911107134f82ac050a1337d7edb03 to your computer and use it in GitHub Desktop.
Working (mostly) to grab summoner, league and icon.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class LeagueAW{ | |
const $APIKEY = "your key here"; | |
private $api = [ | |
"getSummoner" => "https://%s.api.pvp.net/api/lol/%s/v1.4/summoner/by-name/%s?api_key=" . $this->APIKEY, | |
"getLeague" => "https://%s.api.pvp.net/api/lol/%s/v2.5/league/by-summoner/%s/entry?api_key=" . $this->APIKEY, | |
"getIcon" => "http://ddragon.leagueoflegends.com/cdn/6.20.1/img/profileicon/%d.png" | |
]; | |
private $current; | |
private $league; | |
public function __construct($r, $b){ | |
/* region , summoner */ | |
$summoner = strtolower($b); | |
$region = strtolower($r); | |
$getSummoner = file_get_contents( sprintf($this->api["getSummoner"], $region, $region, $summoner ) ); | |
if($getSummoner){ | |
$results = json_decode($getSummoner); | |
$getLeague = $this->getLeague($region, $results->$summoner->id); | |
/*if(!$getLeague){ | |
$getLeague = $this->getLeague($region, $results->$summoner->id); | |
}*/ | |
$summID = $results->$summoner->id; | |
$json = json_decode($getLeague, true); | |
// there is a decent amount more information, however I only needed this. | |
$current = [ | |
"icon_url" => "//ddragon.leagueoflegends.com/cdn/6.20.1/img/profileicon/" . $results->$summoner->profileIconId . ".png", | |
"summonerID" => $results->$summoner->id, | |
"summoner" => $results->$summoner->name, | |
"summonerLevel" => $results->$summoner->summonerLevel, | |
"region" => $region, | |
"league" => [ | |
"tier" => $json[$summID][0]["tier"], | |
"lp" => $json[$summID][0]["entries"][0]["leaguePoints"], | |
"isInactive" => $json[$summID][0]["entries"][0]["isInactive"] | |
] | |
]; | |
$this->current = $current; | |
}else{ | |
$current = [ | |
"icon_url" => "//ddragon.leagueoflegends.com/cdn/6.20.1/img/profileicon/" . $results->$summoner->profileIconId . ".png", | |
"summonerID" => "", | |
"summoner" => "Error!", | |
"summonerLevel" => "", | |
"region" => "N/A", | |
"league" => "" | |
]; | |
} | |
} | |
public function debug(){ | |
print_r($this->current); | |
echo "<hr>"; | |
print_r($this->leagueResponse); | |
} | |
public function getLeague($region, $summonerID){ | |
$league = file_get_contents( sprintf($this->api["getLeague"], $region, $region, $summonerID) ); | |
$this->leagueHTTP = preg_match('|HTTP/\d\.\d\s+(\d+)\s+.*|', $http_response_header[0], $this->leagueResponse); | |
if($this->leagueResponse[1] == "200"){ | |
return $league; | |
}elseif($this->leagueResponse[1] == "400"){ | |
return "No league found for summonerID " . $summonerID; | |
}else{ | |
return 'An unknown error has occurred'; | |
} | |
/** | |
For some reason the league API tends to be a 50/50 success rate, hence the 'unknown' error. | |
*/ | |
} | |
public function display(){ | |
// will display a bootstrap 'rectangular box thing' showing data. | |
$opts = $this->current; | |
if($this->leagueResponse[1] == "200"){ | |
if($opts["league"]["isInactive"] == false){ | |
$active = "False"; | |
}else{ | |
$active = "True"; | |
} | |
$league = '<p>Current League: <strong>'.ucfirst(strtolower($opts["league"]["tier"])).'</strong></p><p>LP: '.$opts["league"]["lp"] . '</p><p>Inactive: ' . $active . '</p>'; | |
}else{ | |
$league = "Not currently in a league (".$this->leagueResponse[1].",".$opts["summonerID"].")"; | |
// Includes API HTTP code as well as summonerID (likely should not be included in final/production) | |
} | |
if($opts["summoner"] != ""){ | |
echo ' | |
<div data-summoner="'.$opts["summoner"].'" data-region="'.$opts["region"].'" class="media"> | |
<div class="media-left media-middle"> | |
<a> | |
<img class="media-object img-thumbnail" src="'.$opts["icon_url"].'"> | |
</a> | |
</div> | |
<div class="media-body"> | |
<h4 class="media-heading"><strong>'.$opts["summoner"].'</strong> — <strong>'.strtoupper($opts["region"]).'</strong> <i onClick="refresh( $(this) );" style="cursor:pointer;" class="fa fa-refresh" aria-hidden="true"></i></h4> | |
'.$league.' | |
</div> | |
</div> | |
'; | |
}else{ | |
echo 'Error'; | |
} | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment