#include "apiUrl.hpp" #include #include #include #include #include #include #include class DownloadMethod { public: virtual nlohmann::json download(const std::shared_ptr &iToken) = 0; virtual ~DownloadMethod() = default; }; class DefaultDownloadMethod : public DownloadMethod { public: DefaultDownloadMethod() = default; ~DefaultDownloadMethod() = default; nlohmann::json download(const std::shared_ptr &iToken) override { const std::string kContentType{"cards"}; const std::string kRegion{"eu"}; bnet::ApiUrl aApiUrl(kContentType, kRegion); aApiUrl.setLocale("fr_FR"); aApiUrl.setGameMode(bnet::GameMode::constructed); aApiUrl.setPageSize(100); if (iToken) { return bnet::HearthstoneApi::downloadCards(aApiUrl, *iToken); } return nlohmann::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); } nlohmann::json download(const std::shared_ptr &iToken) { if (mDownloader) { return mDownloader->download(iToken); } else { std::cerr << "No download method available in DownloaderContext\n"; return nlohmann::json({}); } } private: std::unique_ptr mDownloader; }; int main(int argc, char *argv[]) { if (argc != 3) { throw std::invalid_argument( "/path/to/executable /path/to/credentials.json /path/to/output_file.json"); } DownloaderContext aDownloaderContext{std::make_unique()}; bnet::HearthstoneTokenBuilder aHearthstoneTokenBuilder(argv[1]); std::ofstream aOutputJsonFile(argv[2]); aOutputJsonFile << aDownloaderContext.download(aHearthstoneTokenBuilder.buildToken().getToken()).dump(4) << '\n'; return 0; }