From f01072eb4166fc68f59519ebf84de46e7386abf5 Mon Sep 17 00:00:00 2001 From: Aotrix <9aotrix@protonmail.com> Date: Fri, 27 Mar 2026 18:48:55 +0100 Subject: Generate json card lists with static methods Instead of creating a useless instance of HearthstoneApi class, calls static methods. --- battleNetApi/src/main.cpp | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) (limited to 'battleNetApi/src/main.cpp') diff --git a/battleNetApi/src/main.cpp b/battleNetApi/src/main.cpp index 3c36a8d..7f2450e 100644 --- a/battleNetApi/src/main.cpp +++ b/battleNetApi/src/main.cpp @@ -1,27 +1,34 @@ #include "apiUrl.hpp" #include #include -#include +#include +#include class DownloadMethod { public: virtual void download() = 0; + virtual ~DownloadMethod() = default; }; class DefaultDownloadMethod : public DownloadMethod { public: - void download() { - std::cout << "OMG je suis une méthode de téléchargement !\n"; - // const std::string kContentType{"cards"}; - // const std::string kRegion{"eu"}; - // ApiUrl aApiUrl(kContentType, kRegion); - // aApiUrl.setLocale("fr_FR"); - // aApiUrl.setGameMode("constructed"); - // aApiUrl.setPageSize("100"); - // std::cout << "Downloading cards...\n"; - // aHearthstoneApi.downloadAllCards(aApiUrl, aOutputPath); - // std::cout << "Download done.\n"; - } + DefaultDownloadMethod() = default; + ~DefaultDownloadMethod() = default; + void download() override { + const std::string kContentType{"cards"}; + const std::string kRegion{"eu"}; + ApiUrl aApiUrl(kContentType, kRegion); + aApiUrl.setLocale("fr_FR"); + aApiUrl.setGameMode("constructed"); + aApiUrl.setPageSize("100"); + std::println("Downloading cards..."); + TokenPool::fillTokenSource("tests/resources/credentials.json"); + std::optional aToken{TokenPool::unusedToken()}; + if (aToken.has_value()) { + HearthstoneApi::downloadCards(aApiUrl, aToken.value()); + std::println("Download done."); + } + }; }; class DownloaderContext { @@ -61,5 +68,7 @@ int main(int argc, char *argv[]) { } aDownloaderContext.download(); + // std::ofstream aOutputJson(iOutputJsonPath); + // aOutputJson << aMergedCards.dump(4); return 0; } -- cgit v1.2.3