GetCounters - but doesn't seem to work (at least in my installation)

This commit is contained in:
Adam R Grey 2023-04-03 13:09:39 -04:00
parent 1480efdd82
commit 5797e4f415
4 changed files with 70 additions and 9 deletions

View File

@ -16,8 +16,8 @@ namespace ttrss_co_client
var apiLevel = await ttrssClient.GetApiLevel(); var apiLevel = await ttrssClient.GetApiLevel();
Console.WriteLine($"api level: {apiLevel}"); Console.WriteLine($"api level: {apiLevel}");
var unread = await ttrssClient.GetUnread(); var counters = await ttrssClient.GetCounters(true, false, false, false);
Console.WriteLine($"{unread} unread article{(unread == 1 ? "" : "s")}"); Console.WriteLine($"{counters.Count()} counter{(counters.Count() == 1 ? "" : "s")} found");
var loggedout = await ttrssClient.Logout(); var loggedout = await ttrssClient.Logout();
Console.WriteLine($"logged out: {loggedout}"); Console.WriteLine($"logged out: {loggedout}");

View File

@ -2,6 +2,7 @@ using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using Newtonsoft.Json; using Newtonsoft.Json;
using System.Net.Http.Json; using System.Net.Http.Json;
using ttrss_co_client.ttrss.datastructures;
// https://tt-rss.org/wiki/ApiReference // https://tt-rss.org/wiki/ApiReference
@ -66,6 +67,28 @@ namespace ttrss_co_client.ttrss
return await oneValueGet<int>("getUnread", "unread"); return await oneValueGet<int>("getUnread", "unread");
} }
///<summary>at least in my installation, it doesn't seem to respect the parameters I give it, be it curl or here.</summary>
public async Task<IEnumerable<CounterInfo>> 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<ttrss.messages.CounterInfoResponse>(response);
return apiResult.content;
}
public async Task GetFeeds(int cat_id, bool unread_only, int limit, int offset, bool include_nested) public async Task GetFeeds(int cat_id, bool unread_only, int limit, int offset, bool include_nested)
{ {
assertInitialized(); assertInitialized();
@ -138,11 +161,6 @@ namespace ttrss_co_client.ttrss
assertInitialized(); assertInitialized();
throw new NotImplementedException(); 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) public async Task GetLabels(int? article_id)
{ {
assertInitialized(); assertInitialized();
@ -206,8 +224,8 @@ namespace ttrss_co_client.ttrss
private async Task<T> oneValueGet<T>(string op, string key) private async Task<T> oneValueGet<T>(string op, string key)
{ {
//mostly you post {"op": "aThingToDo", "sid": "sessionId", "some other param": "some other value"} //mostly you post {"op": "getAThing", "sid": "sessionId"}
//and get back something like {"seq": 0, "status", "content": {"the value you asked for": 0}} //and get back something like {"seq": 0, "status": 0, "content": {"the value you asked for": 0}}
var json = JsonContent.Create(new var json = JsonContent.Create(new
{ {
op = op, op = op,

View File

@ -0,0 +1,34 @@
using System.Collections.Generic;
namespace ttrss_co_client.ttrss.datastructures
{
///<summary>"Counter Information" - not sure what that is</summary>
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; }
}
}

View File

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