Advertisement
Guest User

Untitled

a guest
Jun 8th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.19 KB | None | 0 0
  1. <?php
  2.  
  3.   spl_autoload_register(function ($v) {
  4.     require_once "models/$v.php";
  5. });
  6.  
  7. class FootballData {
  8.    
  9.     public $baseUri;
  10.     public $reqPrefs = array();
  11.        
  12.     public function __construct() {
  13.  
  14.         $this->baseUri = 'http://api.football-data.org/v1/';
  15.        
  16.         $this->reqPrefs['http']['method'] = 'GET';
  17.     }
  18.  
  19.     public function fetchFixturesFor($date='n1') {
  20.         return $this->endRes("fixtures?timeFrame=$date");
  21.     }
  22.  
  23.     public function headToHead(int $fixtureID, int $count=10) {
  24.         return $this->endRes("fixtures/$fixtureID?head2head=$count");
  25.     }
  26.    
  27.     public function getFixtureId($home, $away, $date) {
  28.         $id;
  29.         foreach ($this->fetchFixturesFor($date)->fixtures as $key => $fixtures) {
  30.             if ($fixtures->homeTeamName == $home && $fixtures->awayTeamName == $away) {
  31.                 $id = @end(explode('/', $fixtures->_links->self->href));
  32.             }
  33.         }
  34.         return $id;
  35.     }
  36.  
  37.     public function endRes ($resource) {
  38.         $response = file_get_contents($this->baseUri . $resource, false, stream_context_create($this->reqPrefs));
  39.        
  40.         return json_decode($response);
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement