diff options
Diffstat (limited to 'src/SMAPI.Web/Framework')
-rw-r--r-- | src/SMAPI.Web/Framework/Clients/Pastebin/IPastebinClient.cs | 17 | ||||
-rw-r--r-- | src/SMAPI.Web/Framework/Clients/Pastebin/PasteInfo.cs (renamed from src/SMAPI.Web/Framework/LogParser/GetPasteResponse.cs) | 4 | ||||
-rw-r--r-- | src/SMAPI.Web/Framework/Clients/Pastebin/PastebinClient.cs (renamed from src/SMAPI.Web/Framework/LogParser/PastebinClient.cs) | 30 | ||||
-rw-r--r-- | src/SMAPI.Web/Framework/Clients/Pastebin/SavePasteResult.cs (renamed from src/SMAPI.Web/Framework/LogParser/SavePasteResponse.cs) | 4 | ||||
-rw-r--r-- | src/SMAPI.Web/Framework/ConfigModels/ApiClientsConfig.cs | 16 | ||||
-rw-r--r-- | src/SMAPI.Web/Framework/ConfigModels/LogParserConfig.cs | 12 |
6 files changed, 52 insertions, 31 deletions
diff --git a/src/SMAPI.Web/Framework/Clients/Pastebin/IPastebinClient.cs b/src/SMAPI.Web/Framework/Clients/Pastebin/IPastebinClient.cs new file mode 100644 index 00000000..630dfb76 --- /dev/null +++ b/src/SMAPI.Web/Framework/Clients/Pastebin/IPastebinClient.cs @@ -0,0 +1,17 @@ +using System; +using System.Threading.Tasks; + +namespace StardewModdingAPI.Web.Framework.Clients.Pastebin +{ + /// <summary>An API client for Pastebin.</summary> + internal interface IPastebinClient : IDisposable + { + /// <summary>Fetch a saved paste.</summary> + /// <param name="id">The paste ID.</param> + Task<PasteInfo> GetAsync(string id); + + /// <summary>Save a paste to Pastebin.</summary> + /// <param name="content">The paste content.</param> + Task<SavePasteResult> PostAsync(string content); + } +} diff --git a/src/SMAPI.Web/Framework/LogParser/GetPasteResponse.cs b/src/SMAPI.Web/Framework/Clients/Pastebin/PasteInfo.cs index 4f8794db..955156eb 100644 --- a/src/SMAPI.Web/Framework/LogParser/GetPasteResponse.cs +++ b/src/SMAPI.Web/Framework/Clients/Pastebin/PasteInfo.cs @@ -1,7 +1,7 @@ -namespace StardewModdingAPI.Web.Framework.LogParser +namespace StardewModdingAPI.Web.Framework.Clients.Pastebin { /// <summary>The response for a get-paste request.</summary> - internal class GetPasteResponse + internal class PasteInfo { /// <summary>Whether the log was successfully fetched.</summary> public bool Success { get; set; } diff --git a/src/SMAPI.Web/Framework/LogParser/PastebinClient.cs b/src/SMAPI.Web/Framework/Clients/Pastebin/PastebinClient.cs index 1cfaed17..ef83a91e 100644 --- a/src/SMAPI.Web/Framework/LogParser/PastebinClient.cs +++ b/src/SMAPI.Web/Framework/Clients/Pastebin/PastebinClient.cs @@ -8,10 +8,10 @@ using System.Threading.Tasks; using System.Web; using Pathoschild.Http.Client; -namespace StardewModdingAPI.Web.Framework.LogParser +namespace StardewModdingAPI.Web.Framework.Clients.Pastebin { /// <summary>An API client for Pastebin.</summary> - internal class PastebinClient : IDisposable + internal class PastebinClient : IPastebinClient { /********* ** Properties @@ -43,7 +43,7 @@ namespace StardewModdingAPI.Web.Framework.LogParser /// <summary>Fetch a saved paste.</summary> /// <param name="id">The paste ID.</param> - public async Task<GetPasteResponse> GetAsync(string id) + public async Task<PasteInfo> GetAsync(string id) { try { @@ -54,30 +54,30 @@ namespace StardewModdingAPI.Web.Framework.LogParser // handle Pastebin errors if (string.IsNullOrWhiteSpace(content)) - return new GetPasteResponse { Error = "Received an empty response from Pastebin." }; + return new PasteInfo { Error = "Received an empty response from Pastebin." }; if (content.StartsWith("<!DOCTYPE")) - return new GetPasteResponse { Error = $"Received a captcha challenge from Pastebin. Please visit https://pastebin.com/{id} in a new window to solve it." }; - return new GetPasteResponse { Success = true, Content = content }; + return new PasteInfo { Error = $"Received a captcha challenge from Pastebin. Please visit https://pastebin.com/{id} in a new window to solve it." }; + return new PasteInfo { Success = true, Content = content }; } catch (ApiException ex) when (ex.Status == HttpStatusCode.NotFound) { - return new GetPasteResponse { Error = "There's no log with that ID." }; + return new PasteInfo { Error = "There's no log with that ID." }; } catch (Exception ex) { - return new GetPasteResponse { Error = ex.ToString() }; + return new PasteInfo { Error = ex.ToString() }; } } /// <summary>Save a paste to Pastebin.</summary> /// <param name="content">The paste content.</param> - public async Task<SavePasteResponse> PostAsync(string content) + public async Task<SavePasteResult> PostAsync(string content) { try { // validate if (string.IsNullOrWhiteSpace(content)) - return new SavePasteResponse { Error = "The log content can't be empty." }; + return new SavePasteResult { Error = "The log content can't be empty." }; // post to API string response = await this.Client @@ -96,19 +96,19 @@ namespace StardewModdingAPI.Web.Framework.LogParser // handle Pastebin errors if (string.IsNullOrWhiteSpace(response)) - return new SavePasteResponse { Error = "Received an empty response from Pastebin." }; + return new SavePasteResult { Error = "Received an empty response from Pastebin." }; if (response.StartsWith("Bad API request")) - return new SavePasteResponse { Error = response }; + return new SavePasteResult { Error = response }; if (!response.Contains("/")) - return new SavePasteResponse { Error = $"Received an unknown response: {response}" }; + return new SavePasteResult { Error = $"Received an unknown response: {response}" }; // return paste ID string pastebinID = response.Split("/").Last(); - return new SavePasteResponse { Success = true, ID = pastebinID }; + return new SavePasteResult { Success = true, ID = pastebinID }; } catch (Exception ex) { - return new SavePasteResponse { Success = false, Error = ex.ToString() }; + return new SavePasteResult { Success = false, Error = ex.ToString() }; } } diff --git a/src/SMAPI.Web/Framework/LogParser/SavePasteResponse.cs b/src/SMAPI.Web/Framework/Clients/Pastebin/SavePasteResult.cs index 1c0960a4..89dab697 100644 --- a/src/SMAPI.Web/Framework/LogParser/SavePasteResponse.cs +++ b/src/SMAPI.Web/Framework/Clients/Pastebin/SavePasteResult.cs @@ -1,7 +1,7 @@ -namespace StardewModdingAPI.Web.Framework.LogParser +namespace StardewModdingAPI.Web.Framework.Clients.Pastebin { /// <summary>The response for a save-log request.</summary> - internal class SavePasteResponse + internal class SavePasteResult { /// <summary>Whether the log was successfully saved.</summary> public bool Success { get; set; } diff --git a/src/SMAPI.Web/Framework/ConfigModels/ApiClientsConfig.cs b/src/SMAPI.Web/Framework/ConfigModels/ApiClientsConfig.cs index 19794920..61219414 100644 --- a/src/SMAPI.Web/Framework/ConfigModels/ApiClientsConfig.cs +++ b/src/SMAPI.Web/Framework/ConfigModels/ApiClientsConfig.cs @@ -52,5 +52,21 @@ namespace StardewModdingAPI.Web.Framework.ConfigModels /// <summary>The URL for a Nexus Mods API query excluding the <see cref="NexusBaseUrl"/>, where {0} is the mod ID.</summary> public string NexusModUrlFormat { get; set; } + + /**** + ** Pastebin + ****/ + /// <summary>The base URL for the Pastebin API.</summary> + public string PastebinBaseUrl { get; set; } + + /// <summary>The user agent for the Pastebin API client, where {0} is the SMAPI version.</summary> + public string PastebinUserAgent { get; set; } + + /// <summary>The user key used to authenticate with the Pastebin API.</summary> + public string PastebinUserKey { get; set; } + + /// <summary>The developer key used to authenticate with the Pastebin API.</summary> + public string PastebinDevKey { get; set; } + } } diff --git a/src/SMAPI.Web/Framework/ConfigModels/LogParserConfig.cs b/src/SMAPI.Web/Framework/ConfigModels/LogParserConfig.cs index df5d605d..198274b2 100644 --- a/src/SMAPI.Web/Framework/ConfigModels/LogParserConfig.cs +++ b/src/SMAPI.Web/Framework/ConfigModels/LogParserConfig.cs @@ -8,17 +8,5 @@ namespace StardewModdingAPI.Web.Framework.ConfigModels *********/ /// <summary>The root URL for the log parser controller.</summary> public string SectionUrl { get; set; } - - /// <summary>The base URL for the Pastebin API.</summary> - public string PastebinBaseUrl { get; set; } - - /// <summary>The user agent for the Pastebin API client, where {0} is the SMAPI version.</summary> - public string PastebinUserAgent { get; set; } - - /// <summary>The user key used to authenticate with the Pastebin API.</summary> - public string PastebinUserKey { get; set; } - - /// <summary>The developer key used to authenticate with the Pastebin API.</summary> - public string PastebinDevKey { get; set; } } } |