Advertisement
villers

Untitled

May 27th, 2013
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.23 KB | None | 0 0
  1. class Elophant
  2. {
  3.  
  4.     /**
  5.      * API Host
  6.      *
  7.      * @var     string
  8.      * @access  private
  9.      **/
  10.     private $_api_url = 'http://api.elophant.com/v2/';
  11.  
  12.     /**
  13.      * LOL Region
  14.      *
  15.      * @var     string
  16.      * @access  private
  17.      **/
  18.     private $_lol_region = 'na';
  19.  
  20.     /**
  21.      * The Api Key
  22.      *
  23.      * @var     string
  24.      * @access  private
  25.      **/
  26.     private $_api_key = '';
  27.  
  28.     /**
  29.      * Constructor
  30.      *
  31.      * @access public
  32.      * @return void
  33.      */
  34.     public function __construct ()
  35.     {}
  36.  
  37.     /**
  38.      * getChampions
  39.      *
  40.      * @access public
  41.      * @return array
  42.      */
  43.     public function getChampions()
  44.     {
  45.         return $this->_apiCall('champions');
  46.     }
  47.  
  48.     /**
  49.      * getItems
  50.      *
  51.      * @access public
  52.      * @return array
  53.      */
  54.     public function getItems()
  55.     {
  56.         return $this->_apiCall('items');
  57.     }
  58.  
  59.     /**
  60.      * getStatus
  61.      *
  62.      * @access public
  63.      * @return array
  64.      */
  65.     public function getStatus()
  66.     {
  67.         return $this->_apiCall('status');
  68.     }
  69.  
  70.     /**
  71.      * getSummonerByName
  72.      *
  73.      * @access public
  74.      * @return array
  75.      */
  76.     public function getSummonerByName($summoner_name)
  77.     {
  78.         $summoner_name = str_replace(' ', '%20', urlencode($summoner_name));
  79.         return $this->_apiCall($this->getLolRegion().'/summoner/'.$summoner_name);
  80.     }
  81.  
  82.     /**
  83.      * getInProgressGameInfo
  84.      *
  85.      * @access public
  86.      * @return array
  87.      */
  88.     public function getInProgressGameInfo($summoner_name)
  89.     {
  90.         return $this->_apiCall($this->getLolRegion().'/in_progress_game_info/'.$summoner_name);
  91.     }
  92.  
  93.     /**
  94.      * getSummonerTeamInfo
  95.      *
  96.      * @access public
  97.      * @param  int     $summoner_id
  98.      * @return array
  99.      */
  100.     public function getSummonerTeamInfo($summoner_id)
  101.     {
  102.         return $this->_apiCall($this->getLolRegion().'/summoner_team_info/'.$summoner_id);
  103.     }
  104.  
  105.     /**
  106.      * getMasteryPages
  107.      *
  108.      * @access public
  109.      * @param  int     $summoner_id
  110.      * @return array
  111.      */
  112.     public function getMasteryPages($summoner_id)
  113.     {
  114.         return $this->_apiCall($this->getLolRegion().'/mastery_pages/'.$summoner_id);
  115.     }
  116.  
  117.     /**
  118.      * getRunePages
  119.      *
  120.      * @access public
  121.      * @param  int      $summoner_id
  122.      * @return array
  123.      */
  124.     public function getRunePages($summoner_id)
  125.     {
  126.         return $this->_apiCall($this->getLolRegion().'/rune_pages/'.$summoner_id);
  127.     }
  128.  
  129.     /**
  130.      * getRecentGames
  131.      *
  132.      * @access public
  133.      * @param  int      $account_id
  134.      * @return array
  135.      */
  136.     public function getRecentGames($account_id)
  137.     {
  138.         return $this->_apiCall($this->getLolRegion().'/recent_games/'.$account_id);
  139.     }
  140.  
  141.     /**
  142.      * getSummonerNames
  143.      *
  144.      * @access public
  145.      * @param  array    $account_ids
  146.      * @return array
  147.      */
  148.     public function getSummonerNames($account_ids)
  149.     {
  150.         return $this->_apiCall($this->getLolRegion().'/summoner_names/'.implode(',', $account_ids));
  151.     }
  152.  
  153.     /**
  154.      * getPlayerStats
  155.      *
  156.      * @access public
  157.      * @return array
  158.      */
  159.     public function getPlayerStats($account_id, $season = 'CURRENT')
  160.     {
  161.         return $this->_apiCall($this->getLolRegion().'/player_stats/'.$account_id.'/'.$season);
  162.     }
  163.  
  164.     /**
  165.      * getRankedStats
  166.      *
  167.      * @access public
  168.      * @return array
  169.      */
  170.     public function getRankedStats($account_id, $season = 'CURRENT')
  171.     {
  172.         return $this->_apiCall($this->getLolRegion().'/ranked_stats/'.$account_id.'/'.$season);
  173.     }
  174.  
  175.     /**
  176.      * getTeamById
  177.      *
  178.      * @access public
  179.      * @return array
  180.      */
  181.     public function getTeamById($team_id)
  182.     {
  183.         return $this->_apiCall($this->getLolRegion().'/team/'.$team_id);
  184.     }
  185.  
  186.     /**
  187.      * getTeamByTagOrName
  188.      *
  189.      * @access public
  190.      * @return array
  191.      */
  192.     public function getTeamByTagOrName($tag_or_name)
  193.     {
  194.         return $this->_apiCall($this->getLolRegion().'/find_team/'.$tag_or_name);
  195.     }
  196.  
  197.     /**
  198.      * getTeamRankedStats
  199.      *
  200.      * @access public
  201.      * @return array
  202.      */
  203.     public function getTeamRankedStats($team_id)
  204.     {
  205.         return $this->_apiCall($this->getLolRegion().'/team/'.$team_id.'/ranked_stats');
  206.     }
  207.  
  208.     /**
  209.      * setApiUrl
  210.      *
  211.      * @access public
  212.      * @param  string  $url
  213.      * @return void
  214.      */
  215.     public function setApiUrl($url)
  216.     {
  217.         $this->_api_url = $url;
  218.     }
  219.  
  220.     /**
  221.      * getApiUrl
  222.      *
  223.      * @access public
  224.      * @return string
  225.      */
  226.     public function getApiUrl()
  227.     {
  228.         return $this->_api_url;
  229.     }
  230.  
  231.     /**
  232.      * getApiKey
  233.      *
  234.      * @access public
  235.      * @return string
  236.      */
  237.     public function getApiKey()
  238.     {
  239.         return $this->_api_key;
  240.     }
  241.  
  242.     /**
  243.      * setApiKey
  244.      *
  245.      * @access public
  246.      * @param  string  $api_key
  247.      * @return void
  248.      */
  249.     public function setApiKey($api_key)
  250.     {
  251.         $this->_api_key = $api_key;
  252.     }
  253.  
  254.     /**
  255.      * getLolRegion
  256.      *
  257.      * @access public
  258.      * @return string
  259.      */
  260.     public function getLolRegion()
  261.     {
  262.         return $this->_lol_region;
  263.     }
  264.  
  265.     /**
  266.      * setLolRegion
  267.      *
  268.      * @access public
  269.      * @param  string  $region
  270.      * @return void
  271.      */
  272.     public function setLolRegion($region= 'na')
  273.     {
  274.         $this->_lol_region = $region;
  275.     }
  276.  
  277.     /**
  278.     * _apiCall
  279.     *
  280.     * @access private
  281.     * @access string  $path
  282.     * @param  array   $get_args
  283.     * @return mixed
  284.     */
  285.     private function _apiCall($path)
  286.     {
  287.         $get_string = '?key='.rawurlencode($this->getApiKey());
  288.         $response = @file_get_contents($this->getApiUrl().$path.$get_string);
  289.         $data = json_decode($response, true);
  290.  
  291.         if ($data && is_array($data))
  292.         {
  293.             if (isset($data['success']) && $data['success'] == false && isset($data['error']))
  294.             {
  295.                 error_log('Elophant API Error: '.$data['error']);
  296.             }
  297.             else
  298.                 return $data;
  299.         }
  300.         else
  301.             return $response;
  302.  
  303.         return false;
  304.     }
  305. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement