diff --git a/src/komens.cpp b/src/komens.cpp new file mode 100644 index 0000000..05d1c05 --- /dev/null +++ b/src/komens.cpp @@ -0,0 +1,41 @@ +#include "const.h" +#include "helper_funcs.h" +#include "memory.h" +#include "net.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using nlohmann::json; + +std::vector komens_allocated; + +void komens_page() { + current_allocated = &komens_allocated; + json resp_from_api; + { + std::string endpoint = "api/3/komens"; + resp_from_api = bakaapi::get_data_from_endpoint(endpoint, GET); + } + setlocale(LC_ALL, ""); + /* Initialize curses */ + initscr(); + start_color(); + cbreak(); + noecho(); + keypad(stdscr, TRUE); + + /* Initialize all the colors */ + for (uint8_t i = 0; i < 8; i++) { + init_pair(i, i, COLOR_BLACK); + } +} \ No newline at end of file diff --git a/src/marks.cpp b/src/marks.cpp index bee4128..2420952 100644 --- a/src/marks.cpp +++ b/src/marks.cpp @@ -40,7 +40,7 @@ void marks_page() { json resp_from_api; { std::string endpoint = "api/3/marks"; - resp_from_api = bakaapi::get_data_from_endpoint(endpoint); + resp_from_api = bakaapi::get_data_from_endpoint(endpoint, GET); } size_t size_my_wins = resp_from_api["Subjects"].size(); WINDOW **my_wins = new (std::nothrow) WINDOW *[size_my_wins]; diff --git a/src/net.cpp b/src/net.cpp index 796657f..bededd3 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -20,12 +20,6 @@ using nlohmann::json; -// metods -enum metod { - GET, - POST, -}; - std::string access_token; CURL *curl = curl_easy_init(); @@ -159,7 +153,7 @@ void is_access_token_empty() { } // supports all endpoints that only require access_token -json get_data_from_endpoint(std::string &endpoint, +json get_data_from_endpoint(std::string &endpoint, metod metod, std::string additional_data) { is_access_token_empty(); access_token_refreshed: diff --git a/src/net.h b/src/net.h index ed81aac..9654734 100644 --- a/src/net.h +++ b/src/net.h @@ -5,12 +5,19 @@ #ifndef _ba_ne_hg_ #define _ba_ne_hg_ +// metods +enum metod { + GET, + POST, +}; + using nlohmann::json; extern CURL *curl; namespace bakaapi { void login(std::string username, std::string password); void refresh_access_token(); -json get_data_from_endpoint(std::string &endpoint, std::string data = ""); +json get_data_from_endpoint(std::string &endpoint, metod metod, + std::string additional_data = ""); } // namespace bakaapi #endif \ No newline at end of file diff --git a/src/timetable.cpp b/src/timetable.cpp index 8df7088..cef87ae 100644 --- a/src/timetable.cpp +++ b/src/timetable.cpp @@ -100,7 +100,8 @@ reload_for_new_week: std::string date_string = "date=" + date_stringstream.str(); std::string endpoint = "api/3/timetable/actual"; - json resp_from_api = bakaapi::get_data_from_endpoint(endpoint, date_string); + json resp_from_api = + bakaapi::get_data_from_endpoint(endpoint, GET, date_string); // this may be unnecessary but i dont have enaugh data to test it // it sorts the hours by start time