summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorSean Molenaar <sean@seanmolenaar.eu>2021-01-20 21:45:05 +0100
committerSean Molenaar <SMillerDev@users.noreply.github.com>2021-01-20 22:52:09 +0100
commit8fa1537cbfa7bc37412c029887dc9ea455aade42 (patch)
treeee1a38664f78028ceb36e7649406e635e9ef0d44 /lib
parent54e3b2e57a9d4b2c312647fbd6247fe1bea41c7d (diff)
Fetcher: Update client and add test
Signed-off-by: Sean Molenaar <sean@seanmolenaar.eu>
Diffstat (limited to 'lib')
-rw-r--r--lib/Fetcher/Client/FeedIoClient.php21
1 files changed, 14 insertions, 7 deletions
diff --git a/lib/Fetcher/Client/FeedIoClient.php b/lib/Fetcher/Client/FeedIoClient.php
index 33a3db2ad..3a1427e84 100644
--- a/lib/Fetcher/Client/FeedIoClient.php
+++ b/lib/Fetcher/Client/FeedIoClient.php
@@ -10,12 +10,14 @@
namespace OCA\News\Fetcher\Client;
+use DateTime;
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;
+use GuzzleHttp\Exception\GuzzleException;
/**
* Guzzle dependent HTTP client
@@ -23,7 +25,7 @@ use GuzzleHttp\Exception\BadResponseException;
class FeedIoClient implements ClientInterface
{
/**
- * @var \GuzzleHttp\ClientInterface
+ * @param \GuzzleHttp\ClientInterface $guzzleClient
*/
protected $guzzleClient;
@@ -37,12 +39,13 @@ class FeedIoClient implements ClientInterface
/**
* @param string $url
- * @param \DateTime $modifiedSince
- * @throws \FeedIo\Adapter\NotFoundException
- * @throws \FeedIo\Adapter\ServerErrorException
- * @return \FeedIo\Adapter\ResponseInterface
+ * @param DateTime $modifiedSince
+ *
+ * @return ResponseInterface
+ * @throws ServerErrorException|GuzzleException
+ * @throws NotFoundException
*/
- public function getResponse(string $url, \DateTime $modifiedSince) : ResponseInterface
+ public function getResponse(string $url, DateTime $modifiedSince) : ResponseInterface
{
$modifiedSince->setTimezone(new \DateTimeZone('GMT'));
try {
@@ -52,7 +55,11 @@ class FeedIoClient implements ClientInterface
]
];
- return new Response($this->guzzleClient->request('get', $url, $options));
+ $start = microtime(true);
+ $psrResponse = $this->guzzleClient->request('get', $url, $options);
+ $duration = intval(round(microtime(true) - $start, 3) * 1000);
+
+ return new Response($psrResponse, $duration);
} catch (BadResponseException $e) {
switch ((int) $e->getResponse()->getStatusCode()) {
case 404: