-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
4,475 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
|
||
namespace lucasaba\RapidAPI\Command; | ||
|
||
|
||
use lucasaba\RapidAPI\Request\FixturesRequest; | ||
use lucasaba\RapidAPI\Response\FixturesResponse; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
class FixturesCommand extends AbstractApiCommand | ||
{ | ||
protected static $defaultName = 'app:get-fixtures'; | ||
|
||
protected function configure(): void | ||
{ | ||
$this->setDescription('Gets teams information') | ||
->addArgument('token', InputArgument::REQUIRED, 'RapidAPI token') | ||
->addOption('league', null, InputOption::VALUE_OPTIONAL, 'The league id of the league') | ||
->addOption('season', null, InputOption::VALUE_REQUIRED, 'The season of the fixtures') | ||
->addOption('from', null, InputOption::VALUE_OPTIONAL, 'Date from') | ||
->addOption('to', null, InputOption::VALUE_OPTIONAL, 'Date to'); | ||
} | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output): int | ||
{ | ||
$client = $this->getClient($input->getArgument('token')); | ||
|
||
$request = new FixturesRequest($input->getOption('season')); | ||
if ($input->getOption('league')) { | ||
$request->withLeague($input->getOption('league')); | ||
} | ||
if ($input->getOption('from')) { | ||
$request->withDateFrom($input->getOption('from')); | ||
} | ||
|
||
if ($input->getOption('to')) { | ||
$request->withDateTo($input->getOption('to')); | ||
} | ||
|
||
$response = $client->get($request, FixturesResponse::class, true); | ||
|
||
$output->write(sprintf('There are %s results', $response->getResults())); | ||
|
||
return Command::SUCCESS; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
<?php | ||
|
||
|
||
namespace lucasaba\RapidAPI\Request; | ||
|
||
|
||
class FixturesRequest implements IRequest | ||
{ | ||
const ENDPOINT = '/fixtures'; | ||
|
||
private ?int $id = null; // The id of the fixture | ||
private ?string $date = null; // string YYYY-MM-DD | ||
private ?int $league = null; // The id of the league | ||
private int $season; // The season of the league | ||
private ?int $team = null; // The id of the team | ||
private ?string $from = null; // string YYYY-MM-DD | ||
private ?string $to = null; // string YYYY-MM-DD | ||
private ?string $round = null; // The round of the fixture | ||
|
||
public function __construct(int $season = null) | ||
{ | ||
$this->season = $season ?? date('Y'); | ||
} | ||
|
||
public function withId(int $id): FixturesRequest | ||
{ | ||
$this->id = $id; | ||
return $this; | ||
} | ||
|
||
public function withDate(string $date): FixturesRequest | ||
{ | ||
$this->date = $date; | ||
return $this; | ||
} | ||
|
||
public function withLeague(int $leagueId): FixturesRequest | ||
{ | ||
$this->league = $leagueId; | ||
return $this; | ||
} | ||
|
||
public function withTeam(int $teamId): FixturesRequest | ||
{ | ||
$this->team = $teamId; | ||
return $this; | ||
} | ||
|
||
public function withDateFrom(string $dateFrom): FixturesRequest | ||
{ | ||
$this->from = $dateFrom; | ||
return $this; | ||
} | ||
|
||
public function withDateTo(string $dateTo): FixturesRequest | ||
{ | ||
$this->to = $dateTo; | ||
return $this; | ||
} | ||
|
||
public function withRound(string $round): FixturesRequest | ||
{ | ||
$this->round = $round; | ||
return $this; | ||
} | ||
|
||
public function getQuery(): array | ||
{ | ||
$query = []; | ||
if ($this->id) { | ||
$query['id'] = $this->id; | ||
} | ||
|
||
if ($this->date) { | ||
$query['date'] = $this->date; | ||
} | ||
|
||
if ($this->league) { | ||
$query['league'] = $this->league; | ||
} | ||
|
||
if ($this->season) { | ||
$query['season'] = $this->season; | ||
} | ||
|
||
if ($this->team) { | ||
$query['team'] = $this->team; | ||
} | ||
|
||
if ($this->from) { | ||
$query['from'] = $this->from; | ||
} | ||
|
||
if ($this->to) { | ||
$query['to'] = $this->to; | ||
} | ||
|
||
if ($this->round) { | ||
$query['round'] = $this->round; | ||
} | ||
|
||
return $query; | ||
} | ||
|
||
public function getEndpoint(): string | ||
{ | ||
return self::ENDPOINT; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
namespace lucasaba\RapidAPI\Request\Tests; | ||
|
||
use lucasaba\RapidAPI\Request\FixturesRequest; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class FixturesRequestTest extends TestCase | ||
{ | ||
public function testAddsAll(): void | ||
{ | ||
$request = new FixturesRequest(2021); | ||
$request->withId(1) | ||
->withLeague(2) | ||
->withTeam(3) | ||
->withDate('2021-01-01') | ||
->withDateFrom('2021-01-01') | ||
->withDateTo('2021-01-01') | ||
->withRound('Round 1'); | ||
|
||
$this->assertEquals( | ||
[ | ||
'id' => 1, | ||
'season' => 2021, | ||
'league' => 2, | ||
'team' => 3, | ||
'date' => '2021-01-01', | ||
'from' => '2021-01-01', | ||
'to' => '2021-01-01', | ||
'round' => 'Round 1', | ||
], | ||
$request->getQuery() | ||
); | ||
} | ||
|
||
public function testEndpointIsReturned() | ||
{ | ||
$request = new FixturesRequest(); | ||
$this->assertEquals('/fixtures', $request->getEndpoint()); | ||
} | ||
} |
Oops, something went wrong.