diff --git a/Program.cs b/Program.cs index 07d5483..ea3106d 100644 --- a/Program.cs +++ b/Program.cs @@ -17,16 +17,16 @@ namespace ttrss_co_client var apiLevel = await ttrssClient.GetApiLevel(); Console.WriteLine($"api level: {apiLevel}"); - 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); + var cats = await ttrssClient.GetCategories(include_empty: true); + Console.WriteLine($"{cats.Count()} categor{(cats.Count() == 1 ? "y" : "ies")} found"); + var firstUnread = cats.FirstOrDefault(f => f.unread > 0); if(firstUnread != null) { Console.WriteLine($"first unread: {firstUnread.title} (id {firstUnread.id})"); } else { - Console.WriteLine("no feeds unread."); + Console.WriteLine("no categories with feeds with unread articles."); } var loggedout = await ttrssClient.Logout(); diff --git a/ttrss/ApiClient.cs b/ttrss/ApiClient.cs index 2feb4a1..ddb9ef1 100644 --- a/ttrss/ApiClient.cs +++ b/ttrss/ApiClient.cs @@ -120,10 +120,23 @@ namespace ttrss_co_client.ttrss var apiResult = JsonConvert.DeserializeObject(response); return apiResult.content; } - public async Task GetCategories(bool unread_only, bool enable_nested, bool include_empty) + ///nested mode (return only top level) + public async Task> GetCategories(bool unread_only = false, bool enable_nested = false, bool include_empty = false) { assertInitialized(); - throw new NotImplementedException(); + + var json = JsonContent.Create(new + { + op = "getCategories", + sid = this.SessionId, + unread_only = unread_only, + enable_nested = enable_nested, + include_empty = include_empty + }); + var response = await (await httpClient.PostAsync(BaseURI, json)).Content.ReadAsStringAsync(); + var apiResult = JsonConvert.DeserializeObject(response); + return apiResult.content; + } public enum VIEWMODE { All, Unread, Adaptive, Marked, Updated } public enum SORTORDER { Default, OldestFirst, NewestFirst } diff --git a/ttrss/datastructures/Category.cs b/ttrss/datastructures/Category.cs new file mode 100644 index 0000000..c1cc3ae --- /dev/null +++ b/ttrss/datastructures/Category.cs @@ -0,0 +1,12 @@ +using System.Collections.Generic; + +namespace ttrss_co_client.ttrss.datastructures +{ + public class Category + { + public int id { get; set; } + public string title { get; set; } + public int unread { get; set; } + public int order_id { get; set; } + } +} \ No newline at end of file diff --git a/ttrss/datastructures/Feed.cs b/ttrss/datastructures/Feed.cs index db84388..61ae180 100644 --- a/ttrss/datastructures/Feed.cs +++ b/ttrss/datastructures/Feed.cs @@ -2,7 +2,6 @@ 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; } diff --git a/ttrss/messages/CategoriesResponse.cs b/ttrss/messages/CategoriesResponse.cs new file mode 100644 index 0000000..b454e37 --- /dev/null +++ b/ttrss/messages/CategoriesResponse.cs @@ -0,0 +1,9 @@ +using ttrss_co_client.ttrss.datastructures; + +namespace ttrss_co_client.ttrss.messages +{ + public class CategoriesResponse : ApiResponse + { + public IEnumerable content { get; set; } + } +} \ No newline at end of file