#include "apiUrl.hpp" #include #include #include #include class DownloadMethod { public: virtual void download() = 0; virtual ~DownloadMethod() = default; }; class DefaultDownloadMethod : public DownloadMethod { public: 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 { public: DownloaderContext() = default; DownloaderContext(std::unique_ptr iDownloader) : mDownloader(std::move(iDownloader)) {}; void setDownloadMethod(std::unique_ptr iDownloader) { mDownloader = std::move(iDownloader); } void download() { if (mDownloader) { mDownloader->download(); } else { std::cerr << "No download method available in DownloaderContext\n"; } } private: std::unique_ptr 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("/ // "); // } // std::string aCredentialsFilePath{argv[1]}; // Token aToken(aCredentialsFilePath); // HearthstoneApi aHearthstoneApi(aToken); // std::string aOutputPath{argv[2]}; DownloaderContext aDownloaderContext; if (argc < 4) { aDownloaderContext.setDownloadMethod(std::make_unique()); } else { // TODO: retrieve config from JSON file } aDownloaderContext.download(); // std::ofstream aOutputJson(iOutputJsonPath); // aOutputJson << aMergedCards.dump(4); return 0; }