diff --git a/Program.cs b/Program.cs index ea3106d..a748178 100644 --- a/Program.cs +++ b/Program.cs @@ -17,17 +17,7 @@ namespace ttrss_co_client var apiLevel = await ttrssClient.GetApiLevel(); Console.WriteLine($"api level: {apiLevel}"); - 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 categories with feeds with unread articles."); - } + var loggedout = await ttrssClient.Logout(); Console.WriteLine($"logged out: {loggedout}"); diff --git a/ttrss/ApiClient.cs b/ttrss/ApiClient.cs index 2994a2f..2637bc0 100644 --- a/ttrss/ApiClient.cs +++ b/ttrss/ApiClient.cs @@ -155,7 +155,6 @@ namespace ttrss_co_client.ttrss var response = await (await httpClient.PostAsync(BaseURI, json)).Content.ReadAsStringAsync(); var apiResult = JsonConvert.DeserializeObject>>(response); return apiResult.Content; - } public enum VIEWMODE { All, Unread, Adaptive, Marked, Updated } public enum SORTORDER { Default, OldestFirst, NewestFirst } @@ -300,7 +299,8 @@ namespace ttrss_co_client.ttrss var apiResult = JsonConvert.DeserializeObject>>(response); return apiResult.Content; } - // public async Task GetHeadlinesAndHeader( + #region Get headlines include_header=true + // public async Task>> GetHeadlinesAndHeader( // int feed_id, // bool is_cat, // int limit=60, @@ -418,25 +418,63 @@ namespace ttrss_co_client.ttrss // }); // return await getHeadlinesAndHeader(json); // } - // private async Task getHeadlinesAndHeader(JsonContent parameters) + + //todo: deserialize array of disparate types. can that be done? + // private async Task>> getHeadlinesAndHeader(JsonContent parameters) // { // var response = await (await httpClient.PostAsync(BaseURI, parameters)).Content.ReadAsStringAsync(); - // var apiResult = JsonConvert.DeserializeObject(response); + // var immediateApiResult = JsonConvert.DeserializeObject>>(response).Content.ToList(); + // var apiResult = JsonConvert.DeserializeObject>>(immediateApiResult[1]); // return apiResult; // } - public enum UPDATEMODE { SetFalse, SetTrue, Toggle } - public enum UPDATEFIELD { starred, published, unread } + #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) { + if(ids == null || ids.Length == 0) + { + 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 + { + op = "updateArticle", + sid = this.SessionId, + article_ids = string.Join(',', ids), + mode = (int)mode, + field = (int)field + }); + var response = await (await httpClient.PostAsync(BaseURI, json)).Content.ReadAsStringAsync(); + var apiResult = JsonConvert.DeserializeObject>(response); + return apiResult.Content.updated; + throw new NotImplementedException(); } + ///for fields other than note, we have a separate method UpdateArticleField public async Task UpdateArticleNote(string data, params int[] ids) { - //documentation: UpdateArticle - for fields other than note, we have a separate method UpdateArticleField + if(ids == null || ids.Length == 0) + { + throw new System.ArgumentNullException("ids", "need to specify at least one id"); + } + //documentation: UpdateArticle - for note, we have a separate method UpdateArticleNote assertInitialized(); - throw new NotImplementedException(); + + var json = JsonContent.Create(new + { + op = "updateArticle", + sid = this.SessionId, + article_ids = string.Join(',', ids), + field = 3, + data = data, + }); + var response = await (await httpClient.PostAsync(BaseURI, json)).Content.ReadAsStringAsync(); + var apiResult = JsonConvert.DeserializeObject>(response); + return apiResult.Content.updated; } public async Task> GetArticle(params int[] article_id) { diff --git a/ttrss/messages/ArticleUpdateFieldResponse.cs b/ttrss/messages/ArticleUpdateFieldResponse.cs new file mode 100644 index 0000000..ef964df --- /dev/null +++ b/ttrss/messages/ArticleUpdateFieldResponse.cs @@ -0,0 +1,10 @@ +using ttrss_co_client.ttrss.datastructures; + +namespace ttrss_co_client.ttrss.messages +{ + public class ArticleUpdateFieldResponse + { + public string status {get;set;} + public int updated { get; set; } + } +} \ No newline at end of file diff --git a/ttrss/messages/HeadlinesHeaderResponse.cs b/ttrss/messages/HeadlinesHeaderResponse.cs index d02ae4d..d5af94a 100644 --- a/ttrss/messages/HeadlinesHeaderResponse.cs +++ b/ttrss/messages/HeadlinesHeaderResponse.cs @@ -2,7 +2,7 @@ using ttrss_co_client.ttrss.datastructures; namespace ttrss_co_client.ttrss.messages { - public class HeadlinesHeaderContent + public class HeadlinesHeaderResponse { public int id { get; set; } public int first_id { get; set; }