Skip to content

Commit

Permalink
Fix Rue89 blog API
Browse files Browse the repository at this point in the history
  • Loading branch information
j0k3r committed Jul 24, 2016
1 parent 7a7f8a3 commit 9646433
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/FeedBundle/Extractor/Rue89.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
class Rue89 extends AbstractExtractor
{
protected $rue89Id = null;
protected $isBlog = false;

/**
* {@inheritdoc}
Expand All @@ -24,6 +25,8 @@ public function match($url)
return false;
}

$this->isBlog = 0 === strpos($path, '/blog/');

preg_match('/\-([0-9]+)$/i', $path, $matches);

if (!isset($matches[1])) {
Expand All @@ -44,9 +47,14 @@ public function getContent()
return '';
}

$host = 'api.rue89.nouvelobs.com';
if ($this->isBlog) {
$host = 'api.blogs.rue89.nouvelobs.com';
}

try {
$data = $this->client
->get('http://api.rue89.nouvelobs.com/export/mobile2/node/'.$this->rue89Id.'/full')
->get('http://'.$host.'/export/mobile2/node/'.$this->rue89Id.'/full')
->json();
} catch (RequestException $e) {
$this->logger->warning('Rue89 extract failed for: '.$this->rue89Id, [
Expand Down
27 changes: 27 additions & 0 deletions tests/FeedBundle/Extractor/Rue89Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public function dataMatch()
array('http://api.rue89.nouvelobs.com/2015/10/26/ils-protegent-vie-privee-autres-prejuges-les-allemands-261832', true),
array('https://api.rue89.nouvelobs.com/2015/10/26/ils-protegent-vie-privee-autres-prejuges-les-allemands-261832', true),
array('http://rue89.nouvelobs.com/2015/10/26/algorithmes-antimensonge-fin-bobards-politique-261827.html', false),
array('http://rue89.nouvelobs.com/blog/bad-taste/2016/07/18/fausses-bandes-annonces-le-net-permet-des-conneries-hallucinantes-235352', true),
array('http://rue89.nouvelobs.com/blog/extension-du-domaine-du-jeu/2016/07/22/pokemon-go-puise-dans-nos-instincts-les-plus-profonds-235356', true),
array('https://goog.co', false),
array('http://user@:80', false),
);
Expand Down Expand Up @@ -66,4 +68,29 @@ public function testContent()

$this->assertTrue($logHandler->hasWarning('Rue89 extract failed for: 261827'), 'Warning message matched');
}

public function testBlogContent()
{
$client = new Client();

$mock = new Mock([
new Response(200, [], Stream::factory(json_encode(array('node' => array('title' => 'my title', 'intro' => 'my description', 'imgTabletteCarousel' => 'http://0.0.0.0/img.jpg', 'body' => '<iframe/>'))))),
]);

$client->getEmitter()->attach($mock);

$rue89 = new Rue89();
$rue89->setClient($client);

$logHandler = new TestHandler();
$logger = new Logger('test', array($logHandler));
$rue89->setLogger($logger);

// first test fail because we didn't match an url, so Rue89Url isn't defined
$this->assertEmpty($rue89->getContent());

$rue89->match('http://rue89.nouvelobs.com/blog/extension-du-domaine-du-jeu/2016/07/22/pokemon-go-puise-dans-nos-instincts-les-plus-profonds-235356');

$this->assertEquals('<div><p>my description</p><p><img src="http://0.0.0.0/img.jpg"></p><iframe/></div>', $rue89->getContent());
}
}

0 comments on commit 9646433

Please sign in to comment.