Compare commits

..

No commits in common. "3936850913930f52ed80ef63bf1b2a119e8560ee" and "364bde427ff68cbf15653f049308f19693af892b" have entirely different histories.

8 changed files with 69 additions and 324 deletions

View File

@ -37,7 +37,7 @@ namespace ttrss_co_client.ttrss
if (loginResult.status == 0)
{
SessionId = loginResult.Content.session_id;
if (loginResult.Content.api_level == null)
if(loginResult.Content.api_level == null)
{
throw new NotImplementedException($"api doesn't report an api level - unsupported. api level 1 is version 1.5.8, so {BaseURI} might be extremely old. (or maybe this library is extremely old and ttrss changed again?)");
}
@ -45,7 +45,7 @@ namespace ttrss_co_client.ttrss
{
api_level = loginResult.Content.api_level.Value;
}
Console.WriteLine(SessionId);
}
else
@ -66,26 +66,25 @@ namespace ttrss_co_client.ttrss
//???? = 7
//???? = 8
//1.14 = 9
//1.15 = 10
assertInitialized();
return await getOneValue<int>("getApiLevel", "level");
return await oneValueGet<int>("getApiLevel", "level");
}
public async Task<bool> Logout()
{
assertInitialized();
return (await getOneValue<string>("logout", "status"))?.ToLower() == "ok";
return (await oneValueGet<string>("logout", "status"))?.ToLower() == "ok";
}
public async Task<bool> IsLoggedIn()
{
//assertInitialized();
return (await getOneValue<bool>("isLoggedIn", "status"));
return (await oneValueGet<bool>("isLoggedIn", "status"));
}
public async Task<int> GetUnread()
{
assertInitialized();
return await getOneValue<int>("getUnread", "unread");
return await oneValueGet<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>
@ -112,12 +111,12 @@ namespace ttrss_co_client.ttrss
///<param name="limit">0 for all</param>
///<param name="offset">skip this amount first</param>
///<param name="include_nested">idk, doesn't affect what the documentation says it should</param>
public async Task<IEnumerable<Feed>> GetFeeds(int cat_id = 0, bool unread_only = false, uint limit = 0, int offset = 0/*, bool include_nested*/)
public async Task<IEnumerable<Feed>> GetFeeds(int cat_id = 0, bool unread_only=false, uint limit = 0, int offset = 0/*, bool include_nested*/)
{
assertInitialized();
if (cat_id < -2)
if(cat_id <-2)
{
if (cat_id == -3 || cat_id == -4)
if(cat_id == -3 || cat_id == -4)
{
assertApiLevel(4);
}
@ -144,7 +143,7 @@ namespace ttrss_co_client.ttrss
public async Task<IEnumerable<Category>> GetCategories(bool unread_only = false, bool enable_nested = false, bool include_empty = false)
{
assertInitialized();
var json = JsonContent.Create(new
{
op = "getCategories",
@ -162,11 +161,11 @@ namespace ttrss_co_client.ttrss
public async Task<IEnumerable<Headline>> GetHeadlines(
int feed_id,
bool is_cat,
int limit = 60,
int skip = 0,
int limit=60,
int skip=0,
/*string filter,*/
bool show_excerpt = false,
bool show_content = false,
bool show_content=false,
VIEWMODE view_mode = VIEWMODE.All,
bool include_attachments = false,
int? since_id = null,
@ -176,16 +175,16 @@ namespace ttrss_co_client.ttrss
bool force_update = false,
bool has_sandbox = false)
{
if (limit > 60)
if(limit>60)
{
assertApiLevel(6);
}
if (limit > 200)
if(limit > 200)
{
throw new ArgumentOutOfRangeException("limit", limit, "capped at 200");
}
if (include_nested)
if(include_nested)
{
assertApiLevel(4);
}
@ -205,12 +204,12 @@ namespace ttrss_co_client.ttrss
}
}
if (sanitize == false)
if(sanitize == false)
{
//TODO: it's version 1.8.0, but no idea what version that is. I can narrow it down to 6, 7, or 8.
assertApiLevel(6);
}
if (force_update)
if(force_update)
{
assertApiLevel(9);
}
@ -238,11 +237,11 @@ namespace ttrss_co_client.ttrss
}
public async Task<IEnumerable<Headline>> GetHeadlinesTag(
string tag,
int limit = 200,
int skip = 0,
int limit=200,
int skip=0,
/*string filter,*/
bool show_excerpt = false,
bool show_content = false,
bool show_content=false,
VIEWMODE view_mode = VIEWMODE.All,
bool include_attachments = false,
int? since_id = null,
@ -255,13 +254,13 @@ namespace ttrss_co_client.ttrss
{
assertApiLevel(18);
if (limit > 200)
if(limit > 200)
{
throw new ArgumentOutOfRangeException("limit", limit, "capped at 200");
}
string sortOrderString;
switch (order_by)
switch(order_by)
{
case SORTORDER.OldestFirst:
sortOrderString = "date_reverse";
@ -429,12 +428,12 @@ 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 enum UPDATEMODE { SetFalse = 0, SetTrue = 1, Toggle = 2 }
public async Task<int> UpdateArticleField(UPDATEFIELD field, UPDATEMODE mode, params int[] ids)
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)
if(ids == null || ids.Length == 0)
{
throw new System.ArgumentNullException("ids", "need to specify at least one id");
}
@ -458,11 +457,11 @@ namespace ttrss_co_client.ttrss
///<summary>for fields other than note, we have a separate method UpdateArticleField</summary>
public async Task<int> UpdateArticleNote(string data, params int[] ids)
{
if (ids == null || ids.Length == 0)
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
@ -477,251 +476,83 @@ namespace ttrss_co_client.ttrss
var apiResult = JsonConvert.DeserializeObject<ApiResponse<ArticleUpdateFieldResponse>>(response);
return apiResult.Content.updated;
}
public async Task<IEnumerable<Article>> GetArticles(params int[] article_id)
public async Task<IEnumerable<object>> GetArticle(params int[] article_id)
{
if (!article_id.Any())
{
throw new ArgumentException("need at least one article_id");
}
assertInitialized();
var json = JsonContent.Create(new
{
op = "getArticle",
sid = this.SessionId,
article_id = string.Join(',', article_id)
});
return await get<IEnumerable<Article>>(json);
throw new NotImplementedException();
}
public async Task<datastructures.Configuration> GetConfig()
public async Task<Configuration> GetConfig()
{
assertInitialized();
var json = JsonContent.Create(new
{
op = "getConfig",
sid = this.SessionId
});
return await get<datastructures.Configuration>(json);
throw new NotImplementedException();
}
///<summary>
///tell the feed to update. As opposed to updating our configuration of the feed.
///</summary>
public async Task<bool> UpdateFeed(int feed_id)
public async Task UpdateFeed(int feed_id)
{
assertInitialized();
var json = JsonContent.Create(new
{
op = "updateFeed",
sid = this.SessionId,
feed_id = feed_id
});
var apiResponse = await get<Dictionary<string, string>>(json);
return apiResponse.ContainsKey("status") && apiResponse["status"]?.ToLower() == "ok";
throw new NotImplementedException();
}
public async Task<T> GetPref<T>(string pref)
public async Task<string> GetPref(string key)
{
assertInitialized();
var json = JsonContent.Create(new
{
op = "getPref",
sid = this.SessionId,
pref_name = pref
});
var apiResponse = await get<Dictionary<string, string>>(json);
try
{
var converter = TypeDescriptor.GetConverter(typeof(T));
if (converter != null)
{
return (T)converter.ConvertFromString(apiResponse["value"]);
}
return default(T);
}
catch (NotSupportedException)
{
return default(T);
}
throw new NotImplementedException();
}
public enum CATCHUPMODE { All, OneDay, OneWeek, TwoWeeks }
///<summary>Tries to catchup (e.g. mark as read) specified feed.</summary>
public async Task<bool> CatchupFeed(int feed_id, bool is_cat, CATCHUPMODE mode = CATCHUPMODE.All)
public async Task CatchupFeed(int feed_id, bool is_cat, CATCHUPMODE mode = CATCHUPMODE.All)
{
assertInitialized();
var modestring = "all";
if (mode != CATCHUPMODE.All)
{
assertApiLevel(15);
switch (mode)
{
case CATCHUPMODE.OneDay:
modestring = "1day";
break;
case CATCHUPMODE.OneWeek:
modestring = "1week";
break;
case CATCHUPMODE.TwoWeeks:
modestring = "2week";
break;
}
}
var json = JsonContent.Create(new
{
op = "catchupFeed",
sid = this.SessionId,
feed_id = feed_id,
is_cat = is_cat,
mode = modestring
});
var apiResponse = await get<Dictionary<string, string>>(json);
return apiResponse.ContainsKey("status") && apiResponse["status"]?.ToLower() == "ok";
throw new NotImplementedException();
}
public async Task<IEnumerable<Label>> GetLabels(int? article_id = null)
public async Task GetLabels(int? article_id)
{
assertInitialized();
var json = JsonContent.Create(new
if (article_id != null)
{
op = "getLabels",
sid = this.SessionId,
article_id = article_id
});
var labels = await get<IEnumerable<Label>>(json);
if (this.api_level < 5)
{
foreach (var l in labels)
{
l.id = -11 - l.id;
}
assertApiLevel(5);
}
return labels;
throw new NotImplementedException();
}
public async Task<int> SetArticleLabel(int label_id, bool assign, params int[] article_ids)
public async Task SetArticleLabel(int label_id, bool assign, params int[] article_ids)
{
if (article_ids == null || article_ids.Length == 0)
{
throw new System.ArgumentNullException("ids", "need to specify at least one id");
}
//there's a label "cache", i guess?
assertInitialized();
var json = JsonContent.Create(new
{
op = "setArticleLabel",
sid = this.SessionId,
article_ids = string.Join(',', article_ids),
label_id = label_id,
assign = assign
});
var apiResponse = await get<Dictionary<string, string>>(json);
if (!apiResponse.ContainsKey("status") && apiResponse["status"]?.ToLower() == "ok")
{
return 0;
}
if (this.api_level <= 10)
{
//update label cache
var tasks = new List<Task>();
foreach (var id in article_ids)
{
tasks.Add(GetLabels(id));
}
Task.WaitAll(tasks.ToArray());
}
int toReturn;
if (int.TryParse(apiResponse["updated"], out toReturn))
{
return toReturn;
}
else
{
throw new Exception("update ostensibly ok, but couldn't parse");
}
throw new NotImplementedException();
}
public async Task<bool> ShareToPublished(string title, Uri url, string content, bool sanitize = true)
public async Task ShareToPublished(string title, Uri url, string content, bool sanitize = true)
{
if (url == null)
{
throw new ArgumentNullException("url");
}
assertInitialized();
assertApiLevel(4);
if (!sanitize)
assertApiLevel(20);
var json = JsonContent.Create(new
{
op = "shareToPublished",
sid = this.SessionId,
title = title,
url = url.ToString(),
content = content,
sanitize = sanitize
});
var apiResponse = await get<Dictionary<string, string>>(json);
return apiResponse.ContainsKey("status") && apiResponse["status"]?.ToLower() == "ok";
throw new NotImplementedException();
}
///<param name="category_id">0 = uncategorized</param>
///<param name="login">probably if the feed requires basic HTTP auth; the login? (decidedly not self-explanatory, gdi)</param>
///<param name="password">probably if the feed requires basic HTTP auth; the password? (decidedly not self-explanatory, gdi)</param>
///<returns>¯\_(ツ)_/¯ - code 1 = success, I think? - the documentation says "See subscribe_to_feed() in functions.php for details" - that function doesn't exist (as of 2023-04-04).</returns>
public async Task<int> SubscribeToFeed(Uri feed_url, int category_id = 0, string login = null, string password = null)
///<summary>
///<param name="login"/>if the feed requires basic HTTP auth; the login. (decidedly not self-explanatory, gdi)</param>
///<param name="password"/>if the feed requires basic HTTP auth; the password. (decidedly not self-explanatory, gdi)</param>
///</summary>
public async Task SubscribeToFeed(Uri feed_url, int category_id, string login, string password)
{
assertInitialized();
assertApiLevel(5);
var json = JsonContent.Create(new
{
op = "subscribeToFeed",
sid = this.SessionId,
feed_url = feed_url.ToString(),
category_id = category_id,
login = login,
password = password
});
var apiResponse = await get<Dictionary<string, Dictionary<string, int>>>(json);
return apiResponse["status"]["code"];
throw new NotImplementedException();
}
public async Task<bool> UnsubscribeFeed(int feed_id)
public async Task UnsubscribeFeed()
{
assertInitialized();
assertApiLevel(5);
var json = JsonContent.Create(new
{
op = "unsubscribeFeed",
sid = this.SessionId,
feed_id = feed_id.ToString()
});
var apiResponse = await get<Dictionary<string, string>>(json);
return apiResponse.ContainsKey("status") && apiResponse["status"]?.ToLower() == "ok";
throw new NotImplementedException();
}
///<returns>(almost) the whole shebang, for a user</returns>
public async Task<Tree> GetFeedTree(bool include_empty = false)
public async Task GetFeedTree()
{
assertInitialized();
assertApiLevel(5);
var json = JsonContent.Create(new
{
op = "getFeedTree",
sid = this.SessionId,
include_empty = include_empty
});
return await get<Tree>(json);
throw new NotImplementedException();
}
private void assertInitialized()
{
@ -739,7 +570,7 @@ namespace ttrss_co_client.ttrss
}
private async Task<T> getOneValue<T>(string op, string key)
private async Task<T> oneValueGet<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}}
@ -764,11 +595,5 @@ 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;
}
}
}

View File

@ -1,7 +1,7 @@
using System.Collections.Generic;
using System.Net.Http.Json;
namespace ttrss_co_client.ttrss.datastructures
namespace ttrss_co_client.ttrss
{
public class Configuration
{

View File

@ -1,28 +0,0 @@
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;
//label-like. seems to be id, caption, fg color, bg color.
public IEnumerable<IEnumerable<string>> 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

@ -1,17 +0,0 @@
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,7 +10,6 @@ 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

View File

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

View File

@ -4,17 +4,16 @@ namespace ttrss_co_client.ttrss.datastructures
{
public class Label
{
public void FromArticle(string[] fromServer)
public Label(string[] fromServer)
{
int.TryParse(fromServer[0], out id);
caption = fromServer[1];
fg_color = System.Drawing.ColorTranslator.FromHtml(fromServer[2]);
bg_color = System.Drawing.ColorTranslator.FromHtml(fromServer[3]);
Title = fromServer[1];
unknown = fromServer[2];
Color = System.Drawing.ColorTranslator.FromHtml(fromServer[3]);
}
public int id;
public string caption { get; set; }
public System.Drawing.Color fg_color { get; set; }
public System.Drawing.Color bg_color { get; set; }
public bool @checked { get; set;}
}
public string Title { get; set; }
public string unknown { get; set; }
public System.Drawing.Color Color {get; set;}
}
}

View File

@ -1,32 +0,0 @@
using System.Collections.Generic;
namespace ttrss_co_client.ttrss.datastructures
{
public class Tree
{
public ItemCollection categories { get; set; }
public class ItemCollection
{
public string identifier { get; set; }
public string label { get; set; }
public IEnumerable<Item> items { get; set; }
public class Item
{
public string id { get; set; }
public int? bare_id { get; set; }
public int? auxcounter { get; set; }
public string name { get; set; }
public IEnumerable<Item> items { get; set; }
public bool? checkbox { get; set; }
public string type { get; set; }
public int? unread { get; set; }
public int? child_unread { get; set; }
public string param { get; set; }
public string fg_color { get; set; }
public string bg_color { get; set; }
public int? updates_disabled { get; set; }
}
}
}
}