summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.cpp19
1 files changed, 15 insertions, 4 deletions
diff --git a/src/main.cpp b/src/main.cpp
index dbc9f8e..1fcbbe4 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -1,11 +1,10 @@
-#include <algorithm>
#include <cctype>
+#include <cstdlib>
#include <curl/curl.h>
#include <curl/easy.h>
-#include <format>
#include <iostream>
#include <pqxx/pqxx>
-#include <string_view>
+#include <regex>
const pqxx::result execute_query(pqxx::work &transaction,
std::string_view query) {
@@ -72,10 +71,22 @@ std::string get_valid_token() {
"MrMkhVMNdOeqPL4Q4XVQAsRPR14J7Yq6");
curl_easy_setopt(curl, CURLOPT_POSTFIELDS,
"grant_type=client_credentials");
- curl_easy_perform(curl);
+ CURLcode result_code;
+ result_code = curl_easy_perform(curl);
curl_easy_cleanup(curl);
+ if (result_code != CURLE_OK) {
+ std::cerr << "ERROR: token request failed" << std::endl;
+ std::exit(EXIT_FAILURE);
+ }
}
+ // FIXME: token_regex is not valid
+ std::regex token_regex("access_token:\"(\\w+)\"");
std::cout << output << std::endl;
+ auto token_it =
+ std::sregex_iterator(output.begin(), output.end(), token_regex);
+ std::smatch token = *token_it;
+ std::string token_str = token.str();
+ std::cout << std::format("Token trouvé: {}", token_str) << std::endl;
return "";
}