From 7c7a2c0ae7351ac53cb24cf349ca5cfcb1a11d6e Mon Sep 17 00:00:00 2001 From: Adam R Grey Date: Tue, 4 Apr 2023 12:08:48 -0400 Subject: [PATCH] getArticle --- ttrss/ApiClient.cs | 33 +++++++++++++++++++++--------- ttrss/datastructures/Article.cs | 27 ++++++++++++++++++++++++ ttrss/datastructures/Attachment.cs | 17 +++++++++++++++ ttrss/datastructures/Feed.cs | 1 + ttrss/datastructures/Headline.cs | 3 ++- 5 files changed, 70 insertions(+), 11 deletions(-) create mode 100644 ttrss/datastructures/Article.cs create mode 100644 ttrss/datastructures/Attachment.cs diff --git a/ttrss/ApiClient.cs b/ttrss/ApiClient.cs index 2637bc0..5ed6a50 100644 --- a/ttrss/ApiClient.cs +++ b/ttrss/ApiClient.cs @@ -67,24 +67,24 @@ namespace ttrss_co_client.ttrss //???? = 8 //1.14 = 9 assertInitialized(); - return await oneValueGet("getApiLevel", "level"); + return await getOneValue("getApiLevel", "level"); } public async Task Logout() { assertInitialized(); - return (await oneValueGet("logout", "status"))?.ToLower() == "ok"; + return (await getOneValue("logout", "status"))?.ToLower() == "ok"; } public async Task IsLoggedIn() { //assertInitialized(); - return (await oneValueGet("isLoggedIn", "status")); + return (await getOneValue("isLoggedIn", "status")); } public async Task GetUnread() { assertInitialized(); - return await oneValueGet("getUnread", "unread"); + return await getOneValue("getUnread", "unread"); } ///at least in my installation, it doesn't seem to respect the parameters I give it, be it curl or here. @@ -428,10 +428,10 @@ namespace ttrss_co_client.ttrss // return apiResult; // } #endregion - public enum UPDATEMODE { SetFalse=0, SetTrue=1, Toggle=2 } ///to update note, see public enum UPDATEFIELD { starred=0, published=1, unread=2 } - public async Task UpdateArticleField(UPDATEMODE mode, UPDATEFIELD field, params int[] ids) + public enum UPDATEMODE { SetFalse=0, SetTrue=1, Toggle=2 } + public async Task UpdateArticleField(UPDATEFIELD field, UPDATEMODE mode, params int[] ids) { if(ids == null || ids.Length == 0) { @@ -461,7 +461,7 @@ namespace ttrss_co_client.ttrss { throw new System.ArgumentNullException("ids", "need to specify at least one id"); } - //documentation: UpdateArticle - for note, we have a separate method UpdateArticleNote + assertInitialized(); var json = JsonContent.Create(new @@ -476,14 +476,21 @@ namespace ttrss_co_client.ttrss var apiResult = JsonConvert.DeserializeObject>(response); return apiResult.Content.updated; } - public async Task> GetArticle(params int[] article_id) + public async Task> GetArticles(params int[] article_id) { if (!article_id.Any()) { throw new ArgumentException("need at least one article_id"); } assertInitialized(); - throw new NotImplementedException(); + + var json = JsonContent.Create(new + { + op = "getArticle", + sid = this.SessionId, + article_id = string.Join(',', article_id) + }); + return await get>(json); } public async Task GetConfig() { @@ -570,7 +577,7 @@ namespace ttrss_co_client.ttrss } - private async Task oneValueGet(string op, string key) + private async Task getOneValue(string op, string key) { //mostly you post {"op": "getAThing", "sid": "sessionId"} //and get back something like {"seq": 0, "status": 0, "content": {"the value you asked for": 0}} @@ -595,5 +602,11 @@ namespace ttrss_co_client.ttrss return default(T); } } + private async Task get(JsonContent json) + { + var response = await (await httpClient.PostAsync(BaseURI, json)).Content.ReadAsStringAsync(); + var apiResult = JsonConvert.DeserializeObject>(response); + return apiResult.Content; + } } } \ No newline at end of file diff --git a/ttrss/datastructures/Article.cs b/ttrss/datastructures/Article.cs new file mode 100644 index 0000000..5dce599 --- /dev/null +++ b/ttrss/datastructures/Article.cs @@ -0,0 +1,27 @@ +using System.Collections.Generic; + +namespace ttrss_co_client.ttrss.datastructures +{ + public class Article + { + public int id { get; set; } + //TODO: custom converter for ttrss's guid + public string guid { get; set; } + public string title; + public Uri link; + public IEnumerable