diff options
| author | Aotrix <[email protected]> | 2026-01-26 23:31:02 +0100 |
|---|---|---|
| committer | Aotrix <[email protected]> | 2026-01-26 23:31:02 +0100 |
| commit | ab280e7beef86d95335d0538fa1f6a6dfdd1125b (patch) | |
| tree | 84a74caddf998a2483f62a73d181521ec0622e3b /battleNetApi/include/hearthstoneApi.hpp | |
| parent | feac00e6819a9c9ad640a586d2fabb9e4e43f41e (diff) | |
added a test to count the number of cards
Diffstat (limited to 'battleNetApi/include/hearthstoneApi.hpp')
| -rw-r--r-- | battleNetApi/include/hearthstoneApi.hpp | 31 |
1 files changed, 5 insertions, 26 deletions
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 <iostream> -#include <regex> +#include <nlohmann/json.hpp> #include <string> +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 <typename T> 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; //<! Bearer authorization string for OAuth 2.0 header |
