fedi-feed-router/app/Services/Parsers/BelgaHomepageParserAdapter.php

40 lines
1.2 KiB
PHP
Raw Normal View History

<?php
namespace App\Services\Parsers;
use App\Contracts\HomepageParserInterface;
class BelgaHomepageParserAdapter implements HomepageParserInterface
{
/**
* Must stay in sync with config('feed.providers.belga.languages.en.url').
* Nothing calls getHomepageUrl() at runtime the fetcher uses $feed->url,
* seeded from that config value so drift here would go unnoticed.
*/
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';
}
}