blob: 7f2450e57fe35518a7995f0535c32a5506539345 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
#include "apiUrl.hpp"
#include <hearthstoneApi.hpp>
#include <iostream>
#include <print>
#include <tokenPool.hpp>
class DownloadMethod {
public:
virtual void download() = 0;
virtual ~DownloadMethod() = default;
};
class DefaultDownloadMethod : public DownloadMethod {
public:
DefaultDownloadMethod() = default;
~DefaultDownloadMethod() = default;
void 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.");
}
};
};
class DownloaderContext {
public:
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() {
if (mDownloader) {
mDownloader->download();
} else {
std::cerr << "No download method available in DownloaderContext\n";
}
}
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) {
aDownloaderContext.setDownloadMethod(std::make_unique<DefaultDownloadMethod>());
} else {
// TODO: retrieve config from JSON file
}
aDownloaderContext.download();
// std::ofstream aOutputJson(iOutputJsonPath);
// aOutputJson << aMergedCards.dump(4);
return 0;
}
|