1
0
mirror of https://github.com/chylex/Nextcloud-News.git synced 2025-04-12 10:15:44 +02:00
Nextcloud-News/lib/Fetcher/Client/FeedIoClient.php
Benjamin Brahmer ae99d52aad
Update to feedio 4+ ()
- bumped dependencies to last supported version
travis:
- removed php 7.0
- move main target to nc 16
- drop support for nc 14 & 15

Signed-off-by: Benjamin Brahmer <info@b-brahmer.de>
2019-08-16 07:57:34 +02:00

65 lines
1.8 KiB
PHP

<?php
/*
* This file is part of the feed-io package.
*
* (c) Alexandre Debril <alex.debril@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace OCA\News\Fetcher\Client;
use FeedIo\Adapter\ClientInterface;
use FeedIo\Adapter\ResponseInterface;
use FeedIo\Adapter\Guzzle\Response;
use FeedIo\Adapter\NotFoundException;
use FeedIo\Adapter\ServerErrorException;
use GuzzleHttp\Exception\BadResponseException;
/**
* Guzzle dependent HTTP client
*/
class FeedIoClient implements ClientInterface
{
/**
* @var \GuzzleHttp\ClientInterface
*/
protected $guzzleClient;
/**
* @param \GuzzleHttp\ClientInterface $guzzleClient
*/
public function __construct(\GuzzleHttp\ClientInterface $guzzleClient)
{
$this->guzzleClient = $guzzleClient;
}
/**
* @param string $url
* @param \DateTime $modifiedSince
* @throws \FeedIo\Adapter\NotFoundException
* @throws \FeedIo\Adapter\ServerErrorException
* @return \FeedIo\Adapter\ResponseInterface
*/
public function getResponse(string $url, \DateTime $modifiedSince) : ResponseInterface
{
try {
$options = [
'headers' => [
'If-Modified-Since' => $modifiedSince->format(\DateTime::RFC2822)
]
];
return new Response($this->guzzleClient->request('get', $url, $options));
} catch (BadResponseException $e) {
switch ((int) $e->getResponse()->getStatusCode()) {
case 404:
throw new NotFoundException($e->getMessage());
default:
throw new ServerErrorException($e->getMessage());
}
}
}
}