diff options
| author | Aotrix <[email protected]> | 2026-02-23 22:25:38 +0100 |
|---|---|---|
| committer | Aotrix <[email protected]> | 2026-02-23 22:25:38 +0100 |
| commit | 2fca87cdbf2da7fcb95bc38e6b09692720a18baf (patch) | |
| tree | a6170e512869f82952c5ad27259c9c56c27c6eee /battleNetApi | |
| parent | 2f698c83b6f5271f8753b69bfcd9aa3a6d532a50 (diff) | |
Added DownloadMethod class
Diffstat (limited to 'battleNetApi')
| -rw-r--r-- | battleNetApi/src/main.cpp | 69 | ||||
| -rw-r--r-- | battleNetApi/tests/tests.cpp | 2 |
2 files changed, 52 insertions, 19 deletions
diff --git a/battleNetApi/src/main.cpp b/battleNetApi/src/main.cpp index 43245d8..a1c64a3 100644 --- a/battleNetApi/src/main.cpp +++ b/battleNetApi/src/main.cpp @@ -3,30 +3,63 @@ #include <iostream> #include <stdexcept> -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>"); +class DownloadMethod { + public: + virtual void download() = 0; +}; + +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"; + } +}; + +class DownloaderContext { + public: + DownloaderContext() = default; + DownloaderContext(std::unique_ptr<DownloadMethod> iDownloader) : mDownloader(std::move(iDownloader)) {}; + void setDownloader(std::unique_ptr<DownloadMethod> iDownloader) { mDownloader = std::move(iDownloader); } + void download() { + if (mDownloader) { + mDownloader->download(); + } else { + std::cerr << "No download method available in DownloaderContext\n"; + } } - std::string aCredentialsFilePath{argv[1]}; - Token aToken(aCredentialsFilePath); - HearthstoneApi aHearthstoneApi(aToken); - std::string aOutputPath{argv[2]}; + private: + std::unique_ptr<DownloadMethod> mDownloader; +}; + +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; if (argc < 4) { - 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"; + aDownloaderContext.setDownloader(std::make_unique<DefaultDownloadMethod>()); } else { // TODO: retrieve config from JSON file } + aDownloaderContext.download(); return 0; } diff --git a/battleNetApi/tests/tests.cpp b/battleNetApi/tests/tests.cpp index d3321d3..cfb22e4 100644 --- a/battleNetApi/tests/tests.cpp +++ b/battleNetApi/tests/tests.cpp @@ -36,7 +36,7 @@ TEST_CASE("Retrieve number of cards", "[countCards]") { REQUIRE(kResponse.size() > 0); REQUIRE(kResponse.contains("pageCount")); std::uint64_t kNumberOfCards{kResponse["pageCount"]}; - REQUIRE(kNumberOfCards == 6033); + REQUIRE(kNumberOfCards == 6048); } TEST_CASE("Retrieve page once", "[retrievePageOnce]") { |
