From 290092df5ac8866eb25c403198d33b10ebf944f2 Mon Sep 17 00:00:00 2001 From: Adam R Grey Date: Mon, 3 Apr 2023 00:10:07 -0400 Subject: [PATCH] runs. generic API response. getApiLevel works. --- .vscode/launch.json | 26 ++++++++++++++++++++ .vscode/tasks.json | 42 +++++++++++++++++++++++++++++++++ Program.cs | 3 ++- README.md | 3 +++ ttrss/ApiClient.cs | 22 ++++++++++------- ttrss/messages/ApiResponse.cs | 14 +++++++++++ ttrss/messages/LoginResponse.cs | 4 +--- 7 files changed, 102 insertions(+), 12 deletions(-) create mode 100644 .vscode/launch.json create mode 100644 .vscode/tasks.json create mode 100644 ttrss/messages/ApiResponse.cs diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..806b2ae --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,26 @@ +{ + "version": "0.2.0", + "configurations": [ + { + // Use IntelliSense to find out which attributes exist for C# debugging + // Use hover for the description of the existing attributes + // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md + "name": ".NET Core Launch (console)", + "type": "coreclr", + "request": "launch", + "preLaunchTask": "build", + // If you have changed target frameworks, make sure to update the program path. + "program": "${workspaceFolder}/bin/Debug/net7.0/ttrss-co-client.dll", + "args": [], + "cwd": "${workspaceFolder}", + // For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console + "console": "internalConsole", + "stopAtEntry": false + }, + { + "name": ".NET Core Attach", + "type": "coreclr", + "request": "attach" + } + ] +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..abe0dd1 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,42 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "build", + "command": "dotnet", + "type": "process", + "args": [ + "build", + "${workspaceFolder}/ttrss-co-client.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "publish", + "command": "dotnet", + "type": "process", + "args": [ + "publish", + "${workspaceFolder}/ttrss-co-client.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "watch", + "command": "dotnet", + "type": "process", + "args": [ + "watch", + "run", + "${workspaceFolder}/ttrss-co-client.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + } + ] +} \ No newline at end of file diff --git a/Program.cs b/Program.cs index 43577ed..ec7e20e 100644 --- a/Program.cs +++ b/Program.cs @@ -9,7 +9,8 @@ namespace ttrss_co_client var conf = Configure(); var ttrssClient = new ttrss.ApiClient(conf.BaseURI); await ttrssClient.Login(conf.Username, conf.Password); - Console.WriteLine("Hello, World!"); + var apiLevel = await ttrssClient.GetApiLevel(); + Console.WriteLine(apiLevel); } static Configuration Configure(string configurationPath = "appsettings.json") { diff --git a/README.md b/README.md index 9902955..c0c1ac1 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,5 @@ # ttrss-co-pilot +wait i wanted to call it ttrss-co-client, dammit + +but that name isn't good anyway \ No newline at end of file diff --git a/ttrss/ApiClient.cs b/ttrss/ApiClient.cs index 756742a..8f9838d 100644 --- a/ttrss/ApiClient.cs +++ b/ttrss/ApiClient.cs @@ -45,13 +45,19 @@ namespace ttrss_co_client.ttrss public async Task GetApiLevel() { assertInitialized(); - throw new NotImplementedException(); - } - public async Task GetVersion() - { - assertInitialized(); - throw new NotImplementedException(); + var json =JsonContent.Create(new + { + op = "getApiLevel", + sid = this.SessionId + }); + var response = await (await httpClient.PostAsync(BaseURI, json)).Content.ReadAsStringAsync(); + var apiResult = JsonConvert.DeserializeObject(response); + int level = 0; + if(int.TryParse(apiResult.Content["level"], out level)) + return level; + else + return 0; } public async Task Logout() @@ -81,11 +87,11 @@ namespace ttrss_co_client.ttrss } public enum VIEWMODE { All, Unread, Adaptive, Marked, Updated } public enum SORTORDER { Default, OldestFirst, NewestFirst } - public async Task GetHeadlines(int feed_id, int limit, int skip, /*string filter, */ bool is_cat, bool show_excerpt, bool show_content, VIEWMODE view_mode, bool include_attachments, int since_id, bool include_nested, SORTORDER order_by, bool sanitize, bool force_update = false, bool has_sandbox = false, bool include_header) + public async Task GetHeadlines(int feed_id, int limit, int skip, /*string filter, */ bool is_cat, bool show_excerpt, bool show_content, VIEWMODE view_mode, bool include_attachments, int since_id, bool include_nested, SORTORDER order_by, bool sanitize, bool force_update = false, bool has_sandbox = false, bool include_header = false) { await getHeadlines(feed_id, null, limit, skip, /*filter, */ is_cat, show_excerpt, show_content, view_mode, include_attachments, since_id, include_nested, order_by, sanitize, force_update, has_sandbox, include_header); } - public async Task GetHeadlines(string feed_id, int limit, int skip, /*string filter, */ bool is_cat, bool show_excerpt, bool show_content, VIEWMODE view_mode, bool include_attachments, int since_id, bool include_nested, SORTORDER order_by, bool sanitize, bool force_update = false, bool has_sandbox = false, bool include_header) + public async Task GetHeadlines(string feed_id, int limit, int skip, /*string filter, */ bool is_cat, bool show_excerpt, bool show_content, VIEWMODE view_mode, bool include_attachments, int since_id, bool include_nested, SORTORDER order_by, bool sanitize, bool force_update = false, bool has_sandbox = false, bool include_header = false) { await getHeadlines(null, feed_id, limit, skip, /*filter, */ is_cat, show_excerpt, show_content, view_mode, include_attachments, since_id, include_nested, order_by, sanitize, force_update, has_sandbox, include_header); } diff --git a/ttrss/messages/ApiResponse.cs b/ttrss/messages/ApiResponse.cs new file mode 100644 index 0000000..69bfdf3 --- /dev/null +++ b/ttrss/messages/ApiResponse.cs @@ -0,0 +1,14 @@ +using System.Collections.Generic; + +namespace ttrss_co_client.ttrss.messages +{ + public abstract class ApiResponse + { + public int seq { get; set; } + public int status { get; set; } + } + public class GenericApiResponse : ApiResponse + { + public Dictionary Content{get; set;} + } +} \ No newline at end of file diff --git a/ttrss/messages/LoginResponse.cs b/ttrss/messages/LoginResponse.cs index a2e0446..2db051d 100644 --- a/ttrss/messages/LoginResponse.cs +++ b/ttrss/messages/LoginResponse.cs @@ -1,9 +1,7 @@ namespace ttrss_co_client.ttrss.messages { - public class LoginResponse + public class LoginResponse : ApiResponse { - public int seq { get; set; } - public int status { get; set; } public Content content { get; set; } public class Content