1
0
mirror of https://github.com/moparisthebest/wallabag synced 2024-12-18 05:32:23 -05:00

Fetch content using full-text-rss

This commit is contained in:
Vincent Jousse 2013-12-10 16:53:16 +01:00
parent efa4cca537
commit 6fe342d0e9
5 changed files with 38 additions and 7 deletions

View File

@ -1,6 +1,7 @@
<?php
use Knp\Provider\ConsoleServiceProvider;
use Poche\Api\EntryApi;
use Poche\Api\ContentFullTextRssApi;
use Poche\Repository\EntryRepository;
use Silex\Provider\FormServiceProvider;
@ -38,6 +39,12 @@ $app['entry_repository'] = $app->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']);
});

View File

@ -0,0 +1,17 @@
<?php
namespace Poche\Api;
use Poche\Util\Url;
class ContentFullTextRssApi
{
public function fetchUrl($url) {
$url = new Url($url);
$content = $url->extract();
return array('title' => $content['title'], 'content' => $content['body']);
}
}

View File

@ -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;
}

View File

@ -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];

View File

@ -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]"}');
}
}