getArticle

This commit is contained in:
Adam R Grey 2023-04-04 12:08:48 -04:00
parent 364bde427f
commit 7c7a2c0ae7
5 changed files with 70 additions and 11 deletions

View File

@ -67,24 +67,24 @@ namespace ttrss_co_client.ttrss
//???? = 8 //???? = 8
//1.14 = 9 //1.14 = 9
assertInitialized(); assertInitialized();
return await oneValueGet<int>("getApiLevel", "level"); return await getOneValue<int>("getApiLevel", "level");
} }
public async Task<bool> Logout() public async Task<bool> Logout()
{ {
assertInitialized(); assertInitialized();
return (await oneValueGet<string>("logout", "status"))?.ToLower() == "ok"; return (await getOneValue<string>("logout", "status"))?.ToLower() == "ok";
} }
public async Task<bool> IsLoggedIn() public async Task<bool> IsLoggedIn()
{ {
//assertInitialized(); //assertInitialized();
return (await oneValueGet<bool>("isLoggedIn", "status")); return (await getOneValue<bool>("isLoggedIn", "status"));
} }
public async Task<int> GetUnread() public async Task<int> GetUnread()
{ {
assertInitialized(); assertInitialized();
return await oneValueGet<int>("getUnread", "unread"); return await getOneValue<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> ///<summary>at least in my installation, it doesn't seem to respect the parameters I give it, be it curl or here.</summary>
@ -428,10 +428,10 @@ namespace ttrss_co_client.ttrss
// return apiResult; // return apiResult;
// } // }
#endregion #endregion
public enum UPDATEMODE { SetFalse=0, SetTrue=1, Toggle=2 }
///<summary>to update note, see <see cref="UpdateArticleNote"/></summary> ///<summary>to update note, see <see cref="UpdateArticleNote"/></summary>
public enum UPDATEFIELD { starred=0, published=1, unread=2 } public enum UPDATEFIELD { starred=0, published=1, unread=2 }
public async Task<int> UpdateArticleField(UPDATEMODE mode, UPDATEFIELD field, params int[] ids) public enum UPDATEMODE { SetFalse=0, SetTrue=1, Toggle=2 }
public async Task<int> UpdateArticleField(UPDATEFIELD field, UPDATEMODE mode, params int[] ids)
{ {
if(ids == null || ids.Length == 0) 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"); throw new System.ArgumentNullException("ids", "need to specify at least one id");
} }
//documentation: UpdateArticle - for note, we have a separate method UpdateArticleNote
assertInitialized(); assertInitialized();
var json = JsonContent.Create(new var json = JsonContent.Create(new
@ -476,14 +476,21 @@ namespace ttrss_co_client.ttrss
var apiResult = JsonConvert.DeserializeObject<ApiResponse<ArticleUpdateFieldResponse>>(response); var apiResult = JsonConvert.DeserializeObject<ApiResponse<ArticleUpdateFieldResponse>>(response);
return apiResult.Content.updated; return apiResult.Content.updated;
} }
public async Task<IEnumerable<object>> GetArticle(params int[] article_id) public async Task<IEnumerable<Article>> GetArticles(params int[] article_id)
{ {
if (!article_id.Any()) if (!article_id.Any())
{ {
throw new ArgumentException("need at least one article_id"); throw new ArgumentException("need at least one article_id");
} }
assertInitialized(); assertInitialized();
throw new NotImplementedException();
var json = JsonContent.Create(new
{
op = "getArticle",
sid = this.SessionId,
article_id = string.Join(',', article_id)
});
return await get<IEnumerable<Article>>(json);
} }
public async Task<Configuration> GetConfig() public async Task<Configuration> GetConfig()
{ {
@ -570,7 +577,7 @@ namespace ttrss_co_client.ttrss
} }
private async Task<T> oneValueGet<T>(string op, string key) private async Task<T> getOneValue<T>(string op, string key)
{ {
//mostly you post {"op": "getAThing", "sid": "sessionId"} //mostly you post {"op": "getAThing", "sid": "sessionId"}
//and get back something like {"seq": 0, "status": 0, "content": {"the value you asked for": 0}} //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); return default(T);
} }
} }
private async Task<T> get<T>(JsonContent json)
{
var response = await (await httpClient.PostAsync(BaseURI, json)).Content.ReadAsStringAsync();
var apiResult = JsonConvert.DeserializeObject<ttrss.messages.ApiResponse<T>>(response);
return apiResult.Content;
}
} }
} }

View File

@ -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<Label> labels;
public bool unread;
public bool marked;
public bool published;
public string comments;
public string author;
public int updated;
public int feed_id;
public IEnumerable<Attachment> attachments;
public double score;
public string feed_title;
public string note;
public string lang;
public string content;
}
}

View File

@ -0,0 +1,17 @@
using System.Collections.Generic;
namespace ttrss_co_client.ttrss.datastructures
{
public class Attachment
{
public int id { get; set; }
public Uri content_url { get; set; }
public string content_type { get; set; }
///<summary>a.k.a. article id</summary>
public int post_id { get; set; }
public string title { get; set; }
public string duration { get; set; }
public int width { get; set; }
public int height { get; set; }
}
}

View File

@ -10,6 +10,7 @@ namespace ttrss_co_client.ttrss.datastructures
public int unread { get; set; } public int unread { get; set; }
public bool has_icon { get; set; } public bool has_icon { get; set; }
public int cat_id { get; set; } public int cat_id { get; set; }
//TODO: custom converter for unix timestamps
///<summary>unix timestamp, see <see cref="TimeStamp" /></summary> ///<summary>unix timestamp, see <see cref="TimeStamp" /></summary>
public int last_updated { get; set; } public int last_updated { get; set; }
public DateTime? TimeStamp public DateTime? TimeStamp

View File

@ -5,7 +5,8 @@ namespace ttrss_co_client.ttrss.datastructures
public class Headline public class Headline
{ {
public int id { get; set; } public int id { get; set; }
public Guid guid { get; set; } //TODO: custom converter for ttrss's guid
public string guid { get; set; }
public bool unread { get; set; } public bool unread { get; set; }
public bool marked { get; set; } public bool marked { get; set; }
public bool published { get; set; } public bool published { get; set; }