summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--battleNetApi/include/apiUrl.hpp1
-rw-r--r--battleNetApi/src/apiUrl.cpp24
-rw-r--r--battleNetApi/src/main.cpp23
3 files changed, 32 insertions, 16 deletions
diff --git a/battleNetApi/include/apiUrl.hpp b/battleNetApi/include/apiUrl.hpp
index 29851eb..9c051f1 100644
--- a/battleNetApi/include/apiUrl.hpp
+++ b/battleNetApi/include/apiUrl.hpp
@@ -11,6 +11,7 @@ class ApiUrl {
void setGameMode(const std::string &iGameMode);
void setPage(const std::string &iPage);
void setPageSize(const std::string &iPageSize);
+ void setValue(const std::string &iKey, const std::string &iValue);
std::string operator()() const;
private:
diff --git a/battleNetApi/src/apiUrl.cpp b/battleNetApi/src/apiUrl.cpp
index 7c05720..5435fd9 100644
--- a/battleNetApi/src/apiUrl.cpp
+++ b/battleNetApi/src/apiUrl.cpp
@@ -10,27 +10,37 @@ void ApiUrl::setRegion(const std::string &iRegion) {
}
void ApiUrl::setLocale(const std::string &iLocale) {
if (not iLocale.empty()) {
- aParameters["locale"] = iLocale; //!< The locale to reflect in localized data, e.g. "fr_FR" or "ko_KR"
- //!< If you do not supply a value, all translations are returned.
+ //!< The locale to reflect in localized data, e.g. "fr_FR" or "ko_KR"
+ //!< If you do not supply a value, all translations are returned.
+ const std::string kKey{"locale"};
+ setValue(kKey, iLocale);
}
}
void ApiUrl::setGameMode(const std::string &iGameMode) {
if (not iGameMode.empty()) {
- aParameters["gameMode"] =
- iGameMode; //!< A recognized game mode, e.g. "constructed"
- //!< @see https://community.developer.battle.net/documentation/hearthstone/guides/game-modes
+ //!< A recognized game mode, e.g. "constructed"
+ //!< @see https://community.developer.battle.net/documentation/hearthstone/guides/game-modes
+ const std::string kKey{"gameMode"};
+ setValue(kKey, iGameMode);
}
}
void ApiUrl::setPage(const std::string &iPage) {
if (not iPage.empty()) {
- aParameters["page"] = iPage; //!< The page to retrieve, e.g. "9"
+ //!< The page to retrieve, e.g. "9"
+ const std::string kKey{"page"};
+ setValue(kKey, iPage);
}
}
void ApiUrl::setPageSize(const std::string &iPageSize) {
if (not iPageSize.empty()) {
- aParameters["pageSize"] = iPageSize; //!< The number of results to choose per page, e.g. "40"
+ //!< The number of results to choose per page, e.g. "40"
+ const std::string kKey{"pageSize"};
+ setValue(kKey, iPageSize);
}
}
+
+void ApiUrl::setValue(const std::string &iKey, const std::string &iValue) { aParameters[iKey] = iValue; }
+
std::string ApiUrl::operator()() const {
std::string aFormattedParameters;
for (const auto &[key, value] : aParameters) {
diff --git a/battleNetApi/src/main.cpp b/battleNetApi/src/main.cpp
index 4e3885b..43245d8 100644
--- a/battleNetApi/src/main.cpp
+++ b/battleNetApi/src/main.cpp
@@ -13,15 +13,20 @@ int main(int argc, char *argv[]) {
Token aToken(aCredentialsFilePath);
HearthstoneApi aHearthstoneApi(aToken);
std::string aOutputPath{argv[2]};
- 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";
+
+ 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";
+ } else {
+ // TODO: retrieve config from JSON file
+ }
return 0;
}