Advertisement
villers

Elophant.class.php

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