Advertisement
villers

Untitled

Jan 12th, 2014
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.50 KB | None | 0 0
  1. <?php
  2.  
  3. class StaticDataService Extends Service
  4. {
  5.     private $apiHost = 'http://ddragon.leagueoflegends.com';
  6.     private $version = array();
  7.     private $apiURLs = array (
  8.         'champion',
  9.         'item',
  10.         'profileicon',
  11.         'spell',
  12.         'mastery',
  13.         'rune'
  14.     );
  15.  
  16.     function __construct()
  17.     {
  18.         $this->version = $this->get($this->apiHost . "/realms/na.json");
  19.     }
  20.  
  21.     public function __call ($function, $args = NULL)
  22.     {
  23.         if (!in_array($function, $this->apiURLs))
  24.             throw new Exception ("La fonction n'existe pas");
  25.  
  26.         if (empty($args))
  27.             $args[0] = $this->version->n->$function;
  28.  
  29.         return $this->get($this->apiHost . "/cdn/{$args[0]}/data/en_US/{$function}.json");
  30.     }
  31.  
  32.     public function getStaticImage ($type, $img)
  33.     {
  34.         if ((!in_array($type, $this->apiURLs)) &&  $type != 'sprite')
  35.             throw new Exception ("La type n'existe pas");
  36.  
  37.         return $this->apiHost . "/cdn/{$this->version->n->$type}/img/$type/{$img}.png";
  38.     }
  39. }
  40. /*
  41.     $image = new StaticDataService();
  42.     print_r($image->items("3.15.5"));
  43.     print_r($image->items());
  44.     print_r($image->getStaticImage("champions", "Shaco"));
  45. */
  46. ?>
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53. <?php
  54.  
  55. class Service
  56. {
  57.     public function get($url)
  58.     {
  59.         switch(Unirest::get($url)->code)
  60.         {
  61.             case 200:
  62.                 return Unirest::get($url)->body;
  63.                 break;
  64.  
  65.             default:
  66.             case 404: // Page Not Found
  67.             case 400: // Bad Request
  68.             case 401: // Bad URL
  69.             case 500: // Internal Server Error
  70.                 return array("error" => Unirest::get($url)->code);
  71.                 break;
  72.         }
  73.     }
  74. }
  75. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement