Tidy up of the API service
This commit is contained in:
parent
cc779051bf
commit
909038ff79
5 changed files with 135 additions and 189 deletions
|
@ -1,10 +1,12 @@
|
||||||
using Microsoft.AspNetCore.Components;
|
using Microsoft.AspNetCore.Components;
|
||||||
using Microsoft.AspNetCore.Components.Forms;
|
using Microsoft.AspNetCore.Components.Forms;
|
||||||
using Neighbourhood.omg.lol.Models;
|
using Neighbourhood.omg.lol.Models;
|
||||||
|
using System;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Net.Http.Json;
|
using System.Net.Http.Json;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
|
using System.Threading;
|
||||||
|
|
||||||
namespace Neighbourhood.omg.lol
|
namespace Neighbourhood.omg.lol
|
||||||
{
|
{
|
||||||
|
@ -19,13 +21,23 @@ namespace Neighbourhood.omg.lol
|
||||||
_client.DefaultRequestHeaders.UserAgent.Add(new System.Net.Http.Headers.ProductInfoHeaderValue(App.Name, App.Version));
|
_client.DefaultRequestHeaders.UserAgent.Add(new System.Net.Http.Headers.ProductInfoHeaderValue(App.Name, App.Version));
|
||||||
_serializerOptions = new JsonSerializerOptions {
|
_serializerOptions = new JsonSerializerOptions {
|
||||||
PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower,
|
PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower,
|
||||||
|
#if DEBUG
|
||||||
WriteIndented = true
|
WriteIndented = true
|
||||||
|
#else
|
||||||
|
WriteIndented = false
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
AddToken(token);
|
AddToken(token);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Deserialize json convenience function with default serializer options
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T">The type to deserialize</typeparam>
|
||||||
|
/// <param name="str">The string to deserialize</param>
|
||||||
|
/// <returns>The deserialized object if successful, otherwise default</returns>
|
||||||
public T? Deserialize<T>(string str) {
|
public T? Deserialize<T>(string str) {
|
||||||
T? responseObj = default(T);
|
T? responseObj = default;
|
||||||
try {
|
try {
|
||||||
responseObj = JsonSerializer.Deserialize<T>(str, _serializerOptions);
|
responseObj = JsonSerializer.Deserialize<T>(str, _serializerOptions);
|
||||||
}
|
}
|
||||||
|
@ -36,78 +48,30 @@ namespace Neighbourhood.omg.lol
|
||||||
return responseObj;
|
return responseObj;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddToken(string? token = null) {
|
#region Base Requests
|
||||||
if (token == null) token = Task.Run(() => SecureStorage.GetAsync("accounttoken")).GetAwaiter().GetResult();
|
|
||||||
if (token != null) _client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", token);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void RemoveToken() {
|
/// <summary>
|
||||||
_client.DefaultRequestHeaders.Remove("Authorization");
|
/// Decode the response from an API call
|
||||||
}
|
/// </summary>
|
||||||
|
/// <typeparam name="TResponse">The type of response object we are trying to get</typeparam>
|
||||||
private async Task<T?> Get<T>(string uri, CancellationToken cancellationToken = default) where T : IOmgLolResponseData {
|
/// <param name="response">The raw Http Response Message</param>
|
||||||
T? responseData = default(T);
|
/// <param name="cancellationToken">A cancellation token to cancel the operation</param>
|
||||||
|
/// <returns>The decoded object if successfull, otherwise default</returns>
|
||||||
|
private async Task<TResponse?> DecodeResponse<TResponse>(HttpResponseMessage response, CancellationToken cancellationToken = default)
|
||||||
|
where TResponse : IOmgLolResponseData
|
||||||
|
{
|
||||||
|
TResponse? responseData = default;
|
||||||
try {
|
try {
|
||||||
HttpResponseMessage response = await _client.GetAsync(uri, cancellationToken: cancellationToken);
|
|
||||||
if (response.IsSuccessStatusCode) {
|
|
||||||
string str = await response.Content.ReadAsStringAsync();
|
string str = await response.Content.ReadAsStringAsync();
|
||||||
try {
|
if (response.IsSuccessStatusCode) {
|
||||||
OmgLolResponse<T>? responseObj = await response.Content.ReadFromJsonAsync<OmgLolResponse<T>>(_serializerOptions, cancellationToken: cancellationToken);
|
OmgLolResponse<TResponse>? responseObj = Deserialize<OmgLolResponse<TResponse>>(str);
|
||||||
if (responseObj?.Request == null || (responseObj?.Request?.Success ?? false)) {
|
if (responseObj?.Request == null || (responseObj?.Request?.Success ?? false)) {
|
||||||
responseData = responseObj!.Response;
|
responseData = responseObj!.Response;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (JsonException ex) {
|
else {
|
||||||
Debug.WriteLine(@"\tERROR {0}", ex.Message);
|
OmgLolResponse<TResponse>? responseObj = Deserialize<OmgLolResponse<TResponse>>(str);
|
||||||
Debug.WriteLine(str);
|
throw responseObj == null ? new OmgLolApiException<TResponse>(str) : new OmgLolApiException<TResponse>(responseObj);
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex) {
|
|
||||||
Debug.WriteLine(@"\tERROR {0}", ex.Message);
|
|
||||||
}
|
|
||||||
|
|
||||||
return responseData;
|
|
||||||
}
|
|
||||||
|
|
||||||
private async Task<TResponse?> Post<TResponse, TData>(string uri, TData data, CancellationToken cancellationToken = default) where TResponse : IOmgLolResponseData {
|
|
||||||
TResponse? responseData = default(TResponse);
|
|
||||||
try {
|
|
||||||
HttpResponseMessage response = await _client.PostAsJsonAsync(uri, data, _serializerOptions, cancellationToken: cancellationToken);
|
|
||||||
string str = await response.Content.ReadAsStringAsync();
|
|
||||||
if (response.IsSuccessStatusCode) {
|
|
||||||
OmgLolResponse<TResponse>? responseObj = await response.Content.ReadFromJsonAsync<OmgLolResponse<TResponse>>(_serializerOptions, cancellationToken: cancellationToken);
|
|
||||||
if (responseObj?.Request?.Success ?? false) {
|
|
||||||
responseData = responseObj.Response;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex) {
|
|
||||||
Debug.WriteLine(@"\tERROR {0}", ex.Message);
|
|
||||||
}
|
|
||||||
|
|
||||||
return responseData;
|
|
||||||
}
|
|
||||||
|
|
||||||
private async Task<TResponse?> PostBinary<TResponse, TData>(string uri, FileResult? fileResult = null, CancellationToken cancellationToken = default) where TResponse : IOmgLolResponseData {
|
|
||||||
TResponse? responseData = default(TResponse);
|
|
||||||
try {
|
|
||||||
if (fileResult != null) using (var fileStream = await fileResult.OpenReadAsync()) {
|
|
||||||
Uri url = new Uri(_client.BaseAddress?.AbsoluteUri + uri);
|
|
||||||
if (string.IsNullOrEmpty(url.Query)) uri += "?binary";
|
|
||||||
else if (!url.Query.Contains("binary")) uri += "&binary";
|
|
||||||
|
|
||||||
HttpContent fileStreamContent = new StreamContent(fileStream);
|
|
||||||
fileStreamContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue(fileResult.ContentType ?? "application/octet-stream");
|
|
||||||
fileStreamContent.Headers.ContentLength = fileStream.Length;
|
|
||||||
HttpResponseMessage response = await _client.PostAsync(uri, fileStreamContent, cancellationToken: cancellationToken);
|
|
||||||
string str = await response.Content.ReadAsStringAsync();
|
|
||||||
if (response.IsSuccessStatusCode) {
|
|
||||||
OmgLolResponse<TResponse>? responseObj = await response.Content.ReadFromJsonAsync<OmgLolResponse<TResponse>>(_serializerOptions, cancellationToken: cancellationToken);
|
|
||||||
if (responseObj?.Request?.Success ?? false) {
|
|
||||||
responseData = responseObj.Response;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
|
@ -117,66 +81,46 @@ namespace Neighbourhood.omg.lol
|
||||||
return responseData;
|
return responseData;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<TResponse?> PostMultipart<TResponse, TData>(string uri, TData? data = null, FileResult? fileResult = null, CancellationToken cancellationToken = default)
|
/// <summary>
|
||||||
where TResponse : IOmgLolResponseData where TData : class
|
/// Performs a request for the supplied uri, with the supplied Http Method,
|
||||||
{
|
/// with the supplied data in the body (if present)
|
||||||
if(fileResult != null) {
|
/// </summary>
|
||||||
using (var fileStream = await fileResult.OpenReadAsync())
|
/// <typeparam name="TResponse">The type of response we are expecting</typeparam>
|
||||||
return await PostMultipart<TResponse, TData>(uri, data: data, fileStream: fileStream, fileName: fileResult.FileName, contentType: fileResult.ContentType);
|
/// <typeparam name="TData">The type of data we are sending</typeparam>
|
||||||
}
|
/// <param name="uri">The uri to request</param>
|
||||||
else return await PostMultipart<TResponse, TData>(uri, data, fileStream: null);
|
/// <param name="method">The Http Method to use for the request</param>
|
||||||
}
|
/// <param name="data">The data to send in the body of the request</param>
|
||||||
|
/// <param name="file">A FileResult for the file to send in the body of the request as binary data</param>
|
||||||
private async Task<TResponse?> PostMultipart<TResponse, TData>(string uri, TData? data = null, Stream? fileStream = null, string? fileName = null, string? contentType = null, CancellationToken cancellationToken = default)
|
/// <param name="cancellationToken">A cancellation token</param>
|
||||||
where TResponse : IOmgLolResponseData where TData : class
|
/// <returns>The returned data if successful, otherwise default</returns>
|
||||||
|
private async Task<TResponse?> Request<TResponse, TData>(string uri, HttpMethod method, TData? data = default, FileResult? file = null, CancellationToken cancellationToken = default)
|
||||||
|
where TResponse : IOmgLolResponseData
|
||||||
{
|
{
|
||||||
TResponse? responseData = default;
|
TResponse? responseData = default;
|
||||||
try {
|
try {
|
||||||
using (MultipartFormDataContent formData = new MultipartFormDataContent()) {
|
HttpRequestMessage request = new HttpRequestMessage(method, uri);
|
||||||
if(fileStream != null) {
|
Stream? fileStream = null;
|
||||||
|
if (file != null) {
|
||||||
|
// append "binary" query parameter (if not already present)
|
||||||
|
Uri url = new Uri(_client.BaseAddress?.AbsoluteUri + uri);
|
||||||
|
if (string.IsNullOrEmpty(url.Query)) uri += "?binary";
|
||||||
|
else if (!url.Query.Contains("binary")) uri += "&binary";
|
||||||
|
request = new HttpRequestMessage(method, uri);
|
||||||
|
|
||||||
|
fileStream = await file.OpenReadAsync();
|
||||||
HttpContent fileStreamContent = new StreamContent(fileStream);
|
HttpContent fileStreamContent = new StreamContent(fileStream);
|
||||||
fileStreamContent.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("form-data") {
|
fileStreamContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue(file.ContentType ?? "application/octet-stream");
|
||||||
Name = "\"file\"",
|
fileStreamContent.Headers.ContentLength = fileStream.Length;
|
||||||
FileName = $"\"{fileName}\"" ?? "\"unknown\""
|
request.Content = fileStreamContent;
|
||||||
};
|
|
||||||
fileStreamContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue(contentType ?? "application/octet-stream");
|
|
||||||
formData.Add(fileStreamContent);
|
|
||||||
}
|
}
|
||||||
if (data != null) {
|
else if (data != null) {
|
||||||
HttpContent jsonContent = JsonContent.Create(data, options: _serializerOptions);
|
|
||||||
formData.Add(jsonContent);
|
|
||||||
}
|
|
||||||
|
|
||||||
HttpResponseMessage response = await _client.PostAsync(uri, formData, cancellationToken: cancellationToken);
|
|
||||||
string str = await response.Content.ReadAsStringAsync();
|
|
||||||
if (response.IsSuccessStatusCode) {
|
|
||||||
OmgLolResponse<TResponse>? responseObj = await response.Content.ReadFromJsonAsync<OmgLolResponse<TResponse>>(_serializerOptions, cancellationToken: cancellationToken);
|
|
||||||
if (responseObj?.Request?.Success ?? false) {
|
|
||||||
responseData = responseObj.Response;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex) {
|
|
||||||
Debug.WriteLine(@"\tERROR {0}", ex.Message);
|
|
||||||
}
|
|
||||||
|
|
||||||
return responseData;
|
|
||||||
}
|
|
||||||
|
|
||||||
private async Task<TResponse?> Put<TResponse, TData>(string uri, TData data, CancellationToken cancellationToken = default) where TResponse : IOmgLolResponseData {
|
|
||||||
TResponse? responseData = default(TResponse);
|
|
||||||
try {
|
|
||||||
string json = JsonSerializer.Serialize(data, _serializerOptions);
|
string json = JsonSerializer.Serialize(data, _serializerOptions);
|
||||||
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Put, uri);
|
|
||||||
request.Content = new StringContent(json, Encoding.UTF8, "application/json");
|
request.Content = new StringContent(json, Encoding.UTF8, "application/json");
|
||||||
|
}
|
||||||
HttpResponseMessage response = await _client.SendAsync(request, cancellationToken: cancellationToken);
|
HttpResponseMessage response = await _client.SendAsync(request, cancellationToken: cancellationToken);
|
||||||
if (response.IsSuccessStatusCode) {
|
responseData = await DecodeResponse<TResponse>(response, cancellationToken);
|
||||||
OmgLolResponse<TResponse>? responseObj = await response.Content.ReadFromJsonAsync<OmgLolResponse<TResponse>>(_serializerOptions, cancellationToken: cancellationToken);
|
|
||||||
if (responseObj?.Request?.Success ?? false) {
|
fileStream?.Dispose();
|
||||||
responseData = responseObj.Response;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
Debug.WriteLine(@"\tERROR {0}", ex.Message);
|
Debug.WriteLine(@"\tERROR {0}", ex.Message);
|
||||||
|
@ -185,50 +129,38 @@ namespace Neighbourhood.omg.lol
|
||||||
return responseData;
|
return responseData;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<TResponse?> Patch<TResponse, TData>(string uri, TData data, CancellationToken cancellationToken = default) where TResponse : IOmgLolResponseData {
|
// GET request
|
||||||
TResponse? responseData = default(TResponse);
|
private async Task<TResponse?> Get<TResponse>(string uri, CancellationToken cancellationToken = default)
|
||||||
try {
|
where TResponse : IOmgLolResponseData
|
||||||
HttpResponseMessage response = await _client.PatchAsJsonAsync(uri, data, _serializerOptions, cancellationToken: cancellationToken);
|
=> await Request<TResponse, object>(uri, HttpMethod.Get, cancellationToken: cancellationToken);
|
||||||
string str = await response.Content.ReadAsStringAsync();
|
|
||||||
if (response.IsSuccessStatusCode) {
|
|
||||||
OmgLolResponse<TResponse>? responseObj = await response.Content.ReadFromJsonAsync<OmgLolResponse<TResponse>>(_serializerOptions, cancellationToken: cancellationToken);
|
|
||||||
if (responseObj?.Request?.Success ?? false) {
|
|
||||||
responseData = responseObj.Response;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex) {
|
|
||||||
Debug.WriteLine(@"\tERROR {0}", ex.Message);
|
|
||||||
}
|
|
||||||
|
|
||||||
return responseData;
|
// POST request
|
||||||
}
|
private async Task<TResponse?> Post<TResponse, TData>(string uri, TData data, CancellationToken cancellationToken = default)
|
||||||
|
where TResponse : IOmgLolResponseData
|
||||||
|
=> await Request<TResponse, TData>(uri, HttpMethod.Post, data: data, cancellationToken: cancellationToken);
|
||||||
|
|
||||||
private async Task<T?> Delete<T>(string uri, CancellationToken cancellationToken = default) where T : IOmgLolResponseData {
|
// POST request, but with a file as binary data
|
||||||
T? responseData = default(T);
|
private async Task<TResponse?> PostBinary<TResponse>(string uri, FileResult? fileResult = null, CancellationToken cancellationToken = default)
|
||||||
try {
|
where TResponse : IOmgLolResponseData
|
||||||
HttpResponseMessage response = await _client.DeleteAsync(uri, cancellationToken: cancellationToken);
|
=> await Request<TResponse, object>(uri, HttpMethod.Post, file: fileResult, cancellationToken: cancellationToken);
|
||||||
if (response.IsSuccessStatusCode) {
|
|
||||||
string str = await response.Content.ReadAsStringAsync();
|
|
||||||
try {
|
|
||||||
OmgLolResponse<T>? responseObj = await response.Content.ReadFromJsonAsync<OmgLolResponse<T>>(_serializerOptions, cancellationToken: cancellationToken);
|
|
||||||
if (responseObj?.Request?.Success ?? false) {
|
|
||||||
responseData = responseObj.Response;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (JsonException ex) {
|
|
||||||
Debug.WriteLine(@"\tERROR {0}", ex.Message);
|
|
||||||
Debug.WriteLine(str);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex) {
|
|
||||||
Debug.WriteLine(@"\tERROR {0}", ex.Message);
|
|
||||||
}
|
|
||||||
|
|
||||||
return responseData;
|
// PUT request
|
||||||
}
|
private async Task<TResponse?> Put<TResponse, TData>(string uri, TData data, CancellationToken cancellationToken = default)
|
||||||
|
where TResponse : IOmgLolResponseData
|
||||||
|
=> await Request<TResponse, TData>(uri, HttpMethod.Put, data: data, cancellationToken: cancellationToken);
|
||||||
|
|
||||||
|
// PATCH request
|
||||||
|
private async Task<TResponse?> Patch<TResponse, TData>(string uri, TData data, CancellationToken cancellationToken = default)
|
||||||
|
where TResponse : IOmgLolResponseData
|
||||||
|
=> await Request<TResponse, TData>(uri, HttpMethod.Patch, data: data, cancellationToken: cancellationToken);
|
||||||
|
|
||||||
|
// Delete request
|
||||||
|
private async Task<TResponse?> Delete<TResponse>(string uri, CancellationToken cancellationToken = default)
|
||||||
|
where TResponse : IOmgLolResponseData
|
||||||
|
=> await Request<TResponse, object>(uri, HttpMethod.Delete, cancellationToken: cancellationToken);
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Specific Requests
|
||||||
public async Task<List<Status>> StatuslogLatest() =>
|
public async Task<List<Status>> StatuslogLatest() =>
|
||||||
(await Get<StatusResponseData>("/statuslog/latest"))?.Statuses ?? new List<Status>();
|
(await Get<StatusResponseData>("/statuslog/latest"))?.Statuses ?? new List<Status>();
|
||||||
|
|
||||||
|
@ -257,25 +189,6 @@ namespace Neighbourhood.omg.lol
|
||||||
|
|
||||||
public async Task<PutPicResponseData?> PutPic(string address, string base64Image) =>
|
public async Task<PutPicResponseData?> PutPic(string address, string base64Image) =>
|
||||||
(await Put<PutPicResponseData, PutPic>($"/address/{address}/pics/upload", new PutPic { Pic = base64Image }));
|
(await Put<PutPicResponseData, PutPic>($"/address/{address}/pics/upload", new PutPic { Pic = base64Image }));
|
||||||
public async Task<PutPicResponseData?> PutPic(string address, IBrowserFile file) {
|
|
||||||
byte[] bytes;
|
|
||||||
using (var memoryStream = new MemoryStream()) {
|
|
||||||
await file.OpenReadStream().CopyToAsync(memoryStream);
|
|
||||||
bytes = memoryStream.ToArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
return await PutPic(address, bytes);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<PutPicResponseData?> PutPic(string address, FileResult file) {
|
|
||||||
byte[] bytes;
|
|
||||||
using var memoryStream = new MemoryStream();
|
|
||||||
using var fileStream = await file.OpenReadAsync();
|
|
||||||
await fileStream.CopyToAsync(memoryStream);
|
|
||||||
bytes = memoryStream.ToArray();
|
|
||||||
|
|
||||||
return await PutPic(address, bytes);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<PutPicResponseData?> PutPic(string address, byte[] bytes) =>
|
public async Task<PutPicResponseData?> PutPic(string address, byte[] bytes) =>
|
||||||
await PutPic(address, Convert.ToBase64String(bytes));
|
await PutPic(address, Convert.ToBase64String(bytes));
|
||||||
|
@ -324,7 +237,26 @@ namespace Neighbourhood.omg.lol
|
||||||
(MarkupString)((await Get<ThemePreviewResponseData>($"/theme/{theme}/preview"))?.Html ?? string.Empty);
|
(MarkupString)((await Get<ThemePreviewResponseData>($"/theme/{theme}/preview"))?.Html ?? string.Empty);
|
||||||
|
|
||||||
public async Task<BasicResponseData?> PostProfilePic(string address, FileResult image) =>
|
public async Task<BasicResponseData?> PostProfilePic(string address, FileResult image) =>
|
||||||
await PostBinary<BasicResponseData, object>($"/address/{address}/pfp", fileResult: image);
|
await PostBinary<BasicResponseData>($"/address/{address}/pfp", fileResult: image);
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Auth
|
||||||
|
/// <summary>
|
||||||
|
/// Add the api token into the default headers
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="token">The api token</param>
|
||||||
|
public void AddToken(string? token = null) {
|
||||||
|
if (token == null) token = Task.Run(() => SecureStorage.GetAsync("accounttoken")).GetAwaiter().GetResult();
|
||||||
|
if (token != null) _client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", token);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Remove the api token from the default headers
|
||||||
|
/// </summary>
|
||||||
|
public void RemoveToken() {
|
||||||
|
_client.DefaultRequestHeaders.Remove("Authorization");
|
||||||
|
}
|
||||||
|
|
||||||
public async Task<string?> OAuth(string code, string client_id, string client_secret, string redirect_uri) {
|
public async Task<string?> OAuth(string code, string client_id, string client_secret, string redirect_uri) {
|
||||||
string? token = null;
|
string? token = null;
|
||||||
|
@ -343,6 +275,7 @@ namespace Neighbourhood.omg.lol
|
||||||
}
|
}
|
||||||
return token;
|
return token;
|
||||||
}
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
public async Task<MarkupString?> GetHtml(string url) {
|
public async Task<MarkupString?> GetHtml(string url) {
|
||||||
string? raw = null;
|
string? raw = null;
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
namespace Neighbourhood.omg.lol.Models {
|
namespace Neighbourhood.omg.lol.Models {
|
||||||
public class AddressResponseList : List<AddressResponseData>, IOmgLolResponseList<AddressResponseData> {
|
public class AddressResponseList : List<AddressResponseData>, IOmgLolResponseList<AddressResponseData> {
|
||||||
|
public string Message { get; set; } = string.Empty;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
namespace Neighbourhood.omg.lol.Models {
|
namespace Neighbourhood.omg.lol.Models {
|
||||||
public interface IOmgLolResponseData {
|
public interface IOmgLolResponseData {
|
||||||
|
public string Message { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
11
Models/API/OmgLolApiException.cs
Normal file
11
Models/API/OmgLolApiException.cs
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
namespace Neighbourhood.omg.lol.Models {
|
||||||
|
public class OmgLolApiException<T> : Exception where T : IOmgLolResponseData {
|
||||||
|
public OmgLolResponse<T>? Response { get; set; }
|
||||||
|
|
||||||
|
public OmgLolApiException(OmgLolResponse<T>? response) : base(response?.Response?.Message) {
|
||||||
|
Response = response;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OmgLolApiException(string? response) : base(response) { }
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
namespace Neighbourhood.omg.lol.Models {
|
namespace Neighbourhood.omg.lol.Models {
|
||||||
public class StatusPostResponseData : IOmgLolResponseData {
|
public class StatusPostResponseData : IOmgLolResponseData {
|
||||||
public string? Message { get; set; }
|
public string Message { get; set; } = string.Empty;
|
||||||
public string? Id { get; set; }
|
public string? Id { get; set; }
|
||||||
public string? Url { get; set; }
|
public string? Url { get; set; }
|
||||||
public string? ExternalUrl { get; set; }
|
public string? ExternalUrl { get; set; }
|
||||||
|
|
Loading…
Reference in a new issue