diff options
| author | Aotrix <[email protected]> | 2025-03-05 21:55:42 +0100 |
|---|---|---|
| committer | Aotrix <[email protected]> | 2025-03-05 21:55:42 +0100 |
| commit | cdd357cdb3f6165c9e68a3b3051b63f901ad3365 (patch) | |
| tree | f2d69e72927e0fc81728b86f99dc9bef60f4b845 /src/main.cpp | |
| parent | afbca22035804f7fc65032d0c66bf198e7739bd5 (diff) | |
added curl lib
Diffstat (limited to 'src/main.cpp')
| -rw-r--r-- | src/main.cpp | 40 |
1 files changed, 32 insertions, 8 deletions
diff --git a/src/main.cpp b/src/main.cpp index 4282118..978bae7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,20 +1,44 @@ +#include <curl/curl.h> #include <format> #include <iostream> #include <pqxx/pqxx> +#include <string_view> -// TODO: Parser les cartes - -int main() { - // TODO: Récupérer le nombre de cartes - pqxx::connection cx{ - "postgresql://aotrix@localhost:5432/hearthstonegameinfo"}; - pqxx::work tx{cx}; - pqxx::result r{tx.exec("SELECT * FROM cards")}; +void display_result(pqxx::result r) { + // FIXME: not flexible for (auto row : r) { std::cout << std::format( "{}; {}; {}; {}; {}", row[0].as<std::string>(), row[1].as<std::string>(), row[2].as<std::string>(), row[3].as<std::string>(), row[4].as<std::string>()); } +} + +const pqxx::result execute_query(pqxx::work &transaction, + std::string_view query) { + return transaction.exec(query); +} + +void do_curl_request(const char *url) { + CURL *curl = curl_easy_init(); + if (curl) { + CURLcode res; + curl_easy_setopt(curl, CURLOPT_URL, url); + res = curl_easy_perform(curl); + curl_easy_cleanup(curl); + } +} + +int main() { + pqxx::connection cx{ + "postgresql://aotrix@localhost:5432/hearthstonegameinfo"}; + pqxx::work tx{cx}; + std::string_view access_token{"EUCCbw5IzCx5gF4PMJLT7zGAFs0RSxRhqK"}; + std::string_view header{ + std::format("Authorization: Bearer {}", access_token)}; + // TODO: add header to curl request + do_curl_request( + "https://eu.api.blizzard.com/hearthstone/cards/678?locale=fr_FR"); + // display_result(execute_query(tx, "SELECT * FROM cards")); return 0; } |
