summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <github@jplamondonw.com>2018-03-04 21:05:50 -0500
committerJesse Plamondon-Willard <github@jplamondonw.com>2018-03-04 21:05:50 -0500
commit0a71285c631a6ef52ea381c35224f353a618e3fa (patch)
tree60201304919b95501bb03eb05aa0085d2920c3db /src
parent99023f94871e1f9bad5ee5f5db0ff041a02e9ed5 (diff)
downloadSMAPI-0a71285c631a6ef52ea381c35224f353a618e3fa.tar.gz
SMAPI-0a71285c631a6ef52ea381c35224f353a618e3fa.tar.bz2
SMAPI-0a71285c631a6ef52ea381c35224f353a618e3fa.zip
fix broken Nexus mod URLs
Diffstat (limited to 'src')
-rw-r--r--src/SMAPI.Web/Framework/Clients/Chucklefish/ChucklefishClient.cs19
-rw-r--r--src/SMAPI.Web/Framework/Clients/Nexus/NexusWebScrapeClient.cs15
2 files changed, 28 insertions, 6 deletions
diff --git a/src/SMAPI.Web/Framework/Clients/Chucklefish/ChucklefishClient.cs b/src/SMAPI.Web/Framework/Clients/Chucklefish/ChucklefishClient.cs
index 6772672c..029553ce 100644
--- a/src/SMAPI.Web/Framework/Clients/Chucklefish/ChucklefishClient.cs
+++ b/src/SMAPI.Web/Framework/Clients/Chucklefish/ChucklefishClient.cs
@@ -12,9 +12,6 @@ namespace StardewModdingAPI.Web.Framework.Clients.Chucklefish
/*********
** Properties
*********/
- /// <summary>The base URL for the Chucklefish mod site.</summary>
- private readonly string BaseUrl;
-
/// <summary>The URL for a mod page excluding the base URL, where {0} is the mod ID.</summary>
private readonly string ModPageUrlFormat;
@@ -31,7 +28,6 @@ namespace StardewModdingAPI.Web.Framework.Clients.Chucklefish
/// <param name="modPageUrlFormat">The URL for a mod page excluding the <paramref name="baseUrl"/>, where {0} is the mod ID.</param>
public ChucklefishClient(string userAgent, string baseUrl, string modPageUrlFormat)
{
- this.BaseUrl = baseUrl;
this.ModPageUrlFormat = modPageUrlFormat;
this.Client = new FluentClient(baseUrl).SetUserAgent(userAgent);
}
@@ -59,7 +55,7 @@ namespace StardewModdingAPI.Web.Framework.Clients.Chucklefish
doc.LoadHtml(html);
// extract mod info
- string url = new UriBuilder(new Uri(this.BaseUrl)) { Path = string.Format(this.ModPageUrlFormat, id) }.Uri.ToString();
+ string url = this.GetModUrl(id);
string name = doc.DocumentNode.SelectSingleNode("//meta[@name='twitter:title']").Attributes["content"].Value;
if (name.StartsWith("[SMAPI] "))
name = name.Substring("[SMAPI] ".Length);
@@ -79,5 +75,18 @@ namespace StardewModdingAPI.Web.Framework.Clients.Chucklefish
{
this.Client?.Dispose();
}
+
+
+ /*********
+ ** Private methods
+ *********/
+ /// <summary>Get the full mod page URL for a given ID.</summary>
+ /// <param name="id">The mod ID.</param>
+ private string GetModUrl(uint id)
+ {
+ UriBuilder builder = new UriBuilder(this.Client.BaseClient.BaseAddress);
+ builder.Path += string.Format(this.ModPageUrlFormat, id);
+ return builder.Uri.ToString();
+ }
}
}
diff --git a/src/SMAPI.Web/Framework/Clients/Nexus/NexusWebScrapeClient.cs b/src/SMAPI.Web/Framework/Clients/Nexus/NexusWebScrapeClient.cs
index 1e941e3d..d0597965 100644
--- a/src/SMAPI.Web/Framework/Clients/Nexus/NexusWebScrapeClient.cs
+++ b/src/SMAPI.Web/Framework/Clients/Nexus/NexusWebScrapeClient.cs
@@ -72,7 +72,7 @@ namespace StardewModdingAPI.Web.Framework.Clients.Nexus
}
// extract mod info
- string url = new UriBuilder(this.Client.BaseClient.BaseAddress) { Path = string.Format(this.ModUrlFormat, id) }.Uri.ToString();
+ string url = this.GetModUrl(id);
string name = doc.DocumentNode.SelectSingleNode("//h1")?.InnerText.Trim();
string version = doc.DocumentNode.SelectSingleNode("//ul[contains(@class, 'stats')]//li[@class='stat-version']//div[@class='stat']")?.InnerText.Trim();
@@ -89,5 +89,18 @@ namespace StardewModdingAPI.Web.Framework.Clients.Nexus
{
this.Client?.Dispose();
}
+
+
+ /*********
+ ** Private methods
+ *********/
+ /// <summary>Get the full mod page URL for a given ID.</summary>
+ /// <param name="id">The mod ID.</param>
+ private string GetModUrl(uint id)
+ {
+ UriBuilder builder = new UriBuilder(this.Client.BaseClient.BaseAddress);
+ builder.Path += string.Format(this.ModUrlFormat, id);
+ return builder.Uri.ToString();
+ }
}
}