summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAotrix <[email protected]>2025-03-08 23:13:49 +0100
committerAotrix <[email protected]>2025-03-08 23:13:49 +0100
commit9c280e05547671aa346530c4c7c0ddbc4729348f (patch)
tree3ef3c21d14c8b8c72c8d63c68e0c6d20a6ad835b /src
parent61425111dc8ac7aca986d87b524d7d4647306e2d (diff)
added std::string output
Diffstat (limited to 'src')
-rw-r--r--src/hearthstoneAPIHandler.cpp26
-rw-r--r--src/main.cpp2
2 files changed, 18 insertions, 10 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);
}
diff --git a/src/main.cpp b/src/main.cpp
index 60c921f..90a4fe6 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -19,7 +19,7 @@ void display_query_result(pqxx::result t_r) {
int main() {
HearthstoneAPIHandler hs_handler;
- hs_handler.get_cards("678?locale=en_US");
+ std::cout << hs_handler.get_cards("678?locale=en_US") << std::endl;
pqxx::connection cx{
"postgresql://aotrix@localhost:5432/hearthstonegameinfo"};