aboutsummaryrefslogtreecommitdiff
path: root/bridges/EpicGamesFreeBridge.php
blob: 087b95be7cd2313dc5cd4bf70004b7f449902b00 (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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php

class EpicGamesFreeBridge extends BridgeAbstract
{
    const NAME = 'Epic Games Free Games';
    const MAINTAINER = 'phantop';
    const URI = 'https://store.epicgames.com/';
    const DESCRIPTION = 'Returns the latest free games from Epic Games';
    const PARAMETERS = [ [
        'locale' => [
            'name' => 'Language',
            'type' => 'list',
            'values' => [
                'English' => 'en-US',
                'العربية' => 'ar',
                'Deutsch' => 'de',
                'Español (Spain)' => 'es-ES',
                'Español (LA)' => 'es-MX',
                'Français' => 'fr',
                'Italiano' => 'it',
                '日本語' => 'ja',
                '한국어' => 'ko',
                'Polski' => 'pl',
                'Português (Brasil)' => 'pt-BR',
                'Русский' => 'ru',
                'ไทย' => 'th',
                'Türkçe' => 'tr',
                '简体中文' => 'zh-CN',
                '繁體中文' => 'zh-Hant',
             ],
            'title' => 'Language for game information',
            'defaultValue' => 'en-US',
        ],
        'country' => [
            'name' => 'Country',
            'title' => 'Country store to check for deals',
            'defaultValue' => 'US',
        ]
    ]];

    public function collectData()
    {
        $url = 'https://store-site-backend-static.ak.epicgames.com/freeGamesPromotions?';
        $params = [
            'locale' => $this->getInput('locale'),
            'country' => $this->getInput('country'),
            'allowCountries' => $this->getInput('country'),
        ];
        $url .= http_build_query($params);
        $json = Json::decode(getContents($url));

        $data = $json['data']['Catalog']['searchStore']['elements'];
        foreach ($data as $element) {
            if (!isset($element['promotions']['promotionalOffers'][0])) {
                continue;
            }
            $item = [
                'author' => $element['seller']['name'],
                'content' => $element['description'],
                'enclosures' => array_map(fn($item) => $item['url'], $element['keyImages']),
                'timestamp' => strtotime($element['promotions']['promotionalOffers'][0]['promotionalOffers'][0]['startDate']),
                'title' => $element['title'],
                'url' => parent::getURI() . $this->getInput('locale') . '/p/' . $element['urlSlug'],
            ];
            $this->items[] = $item;
        }
    }

    public function getURI()
    {
        $uri = parent::getURI() . $this->getInput('locale') . '/free-games';
        return $uri;
    }
}