aboutsummaryrefslogtreecommitdiff
path: root/maar/main.c
blob: ee139076b22cbd83a2734b6fe12ee9aac219a3ea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#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"

void maar_subscription(const struct subscription* subscription)
{
    if (subscription->unread >0 || subscription->alert) {
        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;
}