diff --git a/src/const.h b/src/const.h index 184fbab..d73efeb 100644 --- a/src/const.h +++ b/src/const.h @@ -1 +1,2 @@ -#define VERSION "0.5" \ No newline at end of file +#define VERSION "0.5" +#define NAME "bakatui" \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index e28a0f2..2e14d76 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5,6 +5,7 @@ #include "marks.h" #include "net.h" #include +#include #include #include #include @@ -12,9 +13,18 @@ #include #include #include +#include "const.h" std::string baka_api_url; +void PrintHelp() { + std::cout << "Usage: " << NAME << " [OPTIONS]" << "\n" + << "-h Show this help menu\n" + << "-v Show version\n" + << "-L Force new login\n"; + safe_exit(0); +} + int main(int argc, char **argv) { // signal handlers signal(SIGTERM, safe_exit); @@ -25,10 +35,17 @@ int main(int argc, char **argv) { // error signal handlers signal(SIGSEGV, safe_exit); - // marks_page(); - - { + int opt; + while ((opt = getopt(argc, argv, "vf:")) != -1) { // "f:" expects a value + switch (opt) { + case 'h': PrintHelp(); break; + case 'L': break; + case 'v': break; + default: /* handle error */; + } + } + std::string savedir_path = std::getenv("HOME"); savedir_path.append("/.local/share/bakatui"); std::string urlfile_path = std::string(savedir_path) + "/url"; diff --git a/src/main_menu.cpp b/src/main_menu.cpp index 9c0899a..a08c03b 100644 --- a/src/main_menu.cpp +++ b/src/main_menu.cpp @@ -12,7 +12,7 @@ #define CTRLD 4 char *choices[] = { - "login", "Marks", "shedule", "Komens", + "login", "Marks", "timetable", "Komens", "Homework", "Absence", "Exit", (char *)NULL, }; void (*choicesFuncs[])() = { diff --git a/src/marks.cpp b/src/marks.cpp index 6be4df8..41b1b86 100644 --- a/src/marks.cpp +++ b/src/marks.cpp @@ -58,7 +58,7 @@ void win_show(WINDOW *win, char *label, int label_color, int width, int height, void marks_page() { // DONT FORGET TO UNCOMMENT - json resp_from_api = bakaapi::get_grades(); + json resp_from_api = bakaapi::get_data_from_endpoint("api/3/marks"); // std::ifstream f("test-data/marks3.json"); // json resp_from_api = json::parse(f); diff --git a/src/net.cpp b/src/net.cpp index 351f2c8..baae879 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -155,21 +155,25 @@ void refresh_access_token() { access_token = resp_parsed["access_token"]; } - -json get_grades() { +void is_access_token_empty() { if(access_token.empty()) { json authfile_parsed = json::parse(SoRAuthFile(false, "")); access_token = authfile_parsed["access_token"]; } +} + +// supports all endpoints that only require access_token +json get_data_from_endpoint(std::string endpoint) { + is_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", GET, req_data); + auto [response, http_code] = send_curl_request(endpoint, GET, req_data); if(http_code != 200) { // DEBUG - std::clog << "Failed geting marks code: " << http_code << "\nrequest: " << req_data <<"\nresponse: " << response << std::endl; + std::clog << "Failed geting data from endpoint: " << endpoint << " code: " << http_code << "\nrequest: " << req_data <<"\nresponse: " << response << std::endl; refresh_access_token(); } diff --git a/src/net.h b/src/net.h index a909616..2f6191c 100644 --- a/src/net.h +++ b/src/net.h @@ -8,5 +8,5 @@ extern CURL *curl; namespace bakaapi { void login(std::string username, std::string password); void refresh_access_token(); -json get_grades(); +json get_data_from_endpoint(std::string endpoint); } // namespace bakaapi \ No newline at end of file diff --git a/src/timetable.cpp b/src/timetable.cpp new file mode 100644 index 0000000..3b3655f --- /dev/null +++ b/src/timetable.cpp @@ -0,0 +1,13 @@ +#include "timetable.h" + +#define NLINES 10 +#define NCOLS 40 + +#define DEFAULT_X_OFFSET 10 +#define DEFAULT_Y_OFFSET 2 + +#define DEFAULT_PADDING 4 + +void timetable_page() { + +} \ No newline at end of file diff --git a/src/timetable.h b/src/timetable.h new file mode 100644 index 0000000..f79d1b6 --- /dev/null +++ b/src/timetable.h @@ -0,0 +1 @@ +void timetable_page(); \ No newline at end of file