hey adam... y'all ever heard of a generic object?
This commit is contained in:
parent
e4cbf5e7d4
commit
794d03b424
@ -2,6 +2,7 @@ using System.Collections.Generic;
|
|||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using System.Net.Http.Json;
|
using System.Net.Http.Json;
|
||||||
|
using ttrss_co_client.ttrss.messages;
|
||||||
using ttrss_co_client.ttrss.datastructures;
|
using ttrss_co_client.ttrss.datastructures;
|
||||||
|
|
||||||
// https://tt-rss.org/wiki/ApiReference
|
// https://tt-rss.org/wiki/ApiReference
|
||||||
@ -32,17 +33,17 @@ namespace ttrss_co_client.ttrss
|
|||||||
};
|
};
|
||||||
var content = JsonContent.Create(json);
|
var content = JsonContent.Create(json);
|
||||||
var response = await (await httpClient.PostAsync(BaseURI, content)).Content.ReadAsStringAsync();
|
var response = await (await httpClient.PostAsync(BaseURI, content)).Content.ReadAsStringAsync();
|
||||||
var loginResult = JsonConvert.DeserializeObject<ttrss.messages.LoginResponse>(response);
|
var loginResult = JsonConvert.DeserializeObject<ApiResponse<LoginResponseContent>>(response);
|
||||||
if (loginResult.status == 0)
|
if (loginResult.status == 0)
|
||||||
{
|
{
|
||||||
SessionId = loginResult.content.session_id;
|
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?)");
|
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?)");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
api_level = loginResult.content.api_level.Value;
|
api_level = loginResult.Content.api_level.Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
Console.WriteLine(SessionId);
|
Console.WriteLine(SessionId);
|
||||||
@ -104,8 +105,8 @@ namespace ttrss_co_client.ttrss
|
|||||||
output_mode = output_mode
|
output_mode = output_mode
|
||||||
});
|
});
|
||||||
var response = await (await httpClient.PostAsync(BaseURI, json)).Content.ReadAsStringAsync();
|
var response = await (await httpClient.PostAsync(BaseURI, json)).Content.ReadAsStringAsync();
|
||||||
var apiResult = JsonConvert.DeserializeObject<ttrss.messages.CounterInfoResponse>(response);
|
var apiResult = JsonConvert.DeserializeObject<ApiResponse<IEnumerable<CounterInfo>>>(response);
|
||||||
return apiResult.content;
|
return apiResult.Content;
|
||||||
}
|
}
|
||||||
///<param name="limit">0 for all</param>
|
///<param name="limit">0 for all</param>
|
||||||
///<param name="offset">skip this amount first</param>
|
///<param name="offset">skip this amount first</param>
|
||||||
@ -135,8 +136,8 @@ namespace ttrss_co_client.ttrss
|
|||||||
offset = offset
|
offset = offset
|
||||||
});
|
});
|
||||||
var response = await (await httpClient.PostAsync(BaseURI, json)).Content.ReadAsStringAsync();
|
var response = await (await httpClient.PostAsync(BaseURI, json)).Content.ReadAsStringAsync();
|
||||||
var apiResult = JsonConvert.DeserializeObject<ttrss.messages.FeedsResponse>(response);
|
var apiResult = JsonConvert.DeserializeObject<ApiResponse<IEnumerable<Feed>>>(response);
|
||||||
return apiResult.content;
|
return apiResult.Content;
|
||||||
}
|
}
|
||||||
///<param name="enable_nested">nested mode (return only top level)</param>
|
///<param name="enable_nested">nested mode (return only top level)</param>
|
||||||
public async Task<IEnumerable<Category>> GetCategories(bool unread_only = false, bool enable_nested = false, bool include_empty = false)
|
public async Task<IEnumerable<Category>> GetCategories(bool unread_only = false, bool enable_nested = false, bool include_empty = false)
|
||||||
@ -152,8 +153,8 @@ namespace ttrss_co_client.ttrss
|
|||||||
include_empty = include_empty
|
include_empty = include_empty
|
||||||
});
|
});
|
||||||
var response = await (await httpClient.PostAsync(BaseURI, json)).Content.ReadAsStringAsync();
|
var response = await (await httpClient.PostAsync(BaseURI, json)).Content.ReadAsStringAsync();
|
||||||
var apiResult = JsonConvert.DeserializeObject<ttrss.messages.CategoriesResponse>(response);
|
var apiResult = JsonConvert.DeserializeObject<ApiResponse<IEnumerable<Category>>>(response);
|
||||||
return apiResult.content;
|
return apiResult.Content;
|
||||||
|
|
||||||
}
|
}
|
||||||
public enum VIEWMODE { All, Unread, Adaptive, Marked, Updated }
|
public enum VIEWMODE { All, Unread, Adaptive, Marked, Updated }
|
||||||
@ -296,8 +297,8 @@ namespace ttrss_co_client.ttrss
|
|||||||
private async Task<IEnumerable<Headline>> getHeadlines(JsonContent parameters)
|
private async Task<IEnumerable<Headline>> getHeadlines(JsonContent parameters)
|
||||||
{
|
{
|
||||||
var response = await (await httpClient.PostAsync(BaseURI, parameters)).Content.ReadAsStringAsync();
|
var response = await (await httpClient.PostAsync(BaseURI, parameters)).Content.ReadAsStringAsync();
|
||||||
var apiResult = JsonConvert.DeserializeObject<ttrss.messages.HeadlinesResponse>(response);
|
var apiResult = JsonConvert.DeserializeObject<ApiResponse<IEnumerable<Headline>>>(response);
|
||||||
return apiResult.content;
|
return apiResult.Content;
|
||||||
}
|
}
|
||||||
// public async Task<HeadlinesHeaderResponse> GetHeadlinesAndHeader(
|
// public async Task<HeadlinesHeaderResponse> GetHeadlinesAndHeader(
|
||||||
// int feed_id,
|
// int feed_id,
|
||||||
@ -541,7 +542,7 @@ namespace ttrss_co_client.ttrss
|
|||||||
sid = this.SessionId
|
sid = this.SessionId
|
||||||
});
|
});
|
||||||
var response = await (await httpClient.PostAsync(BaseURI, json)).Content.ReadAsStringAsync();
|
var response = await (await httpClient.PostAsync(BaseURI, json)).Content.ReadAsStringAsync();
|
||||||
var apiResult = JsonConvert.DeserializeObject<ttrss.messages.GenericApiResponse>(response);
|
var apiResult = JsonConvert.DeserializeObject<ttrss.messages.ApiResponse<Dictionary<string, string>>>(response);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var converter = TypeDescriptor.GetConverter(typeof(T));
|
var converter = TypeDescriptor.GetConverter(typeof(T));
|
||||||
|
@ -2,13 +2,10 @@ using System.Collections.Generic;
|
|||||||
|
|
||||||
namespace ttrss_co_client.ttrss.messages
|
namespace ttrss_co_client.ttrss.messages
|
||||||
{
|
{
|
||||||
public abstract class ApiResponse
|
public class ApiResponse<T>
|
||||||
{
|
{
|
||||||
public int seq { get; set; }
|
public int seq { get; set; }
|
||||||
public int status { get; set; }
|
public int status { get; set; }
|
||||||
}
|
public T Content {get; set;}
|
||||||
public class GenericApiResponse : ApiResponse
|
|
||||||
{
|
|
||||||
public Dictionary<string, string> Content{get; set;}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,9 +0,0 @@
|
|||||||
using ttrss_co_client.ttrss.datastructures;
|
|
||||||
|
|
||||||
namespace ttrss_co_client.ttrss.messages
|
|
||||||
{
|
|
||||||
public class CategoriesResponse : ApiResponse
|
|
||||||
{
|
|
||||||
public IEnumerable<Category> content { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,9 +0,0 @@
|
|||||||
using ttrss_co_client.ttrss.datastructures;
|
|
||||||
|
|
||||||
namespace ttrss_co_client.ttrss.messages
|
|
||||||
{
|
|
||||||
public class CounterInfoResponse : ApiResponse
|
|
||||||
{
|
|
||||||
public IEnumerable<CounterInfo> content { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,9 +0,0 @@
|
|||||||
using ttrss_co_client.ttrss.datastructures;
|
|
||||||
|
|
||||||
namespace ttrss_co_client.ttrss.messages
|
|
||||||
{
|
|
||||||
public class FeedsResponse : ApiResponse
|
|
||||||
{
|
|
||||||
public IEnumerable<Feed> content { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
@ -2,8 +2,10 @@ using ttrss_co_client.ttrss.datastructures;
|
|||||||
|
|
||||||
namespace ttrss_co_client.ttrss.messages
|
namespace ttrss_co_client.ttrss.messages
|
||||||
{
|
{
|
||||||
public class HeadlinesHeaderResponse : ApiResponse
|
public class HeadlinesHeaderContent
|
||||||
{
|
{
|
||||||
public IEnumerable<Headline> content { get; set; }
|
public int id { get; set; }
|
||||||
|
public int first_id { get; set; }
|
||||||
|
public bool is_cat { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,9 +0,0 @@
|
|||||||
using ttrss_co_client.ttrss.datastructures;
|
|
||||||
|
|
||||||
namespace ttrss_co_client.ttrss.messages
|
|
||||||
{
|
|
||||||
public class HeadlinesResponse : ApiResponse
|
|
||||||
{
|
|
||||||
public IEnumerable<Headline> content { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,15 +0,0 @@
|
|||||||
namespace ttrss_co_client.ttrss.messages
|
|
||||||
{
|
|
||||||
public class LoginResponse : ApiResponse
|
|
||||||
{
|
|
||||||
public Content content { get; set; }
|
|
||||||
|
|
||||||
public class Content
|
|
||||||
{
|
|
||||||
public string session_id { get; set; }
|
|
||||||
public Configuration config { get; set; }
|
|
||||||
public int? api_level { get; set; }
|
|
||||||
public string error { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
10
ttrss/messages/LoginResponseContent.cs
Normal file
10
ttrss/messages/LoginResponseContent.cs
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
namespace ttrss_co_client.ttrss.messages
|
||||||
|
{
|
||||||
|
public class LoginResponseContent
|
||||||
|
{
|
||||||
|
public string session_id { get; set; }
|
||||||
|
public Configuration config { get; set; }
|
||||||
|
public int? api_level { get; set; }
|
||||||
|
public string error { get; set; }
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user