summaryrefslogtreecommitdiff
path: root/bridges/Rue89Bridge.php
blob: ca0e9b66f9b6204246599ed83781d324095bf9a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
class Rue89Bridge extends BridgeAbstract {

	const MAINTAINER = 'teromene';
	const NAME = 'Rue89';
	const URI = 'https://www.nouvelobs.com/rue89/';
	const DESCRIPTION = 'Returns the newest posts from Rue89';


	public function collectData() {

		$jsonArticles = getContents('https://appdata.nouvelobs.com/rue89/feed.json')
				or die('Unable to query Rue89 !');
		$articles = json_decode($jsonArticles)->items;
		foreach($articles as $article) {
			$this->items[] = $this->getArticle($article);
		}

	}

	private function getArticle($articleInfo) {

		$articleJson = getContents($articleInfo->json_url) or die('Unable to get article !');
		$article = json_decode($articleJson);
		$item = array();
		$item['title'] = $article->title;
		$item['uri'] = $article->url;
		if($article->content_premium !== null) {
			$item['content'] = $article->content_premium;
		} else {
			$item['content'] = $article->content;
		}
		$item['timestamp'] = $article->date_publi;
		$item['author'] = $article->author->show_name;

		$item['enclosures'] = array();
		foreach($article->images as $image) {
			$item['enclosures'][] = $image->url;
		}

		$item['categories'] = array();
		foreach($article->categories as $category) {
			$item['categories'][] = $category->title;
		}

		return $item;

	}

}