From 832e276e94d4d5a30885e6e352ffdd19f4f16f04 Mon Sep 17 00:00:00 2001 From: Aotrix <9aotrix@protonmail.com> Date: Tue, 11 Nov 2025 18:02:09 +0100 Subject: added parameters --- subprojects/battleNetApi/include/apiUrl.hpp | 9 ++++++--- subprojects/battleNetApi/include/token.hpp | 2 +- subprojects/battleNetApi/src/apiUrl.cpp | 14 +++++++++----- subprojects/battleNetApi/src/token.cpp | 4 ++-- subprojects/battleNetApi/tests/tests.cpp | 4 +++- 5 files changed, 21 insertions(+), 12 deletions(-) (limited to 'subprojects/battleNetApi') diff --git a/subprojects/battleNetApi/include/apiUrl.hpp b/subprojects/battleNetApi/include/apiUrl.hpp index cefce0b..12124c6 100644 --- a/subprojects/battleNetApi/include/apiUrl.hpp +++ b/subprojects/battleNetApi/include/apiUrl.hpp @@ -4,12 +4,15 @@ class ApiUrl { public: - ApiUrl(const std::string iContentType); - void setLocale(const std::string iLocale); - void setGameMode(const std::string iGameMode); + ApiUrl(const std::string &iContentType, const std::string &iRegion); + + void setRegion(const std::string &iRegion); + void setLocale(const std::string &iLocale); + void setGameMode(const std::string &iGameMode); std::string operator()(); private: std::string mContentType; + std::string mRegion; std::unordered_map aParameters; }; diff --git a/subprojects/battleNetApi/include/token.hpp b/subprojects/battleNetApi/include/token.hpp index fc5e19a..def5dc2 100644 --- a/subprojects/battleNetApi/include/token.hpp +++ b/subprojects/battleNetApi/include/token.hpp @@ -18,7 +18,7 @@ class Token { void writeTokenToFile(const std::string &iToken) const; std::string getValidTokenWithApi() const; std::chrono::seconds getCurrentTime() const; - std::string extractFirstMatchRegex(const std::string &t_str, const std::string &t_regex) const; + std::string extractTokenWithRegex(const std::string &t_str, const std::string &t_regex) const; static size_t curlCallbackStringOutput(void *t_contents, size_t t_size, size_t t_nmemb, std::string *t_s); friend class TokenTests; diff --git a/subprojects/battleNetApi/src/apiUrl.cpp b/subprojects/battleNetApi/src/apiUrl.cpp index 89f7a5f..e08c8c7 100644 --- a/subprojects/battleNetApi/src/apiUrl.cpp +++ b/subprojects/battleNetApi/src/apiUrl.cpp @@ -1,11 +1,15 @@ #include "apiUrl.hpp" #include -ApiUrl::ApiUrl(const std::string iContentType) : mContentType{iContentType} {} -void ApiUrl::setLocale(const std::string iLocale) { - aParameters["locale"] = iLocale; //(std::chrono::utc_clock::now().time_since_epoch()); } -std::string Token::extractFirstMatchRegex(const std::string &iText, const std::string &iRegex) const { +std::string Token::extractTokenWithRegex(const std::string &iText, const std::string &iRegex) const { std::regex regex(iRegex); auto aMatchBegin = std::sregex_iterator(iText.begin(), iText.end(), regex); auto aMatchEnd = std::sregex_iterator(); diff --git a/subprojects/battleNetApi/tests/tests.cpp b/subprojects/battleNetApi/tests/tests.cpp index 6994d2f..368a767 100644 --- a/subprojects/battleNetApi/tests/tests.cpp +++ b/subprojects/battleNetApi/tests/tests.cpp @@ -45,7 +45,9 @@ TEST_CASE("Retrieve number of pages", "[getPagesCount]") { TEST_CASE("Retrieve cards", "[retrieveCards]") { HearthstoneApiMock aHearthstoneApi; - ApiUrl aApiUrl("cards"); + const std::string kContentType{"cards"}; + const std::string kRegion{"eu"}; + ApiUrl aApiUrl(kContentType, kRegion); aApiUrl.setLocale("fr_FR"); aApiUrl.setGameMode("constructed"); std::cout << aHearthstoneApi.makeApiRequest(aApiUrl()) << '\n'; -- cgit v1.2.3