diff options
author | Julien Dessaux | 2019-09-12 18:05:01 +0200 |
---|---|---|
committer | Julien Dessaux | 2019-09-12 18:10:36 +0200 |
commit | 820e76108bc85051d64431495d70f27379756cc8 (patch) | |
tree | 78a9c901b5ea6c349baf0213de43cd69781ec95f /maar | |
parent | Reduced the scope of a useless global variable to static (diff) | |
download | rocket-cli-client-820e76108bc85051d64431495d70f27379756cc8.tar.gz rocket-cli-client-820e76108bc85051d64431495d70f27379756cc8.tar.bz2 rocket-cli-client-820e76108bc85051d64431495d70f27379756cc8.zip |
Added liveapi support, and the maar tool (mark all as read)
Diffstat (limited to 'maar')
-rw-r--r-- | maar/CMakeLists.txt | 6 | ||||
-rw-r--r-- | maar/main.c | 54 |
2 files changed, 60 insertions, 0 deletions
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 <stdlib.h> +#include <stdio.h> + +#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; +} |