2
* @file ttrss_source_feed.c tt-rss feed subscription routines
4
* Copyright (C) 2010-2011 Lars Lindner <lars.lindner@gmail.com>
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
32
#include "subscription.h"
34
#include "fl_sources/ttrss_source.h"
37
ttrss_feed_subscription_process_update_result (subscriptionPtr subscription, const struct updateResult* const result, updateFlags flags)
39
if (result->data && result->httpstatus == 200) {
40
JsonParser *parser = json_parser_new ();
42
if (json_parser_load_from_data (parser, result->data, -1, NULL)) {
43
JsonArray *array = json_node_get_array (json_get_node (json_parser_get_root (parser), "content"));
44
GList *iter = json_array_get_elements (array);
48
We expect to get something like this
55
"title":"IBM Says New ...",
56
"link":"http:\/\/rss.slashdot.org\/~r\/Slashdot\/slashdot\/~3\/ALuhNKO3NV4\/story01.htm",
58
"content":"coondoggie writes ..."
68
JsonNode *node = (JsonNode *)iter->data;
69
itemPtr item = item_new ();
71
item_set_id (item, g_strdup_printf ("%lld", json_get_int (node, "id")));
72
item_set_title (item, json_get_string (node, "title"));
73
item_set_source (item, json_get_string (node, "link"));
74
item_set_description (item, json_get_string (node, "content"));
75
item->time = json_get_int (node, "updated");
77
if (json_get_bool (node, "unread")) {
78
item->readStatus = FALSE;
81
item->readStatus = TRUE;
83
if (json_get_bool (node, "marked"))
84
item->flagStatus = TRUE;
86
items = g_list_append (items, (gpointer)item);
88
iter = g_list_next (iter);
91
/* merge against feed cache */
93
itemSetPtr itemSet = node_get_itemset (subscription->node);
94
gint newCount = itemset_merge_items (itemSet, items, TRUE /* feed valid */, FALSE /* markAsRead */);
95
itemlist_merge_itemset (itemSet);
96
itemset_free (itemSet);
98
feedlist_node_was_updated (subscription->node, newCount);
101
subscription->node->available = TRUE;
103
subscription->node->available = FALSE;
105
g_string_append (((feedPtr)subscription->node->data)->parseErrors, _("Could not parse JSON returned by tt-rss API!"));
108
subscription->node->available = FALSE;
113
ttrss_feed_subscription_prepare_update_request (subscriptionPtr subscription,
114
struct updateRequest *request)
116
debug0 (DEBUG_UPDATE, "ttrss_feed_subscription_prepare_update_request()");
117
nodePtr root = node_source_root_from_node (subscription->node);
118
ttrssSourcePtr source = (ttrssSourcePtr) root->data;
119
const gchar *feed_id;
121
debug0 (DEBUG_UPDATE, "preparing tt-rss feed subscription for update");
124
if (source->loginState == TTRSS_SOURCE_STATE_NONE) {
125
subscription_update (root->subscription, 0);
129
feed_id = metadata_list_get (subscription->metadata, "ttrss-feed-id");
131
g_warning ("tt-rss feed without id! (%s)", subscription->node->title);
134
update_request_set_source (request, g_strdup_printf (TTRSS_HEADLINES_URL,
135
metadata_list_get (root->subscription->metadata, "ttrss-url"),
138
15 /* items to fetch */));
143
struct subscriptionType ttrssSourceFeedSubscriptionType = {
144
ttrss_feed_subscription_prepare_update_request,
145
ttrss_feed_subscription_process_update_result