summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAotrix <[email protected]>2026-02-23 22:25:38 +0100
committerAotrix <[email protected]>2026-02-23 22:25:38 +0100
commit2fca87cdbf2da7fcb95bc38e6b09692720a18baf (patch)
treea6170e512869f82952c5ad27259c9c56c27c6eee
parent2f698c83b6f5271f8753b69bfcd9aa3a6d532a50 (diff)
Added DownloadMethod class
-rw-r--r--battleNetApi/src/main.cpp69
-rw-r--r--battleNetApi/tests/tests.cpp2
-rw-r--r--gameView/main.cpp2
3 files changed, 53 insertions, 20 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]") {
diff --git a/gameView/main.cpp b/gameView/main.cpp
index 6f4e145..5b3a1ae 100644
--- a/gameView/main.cpp
+++ b/gameView/main.cpp
@@ -31,7 +31,7 @@ void configureMainMenuBar(QMenuBar &iMenuBar) {
int main(int argc, char *argv[]) {
QApplication aApplication(argc, argv);
QWidget aWindow;
- aWindow.resize(500, 700);
+ aWindow.resize(440, 650);
// Set Dialog flag for i3 users
aWindow.setWindowFlag(Qt::WindowType::Dialog);