summaryrefslogtreecommitdiff
path: root/battleNetApi/src
diff options
context:
space:
mode:
Diffstat (limited to 'battleNetApi/src')
-rw-r--r--battleNetApi/src/main.cpp39
-rw-r--r--battleNetApi/src/tokenPool.cpp3
2 files changed, 17 insertions, 25 deletions
diff --git a/battleNetApi/src/main.cpp b/battleNetApi/src/main.cpp
index 7f2450e..4a5594c 100644
--- a/battleNetApi/src/main.cpp
+++ b/battleNetApi/src/main.cpp
@@ -1,12 +1,12 @@
#include "apiUrl.hpp"
+#include <fstream>
#include <hearthstoneApi.hpp>
#include <iostream>
-#include <print>
#include <tokenPool.hpp>
class DownloadMethod {
public:
- virtual void download() = 0;
+ virtual json download() = 0;
virtual ~DownloadMethod() = default;
};
@@ -14,20 +14,18 @@ class DefaultDownloadMethod : public DownloadMethod {
public:
DefaultDownloadMethod() = default;
~DefaultDownloadMethod() = default;
- void download() override {
+ 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::println("Downloading cards...");
- TokenPool::fillTokenSource("tests/resources/credentials.json");
std::optional<Token> aToken{TokenPool::unusedToken()};
if (aToken.has_value()) {
HearthstoneApi::downloadCards(aApiUrl, aToken.value());
- std::println("Download done.");
}
+ return json({});
};
};
@@ -36,11 +34,12 @@ class DownloaderContext {
DownloaderContext() = default;
DownloaderContext(std::unique_ptr<DownloadMethod> iDownloader) : mDownloader(std::move(iDownloader)) {};
void setDownloadMethod(std::unique_ptr<DownloadMethod> iDownloader) { mDownloader = std::move(iDownloader); }
- void download() {
+ json download() {
if (mDownloader) {
- mDownloader->download();
+ return mDownloader->download();
} else {
std::cerr << "No download method available in DownloaderContext\n";
+ return json({});
}
}
@@ -49,26 +48,18 @@ class DownloaderContext {
};
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;
+ std::string aOutputJsonPath;
if (argc < 4) {
+ TokenPool::fillTokenSource("tests/resources/credentials.json");
aDownloaderContext.setDownloadMethod(std::make_unique<DefaultDownloadMethod>());
+ aOutputJsonPath = "tests/output/list_of_cards.json";
} else {
- // TODO: retrieve config from JSON file
+ std::string aCredentialsFilePath{argv[1]};
+ TokenPool::fillTokenSource(aCredentialsFilePath);
+ aOutputJsonPath = argv[2];
}
- aDownloaderContext.download();
-
- // std::ofstream aOutputJson(iOutputJsonPath);
- // aOutputJson << aMergedCards.dump(4);
+ std::ofstream aOutputJsonFile(aOutputJsonPath);
+ aOutputJsonFile << aDownloaderContext.download().dump(4) << '\n';
return 0;
}
diff --git a/battleNetApi/src/tokenPool.cpp b/battleNetApi/src/tokenPool.cpp
index 20ea6cd..f8a6256 100644
--- a/battleNetApi/src/tokenPool.cpp
+++ b/battleNetApi/src/tokenPool.cpp
@@ -9,4 +9,5 @@ std::optional<std::string> TokenPool::unusedToken() {
return aOutputToken.text();
}
-void TokenPool::fillTokenSource(const std::string &iJsonPath) { mTokenContainer.emplace(Token(iJsonPath)); }
+void TokenPool::fillTokenSource(const std::string &iJsonPath) { // mTokenContainer.emplace(Token(iJsonPath));
+}