blob: 978bae71d86b8ddc85eed82c1ce0382e280f80fc (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
#include <curl/curl.h>
#include <format>
#include <iostream>
#include <pqxx/pqxx>
#include <string_view>
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;
}
|