getArticle
This commit is contained in:
parent
364bde427f
commit
7c7a2c0ae7
@ -67,24 +67,24 @@ namespace ttrss_co_client.ttrss
|
||||
//???? = 8
|
||||
//1.14 = 9
|
||||
assertInitialized();
|
||||
return await oneValueGet<int>("getApiLevel", "level");
|
||||
return await getOneValue<int>("getApiLevel", "level");
|
||||
}
|
||||
|
||||
public async Task<bool> Logout()
|
||||
{
|
||||
assertInitialized();
|
||||
|
||||
return (await oneValueGet<string>("logout", "status"))?.ToLower() == "ok";
|
||||
return (await getOneValue<string>("logout", "status"))?.ToLower() == "ok";
|
||||
}
|
||||
public async Task<bool> IsLoggedIn()
|
||||
{
|
||||
//assertInitialized();
|
||||
return (await oneValueGet<bool>("isLoggedIn", "status"));
|
||||
return (await getOneValue<bool>("isLoggedIn", "status"));
|
||||
}
|
||||
public async Task<int> GetUnread()
|
||||
{
|
||||
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>
|
||||
@ -428,10 +428,10 @@ namespace ttrss_co_client.ttrss
|
||||
// return apiResult;
|
||||
// }
|
||||
#endregion
|
||||
public enum UPDATEMODE { SetFalse=0, SetTrue=1, Toggle=2 }
|
||||
///<summary>to update note, see <see cref="UpdateArticleNote"/></summary>
|
||||
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)
|
||||
{
|
||||
@ -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<ApiResponse<ArticleUpdateFieldResponse>>(response);
|
||||
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())
|
||||
{
|
||||
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<IEnumerable<Article>>(json);
|
||||
}
|
||||
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"}
|
||||
//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<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;
|
||||
}
|
||||
}
|
||||
}
|
27
ttrss/datastructures/Article.cs
Normal file
27
ttrss/datastructures/Article.cs
Normal 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;
|
||||
}
|
||||
}
|
17
ttrss/datastructures/Attachment.cs
Normal file
17
ttrss/datastructures/Attachment.cs
Normal 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; }
|
||||
}
|
||||
}
|
@ -10,6 +10,7 @@ namespace ttrss_co_client.ttrss.datastructures
|
||||
public int unread { get; set; }
|
||||
public bool has_icon { get; set; }
|
||||
public int cat_id { get; set; }
|
||||
//TODO: custom converter for unix timestamps
|
||||
///<summary>unix timestamp, see <see cref="TimeStamp" /></summary>
|
||||
public int last_updated { get; set; }
|
||||
public DateTime? TimeStamp
|
||||
|
@ -5,7 +5,8 @@ namespace ttrss_co_client.ttrss.datastructures
|
||||
public class Headline
|
||||
{
|
||||
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 marked { get; set; }
|
||||
public bool published { get; set; }
|
||||
|
Loading…
Reference in New Issue
Block a user