Skip to content

Commit

Permalink
Merge pull request #34 from aminvakil/master
Browse files Browse the repository at this point in the history
Making it compatible with api v2
  • Loading branch information
cmihaylov committed Dec 29, 2018
2 parents 56e806f + 4180783 commit fef6120
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 20 deletions.
4 changes: 2 additions & 2 deletions app/config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ parameters:
locale: en
# application parameters
football_api.name: football_data_org
football_api.base_uri: http://api.football-data.org/v1
football_api.base_uri: http://api.football-data.org/v2

framework:
#esi: ~
Expand Down Expand Up @@ -175,4 +175,4 @@ fos_oauth_server:
options:
access_token_lifetime: 7776000 # 90 days in seconds

nelmio_api_doc: ~
nelmio_api_doc: ~
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ public function processResponse(Response $response, $bodyProperty = null)
*/
public function fetchFixturesByTournamentAndMatchDay($apiTournamentId, $matchDay)
{
$uri = $this->baseUri.'/competitions/'.$apiTournamentId.'/fixtures/?matchday='.$matchDay;
$uri = $this->baseUri.'/competitions/'.$apiTournamentId.'/matches/?matchday='.$matchDay;

return $this->processResponse($this->getResponse($uri), 'fixtures');
return $this->processResponse($this->getResponse($uri), 'matches');
}

/**
Expand All @@ -96,9 +96,9 @@ public function fetchFixturesByTournamentAndMatchDay($apiTournamentId, $matchDay
*/
public function fetchFixturesByTournamentAndTimeRange($apiTournamentId, $dateFrom, $dateTo)
{
$uri = $this->baseUri.'/competitions/'.$apiTournamentId.'/fixtures/?timeFrameStart='.$dateFrom.'&timeFrameEnd='.$dateTo;
$uri = $this->baseUri.'/competitions/'.$apiTournamentId.'/matches/?dateFrom='.$dateFrom.'&dateTo='.$dateTo;

return $this->processResponse($this->getResponse($uri), 'fixtures');
return $this->processResponse($this->getResponse($uri), 'matches');
}

/**
Expand All @@ -122,7 +122,6 @@ public function fetchTeamsByTournament($apiTournamentId)
public function fetchAllTournaments()
{
$uri = $this->baseUri.'/competitions';

return $this->processResponse($this->getResponse($uri));
return $this->processResponse($this->getResponse($uri), 'competitions');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function parseTeams(array $teams)
foreach ($teams as &$team) {
$parsedTeam = array();

$parsedTeam['team_id'] = $this->getNumberAtEndOfString($team->_links->self->href);
$parsedTeam['team_id'] = $team->id;
$parsedTeam['name'] = $team->name;
$parsedTeam['team_logo'] = $team->crestUrl;

Expand All @@ -40,22 +40,30 @@ public function parseFixtures(array $fixtures)
foreach ($fixtures as &$fixture) {
$parsedFixture = array();

$parsedFixture['match_id'] = $this->getNumberAtEndOfString($fixture->_links->self->href);
$parsedFixture['tournament_id'] = $this->getNumberAtEndOfString($fixture->_links->competition->href);
$parsedFixture['home_team_id'] = $this->getNumberAtEndOfString($fixture->_links->homeTeam->href);
$parsedFixture['away_team_id'] = $this->getNumberAtEndOfString($fixture->_links->awayTeam->href);
$parsedFixture['match_local_time'] = date('Y-m-d H:i:s', strtotime($fixture->date));
$parsedFixture['match_id'] = $fixture->id;
$parsedFixture['tournament_id'] = $fixture->season->id;
$parsedFixture['home_team_id'] = $fixture->homeTeam->id;
$parsedFixture['away_team_id'] = $fixture->awayTeam->id;

// NOTE: team id 757 is just a placeholder used in this API,
// when match is scheduled, but teams are still not clear.
// This occurs in scheduled knock-out round matches.
if ($parsedFixture['home_team_id'] == 757 || $parsedFixture['away_team_id'] == 757) {
continue;
}

$parsedFixture['match_local_time'] = date('Y-m-d H:i:s', strtotime($fixture->utcDate));
$parsedFixture['status'] = $fixture->status;

if ($fixture->status === 'FINISHED') {
$parsedFixture['home_team_goals'] = $fixture->result->goalsHomeTeam;
$parsedFixture['away_team_goals'] = $fixture->result->goalsAwayTeam;
$parsedFixture['home_team_goals'] = $fixture->score->fullTime->homeTeam;
$parsedFixture['away_team_goals'] = $fixture->score->fullTime->awayTeam;
} else {
$parsedFixture['home_team_goals'] = null;
$parsedFixture['away_team_goals'] = null;
}

if ($fixture->odds && ($fixture->odds !== 'null')) {
/* if ($fixture->odds && ($fixture->odds !== 'null')) {
$parsedFixture['odds_home_win'] = $fixture->odds->homeWin;
$parsedFixture['odds_draw'] = $fixture->odds->draw;
$parsedFixture['odds_away_win'] = $fixture->odds->awayWin;
Expand All @@ -64,7 +72,7 @@ public function parseFixtures(array $fixtures)
$parsedFixture['odds_draw'] = null;
$parsedFixture['odds_away_win'] = null;
}

*/
$fixture = $parsedFixture;
}

Expand All @@ -83,8 +91,7 @@ public function parseTournaments(array $tournaments)
$parsedTournament = array();

$parsedTournament['id'] = $tournament->id;
$parsedTournament['name'] = $tournament->caption;

$parsedTournament['name'] = $tournament->name;
$tournament = $parsedTournament;
}

Expand Down

0 comments on commit fef6120

Please sign in to comment.