From 6fe342d0e93a995da73a894fcb0e01354dc5dbb7 Mon Sep 17 00:00:00 2001 From: Vincent Jousse Date: Tue, 10 Dec 2013 16:53:16 +0100 Subject: [PATCH] Fetch content using full-text-rss --- app/app.php | 11 +++++++++-- src/Poche/Api/ContentFullTextRssApi.php | 17 +++++++++++++++++ src/Poche/Api/EntryApi.php | 9 +++++++-- src/Poche/Util/Url.php | 3 ++- tests/functionals/ApiTest.php | 5 +++-- 5 files changed, 38 insertions(+), 7 deletions(-) create mode 100644 src/Poche/Api/ContentFullTextRssApi.php diff --git a/app/app.php b/app/app.php index 4541be1..ce8389f 100644 --- a/app/app.php +++ b/app/app.php @@ -1,6 +1,7 @@ share(function ($app) { return new EntryRepository($app['db']); }); -$app['entry_api'] = $app->share(function ($app) { - return new EntryApi($app['entry_repository']); +$app['content_api'] = $app->share(function ($app) { + return new ContentFullTextRssApi(); }); + +$app['entry_api'] = $app->share(function ($app) { + return new EntryApi($app['entry_repository'], $app['content_api']); +}); + + diff --git a/src/Poche/Api/ContentFullTextRssApi.php b/src/Poche/Api/ContentFullTextRssApi.php new file mode 100644 index 0000000..a93b685 --- /dev/null +++ b/src/Poche/Api/ContentFullTextRssApi.php @@ -0,0 +1,17 @@ +extract(); + return array('title' => $content['title'], 'content' => $content['body']); + } +} diff --git a/src/Poche/Api/EntryApi.php b/src/Poche/Api/EntryApi.php index b526877..26f46e9 100644 --- a/src/Poche/Api/EntryApi.php +++ b/src/Poche/Api/EntryApi.php @@ -6,8 +6,9 @@ class EntryApi { private $entryRepository; - public function __construct($entryRepository) { + public function __construct($entryRepository, $contentApi) { $this->entryRepository = $entryRepository; + $this->contentApi = $contentApi; } public function getEntries() { @@ -18,8 +19,12 @@ class EntryApi //TODO: Fetch all what we need, fill the title, content … + $content = $this->contentApi->fetchUrl($url); + $entry = array( - 'url' => $url + 'url' => $url, + 'title' => $content['title'], + 'content' => $content['content'] ); return $entry; } diff --git a/src/Poche/Util/Url.php b/src/Poche/Util/Url.php index dae4c4e..7f3cfab 100644 --- a/src/Poche/Util/Url.php +++ b/src/Poche/Util/Url.php @@ -55,7 +55,7 @@ class Url function __construct($url) { - $this->url = base64_decode($url); + $this->url = $url; } public function getUrl() { @@ -136,6 +136,7 @@ class Url // look for full mime type (e.g. image/jpeg) or just type (e.g. image) $match[1] = strtolower(trim($match[1])); $match[2] = strtolower(trim($match[2])); + foreach (array($match[1], $match[2]) as $_mime) { if (isset($this->content_type_exc[$_mime])) { $type = $match[1]; diff --git a/tests/functionals/ApiTest.php b/tests/functionals/ApiTest.php index e7ab34b..147b2b1 100644 --- a/tests/functionals/ApiTest.php +++ b/tests/functionals/ApiTest.php @@ -59,7 +59,7 @@ class ApiTest extends PocheWebTestCase array(), array(), array('CONTENT_TYPE' => 'application/json'), - '{"url":"http:\/\/deboutlesgens.com\/blog\/le-courage-de-vivre-consciemment\/"}' + '{"url":"http:\/\/perdu.com"}' ); $this->assertEquals($client->getResponse()->getStatusCode(), 201); @@ -72,7 +72,8 @@ class ApiTest extends PocheWebTestCase ) ); - $this->assertEquals($client->getResponse()->getContent(),'{"url":"http:\/\/deboutlesgens.com\/blog\/le-courage-de-vivre-consciemment\/"}'); + $this->assertEquals($client->getResponse()->getContent(),'{"url":"http:\/\/perdu.com","title":"Vous Etes Perdu ?","content":"[unable to retrieve full-text content]"}'); + } }