summaryrefslogtreecommitdiffstats
path: root/lib/Config/LegacyGuzzleResponse.php
diff options
context:
space:
mode:
authorSean Molenaar <sean@seanmolenaar.eu>2019-01-30 20:36:40 +0100
committerSean Molenaar <sean@seanmolenaar.eu>2019-01-30 20:36:40 +0100
commita3246a927de542e1b3ab403359bfd3c08705b6a7 (patch)
tree2062fe74608d41017d4403f2efa388488ca9bdb7 /lib/Config/LegacyGuzzleResponse.php
parent270409d0d6d4cd9cbae6588c39e3058b22b4734e (diff)
Parser: Switch to feedIO for parsing instead of picoFeed
Diffstat (limited to 'lib/Config/LegacyGuzzleResponse.php')
-rw-r--r--lib/Config/LegacyGuzzleResponse.php86
1 files changed, 86 insertions, 0 deletions
diff --git a/lib/Config/LegacyGuzzleResponse.php b/lib/Config/LegacyGuzzleResponse.php
new file mode 100644
index 000000000..d9f6102ee
--- /dev/null
+++ b/lib/Config/LegacyGuzzleResponse.php
@@ -0,0 +1,86 @@
+<?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\Config;
+
+use FeedIo\Adapter\ResponseInterface;
+use GuzzleHttp\Message\ResponseInterface as GuzzleResponseInterface;
+
+/**
+ * Guzzle dependent HTTP Response
+ */
+class LegacyGuzzleResponse implements ResponseInterface
+{
+ const HTTP_LAST_MODIFIED = 'Last-Modified';
+
+ /**
+ * @var \GuzzleHttp\Message\ResponseInterface
+ */
+ protected $response;
+
+ /**
+ * @param \GuzzleHttp\Message\ResponseInterface
+ */
+ public function __construct(GuzzleResponseInterface $psrResponse)
+ {
+ $this->response = $psrResponse;
+ }
+
+ /**
+ * @return boolean
+ */
+ public function isModified()
+ {
+ return $this->response->getStatusCode() !== 304 && $this->response->getBody()->getSize() > 0;
+ }
+
+ /**
+ * @return \Psr\Http\Message\StreamInterface
+ */
+ public function getBody()
+ {
+ return $this->response->getBody();
+ }
+
+ /**
+ * @return \DateTime|null
+ */
+ public function getLastModified()
+ {
+ if ($this->response->hasHeader(static::HTTP_LAST_MODIFIED)) {
+ $lastModified = \DateTime::createFromFormat(
+ \DateTime::RFC2822,
+ $this->getHeader(static::HTTP_LAST_MODIFIED)
+ );
+
+ return false === $lastModified ? null : $lastModified;
+ }
+
+ return;
+ }
+
+ /**
+ * @return array
+ */
+ public function getHeaders()
+ {
+ return $this->response->getHeaders();
+ }
+
+ /**
+ * @param string $name
+ * @return string[]
+ */
+ public function getHeader($name)
+ {
+ return $this->response->getHeader($name);
+ }
+}