diff options
Diffstat (limited to 'src/hearthstoneAPIHandler.cpp')
| -rw-r--r-- | src/hearthstoneAPIHandler.cpp | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/src/hearthstoneAPIHandler.cpp b/src/hearthstoneAPIHandler.cpp index 78f084b..6528ed0 100644 --- a/src/hearthstoneAPIHandler.cpp +++ b/src/hearthstoneAPIHandler.cpp @@ -9,7 +9,7 @@ HearthstoneAPIHandler::HearthstoneAPIHandler() : m_access_token(get_valid_token()), m_header(generate_request_header()) {} -size_t HearthstoneAPIHandler::curl_callback_token_request(void *t_contents, +size_t HearthstoneAPIHandler::curl_callback_string_output(void *t_contents, size_t t_size, size_t t_nmemb, std::string *t_s) { @@ -47,7 +47,7 @@ void HearthstoneAPIHandler::write_new_token_info_to_file( curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L); curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, - curl_callback_token_request); + curl_callback_string_output); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &token_info); curl_easy_setopt(curl, CURLOPT_USERPWD, "2b50f1123b424d5e9c21971a110fdd04:" @@ -111,26 +111,34 @@ const std::string HearthstoneAPIHandler::get_set_of_cards_url( return get_url(std::format("cards/{}", t_card_parameters)); } -void HearthstoneAPIHandler::make_api_request(const char *t_url, - const char *t_header) { +std::string HearthstoneAPIHandler::make_api_request(const char *t_url, + const char *t_header) { CURL *curl = curl_easy_init(); + std::string request_output; if (curl) { curl_easy_setopt(curl, CURLOPT_URL, t_url); curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L); curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L); + curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, + curl_callback_string_output); + curl_easy_setopt(curl, CURLOPT_WRITEDATA, &request_output); struct curl_slist *chunk = nullptr; chunk = curl_slist_append(chunk, t_header); curl_easy_setopt(curl, CURLOPT_HTTPHEADER, chunk); curl_easy_perform(curl); curl_easy_cleanup(curl); } + return request_output; } -void HearthstoneAPIHandler::make_api_request(const std::string &t_url, - const std::string &t_header) { - make_api_request(t_url.c_str(), t_header.c_str()); +std::string +HearthstoneAPIHandler::make_api_request(const std::string &t_url, + const std::string &t_header) { + return make_api_request(t_url.c_str(), t_header.c_str()); } -void HearthstoneAPIHandler::get_cards(const std::string &t_card_parameters) { - make_api_request(get_set_of_cards_url(t_card_parameters), m_header); +std::string +HearthstoneAPIHandler::get_cards(const std::string &t_card_parameters) { + // TODO: Use a parser to generate a std::map or something like that + return make_api_request(get_set_of_cards_url(t_card_parameters), m_header); } |
