From ab280e7beef86d95335d0538fa1f6a6dfdd1125b Mon Sep 17 00:00:00 2001 From: Aotrix <9aotrix@protonmail.com> Date: Mon, 26 Jan 2026 23:31:02 +0100 Subject: added a test to count the number of cards --- battleNetApi/include/hearthstoneApi.hpp | 31 +++++-------------------------- 1 file changed, 5 insertions(+), 26 deletions(-) (limited to 'battleNetApi/include') diff --git a/battleNetApi/include/hearthstoneApi.hpp b/battleNetApi/include/hearthstoneApi.hpp index c11acc7..72f5141 100644 --- a/battleNetApi/include/hearthstoneApi.hpp +++ b/battleNetApi/include/hearthstoneApi.hpp @@ -1,41 +1,20 @@ #pragma once #include "token.hpp" -#include -#include +#include #include +using json = nlohmann::json; + class HearthstoneApi { public: + HearthstoneApi(const Token &iToken); HearthstoneApi(Token &&iToken); - std::uint64_t numberOfCards(const std::string &iApiResponse) const; + json makeApiRequest(const std::string &iUrl) const; private: std::string authorizationHeader(); - std::string makeApiRequest(const std::string &iUrl) const; static size_t curlCallbackStringOutput(void *iContent, size_t iSize, size_t iNmemb, std::string *iS); - /** - * @brief - * @param[in] iJsonContent The std::string which contains Json (Battle.net API response for instance) - * @param[in] iKeyValueRegex The regex used to retrieve value from (key, value) pair - * An example: "\"cardCount\":(\\d+)" - */ - template T valueInJson(const std::string &iJsonContent, const std::string &iKeyValueRegex) const { - const std::regex iRegex{iKeyValueRegex}; - std::smatch aMatches; - if (std::regex_search(iJsonContent, aMatches, iRegex)) { - const std::string kValueString{aMatches[1].str()}; - T aValue; - const auto kConversionStatus = - std::from_chars(kValueString.data(), kValueString.data() + kValueString.size(), aValue); - if (kConversionStatus.ec == std::errc{}) { - return aValue; - } - } - std::cerr << std::format("Unable to find value with regex: '{}'\n", iKeyValueRegex); - return 0; - } - Token mToken; std::string mAuthorizationHeader; //