#include "apiUrl.hpp" #include #include #include #include #include #include class DownloadMethod { public: virtual json download(const std::shared_ptr &iToken) = 0; virtual ~DownloadMethod() = default; }; class DefaultDownloadMethod : public DownloadMethod { public: DefaultDownloadMethod() = default; ~DefaultDownloadMethod() = default; json download(const std::shared_ptr &iToken) 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); if (iToken) { return HearthstoneApi::downloadCards(aApiUrl, *iToken); } 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(const std::shared_ptr &iToken) { if (mDownloader) { return mDownloader->download(iToken); } 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 aCredentialsFilePath; std::string aOutputJsonPath; if (argc < 3) { aCredentialsFilePath = "tests/resources/credentials.json"; aDownloaderContext.setDownloadMethod( std::make_unique()); aOutputJsonPath = "tests/output/list_of_cards.json"; } else { aCredentialsFilePath = argv[1]; aDownloaderContext.setDownloadMethod( std::make_unique()); aOutputJsonPath = argv[2]; } HearthstoneTokenBuilder aHearthstoneTokenBuilder(aCredentialsFilePath); std::ofstream aOutputJsonFile(aOutputJsonPath); aOutputJsonFile << aDownloaderContext .download( aHearthstoneTokenBuilder.buildToken().getToken()) .dump(4) << '\n'; return 0; }