(no commit message)
[prss.git] / src / ttrss.c
index ec67cc8..18b6369 100644 (file)
@@ -21,8 +21,9 @@
 #include <string.h>
 
 #include <json/json.h>
+#include <gtk/gtk.h>
 
-#include "phttp.h"
+#include "http.h"
 #include "ttrss.h"
 #include "url.h"
 
@@ -58,14 +59,13 @@ void ttrss_login(const char *url, const char *user, const char *password)
        strcat(session_url, "/api/");
        free(tmp);
 
-
        rq = create_op("login");
        json_object_object_add(rq, "user", json_object_new_string(user));
        json_object_object_add(rq,
                               "password",
                               json_object_new_string(password));
 
-       rp = post_json_object(session_url, rq);
+       rp = http_json_get(session_url, rq);
        json_object_put(rq);
 
        content = json_object_object_get(rp, "content");
@@ -94,6 +94,41 @@ void ttrss_login(const char *url, const char *user, const char *password)
        json_object_put(rp);
 }
 
+const char *ttrss_get_headline_content(struct headline *h)
+{
+       struct json_object *rp, *rq, *content, *array, *item;
+
+       printf("get_headlines %d\n", h->id);
+
+       if (!h->content) {
+               rq = create_op("getArticle");
+               json_object_object_add(rq, "article_id",
+                                      json_object_new_int(h->id));
+               
+               rp = http_json_get(session_url, rq);
+               
+               json_object_put(rq);
+               
+               array = json_object_object_get(rp, "content");
+
+               if (!array)
+                       goto release;
+
+               item = json_object_array_get_idx(array, 0);
+
+               if (!item)
+                       goto release;
+
+               content = json_object_object_get(item, "content");
+
+               h->content = strdup(json_object_get_string(content));
+                       
+       release:
+               json_object_put(rp);
+       }
+       return h->content;
+}
+
 static struct headline **get_headlines(int feed_id)
 {
        struct json_object *rp, *rq, *content, *jheadline, *j;
@@ -104,10 +139,8 @@ static struct headline **get_headlines(int feed_id)
 
        rq = create_op("getHeadlines");
        json_object_object_add(rq, "feed_id", json_object_new_int(feed_id));
-       json_object_object_add(rq, "show_excerpt", json_object_new_boolean(1));
-       json_object_object_add(rq, "show_content", json_object_new_boolean(1));
 
-       rp = post_json_object(session_url, rq);
+       rp = http_json_get(session_url, rq);
 
        json_object_put(rq);
 
@@ -121,14 +154,17 @@ static struct headline **get_headlines(int feed_id)
 
                        h = malloc(sizeof(struct headline));
 
+                       j = json_object_object_get(jheadline, "id");
+                       h->id = json_object_get_int(j);
+
                        j = json_object_object_get(jheadline, "title");
                        h->title = strdup(json_object_get_string(j));
 
-                       j = json_object_object_get(jheadline, "excerpt");
-                       h->excerpt = strdup(json_object_get_string(j));
+                       j = json_object_object_get(jheadline, "link");
+                       h->url = strdup(json_object_get_string(j));
 
-                       j = json_object_object_get(jheadline, "content");
-                       h->content = strdup(json_object_get_string(j));
+                       h->excerpt = NULL;
+                       h->content = NULL;
 
                        j = json_object_object_get(jheadline, "unread");
                        h->unread = json_object_get_boolean(j);
@@ -191,7 +227,7 @@ struct feed **ttrss_get_feeds()
 
        rq = create_op("getFeeds");
 
-       rp = post_json_object(session_url, rq);
+       rp = http_json_get(session_url, rq);
        json_object_put(rq);
 
        content = json_object_object_get(rp, "content");
@@ -241,3 +277,20 @@ struct headline **ttrss_get_headlines(struct feed *f)
 
        return f->headlines;
 }
+
+void ttrss_set_article_unread(int id, int unread)
+{
+       struct json_object *rp, *rq;
+
+       printf("ttrss_set_article_unread %d %d\n", id, unread);
+
+       rq = create_op("updateArticle");
+       json_object_object_add(rq, "article_ids", json_object_new_int(id));
+       json_object_object_add(rq, "field", json_object_new_int(2));
+       json_object_object_add(rq, "mode", json_object_new_int(unread));
+
+       rp = http_json_get(session_url, rq);
+       
+       json_object_put(rq);
+       json_object_put(rp);
+}