diff options
| author | Aotrix <[email protected]> | 2025-11-16 21:07:44 +0100 |
|---|---|---|
| committer | Aotrix <[email protected]> | 2025-11-16 21:07:44 +0100 |
| commit | e006ece3289c848ca2975f06386d6a2a51bdb67f (patch) | |
| tree | 1d72ae49b6a14cd43b3dec06ff78a7ae6d628f3c /subprojects/battleNetApi/src | |
| parent | 832e276e94d4d5a30885e6e352ffdd19f4f16f04 (diff) | |
Refactored JSON value retrieval
Diffstat (limited to 'subprojects/battleNetApi/src')
| -rw-r--r-- | subprojects/battleNetApi/src/apiUrl.cpp | 22 | ||||
| -rw-r--r-- | subprojects/battleNetApi/src/hearthstoneApi.cpp | 7 |
2 files changed, 21 insertions, 8 deletions
diff --git a/subprojects/battleNetApi/src/apiUrl.cpp b/subprojects/battleNetApi/src/apiUrl.cpp index e08c8c7..3de13cd 100644 --- a/subprojects/battleNetApi/src/apiUrl.cpp +++ b/subprojects/battleNetApi/src/apiUrl.cpp @@ -4,15 +4,29 @@ ApiUrl::ApiUrl(const std::string &iContentType, const std::string &iRegion) : mContentType{iContentType}, mRegion{iRegion} {} void ApiUrl::setRegion(const std::string &iRegion) { - mRegion = iRegion; //<! eu + if (not iRegion.empty()) { + mRegion = iRegion; //!< The region of the data to receive, e.g. "eu" + } } void ApiUrl::setLocale(const std::string &iLocale) { - aParameters["locale"] = iLocale; //<! fr_FR, ko_KR + 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. + } } void ApiUrl::setGameMode(const std::string &iGameMode) { - aParameters["gameMode"] = iGameMode; //<! constructed + 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 + } +} +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" + } } -std::string ApiUrl::operator()() { +std::string ApiUrl::operator()() const { std::string aFormattedParameters; for (const auto &[key, value] : aParameters) { aFormattedParameters += std::format("&{}={}", key, value); diff --git a/subprojects/battleNetApi/src/hearthstoneApi.cpp b/subprojects/battleNetApi/src/hearthstoneApi.cpp index b6eaf71..c34e6ad 100644 --- a/subprojects/battleNetApi/src/hearthstoneApi.cpp +++ b/subprojects/battleNetApi/src/hearthstoneApi.cpp @@ -4,11 +4,10 @@ HearthstoneApi::HearthstoneApi(Token &&iToken) : mToken(iToken), mAuthorizationHeader(authorizationHeader()) {} -std::uint64_t HearthstoneApi::numberOfCards() { - // TODO: implement logic - return 123456; +std::uint64_t HearthstoneApi::numberOfCards(const std::string &iApiResponse) const { + const std::string aCardCountRegex{"\"cardCount\":(\\d+)"}; + return valueInJson<std::uint64_t>(iApiResponse, aCardCountRegex); } - std::string HearthstoneApi::authorizationHeader() { return std::format("Authorization: Bearer {}", mToken.toString()); } size_t HearthstoneApi::curlCallbackStringOutput(void *iContent, size_t iSize, size_t iNmemb, std::string *iS) { |
