From b0f58f5f400b284d6aff72a3cb77b045d664dd8a Mon Sep 17 00:00:00 2001 From: PoliEcho Date: Mon, 25 Nov 2024 13:27:30 +0100 Subject: [PATCH] qol changes --- src/helper_funcs.cpp | 35 +++++++++++++++++++++++++++++++---- src/main_menu.cpp | 1 + src/net.cpp | 15 ++++++++++++++- 3 files changed, 46 insertions(+), 5 deletions(-) diff --git a/src/helper_funcs.cpp b/src/helper_funcs.cpp index 5a6d38f..3960928 100644 --- a/src/helper_funcs.cpp +++ b/src/helper_funcs.cpp @@ -1,5 +1,7 @@ #include #include +#include +#include #include #include #include @@ -34,9 +36,34 @@ void safe_exit(int code) { } std::string bool_to_string(bool bool_in) { - if (bool_in) { - return "true"; + return bool_in ? "true" : "false"; +} + +std::string SoRAuthFile(bool save, std::string data){ + + std::string savedir_path = std::getenv("HOME"); + savedir_path.append("/.local/share/bakatui"); + + DIR *savedir = opendir(savedir_path.c_str()); + if (savedir) { + /* Directory exists. */ + closedir(savedir); + } else if (ENOENT == errno) { + /* Directory does not exist. */ + std::filesystem::create_directories(savedir_path); } else { - return "false"; + /* opendir() failed for some other reason. */ + std::cerr << "cannot access ~/.local/share/bakatui\n"; + safe_exit(100); } -} \ No newline at end of file + + std::string authfile_path = std::string(savedir_path) + "/auth"; + + if(save){ + + } else { + + } +} + + diff --git a/src/main_menu.cpp b/src/main_menu.cpp index 9b65ac1..5e77148 100644 --- a/src/main_menu.cpp +++ b/src/main_menu.cpp @@ -1,5 +1,6 @@ #include "helper_funcs.h" #include "net.h" +#include #include #include #include diff --git a/src/net.cpp b/src/net.cpp index f834986..c007799 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -161,5 +161,18 @@ void refresh_access_token() { access_token = resp_parsed["access_token"]; } -bool is_logged_in() {} +json get_grades() { + if(access_token.empty()) { + + } + std::string req_data = + std::format("Authorization=Bearer&access_token={}", + access_token); + + auto [response, http_code] = send_curl_request("api/3/marks", "POST", req_data); + + + + +} } // namespace bakaapi \ No newline at end of file