Advertisement
villers

Untitled

May 29th, 2013
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 8.95 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4. * Elophant class
  5. *
  6. * key:
  7. */
  8. class Elophant
  9. {
  10.  
  11.     /**
  12.      * API Host
  13.      *
  14.      * @var     string
  15.      * @access  private
  16.      **/
  17.     private $_api_url = 'http://api.elophant.com/v2/';
  18.  
  19.     /**
  20.      * LOL Region
  21.      *
  22.      * @var     string
  23.      * @access  private
  24.      **/
  25.     private $_lol_region = 'na';
  26.  
  27.     /**
  28.      * The Api Key
  29.      *
  30.      * @var     string
  31.      * @access  private
  32.      **/
  33.     private $_api_key = '';
  34.  
  35.     /**
  36.      * Constructor
  37.      *
  38.      * @access public
  39.      * @return void
  40.      */
  41.     public function __construct ()
  42.     {}
  43.  
  44.     /**
  45.      * getChampions
  46.      *
  47.      * @access public
  48.      * @return array
  49.      */
  50.     public function getChampions()
  51.     {
  52.         return $this->_apiCall('champions');
  53.     }
  54.  
  55.     /**
  56.      * getItems
  57.      *
  58.      * @access public
  59.      * @return array
  60.      */
  61.     public function getItems()
  62.     {
  63.         return $this->_apiCall('items');
  64.     }
  65.  
  66.     /**
  67.      * getStatus
  68.      *
  69.      * @access public
  70.      * @return array
  71.      */
  72.     public function getStatus()
  73.     {
  74.         return $this->_apiCall('status');
  75.     }
  76.  
  77.     /**
  78.      * getSummonerByName
  79.      *
  80.      * @access public
  81.      * @return array
  82.      */
  83.     public function getSummonerByName($summoner_name)
  84.     {
  85.         $summoner_name = str_replace(' ', '%20', urlencode($summoner_name));
  86.         return $this->_apiCall($this->getLolRegion().'/summoner/'.$summoner_name);
  87.     }
  88.  
  89.     /**
  90.      * getInProgressGameInfo
  91.      *
  92.      * @access public
  93.      * @return array
  94.      */
  95.     public function getInProgressGameInfo($summoner_name)
  96.     {
  97.         return $this->_apiCall($this->getLolRegion().'/in_progress_game_info/'.$summoner_name);
  98.     }
  99.  
  100.     /**
  101.      * getSummonerTeamInfo
  102.      *
  103.      * @access public
  104.      * @param  int     $summoner_id
  105.      * @return array
  106.      */
  107.     public function getSummonerTeamInfo($summoner_id)
  108.     {
  109.         return $this->_apiCall($this->getLolRegion().'/summoner_team_info/'.$summoner_id);
  110.     }
  111.  
  112.     /**
  113.      * getMasteryPages
  114.      *
  115.      * @access public
  116.      * @param  int     $summoner_id
  117.      * @return array
  118.      */
  119.     public function getMasteryPages($summoner_id)
  120.     {
  121.         return $this->_apiCall($this->getLolRegion().'/mastery_pages/'.$summoner_id);
  122.     }
  123.  
  124.     /**
  125.      * getRunePages
  126.      *
  127.      * @access public
  128.      * @param  int      $summoner_id
  129.      * @return array
  130.      */
  131.     public function getRunePages($summoner_id)
  132.     {
  133.         return $this->_apiCall($this->getLolRegion().'/rune_pages/'.$summoner_id);
  134.     }
  135.  
  136.     /**
  137.      * getRecentGames
  138.      *
  139.      * @access public
  140.      * @param  int      $account_id
  141.      * @return array
  142.      */
  143.     public function getRecentGames($account_id)
  144.     {
  145.         return $this->_apiCall($this->getLolRegion().'/recent_games/'.$account_id);
  146.     }
  147.  
  148.     /**
  149.      * getSummonerNames
  150.      *
  151.      * @access public
  152.      * @param  array    $account_ids
  153.      * @return array
  154.      */
  155.     public function getSummonerNames($account_ids)
  156.     {
  157.         return $this->_apiCall($this->getLolRegion().'/summoner_names/'.implode(',', $account_ids));
  158.     }
  159.  
  160.     /**
  161.      * getPlayerStats
  162.      *
  163.      * @access public
  164.      * @return array
  165.      */
  166.     public function getPlayerStats($account_id, $season = 'CURRENT')
  167.     {
  168.         return $this->_apiCall($this->getLolRegion().'/player_stats/'.$account_id.'/'.$season);
  169.     }
  170.  
  171.     /**
  172.      * getRankedStats
  173.      *
  174.      * @access public
  175.      * @return array
  176.      */
  177.     public function getRankedStats($account_id, $season = 'CURRENT')
  178.     {
  179.         return $this->_apiCall($this->getLolRegion().'/ranked_stats/'.$account_id.'/'.$season);
  180.     }
  181.  
  182.     /**
  183.      * getTeamById
  184.      *
  185.      * @access public
  186.      * @return array
  187.      */
  188.     public function getTeamById($team_id)
  189.     {
  190.         return $this->_apiCall($this->getLolRegion().'/team/'.$team_id);
  191.     }
  192.  
  193.     /**
  194.      * getTeamByTagOrName
  195.      *
  196.      * @access public
  197.      * @return array
  198.      */
  199.     public function getTeamByTagOrName($tag_or_name)
  200.     {
  201.         return $this->_apiCall($this->getLolRegion().'/find_team/'.$tag_or_name);
  202.     }
  203.  
  204.     /**
  205.      * getTeamRankedStats
  206.      *
  207.      * @access public
  208.      * @return array
  209.      */
  210.     public function getTeamRankedStats($team_id)
  211.     {
  212.         return $this->_apiCall($this->getLolRegion().'/team/'.$team_id.'/ranked_stats');
  213.     }
  214.  
  215.     /**
  216.      * setApiUrl
  217.      *
  218.      * @access public
  219.      * @param  string  $url
  220.      * @return void
  221.      */
  222.     public function setApiUrl($url)
  223.     {
  224.         $this->_api_url = $url;
  225.     }
  226.  
  227.     /**
  228.      * getApiUrl
  229.      *
  230.      * @access public
  231.      * @return string
  232.      */
  233.     public function getApiUrl()
  234.     {
  235.         return $this->_api_url;
  236.     }
  237.  
  238.     /**
  239.      * getApiKey
  240.      *
  241.      * @access public
  242.      * @return string
  243.      */
  244.     public function getApiKey()
  245.     {
  246.         return $this->_api_key;
  247.     }
  248.  
  249.     /**
  250.      * setApiKey
  251.      *
  252.      * @access public
  253.      * @param  string  $api_key
  254.      * @return void
  255.      */
  256.     public function setApiKey($api_key)
  257.     {
  258.         $this->_api_key = $api_key;
  259.     }
  260.  
  261.     /**
  262.      * getLolRegion
  263.      *
  264.      * @access public
  265.      * @return string
  266.      */
  267.     public function getLolRegion()
  268.     {
  269.         return $this->_lol_region;
  270.     }
  271.  
  272.     /**
  273.      * setLolRegion
  274.      *
  275.      * @access public
  276.      * @param  string  $region
  277.      * @return void
  278.      */
  279.     public function setLolRegion($region= 'na')
  280.     {
  281.         $this->_lol_region = $region;
  282.     }
  283.  
  284.     /**
  285.     * _apiCall
  286.     *
  287.     * @access private
  288.     * @access string  $path
  289.     * @param  array   $get_args
  290.     * @return mixed
  291.     */
  292.     private function _apiCall($path)
  293.     {
  294.         $get_string = '?key='.rawurlencode($this->getApiKey());
  295.  
  296.         //http://webcodingeasy.com/Site-optimization/Comparing-filegetcontents-with-curl-and-curl-multi-handlers
  297.         $ch=curl_init($this->getApiUrl().$path.$get_string);
  298.         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  299.         $response=curl_exec($ch);
  300.         curl_close($ch);
  301.  
  302.  
  303.         $data = json_decode($response, true);
  304.  
  305.         if ($data && is_array($data))
  306.         {
  307.             if (isset($data['success']) && $data['success'] == false && isset($data['error']))
  308.             {
  309.                 error_log('Elophant API Error: '.$data['error']);
  310.             }
  311.             else
  312.                 return $data;
  313.         }
  314.         else
  315.             return $response;
  316.  
  317.         return false;
  318.     }
  319. }
  320.  
  321. $myElophant = new Elophant();
  322. $myElophant->setApiKey('*****');
  323.  
  324. echo "<pre>";
  325.     echo "getChampions:";
  326.     print_r($myElophant->getChampions());
  327.     echo "--------------------------------------------------------\r\n";
  328.     echo "getItems:";
  329.     print_r($myElophant->getItems());
  330.     echo "--------------------------------------------------------\r\n";
  331.     echo "getStatus:";
  332.     print_r($myElophant->getStatus());
  333.     echo "--------------------------------------------------------\r\n";
  334.     echo "getSummonerByName:";
  335.     print_r($myElophant->getSummonerByName('Dyrus'));
  336.     echo "--------------------------------------------------------\r\n";
  337.     echo "getInProgressGameInfo:";
  338.     print_r($myElophant->getInProgressGameInfo('Dyrus'));
  339.     echo "--------------------------------------------------------\r\n";
  340.     echo "getSummonerTeamInfo:";
  341.     print_r($myElophant->getSummonerTeamInfo(5908));
  342.     echo "--------------------------------------------------------\r\n";
  343.     echo "getMasteryPages:";
  344.     print_r($myElophant->getMasteryPages(5908));
  345.     echo "--------------------------------------------------------\r\n";
  346.     echo "getRunePages:";
  347.     print_r($myElophant->getRunePages(5908));
  348.     echo "--------------------------------------------------------\r\n";
  349.     echo "getRecentGames:";
  350.     print_r($myElophant->getRecentGames(32766));
  351.     echo "--------------------------------------------------------\r\n";
  352.     echo "getSummonerNames:";
  353.     $myElophant->setLolRegion('euw');
  354.     print_r($myElophant->getSummonerNames(array(71500,19307647,125586,19135198)));
  355.     echo "--------------------------------------------------------\r\n";
  356.     echo "getPlayerStats:";
  357.     $myElophant->setLolRegion('na');
  358.     print_r($myElophant->getPlayerStats(32766));
  359.     echo "--------------------------------------------------------\r\n";
  360.     echo "getRankedStats:";
  361.     print_r($myElophant->getRankedStats(32766));
  362.     echo "--------------------------------------------------------\r\n";
  363.     echo "getTeamById:";
  364.     print_r($myElophant->getTeamById('TEAM-e4936d7b-b80e-4367-a76c-5ccf7388c995'));
  365.     echo "--------------------------------------------------------\r\n";
  366.     echo "getTeamByTagOrName:";
  367.     print_r($myElophant->getTeamByTagOrName('tsm'));
  368.     echo "--------------------------------------------------------\r\n";
  369.     echo "getTeamRankedStats:";
  370.     print_r($myElophant->getTeamRankedStats('TEAM-a1ebba15-986f-488a-ae2f-e081b2886ba4'));
  371. echo "</pre>";
  372.  
  373.  
  374.  
  375. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement