Get Feeds
This commit is contained in:
parent
5797e4f415
commit
7f4fdd22b6
16
Program.cs
16
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}");
|
||||
|
||||
|
@ -89,10 +89,36 @@ namespace ttrss_co_client.ttrss
|
||||
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)
|
||||
///<param name="limit">0 for all</param>
|
||||
///<param name="offset">skip this amount first</param>
|
||||
///<param name="include_nested">idk, doesn't affect what the documentation says it should</param>
|
||||
public async Task<IEnumerable<Feed>> 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<ttrss.messages.FeedsResponse>(response);
|
||||
return apiResult.content;
|
||||
}
|
||||
public async Task GetCategories(bool unread_only, bool enable_nested, bool include_empty)
|
||||
{
|
||||
|
26
ttrss/datastructures/Feed.cs
Normal file
26
ttrss/datastructures/Feed.cs
Normal file
@ -0,0 +1,26 @@
|
||||
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; }
|
||||
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; }
|
||||
///<summary>unix timestamp, see <see cref="TimeStamp" /></summary>
|
||||
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; }
|
||||
}
|
||||
}
|
9
ttrss/messages/FeedsResponse.cs
Normal file
9
ttrss/messages/FeedsResponse.cs
Normal file
@ -0,0 +1,9 @@
|
||||
using ttrss_co_client.ttrss.datastructures;
|
||||
|
||||
namespace ttrss_co_client.ttrss.messages
|
||||
{
|
||||
public class FeedsResponse : ApiResponse
|
||||
{
|
||||
public IEnumerable<Feed> content { get; set; }
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user