Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- spl_autoload_register(function ($v) {
- require_once "models/$v.php";
- });
- class FootballData {
- public $baseUri;
- public $reqPrefs = array();
- public function __construct() {
- $this->baseUri = 'http://api.football-data.org/v1/';
- $this->reqPrefs['http']['method'] = 'GET';
- }
- public function fetchFixturesFor($date='n1') {
- return $this->endRes("fixtures?timeFrame=$date");
- }
- public function headToHead(int $fixtureID, int $count=10) {
- return $this->endRes("fixtures/$fixtureID?head2head=$count");
- }
- public function getFixtureId($home, $away, $date) {
- $id;
- foreach ($this->fetchFixturesFor($date)->fixtures as $key => $fixtures) {
- if ($fixtures->homeTeamName == $home && $fixtures->awayTeamName == $away) {
- $id = @end(explode('/', $fixtures->_links->self->href));
- }
- }
- return $id;
- }
- public function endRes ($resource) {
- $response = file_get_contents($this->baseUri . $resource, false, stream_context_create($this->reqPrefs));
- return json_decode($response);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement