feat: HTTPSportRadarEngine
Signed-off-by: Superkooka <aymeric.gueracague@gmail.com>
This commit is contained in:
parent
7e2c6101ba
commit
004a0a201f
|
|
@ -4,7 +4,30 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace App\Application\SportRadar;
|
namespace App\Application\SportRadar;
|
||||||
|
|
||||||
|
use App\Domain\Enum\ENHLSeasonType;
|
||||||
|
|
||||||
interface SportRadarEngine
|
interface SportRadarEngine
|
||||||
{
|
{
|
||||||
public function getNHLSchedule(): void;
|
/**
|
||||||
|
* @return array{
|
||||||
|
* league: array{
|
||||||
|
* providerId: string,
|
||||||
|
* name: string,
|
||||||
|
* alias: string,
|
||||||
|
* },
|
||||||
|
* season: array{
|
||||||
|
* providerId: string,
|
||||||
|
* year: int,
|
||||||
|
* type: string,
|
||||||
|
* },
|
||||||
|
* games: array<array{
|
||||||
|
* providerId: string,
|
||||||
|
* scheduled: \DateTimeImmutable,
|
||||||
|
* homeTeamProviderId: string,
|
||||||
|
* awayTeamProviderId: string,
|
||||||
|
* venueArena: string,
|
||||||
|
* }>
|
||||||
|
* }
|
||||||
|
*/
|
||||||
|
public function getNHLSchedule(int $year, ENHLSeasonType $seasonType): array;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,10 +4,18 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace App\Application\UseCase;
|
namespace App\Application\UseCase;
|
||||||
|
|
||||||
|
use App\Application\SportRadar\SportRadarEngine;
|
||||||
|
use App\Domain\Enum\ENHLSeasonType;
|
||||||
|
|
||||||
class GetNHLMatch
|
class GetNHLMatch
|
||||||
{
|
{
|
||||||
|
public function __construct(
|
||||||
|
private readonly SportRadarEngine $sportRadarEngine,
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
public function __invoke(GetNHLMatchRequest $request): void
|
public function __invoke(GetNHLMatchRequest $request): void
|
||||||
{
|
{
|
||||||
dd($request->type);
|
dd($this->sportRadarEngine->getNHLSchedule($request->year, ENHLSeasonType::from($request->type))['games'][0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ namespace App\Application\UseCase;
|
||||||
class GetNHLMatchRequest
|
class GetNHLMatchRequest
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
|
public readonly int $year,
|
||||||
public readonly string $type,
|
public readonly string $type,
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,12 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Domain\Enum;
|
||||||
|
|
||||||
|
enum ENHLSeasonType: string
|
||||||
|
{
|
||||||
|
case PRE_SEASON = 'PRE';
|
||||||
|
case REGULAR_SEASON = 'REG';
|
||||||
|
case POST_SEASON = 'PST';
|
||||||
|
}
|
||||||
|
|
@ -17,7 +17,7 @@ class GetNHLScheduleCommand
|
||||||
|
|
||||||
public function __invoke(): int
|
public function __invoke(): int
|
||||||
{
|
{
|
||||||
$this->commandBus->ask(new GetNHLMatchRequest('REG'));
|
$this->commandBus->ask(new GetNHLMatchRequest(2025, 'REG'));
|
||||||
|
|
||||||
return Command::SUCCESS;
|
return Command::SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||||
namespace App\Infrastructure\SportRadar;
|
namespace App\Infrastructure\SportRadar;
|
||||||
|
|
||||||
use App\Application\SportRadar\SportRadarEngine;
|
use App\Application\SportRadar\SportRadarEngine;
|
||||||
|
use App\Domain\Enum\ENHLSeasonType;
|
||||||
use Symfony\Component\DependencyInjection\Attribute\Autowire;
|
use Symfony\Component\DependencyInjection\Attribute\Autowire;
|
||||||
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||||
|
|
||||||
|
|
@ -25,10 +26,29 @@ class HTTPSportRadarEngine implements SportRadarEngine
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getNHLSchedule(): void
|
public function getNHLSchedule(int $year, ENHLSeasonType $seasonType): array
|
||||||
{
|
{
|
||||||
$response = $this->client->request('GET', 'https://api.sportradar.com/nhl/trial/v7/en/games/2025/REG/schedule.json');
|
$response = $this->client->request('GET', sprintf('https://api.sportradar.com/nhl/trial/v7/en/games/%s/%s/schedule.json', $year, $seasonType->value));
|
||||||
|
$response = json_decode($response->getContent(), true);
|
||||||
|
|
||||||
// return ['a'];
|
return [
|
||||||
|
'league' => [
|
||||||
|
'providerId' => $response['league']['id'],
|
||||||
|
'name' => $response['league']['name'],
|
||||||
|
'alias' => $response['league']['alias'],
|
||||||
|
],
|
||||||
|
'season' => [
|
||||||
|
'providerId' => $response['season']['id'],
|
||||||
|
'year' => $response['season']['year'],
|
||||||
|
'type' => ENHLSeasonType::from($response['season']['type']),
|
||||||
|
],
|
||||||
|
'games' => array_map(fn ($game) => [
|
||||||
|
'providerId' => $game['id'],
|
||||||
|
'scheduled' => new \DateTimeImmutable($game['scheduled']),
|
||||||
|
'homeTeamProviderId' => $game['home']['id'],
|
||||||
|
'awayTeamProviderId' => $game['away']['id'],
|
||||||
|
'venueArena' => $game['venue']['name'],
|
||||||
|
], $response['games']),
|
||||||
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue