a few untested methods

This commit is contained in:
Adam R Grey 2023-04-04 02:16:56 -04:00
parent 46d1aada59
commit 364bde427f
4 changed files with 58 additions and 20 deletions

View File

@ -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}");

View File

@ -155,7 +155,6 @@ namespace ttrss_co_client.ttrss
var response = await (await httpClient.PostAsync(BaseURI, json)).Content.ReadAsStringAsync();
var apiResult = JsonConvert.DeserializeObject<ApiResponse<IEnumerable<Category>>>(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<ApiResponse<IEnumerable<Headline>>>(response);
return apiResult.Content;
}
// public async Task<HeadlinesHeaderResponse> GetHeadlinesAndHeader(
#region Get headlines include_header=true
// public async Task<Tuple<ttrss.messages.HeadlinesHeaderResponse, IEnumerable<Headline>>> 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<HeadlinesHeaderResponse> getHeadlinesAndHeader(JsonContent parameters)
//todo: deserialize array of disparate types. can that be done?
// private async Task<Tuple<ttrss.messages.HeadlinesHeaderResponse, IEnumerable<Headline>>> getHeadlinesAndHeader(JsonContent parameters)
// {
// var response = await (await httpClient.PostAsync(BaseURI, parameters)).Content.ReadAsStringAsync();
// var apiResult = JsonConvert.DeserializeObject<ttrss.messages.HeadlinesHeaderResponse>(response);
// var immediateApiResult = JsonConvert.DeserializeObject<ApiResponse<IEnumerable<string>>>(response).Content.ToList();
// var apiResult = JsonConvert.DeserializeObject<Tuple<ttrss.messages.HeadlinesHeaderResponse, IEnumerable<Headline>>>(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 }
///<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)
{
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<ApiResponse<ArticleUpdateFieldResponse>>(response);
return apiResult.Content.updated;
throw new NotImplementedException();
}
///<summary>for fields other than note, we have a separate method UpdateArticleField</summary>
public async Task<int> 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<ApiResponse<ArticleUpdateFieldResponse>>(response);
return apiResult.Content.updated;
}
public async Task<IEnumerable<object>> GetArticle(params int[] article_id)
{

View File

@ -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; }
}
}

View File

@ -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; }