aboutsummaryrefslogtreecommitdiff
path: root/bridges/RainbowSixSiegeBridge.php
blob: 2d0762bd2995edafe1a954223eff3e7f73aa6b60 (plain) (blame)
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
<?php
class RainbowSixSiegeBridge extends BridgeAbstract {

	const MAINTAINER = 'corenting';
	const NAME = 'Rainbow Six Siege News';
	const URI = 'https://www.ubisoft.com/en-us/game/rainbow-six/siege/news-updates';
	const CACHE_TIMEOUT = 7200; // 2h
	const DESCRIPTION = 'Latest news about Rainbow Six Siege';

	// API key to call Ubisoft API, extracted from the React frontend
	const NIMBUS_API_KEY = '3u0FfSBUaTSew-2NVfAOSYWevVQHWtY9q3VM8Xx9Lto';

	public function getIcon() {
		return 'https://static-dm.akamaized.net/siege/prod/favicon.ico';
	}

	public function collectData(){
		$dlUrl = 'https://nimbus.ubisoft.com/api/v1/items?categoriesFilter=all';
		$dlUrl = $dlUrl . '&limit=6&mediaFilter=all&skip=0&startIndex=0&tags=BR-rainbow-six%20GA-siege';
		$dlUrl = $dlUrl . '&locale=en-us&fallbackLocale=en-us&environment=master';
		$jsonString = getContents($dlUrl, array(
			'Authorization: ' . self::NIMBUS_API_KEY
		));

		$json = json_decode($jsonString, true);
		$json = $json['items'];

		// Start at index 2 to remove highlighted articles
		for($i = 0; $i < count($json); $i++) {
			$jsonItem = $json[$i];

			$uri = 'https://www.ubisoft.com/en-us/game/rainbow-six/siege';
			$uri = $uri . $jsonItem['button']['buttonUrl'];

			$thumbnail = '<img src="' . $jsonItem['thumbnail']['url'] . '" alt="Thumbnail">';
			$content = $thumbnail . '<br />' . markdownToHtml($jsonItem['content']);

			$item = array();
			$item['uri'] = $uri;
			$item['id'] = $jsonItem['id'];
			$item['title'] = $jsonItem['title'];
			$item['content'] = $content;
			$item['timestamp'] = strtotime($jsonItem['date']);

			$this->items[] = $item;
		}
	}
}