summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAotrix <[email protected]>2026-08-16 03:04:45 +0200
committerAotrix <[email protected]>2026-08-16 03:04:45 +0200
commit8285cb8df3dd6643ac4d5fb927601c9f50546d38 (patch)
treefbacdcf6509e99e44db8aacff4cc05c3636e7542
parentd73b0731593f6ee2918e8480e29ec8082bf43803 (diff)
Update token content and file if needed
-rw-r--r--battleNetApi/src/main.cpp70
1 files changed, 47 insertions, 23 deletions
diff --git a/battleNetApi/src/main.cpp b/battleNetApi/src/main.cpp
index 9d2ed86..fa9de47 100644
--- a/battleNetApi/src/main.cpp
+++ b/battleNetApi/src/main.cpp
@@ -8,39 +8,52 @@
#include <stdexcept>
#include <tokenBuilder.hpp>
-class DownloadMethod {
+class DownloadMethod
+{
public:
- virtual nlohmann::json download(const bnet::ApiUrl &iApiUrl,
- const std::shared_ptr<bnet::Token> &iToken) = 0;
- virtual ~DownloadMethod() = default;
+ virtual nlohmann::json download(const bnet::ApiUrl& iApiUrl,
+ const std::shared_ptr<bnet::Token>& iToken) = 0;
+ virtual ~DownloadMethod() = default;
};
-class DefaultDownloadMethod : public DownloadMethod {
+class DefaultDownloadMethod : public DownloadMethod
+{
public:
- DefaultDownloadMethod() = default;
+ DefaultDownloadMethod() = default;
~DefaultDownloadMethod() = default;
- nlohmann::json download(const bnet::ApiUrl &iApiUrl,
- const std::shared_ptr<bnet::Token> &iToken) override {
- if (iToken) {
+
+ nlohmann::json download(const bnet::ApiUrl& iApiUrl,
+ const std::shared_ptr<bnet::Token>& iToken) override
+ {
+ if (iToken)
+ {
return bnet::HearthstoneApi::downloadCards(iApiUrl, *iToken);
}
return nlohmann::json({});
};
};
-class DownloaderContext {
+class DownloaderContext
+{
public:
DownloaderContext() = default;
DownloaderContext(std::unique_ptr<DownloadMethod> iDownloader)
: mDownloader(std::move(iDownloader)) {};
- void setDownloadMethod(std::unique_ptr<DownloadMethod> iDownloader) {
+
+ void setDownloadMethod(std::unique_ptr<DownloadMethod> iDownloader)
+ {
mDownloader = std::move(iDownloader);
}
- nlohmann::json download(const bnet::ApiUrl &iApiUrl,
- const std::shared_ptr<bnet::Token> &iToken) {
- if (mDownloader) {
+
+ nlohmann::json download(const bnet::ApiUrl& iApiUrl,
+ const std::shared_ptr<bnet::Token>& iToken)
+ {
+ if (mDownloader)
+ {
return mDownloader->download(iApiUrl, iToken);
- } else {
+ }
+ else
+ {
std::cerr << "No download method available in DownloaderContext\n";
return nlohmann::json({});
}
@@ -50,25 +63,33 @@ class DownloaderContext {
std::unique_ptr<DownloadMethod> mDownloader;
};
-bnet::ApiUrl computeApiUrl(nlohmann::json &iApiUrl) {
- if (!iApiUrl.contains("ContentType") || !iApiUrl.contains("Region")) {
+bnet::ApiUrl computeApiUrl(nlohmann::json& iApiUrl)
+{
+ if (!iApiUrl.contains("ContentType") || !iApiUrl.contains("Region"))
+ {
throw std::invalid_argument("computeApiUrl: missing ContentType and Region parameters");
}
bnet::ApiUrl aApiUrl(iApiUrl["ContentType"], iApiUrl["Region"]);
- if (iApiUrl.contains("Locale")) {
+ if (iApiUrl.contains("Locale"))
+ {
aApiUrl.setLocale(iApiUrl["Locale"]);
}
- if (iApiUrl.contains("GameMode")) {
+ if (iApiUrl.contains("GameMode"))
+ {
aApiUrl.setGameMode(iApiUrl["GameMode"]);
}
- if (iApiUrl.contains("PageSize")) {
+ if (iApiUrl.contains("PageSize"))
+ {
aApiUrl.setPageSize(iApiUrl["PageSize"]);
}
return aApiUrl;
}
-int main(int argc, char *argv[]) {
- if (argc != 3) {
+int main(int argc,
+ char* argv[])
+{
+ if (argc != 3)
+ {
throw std::invalid_argument("Provide following arguments: /path/to/executable "
"/path/to/configuration.json /path/to/output_file.json");
}
@@ -78,7 +99,10 @@ int main(int argc, char *argv[]) {
aOutputJsonFile << aDownloaderContext
.download(computeApiUrl(
nlohmann::json::parse(std::ifstream(argv[1]))["ApiUrl"]),
- aHearthstoneTokenBuilder.buildToken().getToken())
+ aHearthstoneTokenBuilder.allowBattleNetApiCall()
+ .allowUpdateSourceFile()
+ .buildToken()
+ .getToken())
.dump(4)
<< '\n';
return 0;