summaryrefslogtreecommitdiffstats
path: root/lib/Fetcher/Client/LegacyGuzzleClient.php
diff options
context:
space:
mode:
authorSean Molenaar <sean@seanmolenaar.eu>2019-03-17 20:17:40 +0100
committerSean Molenaar <SMillerDev@users.noreply.github.com>2019-03-18 10:39:32 +0100
commit9b915e24aff1c1805f1951ea78c09becc2a36271 (patch)
tree7dc18c927c4fc1b6b1653bb6833f2bf717c6d103 /lib/Fetcher/Client/LegacyGuzzleClient.php
parent6ed63bdedd859f6eb4e5ea4a992867a295a200fd (diff)
Use a copy of the FeedIO client that doesn't specify a useragent
Diffstat (limited to 'lib/Fetcher/Client/LegacyGuzzleClient.php')
-rw-r--r--lib/Fetcher/Client/LegacyGuzzleClient.php64
1 files changed, 64 insertions, 0 deletions
diff --git a/lib/Fetcher/Client/LegacyGuzzleClient.php b/lib/Fetcher/Client/LegacyGuzzleClient.php
new file mode 100644
index 000000000..8e41221c9
--- /dev/null
+++ b/lib/Fetcher/Client/LegacyGuzzleClient.php
@@ -0,0 +1,64 @@
+<?php
+/**
+ * Nextcloud - News
+ *
+ * This file is licensed under the Affero General Public License version 3 or
+ * later. See the COPYING file.
+ *
+ * @author Sean Molenaar <smillernl@me.com>
+ * @copyright 2018 Sean Molenaar
+ */
+
+namespace OCA\News\Fetcher\Client;
+
+use FeedIo\Adapter\ClientInterface as FeedIoClientInterface;
+use FeedIo\Adapter\NotFoundException;
+use FeedIo\Adapter\ServerErrorException;
+use Guzzle\Service\ClientInterface;
+use GuzzleHttp\Exception\BadResponseException;
+
+/**
+ * Guzzle dependent HTTP client
+ */
+class LegacyGuzzleClient implements FeedIoClientInterface
+{
+ /**
+ * @var ClientInterface
+ */
+ protected $guzzleClient;
+
+ /**
+ * @param ClientInterface $guzzleClient
+ */
+ public function __construct(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($url, \DateTime $modifiedSince)
+ {
+ try {
+ $options = [
+ 'headers' => [
+ 'If-Modified-Since' => $modifiedSince->format(\DateTime::RFC2822)
+ ]
+ ];
+
+ return new LegacyGuzzleResponse($this->guzzleClient->get($url, $options));
+ } catch (BadResponseException $e) {
+ switch ((int) $e->getResponse()->getStatusCode()) {
+ case 404:
+ throw new NotFoundException($e->getMessage());
+ default:
+ throw new ServerErrorException($e->getMessage());
+ }
+ }
+ }
+}