get categories

This commit is contained in:
Adam R Grey 2023-04-03 14:03:31 -04:00
parent 7f4fdd22b6
commit a5eea59678
5 changed files with 40 additions and 7 deletions

View File

@ -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();

View File

@ -120,10 +120,23 @@ namespace ttrss_co_client.ttrss
var apiResult = JsonConvert.DeserializeObject<ttrss.messages.FeedsResponse>(response);
return apiResult.content;
}
public async Task GetCategories(bool unread_only, bool enable_nested, bool include_empty)
///<param name="enable_nested">nested mode (return only top level)</param>
public async Task<IEnumerable<Category>> 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<ttrss.messages.CategoriesResponse>(response);
return apiResult.content;
}
public enum VIEWMODE { All, Unread, Adaptive, Marked, Updated }
public enum SORTORDER { Default, OldestFirst, NewestFirst }

View File

@ -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; }
}
}

View File

@ -2,7 +2,6 @@ using System.Collections.Generic;
namespace ttrss_co_client.ttrss.datastructures
{
///<summary>"Counter Information" - not sure what that is</summary>
public class Feed
{
public int id { get; set; }

View File

@ -0,0 +1,9 @@
using ttrss_co_client.ttrss.datastructures;
namespace ttrss_co_client.ttrss.messages
{
public class CategoriesResponse : ApiResponse
{
public IEnumerable<Category> content { get; set; }
}
}