From 820e76108bc85051d64431495d70f27379756cc8 Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Thu, 12 Sep 2019 18:05:01 +0200 Subject: Added liveapi support, and the maar tool (mark all as read) --- maar/CMakeLists.txt | 6 ++++++ maar/main.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 maar/CMakeLists.txt create mode 100644 maar/main.c (limited to 'maar') diff --git a/maar/CMakeLists.txt b/maar/CMakeLists.txt new file mode 100644 index 0000000..1062ba1 --- /dev/null +++ b/maar/CMakeLists.txt @@ -0,0 +1,6 @@ +file(GLOB_RECURSE SOURCES *.c) + +ADD_EXECUTABLE(rocket_maar ${SOURCES}) +target_link_libraries(rocket_maar common liveapi restapi) + +install(TARGETS rocket_maar DESTINATION bin) diff --git a/maar/main.c b/maar/main.c new file mode 100644 index 0000000..8ac0225 --- /dev/null +++ b/maar/main.c @@ -0,0 +1,54 @@ +#include +#include + +#include "common/config.h" +#include "common/cli.h" +#include "common/util.h" +#include "liveapi/liveapi.h" +#include "liveapi/messages.h" +#include "restapi/auth.h" +#include "restapi/subscriptions.h" +#include "restapi/users.h" + +void maar_subscription(const struct subscription* subscription) +{ + if (subscription->unread >0) { + printf("%s\n", subscription->name); + liveapi_mark_read(subscription->rid); + liveapi_step(); + } +} + +int main(void) +{ + if (config_load(CONFIG_PATH) != 0) { + return 1; + } + + const char* login = config_get_login(); + if (login == NULL) + login = common_cli_get_login(); + + const char* password = config_get_password(); + if (password == NULL) + password = common_cli_get_password(); + + const char * authToken = restapi_login(login, password); + if (authToken != NULL) { + liveapi_init(authToken); + struct subscription* subscriptions = restapi_subscriptions_get(); + printf("The following active subscriptions are marked as read :\n"); + common_subscriptions_const_walk(subscriptions, &maar_subscription); + common_subscriptions_free(subscriptions); + liveapi_step(); + liveapi_clean(); + restapi_logout(); + } else { + printf("Couldn't init rest api.\n"); + } + + config_clean(); + common_cli_free(); + + return 0; +} -- cgit v1.2.3