diff options
| author | Aotrix <[email protected]> | 2025-03-08 14:05:23 +0100 |
|---|---|---|
| committer | Aotrix <[email protected]> | 2025-03-08 14:05:23 +0100 |
| commit | df9887c3887f77f23550a0f02ad5716a0c017993 (patch) | |
| tree | abddbe10cbd5c267949ead21e64794ac0fa8cd19 /src/main.cpp | |
| parent | 0f3e727c72309dd37ed9a2276e5554963da18207 (diff) | |
simplified api calls
Diffstat (limited to 'src/main.cpp')
| -rw-r--r-- | src/main.cpp | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/src/main.cpp b/src/main.cpp index 40a6da7..5db146d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -119,12 +119,16 @@ std::string get_valid_token() { return token; } -const std::string get_url() { - // FIXME: not flexible - return "https://eu.api.blizzard.com/hearthstone/cards/678?locale=fr_FR"; +const std::string get_url(const std::string &t_parameters) { + return std::format("https://eu.api.blizzard.com/hearthstone/{}", + t_parameters); +} + +const std::string get_set_of_cards_url(const std::string &t_card_parameters) { + return get_url(std::format("cards/{}", t_card_parameters)); } -void display_result(pqxx::result t_r) { +void display_query_result(pqxx::result t_r) { // FIXME: not flexible for (auto row : t_r) { std::cout << std::format( @@ -135,13 +139,14 @@ void display_result(pqxx::result t_r) { } int main() { + // TODO: Create a class to simplify the calls pqxx::connection cx{ "postgresql://aotrix@localhost:5432/hearthstonegameinfo"}; pqxx::work tx{cx}; std::string access_token = get_valid_token(); std::string header = generate_request_header(access_token); - make_api_request(get_url(), header); + make_api_request(get_set_of_cards_url("100?locale=fr_FR"), header); std::cout << std::endl << std::endl; - display_result(execute_query(tx, "SELECT * FROM cards")); + display_query_result(execute_query(tx, "SELECT * FROM cards")); return 0; } |
