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/src/hearthstoneApi.cpp | |
| parent | feac00e6819a9c9ad640a586d2fabb9e4e43f41e (diff) | |
added a test to count the number of cards
Diffstat (limited to 'battleNetApi/src/hearthstoneApi.cpp')
| -rw-r--r-- | battleNetApi/src/hearthstoneApi.cpp | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/battleNetApi/src/hearthstoneApi.cpp b/battleNetApi/src/hearthstoneApi.cpp index 026737a..945425f 100644 --- a/battleNetApi/src/hearthstoneApi.cpp +++ b/battleNetApi/src/hearthstoneApi.cpp @@ -3,11 +3,8 @@ #include <format> HearthstoneApi::HearthstoneApi(Token &&iToken) : mToken(iToken), mAuthorizationHeader(authorizationHeader()) {} +HearthstoneApi::HearthstoneApi(const Token &iToken) : mToken(iToken), mAuthorizationHeader(authorizationHeader()) {} -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.text()); } size_t HearthstoneApi::curlCallbackStringOutput(void *iContent, size_t iSize, size_t iNmemb, std::string *iS) { @@ -21,20 +18,21 @@ size_t HearthstoneApi::curlCallbackStringOutput(void *iContent, size_t iSize, si return kNewLength; } -std::string HearthstoneApi::makeApiRequest(const std::string &iUrl) const { +json HearthstoneApi::makeApiRequest(const std::string &iUrl) const { CURL *curl = curl_easy_init(); - std::string request_output; + std::string aRequestOutput; if (curl) { curl_easy_setopt(curl, CURLOPT_URL, iUrl.c_str()); curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L); curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, curlCallbackStringOutput); - curl_easy_setopt(curl, CURLOPT_WRITEDATA, &request_output); + curl_easy_setopt(curl, CURLOPT_WRITEDATA, &aRequestOutput); struct curl_slist *chunk = nullptr; chunk = curl_slist_append(chunk, mAuthorizationHeader.c_str()); curl_easy_setopt(curl, CURLOPT_HTTPHEADER, chunk); curl_easy_perform(curl); curl_easy_cleanup(curl); } - return request_output; + json aOutputJson = json::parse(aRequestOutput); + return aOutputJson; } |
