Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Elophant class
- *
- * key:
- */
- class Elophant
- {
- /**
- * API Host
- *
- * @var string
- * @access private
- **/
- private $_api_url = 'http://api.elophant.com/v2/';
- /**
- * LOL Region
- *
- * @var string
- * @access private
- **/
- private $_lol_region = 'na';
- /**
- * The Api Key
- *
- * @var string
- * @access private
- **/
- private $_api_key = '';
- /**
- * Constructor
- *
- * @access public
- * @return void
- */
- public function __construct ()
- {}
- /**
- * getChampions
- *
- * @access public
- * @return array
- */
- public function getChampions()
- {
- return $this->_apiCall('champions');
- }
- /**
- * getItems
- *
- * @access public
- * @return array
- */
- public function getItems()
- {
- return $this->_apiCall('items');
- }
- /**
- * getStatus
- *
- * @access public
- * @return array
- */
- public function getStatus()
- {
- return $this->_apiCall('status');
- }
- /**
- * getSummonerByName
- *
- * @access public
- * @return array
- */
- public function getSummonerByName($summoner_name)
- {
- $summoner_name = str_replace(' ', '%20', urlencode($summoner_name));
- return $this->_apiCall($this->getLolRegion().'/summoner/'.$summoner_name);
- }
- /**
- * getInProgressGameInfo
- *
- * @access public
- * @return array
- */
- public function getInProgressGameInfo($summoner_name)
- {
- return $this->_apiCall($this->getLolRegion().'/in_progress_game_info/'.$summoner_name);
- }
- /**
- * getSummonerTeamInfo
- *
- * @access public
- * @param int $summoner_id
- * @return array
- */
- public function getSummonerTeamInfo($summoner_id)
- {
- return $this->_apiCall($this->getLolRegion().'/summoner_team_info/'.$summoner_id);
- }
- /**
- * getMasteryPages
- *
- * @access public
- * @param int $summoner_id
- * @return array
- */
- public function getMasteryPages($summoner_id)
- {
- return $this->_apiCall($this->getLolRegion().'/mastery_pages/'.$summoner_id);
- }
- /**
- * getRunePages
- *
- * @access public
- * @param int $summoner_id
- * @return array
- */
- public function getRunePages($summoner_id)
- {
- return $this->_apiCall($this->getLolRegion().'/rune_pages/'.$summoner_id);
- }
- /**
- * getRecentGames
- *
- * @access public
- * @param int $account_id
- * @return array
- */
- public function getRecentGames($account_id)
- {
- return $this->_apiCall($this->getLolRegion().'/recent_games/'.$account_id);
- }
- /**
- * getSummonerNames
- *
- * @access public
- * @param array $account_ids
- * @return array
- */
- public function getSummonerNames($account_ids)
- {
- return $this->_apiCall($this->getLolRegion().'/summoner_names/'.implode(',', $account_ids));
- }
- /**
- * getPlayerStats
- *
- * @access public
- * @return array
- */
- public function getPlayerStats($account_id, $season = 'CURRENT')
- {
- return $this->_apiCall($this->getLolRegion().'/player_stats/'.$account_id.'/'.$season);
- }
- /**
- * getRankedStats
- *
- * @access public
- * @return array
- */
- public function getRankedStats($account_id, $season = 'CURRENT')
- {
- return $this->_apiCall($this->getLolRegion().'/ranked_stats/'.$account_id.'/'.$season);
- }
- /**
- * getTeamById
- *
- * @access public
- * @return array
- */
- public function getTeamById($team_id)
- {
- return $this->_apiCall($this->getLolRegion().'/team/'.$team_id);
- }
- /**
- * getTeamByTagOrName
- *
- * @access public
- * @return array
- */
- public function getTeamByTagOrName($tag_or_name)
- {
- return $this->_apiCall($this->getLolRegion().'/find_team/'.$tag_or_name);
- }
- /**
- * getTeamRankedStats
- *
- * @access public
- * @return array
- */
- public function getTeamRankedStats($team_id)
- {
- return $this->_apiCall($this->getLolRegion().'/team/'.$team_id.'/ranked_stats');
- }
- /**
- * setApiUrl
- *
- * @access public
- * @param string $url
- * @return void
- */
- public function setApiUrl($url)
- {
- $this->_api_url = $url;
- }
- /**
- * getApiUrl
- *
- * @access public
- * @return string
- */
- public function getApiUrl()
- {
- return $this->_api_url;
- }
- /**
- * getApiKey
- *
- * @access public
- * @return string
- */
- public function getApiKey()
- {
- return $this->_api_key;
- }
- /**
- * setApiKey
- *
- * @access public
- * @param string $api_key
- * @return void
- */
- public function setApiKey($api_key)
- {
- $this->_api_key = $api_key;
- }
- /**
- * getLolRegion
- *
- * @access public
- * @return string
- */
- public function getLolRegion()
- {
- return $this->_lol_region;
- }
- /**
- * setLolRegion
- *
- * @access public
- * @param string $region
- * @return void
- */
- public function setLolRegion($region= 'na')
- {
- $this->_lol_region = $region;
- }
- /**
- * _apiCall
- *
- * @access private
- * @access string $path
- * @param array $get_args
- * @return mixed
- */
- private function _apiCall($path)
- {
- $get_string = '?key='.rawurlencode($this->getApiKey());
- //http://webcodingeasy.com/Site-optimization/Comparing-filegetcontents-with-curl-and-curl-multi-handlers
- $ch=curl_init($this->getApiUrl().$path.$get_string);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- $response=curl_exec($ch);
- curl_close($ch);
- $data = json_decode($response, true);
- if ($data && is_array($data))
- {
- if (isset($data['success']) && $data['success'] == false && isset($data['error']))
- {
- error_log('Elophant API Error: '.$data['error']);
- }
- else
- return $data;
- }
- else
- return $response;
- return false;
- }
- }
- $myElophant = new Elophant();
- $myElophant->setApiKey('*****');
- echo "<pre>";
- echo "getChampions:";
- print_r($myElophant->getChampions());
- echo "--------------------------------------------------------\r\n";
- echo "getItems:";
- print_r($myElophant->getItems());
- echo "--------------------------------------------------------\r\n";
- echo "getStatus:";
- print_r($myElophant->getStatus());
- echo "--------------------------------------------------------\r\n";
- echo "getSummonerByName:";
- print_r($myElophant->getSummonerByName('Dyrus'));
- echo "--------------------------------------------------------\r\n";
- echo "getInProgressGameInfo:";
- print_r($myElophant->getInProgressGameInfo('Dyrus'));
- echo "--------------------------------------------------------\r\n";
- echo "getSummonerTeamInfo:";
- print_r($myElophant->getSummonerTeamInfo(5908));
- echo "--------------------------------------------------------\r\n";
- echo "getMasteryPages:";
- print_r($myElophant->getMasteryPages(5908));
- echo "--------------------------------------------------------\r\n";
- echo "getRunePages:";
- print_r($myElophant->getRunePages(5908));
- echo "--------------------------------------------------------\r\n";
- echo "getRecentGames:";
- print_r($myElophant->getRecentGames(32766));
- echo "--------------------------------------------------------\r\n";
- echo "getSummonerNames:";
- $myElophant->setLolRegion('euw');
- print_r($myElophant->getSummonerNames(array(71500,19307647,125586,19135198)));
- echo "--------------------------------------------------------\r\n";
- echo "getPlayerStats:";
- $myElophant->setLolRegion('na');
- print_r($myElophant->getPlayerStats(32766));
- echo "--------------------------------------------------------\r\n";
- echo "getRankedStats:";
- print_r($myElophant->getRankedStats(32766));
- echo "--------------------------------------------------------\r\n";
- echo "getTeamById:";
- print_r($myElophant->getTeamById('TEAM-e4936d7b-b80e-4367-a76c-5ccf7388c995'));
- echo "--------------------------------------------------------\r\n";
- echo "getTeamByTagOrName:";
- print_r($myElophant->getTeamByTagOrName('tsm'));
- echo "--------------------------------------------------------\r\n";
- echo "getTeamRankedStats:";
- print_r($myElophant->getTeamRankedStats('TEAM-a1ebba15-986f-488a-ae2f-e081b2886ba4'));
- echo "</pre>";
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement