3 Copyright (C) 2018 rubenwardy <rw@rubenwardy.com>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include "content/packages.h"
25 #include "content/mods.h"
26 #include "content/subgames.h"
28 std::string Package::getDownloadURL(const std::string &baseURL) const
30 return baseURL + "/packages/" + author + "/" + name + "/releases/" +
31 std::to_string(release) + "/download/";
35 std::vector<Package> getPackagesFromURL(const std::string &url)
37 std::vector<std::string> extra_headers;
38 extra_headers.emplace_back("Accept: application/json");
40 Json::Value json = fetchJsonValue(url, &extra_headers);
41 if (!json.isArray()) {
42 errorstream << "Invalid JSON download " << std::endl;
43 return std::vector<Package>();
46 std::vector<Package> packages;
48 // Note: `unsigned int` is required to index JSON
49 for (unsigned int i = 0; i < json.size(); ++i) {
52 package.author = json[i]["author"].asString();
53 package.name = json[i]["name"].asString();
54 package.title = json[i]["title"].asString();
55 package.type = json[i]["type"].asString();
56 package.shortDesc = json[i]["shortDesc"].asString();
57 package.release = json[i]["release"].asInt();
58 if (json[i].isMember("thumbnail"))
59 package.thumbnail = json[i]["thumbnail"].asString();
62 packages.push_back(package);
64 errorstream << "Invalid package at " << i << std::endl;