35 lines
943 B
PHP
35 lines
943 B
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Services\Parsers;
|
||
|
|
|
||
|
|
use App\Contracts\HomepageParserInterface;
|
||
|
|
|
||
|
|
class BelgaHomepageParserAdapter implements HomepageParserInterface
|
||
|
|
{
|
||
|
|
private const API_URL = 'https://capi.belga.press/belgapress/api/public/pressreleases?offset=1&count=6&search=&start=&end=&newsroomId=70&language=EN';
|
||
|
|
|
||
|
|
public function __construct(
|
||
|
|
private string $language = 'en',
|
||
|
|
) {}
|
||
|
|
|
||
|
|
public function canParse(string $url): bool
|
||
|
|
{
|
||
|
|
return str_contains($url, 'belganewsagency.eu') || str_contains($url, 'capi.belga.press');
|
||
|
|
}
|
||
|
|
|
||
|
|
public function extractArticleUrls(string $html): array
|
||
|
|
{
|
||
|
|
return BelgaHomepageParser::extractArticleUrls($html);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function getHomepageUrl(): string
|
||
|
|
{
|
||
|
|
return str_replace('language=EN', 'language=' . strtoupper($this->language), self::API_URL);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function getSourceName(): string
|
||
|
|
{
|
||
|
|
return 'Belga News Agency';
|
||
|
|
}
|
||
|
|
}
|