diff --git a/Program.cs b/Program.cs index 5058523..07d5483 100644 --- a/Program.cs +++ b/Program.cs @@ -1,4 +1,5 @@ using Newtonsoft.Json; +using System.Linq; namespace ttrss_co_client { @@ -16,9 +17,18 @@ namespace ttrss_co_client var apiLevel = await ttrssClient.GetApiLevel(); Console.WriteLine($"api level: {apiLevel}"); - var counters = await ttrssClient.GetCounters(true, false, false, false); - Console.WriteLine($"{counters.Count()} counter{(counters.Count() == 1 ? "" : "s")} found"); - + var feeds = await ttrssClient.GetFeeds(cat_id: -3); + Console.WriteLine($"{feeds.Count()} feed{(feeds.Count() == 1 ? "" : "s")} found"); + var firstUnread = feeds.FirstOrDefault(f => f.unread > 0); + if(firstUnread != null) + { + Console.WriteLine($"first unread: {firstUnread.title} (id {firstUnread.id})"); + } + else + { + Console.WriteLine("no feeds unread."); + } + var loggedout = await ttrssClient.Logout(); Console.WriteLine($"logged out: {loggedout}"); diff --git a/ttrss/ApiClient.cs b/ttrss/ApiClient.cs index a925347..2feb4a1 100644 --- a/ttrss/ApiClient.cs +++ b/ttrss/ApiClient.cs @@ -89,10 +89,36 @@ namespace ttrss_co_client.ttrss var apiResult = JsonConvert.DeserializeObject(response); return apiResult.content; } - public async Task GetFeeds(int cat_id, bool unread_only, int limit, int offset, bool include_nested) + ///0 for all + ///skip this amount first + ///idk, doesn't affect what the documentation says it should + public async Task> GetFeeds(int cat_id = 0, bool unread_only=false, uint limit = 0, int offset = 0/*, bool include_nested*/) { assertInitialized(); - throw new NotImplementedException(); + if(cat_id <-2) + { + if(cat_id == -3 || cat_id == -4) + { + assertApiLevel(4); + } + else + { + throw new IndexOutOfRangeException($"cat_id {cat_id} is out of range"); + } + } + + var json = JsonContent.Create(new + { + op = "getFeeds", + sid = this.SessionId, + cat_id = cat_id, + unread_only = unread_only, + limit = limit, + offset = offset + }); + var response = await (await httpClient.PostAsync(BaseURI, json)).Content.ReadAsStringAsync(); + var apiResult = JsonConvert.DeserializeObject(response); + return apiResult.content; } public async Task GetCategories(bool unread_only, bool enable_nested, bool include_empty) { diff --git a/ttrss/datastructures/Feed.cs b/ttrss/datastructures/Feed.cs new file mode 100644 index 0000000..db84388 --- /dev/null +++ b/ttrss/datastructures/Feed.cs @@ -0,0 +1,26 @@ +using System.Collections.Generic; + +namespace ttrss_co_client.ttrss.datastructures +{ + ///"Counter Information" - not sure what that is + public class Feed + { + public int id { get; set; } + public Uri feed_url { get; set; } + public string title { get; set; } + public int unread { get; set; } + public bool has_icon { get; set; } + public int cat_id { get; set; } + ///unix timestamp, see + public int last_updated { get; set; } + public DateTime? TimeStamp + { + get + { + return new DateTime(1970,1,1,0,0,0,0,System.DateTimeKind.Utc) + .AddSeconds( last_updated ).ToLocalTime(); + } + } + public int order_id { get; set; } + } +} \ No newline at end of file diff --git a/ttrss/messages/FeedsResponse.cs b/ttrss/messages/FeedsResponse.cs new file mode 100644 index 0000000..ab59de5 --- /dev/null +++ b/ttrss/messages/FeedsResponse.cs @@ -0,0 +1,9 @@ +using ttrss_co_client.ttrss.datastructures; + +namespace ttrss_co_client.ttrss.messages +{ + public class FeedsResponse : ApiResponse + { + public IEnumerable content { get; set; } + } +} \ No newline at end of file