From 8285cb8df3dd6643ac4d5fb927601c9f50546d38 Mon Sep 17 00:00:00 2001 From: Aotrix <9aotrix@protonmail.com> Date: Sun, 16 Aug 2026 03:04:45 +0200 Subject: Update token content and file if needed --- battleNetApi/src/main.cpp | 70 +++++++++++++++++++++++++++++++---------------- 1 file changed, 47 insertions(+), 23 deletions(-) (limited to 'battleNetApi/src/main.cpp') diff --git a/battleNetApi/src/main.cpp b/battleNetApi/src/main.cpp index 9d2ed86..fa9de47 100644 --- a/battleNetApi/src/main.cpp +++ b/battleNetApi/src/main.cpp @@ -8,39 +8,52 @@ #include #include -class DownloadMethod { +class DownloadMethod +{ public: - virtual nlohmann::json download(const bnet::ApiUrl &iApiUrl, - const std::shared_ptr &iToken) = 0; - virtual ~DownloadMethod() = default; + virtual nlohmann::json download(const bnet::ApiUrl& iApiUrl, + const std::shared_ptr& iToken) = 0; + virtual ~DownloadMethod() = default; }; -class DefaultDownloadMethod : public DownloadMethod { +class DefaultDownloadMethod : public DownloadMethod +{ public: - DefaultDownloadMethod() = default; + DefaultDownloadMethod() = default; ~DefaultDownloadMethod() = default; - nlohmann::json download(const bnet::ApiUrl &iApiUrl, - const std::shared_ptr &iToken) override { - if (iToken) { + + nlohmann::json download(const bnet::ApiUrl& iApiUrl, + const std::shared_ptr& iToken) override + { + if (iToken) + { return bnet::HearthstoneApi::downloadCards(iApiUrl, *iToken); } return nlohmann::json({}); }; }; -class DownloaderContext { +class DownloaderContext +{ public: DownloaderContext() = default; DownloaderContext(std::unique_ptr iDownloader) : mDownloader(std::move(iDownloader)) {}; - void setDownloadMethod(std::unique_ptr iDownloader) { + + void setDownloadMethod(std::unique_ptr iDownloader) + { mDownloader = std::move(iDownloader); } - nlohmann::json download(const bnet::ApiUrl &iApiUrl, - const std::shared_ptr &iToken) { - if (mDownloader) { + + nlohmann::json download(const bnet::ApiUrl& iApiUrl, + const std::shared_ptr& iToken) + { + if (mDownloader) + { return mDownloader->download(iApiUrl, iToken); - } else { + } + else + { std::cerr << "No download method available in DownloaderContext\n"; return nlohmann::json({}); } @@ -50,25 +63,33 @@ class DownloaderContext { std::unique_ptr mDownloader; }; -bnet::ApiUrl computeApiUrl(nlohmann::json &iApiUrl) { - if (!iApiUrl.contains("ContentType") || !iApiUrl.contains("Region")) { +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")) { + if (iApiUrl.contains("Locale")) + { aApiUrl.setLocale(iApiUrl["Locale"]); } - if (iApiUrl.contains("GameMode")) { + if (iApiUrl.contains("GameMode")) + { aApiUrl.setGameMode(iApiUrl["GameMode"]); } - if (iApiUrl.contains("PageSize")) { + if (iApiUrl.contains("PageSize")) + { aApiUrl.setPageSize(iApiUrl["PageSize"]); } return aApiUrl; } -int main(int argc, char *argv[]) { - if (argc != 3) { +int main(int argc, + char* argv[]) +{ + if (argc != 3) + { throw std::invalid_argument("Provide following arguments: /path/to/executable " "/path/to/configuration.json /path/to/output_file.json"); } @@ -78,7 +99,10 @@ int main(int argc, char *argv[]) { aOutputJsonFile << aDownloaderContext .download(computeApiUrl( nlohmann::json::parse(std::ifstream(argv[1]))["ApiUrl"]), - aHearthstoneTokenBuilder.buildToken().getToken()) + aHearthstoneTokenBuilder.allowBattleNetApiCall() + .allowUpdateSourceFile() + .buildToken() + .getToken()) .dump(4) << '\n'; return 0; -- cgit v1.2.3