From d27b6aeb73679737ca921b5fc25a7b9c1f3c832c Mon Sep 17 00:00:00 2001 From: Aotrix <9aotrix@protonmail.com> Date: Fri, 31 Jul 2026 02:03:10 +0200 Subject: Remove GameMode enum class --- battleNetApi/src/main.cpp | 50 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 16 deletions(-) (limited to 'battleNetApi/src/main.cpp') diff --git a/battleNetApi/src/main.cpp b/battleNetApi/src/main.cpp index 64fa935..9d2ed86 100644 --- a/battleNetApi/src/main.cpp +++ b/battleNetApi/src/main.cpp @@ -4,12 +4,14 @@ #include #include #include +#include #include #include class DownloadMethod { public: - virtual nlohmann::json download(const std::shared_ptr &iToken) = 0; + virtual nlohmann::json download(const bnet::ApiUrl &iApiUrl, + const std::shared_ptr &iToken) = 0; virtual ~DownloadMethod() = default; }; @@ -17,15 +19,10 @@ class DefaultDownloadMethod : public DownloadMethod { public: DefaultDownloadMethod() = default; ~DefaultDownloadMethod() = default; - nlohmann::json download(const std::shared_ptr &iToken) override { - const std::string kContentType{"cards"}; - const std::string kRegion{"eu"}; - bnet::ApiUrl aApiUrl(kContentType, kRegion); - aApiUrl.setLocale("fr_FR"); - aApiUrl.setGameMode(bnet::GameMode::constructed); - aApiUrl.setPageSize(100); + nlohmann::json download(const bnet::ApiUrl &iApiUrl, + const std::shared_ptr &iToken) override { if (iToken) { - return bnet::HearthstoneApi::downloadCards(aApiUrl, *iToken); + return bnet::HearthstoneApi::downloadCards(iApiUrl, *iToken); } return nlohmann::json({}); }; @@ -39,9 +36,10 @@ class DownloaderContext { void setDownloadMethod(std::unique_ptr iDownloader) { mDownloader = std::move(iDownloader); } - nlohmann::json download(const std::shared_ptr &iToken) { + nlohmann::json download(const bnet::ApiUrl &iApiUrl, + const std::shared_ptr &iToken) { if (mDownloader) { - return mDownloader->download(iToken); + return mDownloader->download(iApiUrl, iToken); } else { std::cerr << "No download method available in DownloaderContext\n"; return nlohmann::json({}); @@ -52,16 +50,36 @@ class DownloaderContext { std::unique_ptr mDownloader; }; +bnet::ApiUrl computeApiUrl(nlohmann::json &iApiUrl) { + if (!iApiUrl.contains("ContentType") || !iApiUrl.contains("Region")) { + throw std::invalid_argument("computeApiUrl: missing ContentType and Region parameters"); + } + bnet::ApiUrl aApiUrl(iApiUrl["ContentType"], iApiUrl["Region"]); + if (iApiUrl.contains("Locale")) { + aApiUrl.setLocale(iApiUrl["Locale"]); + } + if (iApiUrl.contains("GameMode")) { + aApiUrl.setGameMode(iApiUrl["GameMode"]); + } + if (iApiUrl.contains("PageSize")) { + aApiUrl.setPageSize(iApiUrl["PageSize"]); + } + return aApiUrl; +} + int main(int argc, char *argv[]) { if (argc != 3) { - throw std::invalid_argument( - "/path/to/executable /path/to/credentials.json /path/to/output_file.json"); + throw std::invalid_argument("Provide following arguments: /path/to/executable " + "/path/to/configuration.json /path/to/output_file.json"); } DownloaderContext aDownloaderContext{std::make_unique()}; bnet::HearthstoneTokenBuilder aHearthstoneTokenBuilder(argv[1]); std::ofstream aOutputJsonFile(argv[2]); - aOutputJsonFile - << aDownloaderContext.download(aHearthstoneTokenBuilder.buildToken().getToken()).dump(4) - << '\n'; + aOutputJsonFile << aDownloaderContext + .download(computeApiUrl( + nlohmann::json::parse(std::ifstream(argv[1]))["ApiUrl"]), + aHearthstoneTokenBuilder.buildToken().getToken()) + .dump(4) + << '\n'; return 0; } -- cgit v1.2.3