Advertisement
villers

Untitled

Jan 11th, 2014
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.42 KB | None | 0 0
  1. <?php
  2.  
  3. class StaticData
  4. {
  5.     private $apiHost = 'http://ddragon.leagueoflegends.com';
  6.     private $apiURLs = [
  7.         'versions' => [
  8.             'url' => '/realms/na.json'
  9.         ],
  10.         'items' => [
  11.             'url' => '/cdn/{version}/data/en_US/item.json'
  12.         ],
  13.         'runes' => [
  14.             'url' => '/cdn/{version}/data/en_US/rune.json'
  15.         ],
  16.         'masteries' => [
  17.             'url' => '/cdn/{version}/data/en_US/mastery.json'
  18.         ],
  19.         'champions' => [
  20.             'url' => '/cdn/{version}/data/en_US/champion.json'
  21.         ],
  22.         'profileIcons' => [
  23.             'url' => '/cdn/{version}/data/en_US/profileicon.json'
  24.         ],
  25.         'summonerSpells' => [
  26.             'url' => '/cdn/{version}/data/en_US/summoner.json'
  27.         ],
  28.     ];
  29.     private $imageURLs = [
  30.         'champions' => [
  31.             'url' => '/cdn/{version}/img/champion/{img}.png',
  32.             'version' => 'champion',
  33.         ],
  34.         'items' => [
  35.             'url' => '/cdn/{version}/img/item/{img}.png',
  36.             'version' => 'item',
  37.         ],
  38.         'profileIcons' => [
  39.             'url' => '/cdn/{version}/img/profileicon/{img}.png',
  40.             'version' => 'profile_icon',
  41.         ],
  42.         'summonerSpells' => [
  43.             'url' => '/cdn/{version}/img/spell/{img}.png',
  44.             'version' => 'summoner',
  45.         ],
  46.         'masteries' => [
  47.             'url' => '/cdn/{version}/img/mastery/{img}.png',
  48.             'version' => 'mastery',
  49.         ],
  50.         'runes' => [
  51.             'url' => '/cdn/{version}/img/rune/{img}.png',
  52.             'version' => 'rune',
  53.         ],
  54.         'sprite' => [
  55.             'url' => '/cdn/{version}/img/sprite/{img}.png',
  56.         ],
  57.     ];
  58.  
  59.     public function __call ($function, $args = NULL)
  60.     {
  61.         if (!array_key_exists($function, $this->apiURLs))
  62.             throw new Exception ("La fonction n'existe pas");
  63.  
  64.         $url = $this->apiHost . $this->apiURLs[$function]['url'];
  65.  
  66.         if ($function != 'versions')
  67.             $url = str_replace('{version}', $args[0], $url);
  68.  
  69.         $apiOut = Unirest::get($url);
  70.  
  71.         switch($apiOut->code)
  72.         {
  73.             case 200:
  74.                 return $apiOut->body;
  75.                 break;
  76.  
  77.             default:
  78.             case 404: // Page Not Found
  79.             case 400: // Bad Request
  80.             case 401: // Bad URL
  81.             case 500: // Internal Server Error
  82.                 return array("error" => $apiOut->code);
  83.                 break;
  84.         }
  85.     }
  86.  
  87.     public function getStaticImage ($type, $img, $sprite = false)
  88.     {
  89.  
  90.         $url = $this->apiHost . $this->imageURLs[($sprite ? 'sprite' : $type)]['url'];
  91.         $version = $this->getVersion($this->imageURLs[$type]['version']);
  92.  
  93.         $url = str_replace('{version}', $version, $url);
  94.         $url = str_replace('{img}', $img, $url);
  95.  
  96.         return $url;
  97.     }
  98.  
  99.     private function getVersion ($version)
  100.     {
  101.         return $this->versions()->n->$version;
  102.     }
  103.  
  104. }
  105.  
  106. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement