#include "apiUrl.hpp" #include #include #include #include class DownloadMethod { public: virtual json download() = 0; virtual ~DownloadMethod() = default; }; class DefaultDownloadMethod : public DownloadMethod { public: DefaultDownloadMethod() = default; ~DefaultDownloadMethod() = default; 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::optional aToken{TokenPool::availableToken()}; if (aToken.has_value()) { HearthstoneApi::downloadCards(aApiUrl, aToken.value()); } return json({}); }; }; class DownloaderContext { public: DownloaderContext() = default; DownloaderContext(std::unique_ptr iDownloader) : mDownloader(std::move(iDownloader)) {}; void setDownloadMethod(std::unique_ptr iDownloader) { mDownloader = std::move(iDownloader); } json download() { if (mDownloader) { return mDownloader->download(); } else { std::cerr << "No download method available in DownloaderContext\n"; return json({}); } } private: std::unique_ptr mDownloader; }; int main(int argc, char *argv[]) { DownloaderContext aDownloaderContext; std::string aOutputJsonPath; if (argc < 4) { TokenPool::feedTokenSource("tests/resources/credentials.json"); aDownloaderContext.setDownloadMethod(std::make_unique()); aOutputJsonPath = "tests/output/list_of_cards.json"; } else { std::string aCredentialsFilePath{argv[1]}; TokenPool::feedTokenSource(aCredentialsFilePath); aOutputJsonPath = argv[2]; } std::ofstream aOutputJsonFile(aOutputJsonPath); aOutputJsonFile << aDownloaderContext.download().dump(4) << '\n'; return 0; }