summaryrefslogtreecommitdiff
path: root/src/SMAPI.Web/Framework/Clients/Pastebin
diff options
context:
space:
mode:
Diffstat (limited to 'src/SMAPI.Web/Framework/Clients/Pastebin')
-rw-r--r--src/SMAPI.Web/Framework/Clients/Pastebin/IPastebinClient.cs5
-rw-r--r--src/SMAPI.Web/Framework/Clients/Pastebin/PasteInfo.cs8
-rw-r--r--src/SMAPI.Web/Framework/Clients/Pastebin/PastebinClient.cs58
-rw-r--r--src/SMAPI.Web/Framework/Clients/Pastebin/SavePasteResult.cs15
4 files changed, 1 insertions, 85 deletions
diff --git a/src/SMAPI.Web/Framework/Clients/Pastebin/IPastebinClient.cs b/src/SMAPI.Web/Framework/Clients/Pastebin/IPastebinClient.cs
index a635abe3..431fed7b 100644
--- a/src/SMAPI.Web/Framework/Clients/Pastebin/IPastebinClient.cs
+++ b/src/SMAPI.Web/Framework/Clients/Pastebin/IPastebinClient.cs
@@ -9,10 +9,5 @@ namespace StardewModdingAPI.Web.Framework.Clients.Pastebin
/// <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="name">The paste name.</param>
- /// <param name="content">The paste content.</param>
- Task<SavePasteResult> PostAsync(string name, string content);
}
}
diff --git a/src/SMAPI.Web/Framework/Clients/Pastebin/PasteInfo.cs b/src/SMAPI.Web/Framework/Clients/Pastebin/PasteInfo.cs
index bb2de356..813ea115 100644
--- a/src/SMAPI.Web/Framework/Clients/Pastebin/PasteInfo.cs
+++ b/src/SMAPI.Web/Framework/Clients/Pastebin/PasteInfo.cs
@@ -1,5 +1,3 @@
-using System;
-
namespace StardewModdingAPI.Web.Framework.Clients.Pastebin
{
/// <summary>The response for a get-paste request.</summary>
@@ -11,12 +9,6 @@ namespace StardewModdingAPI.Web.Framework.Clients.Pastebin
/// <summary>The fetched paste content (if <see cref="Success"/> is <c>true</c>).</summary>
public string Content { get; set; }
- /// <summary>When the file will no longer be available.</summary>
- public DateTime? Expiry { get; set; }
-
- /// <summary>The error message if saving succeeded, but a non-blocking issue was encountered.</summary>
- public string Warning { get; set; }
-
/// <summary>The error message if saving failed.</summary>
public string Error { get; set; }
}
diff --git a/src/SMAPI.Web/Framework/Clients/Pastebin/PastebinClient.cs b/src/SMAPI.Web/Framework/Clients/Pastebin/PastebinClient.cs
index d695aab6..1be00be7 100644
--- a/src/SMAPI.Web/Framework/Clients/Pastebin/PastebinClient.cs
+++ b/src/SMAPI.Web/Framework/Clients/Pastebin/PastebinClient.cs
@@ -1,7 +1,5 @@
using System;
-using System.Linq;
using System.Net;
-using System.Net.Http;
using System.Threading.Tasks;
using Pathoschild.Http.Client;
@@ -16,12 +14,6 @@ namespace StardewModdingAPI.Web.Framework.Clients.Pastebin
/// <summary>The underlying HTTP client.</summary>
private readonly IClient Client;
- /// <summary>The user key used to authenticate with the Pastebin API.</summary>
- private readonly string UserKey;
-
- /// <summary>The developer key used to authenticate with the Pastebin API.</summary>
- private readonly string DevKey;
-
/*********
** Public methods
@@ -29,13 +21,9 @@ namespace StardewModdingAPI.Web.Framework.Clients.Pastebin
/// <summary>Construct an instance.</summary>
/// <param name="baseUrl">The base URL for the Pastebin API.</param>
/// <param name="userAgent">The user agent for the API client.</param>
- /// <param name="userKey">The user key used to authenticate with the Pastebin API.</param>
- /// <param name="devKey">The developer key used to authenticate with the Pastebin API.</param>
- public PastebinClient(string baseUrl, string userAgent, string userKey, string devKey)
+ public PastebinClient(string baseUrl, string userAgent)
{
this.Client = new FluentClient(baseUrl).SetUserAgent(userAgent);
- this.UserKey = userKey;
- this.DevKey = devKey;
}
/// <summary>Fetch a saved paste.</summary>
@@ -66,50 +54,6 @@ namespace StardewModdingAPI.Web.Framework.Clients.Pastebin
}
}
- /// <summary>Save a paste to Pastebin.</summary>
- /// <param name="name">The paste name.</param>
- /// <param name="content">The paste content.</param>
- public async Task<SavePasteResult> PostAsync(string name, string content)
- {
- try
- {
- // validate
- if (string.IsNullOrWhiteSpace(content))
- return new SavePasteResult { Error = "The log content can't be empty." };
-
- // post to API
- string response = await this.Client
- .PostAsync("api/api_post.php")
- .WithBody(p => p.FormUrlEncoded(new
- {
- api_option = "paste",
- api_user_key = this.UserKey,
- api_dev_key = this.DevKey,
- api_paste_private = 1, // unlisted
- api_paste_name = name,
- api_paste_expire_date = "N", // never expire
- api_paste_code = content
- }))
- .AsString();
-
- // handle Pastebin errors
- if (string.IsNullOrWhiteSpace(response))
- return new SavePasteResult { Error = "Received an empty response from Pastebin." };
- if (response.StartsWith("Bad API request"))
- return new SavePasteResult { Error = response };
- if (!response.Contains("/"))
- return new SavePasteResult { Error = $"Received an unknown response: {response}" };
-
- // return paste ID
- string pastebinID = response.Split("/").Last();
- return new SavePasteResult { Success = true, ID = pastebinID };
- }
- catch (Exception ex)
- {
- return new SavePasteResult { Success = false, Error = ex.ToString() };
- }
- }
-
/// <summary>Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.</summary>
public void Dispose()
{
diff --git a/src/SMAPI.Web/Framework/Clients/Pastebin/SavePasteResult.cs b/src/SMAPI.Web/Framework/Clients/Pastebin/SavePasteResult.cs
deleted file mode 100644
index 89dab697..00000000
--- a/src/SMAPI.Web/Framework/Clients/Pastebin/SavePasteResult.cs
+++ /dev/null
@@ -1,15 +0,0 @@
-namespace StardewModdingAPI.Web.Framework.Clients.Pastebin
-{
- /// <summary>The response for a save-log request.</summary>
- internal class SavePasteResult
- {
- /// <summary>Whether the log was successfully saved.</summary>
- public bool Success { get; set; }
-
- /// <summary>The saved paste ID (if <see cref="Success"/> is <c>true</c>).</summary>
- public string ID { get; set; }
-
- /// <summary>The error message (if saving failed).</summary>
- public string Error { get; set; }
- }
-}