diff options
| author | Aotrix <[email protected]> | 2026-04-06 00:59:04 +0200 |
|---|---|---|
| committer | Aotrix <[email protected]> | 2026-04-06 00:59:04 +0200 |
| commit | 27459497a5ba0eac18a57e0c15b21972ab7e5284 (patch) | |
| tree | 7ff1c3d2769a866af90cfdb357e74db025e9329f /battleNetApi/src/main.cpp | |
| parent | 7b2f4cb4389d9d33cfabcbea20de43e6ea8654eb (diff) | |
Update main.cpp
Diffstat (limited to 'battleNetApi/src/main.cpp')
| -rw-r--r-- | battleNetApi/src/main.cpp | 39 |
1 files changed, 15 insertions, 24 deletions
diff --git a/battleNetApi/src/main.cpp b/battleNetApi/src/main.cpp index 7f2450e..4a5594c 100644 --- a/battleNetApi/src/main.cpp +++ b/battleNetApi/src/main.cpp @@ -1,12 +1,12 @@ #include "apiUrl.hpp" +#include <fstream> #include <hearthstoneApi.hpp> #include <iostream> -#include <print> #include <tokenPool.hpp> class DownloadMethod { public: - virtual void download() = 0; + virtual json download() = 0; virtual ~DownloadMethod() = default; }; @@ -14,20 +14,18 @@ class DefaultDownloadMethod : public DownloadMethod { public: DefaultDownloadMethod() = default; ~DefaultDownloadMethod() = default; - void download() override { + json 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<Token> aToken{TokenPool::unusedToken()}; if (aToken.has_value()) { HearthstoneApi::downloadCards(aApiUrl, aToken.value()); - std::println("Download done."); } + return json({}); }; }; @@ -36,11 +34,12 @@ class DownloaderContext { DownloaderContext() = default; DownloaderContext(std::unique_ptr<DownloadMethod> iDownloader) : mDownloader(std::move(iDownloader)) {}; void setDownloadMethod(std::unique_ptr<DownloadMethod> iDownloader) { mDownloader = std::move(iDownloader); } - void download() { + json download() { if (mDownloader) { - mDownloader->download(); + return mDownloader->download(); } else { std::cerr << "No download method available in DownloaderContext\n"; + return json({}); } } @@ -49,26 +48,18 @@ class DownloaderContext { }; int main(int argc, char *argv[]) { - // if (argc < 3) { - // // Example of parameters: - // // ./build/downloadCards tests/resources/credentials.json build/output.json - // throw std::invalid_argument("<path_to_executable_dir>/<executable_name> <path_to_credentials> - // <output_path>"); - // } - // std::string aCredentialsFilePath{argv[1]}; - // Token aToken(aCredentialsFilePath); - // HearthstoneApi aHearthstoneApi(aToken); - // std::string aOutputPath{argv[2]}; - DownloaderContext aDownloaderContext; + std::string aOutputJsonPath; if (argc < 4) { + TokenPool::fillTokenSource("tests/resources/credentials.json"); aDownloaderContext.setDownloadMethod(std::make_unique<DefaultDownloadMethod>()); + aOutputJsonPath = "tests/output/list_of_cards.json"; } else { - // TODO: retrieve config from JSON file + std::string aCredentialsFilePath{argv[1]}; + TokenPool::fillTokenSource(aCredentialsFilePath); + aOutputJsonPath = argv[2]; } - aDownloaderContext.download(); - - // std::ofstream aOutputJson(iOutputJsonPath); - // aOutputJson << aMergedCards.dump(4); + std::ofstream aOutputJsonFile(aOutputJsonPath); + aOutputJsonFile << aDownloaderContext.download().dump(4) << '\n'; return 0; } |
