summaryrefslogtreecommitdiff
path: root/src/SMAPI.Web/Framework/ModRepositories/GitHubRepository.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/SMAPI.Web/Framework/ModRepositories/GitHubRepository.cs')
-rw-r--r--src/SMAPI.Web/Framework/ModRepositories/GitHubRepository.cs59
1 files changed, 10 insertions, 49 deletions
diff --git a/src/SMAPI.Web/Framework/ModRepositories/GitHubRepository.cs b/src/SMAPI.Web/Framework/ModRepositories/GitHubRepository.cs
index 9d43adf0..7bad6127 100644
--- a/src/SMAPI.Web/Framework/ModRepositories/GitHubRepository.cs
+++ b/src/SMAPI.Web/Framework/ModRepositories/GitHubRepository.cs
@@ -1,9 +1,7 @@
using System;
-using System.Net;
using System.Threading.Tasks;
-using Newtonsoft.Json;
-using Pathoschild.Http.Client;
using StardewModdingAPI.Common.Models;
+using StardewModdingAPI.Web.Framework.Clients.GitHub;
namespace StardewModdingAPI.Web.Framework.ModRepositories
{
@@ -13,11 +11,8 @@ namespace StardewModdingAPI.Web.Framework.ModRepositories
/*********
** Properties
*********/
- /// <summary>The URL for a Nexus Mods API query excluding the base URL, where {0} is the mod ID.</summary>
- private readonly string ReleaseUrlFormat;
-
- /// <summary>The underlying HTTP client.</summary>
- private readonly IClient Client;
+ /// <summary>The underlying GitHub API client.</summary>
+ private readonly IGitHubClient Client;
/*********
@@ -25,22 +20,11 @@ namespace StardewModdingAPI.Web.Framework.ModRepositories
*********/
/// <summary>Construct an instance.</summary>
/// <param name="vendorKey">The unique key for this vendor.</param>
- /// <param name="baseUrl">The base URL for the Nexus Mods API.</param>
- /// <param name="releaseUrlFormat">The URL for a Nexus Mods API query excluding the <paramref name="baseUrl"/>, where {0} is the mod ID.</param>
- /// <param name="userAgent">The user agent for the API client.</param>
- /// <param name="acceptHeader">The Accept header value expected by the GitHub API.</param>
- /// <param name="username">The username with which to authenticate to the GitHub API.</param>
- /// <param name="password">The password with which to authenticate to the GitHub API.</param>
- public GitHubRepository(string vendorKey, string baseUrl, string releaseUrlFormat, string userAgent, string acceptHeader, string username, string password)
+ /// <param name="client">The underlying GitHub API client.</param>
+ public GitHubRepository(string vendorKey, IGitHubClient client)
: base(vendorKey)
{
- this.ReleaseUrlFormat = releaseUrlFormat;
-
- this.Client = new FluentClient(baseUrl)
- .SetUserAgent(userAgent)
- .AddDefault(req => req.WithHeader("Accept", acceptHeader));
- if (!string.IsNullOrWhiteSpace(username))
- this.Client = this.Client.SetBasicAuthentication(username, password);
+ this.Client = client;
}
/// <summary>Get metadata about a mod in the repository.</summary>
@@ -54,14 +38,10 @@ namespace StardewModdingAPI.Web.Framework.ModRepositories
// fetch info
try
{
- GitRelease release = await this.Client
- .GetAsync(string.Format(this.ReleaseUrlFormat, id))
- .As<GitRelease>();
- return new ModInfoModel(id, this.NormaliseVersion(release.Tag), $"https://github.com/{id}/releases");
- }
- catch (ApiException ex) when (ex.Status == HttpStatusCode.NotFound)
- {
- return new ModInfoModel("Found no mod with this ID.");
+ GitRelease release = await this.Client.GetLatestReleaseAsync(id);
+ return release != null
+ ? new ModInfoModel(id, this.NormaliseVersion(release.Tag), $"https://github.com/{id}/releases")
+ : new ModInfoModel("Found no mod with this ID.");
}
catch (Exception ex)
{
@@ -74,24 +54,5 @@ namespace StardewModdingAPI.Web.Framework.ModRepositories
{
this.Client.Dispose();
}
-
-
- /*********
- ** Private models
- *********/
- /// <summary>Metadata about a GitHub release tag.</summary>
- private class GitRelease
- {
- /*********
- ** Accessors
- *********/
- /// <summary>The display name.</summary>
- [JsonProperty("name")]
- public string Name { get; set; }
-
- /// <summary>The semantic version string.</summary>
- [JsonProperty("tag_name")]
- public string Tag { get; set; }
- }
}
}