diff --git a/Program.cs b/Program.cs index dc7cc27..5058523 100644 --- a/Program.cs +++ b/Program.cs @@ -16,8 +16,8 @@ namespace ttrss_co_client var apiLevel = await ttrssClient.GetApiLevel(); Console.WriteLine($"api level: {apiLevel}"); - var unread = await ttrssClient.GetUnread(); - Console.WriteLine($"{unread} unread article{(unread == 1 ? "" : "s")}"); + var counters = await ttrssClient.GetCounters(true, false, false, false); + Console.WriteLine($"{counters.Count()} counter{(counters.Count() == 1 ? "" : "s")} found"); var loggedout = await ttrssClient.Logout(); Console.WriteLine($"logged out: {loggedout}"); diff --git a/ttrss/ApiClient.cs b/ttrss/ApiClient.cs index 76910e2..a925347 100644 --- a/ttrss/ApiClient.cs +++ b/ttrss/ApiClient.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.ComponentModel; using Newtonsoft.Json; using System.Net.Http.Json; +using ttrss_co_client.ttrss.datastructures; // https://tt-rss.org/wiki/ApiReference @@ -66,6 +67,28 @@ namespace ttrss_co_client.ttrss return await oneValueGet("getUnread", "unread"); } + ///at least in my installation, it doesn't seem to respect the parameters I give it, be it curl or here. + public async Task> GetCounters(bool feeds = true, bool labels = true, bool categories = true, bool tags = false) + { + assertInitialized(); + assertApiLevel(4); + + var output_mode = ""; + if (feeds) output_mode += "f"; + if (labels) output_mode += "l"; + if (categories) output_mode += "c"; + if (tags) output_mode += "t"; + + var json = JsonContent.Create(new + { + op = "getCounters", + sid = this.SessionId, + output_mode = output_mode + }); + var response = await (await httpClient.PostAsync(BaseURI, json)).Content.ReadAsStringAsync(); + 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) { assertInitialized(); @@ -138,11 +161,6 @@ namespace ttrss_co_client.ttrss assertInitialized(); throw new NotImplementedException(); } - public async Task GetCounters(bool actual_feeds = true, bool labels = true, bool categories = true, bool tags = false) - { - assertInitialized(); - throw new NotImplementedException(); - } public async Task GetLabels(int? article_id) { assertInitialized(); @@ -206,8 +224,8 @@ namespace ttrss_co_client.ttrss private async Task oneValueGet(string op, string key) { - //mostly you post {"op": "aThingToDo", "sid": "sessionId", "some other param": "some other value"} - //and get back something like {"seq": 0, "status", "content": {"the value you asked for": 0}} + //mostly you post {"op": "getAThing", "sid": "sessionId"} + //and get back something like {"seq": 0, "status": 0, "content": {"the value you asked for": 0}} var json = JsonContent.Create(new { op = op, diff --git a/ttrss/datastructures/CounterInfo.cs b/ttrss/datastructures/CounterInfo.cs new file mode 100644 index 0000000..9addec0 --- /dev/null +++ b/ttrss/datastructures/CounterInfo.cs @@ -0,0 +1,34 @@ +using System.Collections.Generic; + +namespace ttrss_co_client.ttrss.datastructures +{ + ///"Counter Information" - not sure what that is + public class CounterInfo + { + //there's "global-unread", "subscribed-feeds", and the rest are ints + public string Id { get; set; } + public string Updated { get; set; } + public int? Counter { get; set; } + public int? AuxCounter { get; set; } + public int? Markedcounter { get; set; } + public string Description { get; set; } + public int? ts { get; set; } + public DateTime? TimeStamp + { + get + { + if(ts != null) + { + return new DateTime(1970,1,1,0,0,0,0,System.DateTimeKind.Utc) + .AddSeconds( ts.Value ).ToLocalTime(); + } + else + { + return null; + } + } + } + public string Error { get; set; } + public string Title { get; set; } + } +} \ No newline at end of file diff --git a/ttrss/messages/CounterInfoResponse.cs b/ttrss/messages/CounterInfoResponse.cs new file mode 100644 index 0000000..fd06eaa --- /dev/null +++ b/ttrss/messages/CounterInfoResponse.cs @@ -0,0 +1,9 @@ +using ttrss_co_client.ttrss.datastructures; + +namespace ttrss_co_client.ttrss.messages +{ + public class CounterInfoResponse : ApiResponse + { + public IEnumerable content { get; set; } + } +} \ No newline at end of file