summaryrefslogtreecommitdiff
path: root/src/SMAPI.Web/Framework/Clients/Chucklefish
diff options
context:
space:
mode:
Diffstat (limited to 'src/SMAPI.Web/Framework/Clients/Chucklefish')
-rw-r--r--src/SMAPI.Web/Framework/Clients/Chucklefish/ChucklefishClient.cs38
-rw-r--r--src/SMAPI.Web/Framework/Clients/Chucklefish/ChucklefishMod.cs18
-rw-r--r--src/SMAPI.Web/Framework/Clients/Chucklefish/IChucklefishClient.cs12
3 files changed, 23 insertions, 45 deletions
diff --git a/src/SMAPI.Web/Framework/Clients/Chucklefish/ChucklefishClient.cs b/src/SMAPI.Web/Framework/Clients/Chucklefish/ChucklefishClient.cs
index cdb281e2..ca156da4 100644
--- a/src/SMAPI.Web/Framework/Clients/Chucklefish/ChucklefishClient.cs
+++ b/src/SMAPI.Web/Framework/Clients/Chucklefish/ChucklefishClient.cs
@@ -3,6 +3,7 @@ using System.Net;
using System.Threading.Tasks;
using HtmlAgilityPack;
using Pathoschild.Http.Client;
+using StardewModdingAPI.Toolkit.Framework.UpdateData;
namespace StardewModdingAPI.Web.Framework.Clients.Chucklefish
{
@@ -20,6 +21,13 @@ namespace StardewModdingAPI.Web.Framework.Clients.Chucklefish
/*********
+ ** Accessors
+ *********/
+ /// <summary>The unique key for the mod site.</summary>
+ public ModSiteKey SiteKey => ModSiteKey.Chucklefish;
+
+
+ /*********
** Public methods
*********/
/// <summary>Construct an instance.</summary>
@@ -32,42 +40,40 @@ namespace StardewModdingAPI.Web.Framework.Clients.Chucklefish
this.Client = new FluentClient(baseUrl).SetUserAgent(userAgent);
}
- /// <summary>Get metadata about a mod.</summary>
- /// <param name="id">The Chucklefish mod ID.</param>
- /// <returns>Returns the mod info if found, else <c>null</c>.</returns>
- public async Task<ChucklefishMod> GetModAsync(uint id)
+ /// <summary>Get update check info about a mod.</summary>
+ /// <param name="id">The mod ID.</param>
+ public async Task<IModPage> GetModData(string id)
{
+ IModPage page = new GenericModPage(this.SiteKey, id);
+
+ // get mod ID
+ if (!uint.TryParse(id, out uint parsedId))
+ return page.SetError(RemoteModStatus.DoesNotExist, $"The value '{id}' isn't a valid Chucklefish mod ID, must be an integer ID.");
+
// fetch HTML
string html;
try
{
html = await this.Client
- .GetAsync(string.Format(this.ModPageUrlFormat, id))
+ .GetAsync(string.Format(this.ModPageUrlFormat, parsedId))
.AsString();
}
catch (ApiException ex) when (ex.Status == HttpStatusCode.NotFound || ex.Status == HttpStatusCode.Forbidden)
{
- return null;
+ return page.SetError(RemoteModStatus.DoesNotExist, "Found no Chucklefish mod with this ID.");
}
-
- // parse HTML
var doc = new HtmlDocument();
doc.LoadHtml(html);
// extract mod info
- string url = this.GetModUrl(id);
+ string url = this.GetModUrl(parsedId);
string name = doc.DocumentNode.SelectSingleNode("//meta[@name='twitter:title']").Attributes["content"].Value;
if (name.StartsWith("[SMAPI] "))
name = name.Substring("[SMAPI] ".Length);
string version = doc.DocumentNode.SelectSingleNode("//h1/span")?.InnerText;
- // create model
- return new ChucklefishMod
- {
- Name = name,
- Version = version,
- Url = url
- };
+ // return info
+ return page.SetInfo(name: name, version: version, url: url, downloads: Array.Empty<IModDownload>());
}
/// <summary>Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.</summary>
diff --git a/src/SMAPI.Web/Framework/Clients/Chucklefish/ChucklefishMod.cs b/src/SMAPI.Web/Framework/Clients/Chucklefish/ChucklefishMod.cs
deleted file mode 100644
index fd0101d4..00000000
--- a/src/SMAPI.Web/Framework/Clients/Chucklefish/ChucklefishMod.cs
+++ /dev/null
@@ -1,18 +0,0 @@
-namespace StardewModdingAPI.Web.Framework.Clients.Chucklefish
-{
- /// <summary>Mod metadata from the Chucklefish mod site.</summary>
- internal class ChucklefishMod
- {
- /*********
- ** Accessors
- *********/
- /// <summary>The mod name.</summary>
- public string Name { get; set; }
-
- /// <summary>The mod's semantic version number.</summary>
- public string Version { get; set; }
-
- /// <summary>The mod's web URL.</summary>
- public string Url { get; set; }
- }
-}
diff --git a/src/SMAPI.Web/Framework/Clients/Chucklefish/IChucklefishClient.cs b/src/SMAPI.Web/Framework/Clients/Chucklefish/IChucklefishClient.cs
index 1d8b256e..836d43f7 100644
--- a/src/SMAPI.Web/Framework/Clients/Chucklefish/IChucklefishClient.cs
+++ b/src/SMAPI.Web/Framework/Clients/Chucklefish/IChucklefishClient.cs
@@ -1,17 +1,7 @@
using System;
-using System.Threading.Tasks;
namespace StardewModdingAPI.Web.Framework.Clients.Chucklefish
{
/// <summary>An HTTP client for fetching mod metadata from the Chucklefish mod site.</summary>
- internal interface IChucklefishClient : IDisposable
- {
- /*********
- ** Methods
- *********/
- /// <summary>Get metadata about a mod.</summary>
- /// <param name="id">The Chucklefish mod ID.</param>
- /// <returns>Returns the mod info if found, else <c>null</c>.</returns>
- Task<ChucklefishMod> GetModAsync(uint id);
- }
+ internal interface IChucklefishClient : IModSiteClient, IDisposable { }
}