Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/jangernert/FeedReader.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrendan Long <self@brendanlong.com>2017-10-28 18:32:07 +0300
committerBrendan Long <self@brendanlong.com>2017-10-28 19:01:42 +0300
commitfa827348eded1d2ded3ffb2bbd02626c0eb841bf (patch)
tree57e1cc2825a0eabc0bb20dbacdaef3b7384fcacc
parent09400add79ce708c8179e4391f4610a2a5dc4f6d (diff)
Add support for the favicons Feedbin API
-rw-r--r--plugins/backend/feedbin/TestFeedbin.vala45
-rw-r--r--plugins/backend/feedbin/feedbinAPI.vala18
2 files changed, 63 insertions, 0 deletions
diff --git a/plugins/backend/feedbin/TestFeedbin.vala b/plugins/backend/feedbin/TestFeedbin.vala
index 090fad17..08a0417e 100644
--- a/plugins/backend/feedbin/TestFeedbin.vala
+++ b/plugins/backend/feedbin/TestFeedbin.vala
@@ -189,6 +189,51 @@ void add_login_tests(string host)
assert(starred_entries.contains(entry.id));
*/
});
+
+ Test.add_data_func ("/feedbinapi/favicons", () => {
+ if(username == null || password == null)
+ {
+ Test.skip(@"Need $user_env and $password_env set to run Feedbin tests");
+ return;
+ }
+
+ Bytes? expected_favicon;
+ {
+ var session = new Soup.Session();
+ var message = new Soup.Message("GET", "https://www.brendanlong.com/theme/favicon.ico");
+ var inputstream = session.send(message);
+ var bytearray = new ByteArray();
+ uint8[] buffer = new uint8[4096];
+ size_t bytes_read = 0;
+ do
+ {
+ inputstream.read_all(buffer, out bytes_read);
+ bytearray.append(buffer[0:bytes_read]);
+ }
+ while(bytes_read == 4096);
+ expected_favicon = ByteArray.free_to_bytes(bytearray);
+ }
+
+ var api = new FeedbinAPI(username, password, null, host);
+
+ // Note: This one shouldn't be deleted or recreated, since we want the entries to be available
+ var url = "https://www.brendanlong.com/feeds/all.atom.xml?feed-reader-test-favicons";
+
+ var subscription = api.add_subscription(url);
+ var favicons = api.get_favicons();
+ bool found_favicon = false;
+ foreach(var i in favicons.entries)
+ {
+ if(i.key != "www.brendanlong.com")
+ continue;
+ assert(i.value == expected_favicon);
+ // FIXME: We don't download icons on the test server because favicon downloading
+ // is handled by a different service
+ //found_favicon = true;
+ break;
+ }
+ assert(found_favicon);
+ });
}
void main(string[] args)
diff --git a/plugins/backend/feedbin/feedbinAPI.vala b/plugins/backend/feedbin/feedbinAPI.vala
index 89a5bf7f..faaa3ff1 100644
--- a/plugins/backend/feedbin/feedbinAPI.vala
+++ b/plugins/backend/feedbin/feedbinAPI.vala
@@ -389,4 +389,22 @@ public class FeedbinAPI : Object {
set_entries_status("starred_entries", entry_ids, starred);
}
+ public Gee.Map<string, Bytes?> get_favicons() throws FeedbinError
+ {
+ var root = get_json("favicons.json");
+ if(root == null)
+ return Gee.Map.empty<string, Bytes?>();
+
+ var favicons = new Gee.HashMap<string, Bytes?>();
+ var array = root.get_array();
+ for(var i = 0; i < array.get_length(); ++i)
+ {
+ var obj = array.get_object_element(i);
+ string host = obj.get_string_member("host");
+ var favicon_encoded = obj.get_string_member("favicon");
+ var favicon = favicon_encoded == null ? null : new Bytes.take(Base64.decode(favicon_encoded));
+ favicons.set(host, favicon);
+ }
+ return favicons;
+ }
}