diff --git a/Source/Plex.Library/ApiModels/Accounts/PlexAccount.cs b/Source/Plex.Library/ApiModels/Accounts/PlexAccount.cs index 6fd29f9..9c0c455 100644 --- a/Source/Plex.Library/ApiModels/Accounts/PlexAccount.cs +++ b/Source/Plex.Library/ApiModels/Accounts/PlexAccount.cs @@ -152,18 +152,24 @@ public async Task ClaimToken(string pinId) => /// Get Server Summaries. This does not return a Server Instance but a summary /// of all servers tied to your Plex Account. The servers may not be active/online. /// + /// Forces URI scheme to https + /// Accepts dictionary that overwrites the HOST part of the servers URI. + /// key = serverName, value = custom host string /// AccountServerContainer - public async Task ServerSummaries() => - await this.plexAccountClient.GetAccountServersAsync(this.AuthToken); + public async Task ServerSummaries(bool forceHttps = false, Dictionary overrideHost = null) => + await this.plexAccountClient.GetAccountServersAsync(this.AuthToken, forceHttps, overrideHost); /// /// Get Active Servers tied to this Account /// + /// Forces URI scheme to https + /// Accepts dictionary that overwrites the HOST part of the servers URI. + /// key = serverName, value = custom host string /// List of Server objects - public async Task> Servers() + public async Task> Servers(bool forceHttps = false, Dictionary overrideHost = null) { var servers = new List(); - var accountServerContainer = await this.plexAccountClient.GetAccountServersAsync(this.AuthToken); + var accountServerContainer = await this.plexAccountClient.GetAccountServersAsync(this.AuthToken, forceHttps, overrideHost); foreach (var server in accountServerContainer.Servers) { try diff --git a/Source/Plex.ServerApi/Clients/Interfaces/IPlexAccountClient.cs b/Source/Plex.ServerApi/Clients/Interfaces/IPlexAccountClient.cs index 337f4a5..ed90534 100644 --- a/Source/Plex.ServerApi/Clients/Interfaces/IPlexAccountClient.cs +++ b/Source/Plex.ServerApi/Clients/Interfaces/IPlexAccountClient.cs @@ -70,8 +70,11 @@ public interface IPlexAccountClient /// Retrieves a list of servers tied to your Plex Account. /// /// Authentication Token. + /// Forces URI scheme to https + /// Accepts dictionary that overwrites the HOST part of the servers URI. + /// key = serverName, value = custom host string /// AccountServerContainer. - Task GetAccountServersAsync(string authToken); + Task GetAccountServersAsync(string authToken, bool forceHttps = false, Dictionary overrideHost = null); /// /// Get Plex Announcements diff --git a/Source/Plex.ServerApi/Clients/PlexAccountClient.cs b/Source/Plex.ServerApi/Clients/PlexAccountClient.cs index 8c5dd1b..bc28a92 100644 --- a/Source/Plex.ServerApi/Clients/PlexAccountClient.cs +++ b/Source/Plex.ServerApi/Clients/PlexAccountClient.cs @@ -143,7 +143,7 @@ public async Task SignInAsync(string username, string password) } /// - public async Task GetAccountServersAsync(string authToken) + public async Task GetAccountServersAsync(string authToken, bool forceHttps = false, Dictionary overrideHost = null) { var apiRequest = new ApiRequestBuilder("https://plex.tv/pms/servers.xml", string.Empty, HttpMethod.Get) .AddPlexToken(authToken) @@ -152,6 +152,19 @@ public async Task GetAccountServersAsync(string authToke var serverContainer = await this.apiService.InvokeApiAsync(apiRequest); + foreach (var server in serverContainer.Servers) + { + if (forceHttps) + { + server.Scheme = "https"; + } + + if (overrideHost != null && overrideHost.TryGetValue(server.Name, out var host)) + { + server.Host = host; + } + } + return serverContainer; } diff --git a/Tests/Plex.ServerApi.Test/Tests/AccountTest.cs b/Tests/Plex.ServerApi.Test/Tests/AccountTest.cs index e4cded6..42bf7e8 100644 --- a/Tests/Plex.ServerApi.Test/Tests/AccountTest.cs +++ b/Tests/Plex.ServerApi.Test/Tests/AccountTest.cs @@ -1,5 +1,6 @@ namespace Plex.ServerApi.Test.Tests { + using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Clients.Interfaces; @@ -209,6 +210,24 @@ public async void Test_Get_Plex_ServerSummaries() Assert.NotNull(container); } + [Fact] + public async void Test_Get_Plex_ServerSummaries_ForceHttps() + { + var container = await this.fixture.PlexAccount.ServerSummaries(true); + Assert.NotNull(container); + } + + [Fact] + public async void Test_Get_Plex_ServerSummaries_OverrideHosts() + { + var overrideHosts = new Dictionary(); + + // overrideHosts.Add("serverName", "customHost"); + + var container = await this.fixture.PlexAccount.ServerSummaries(true, overrideHosts); + Assert.NotNull(container); + } + [Fact] public async void Test_Opt_Out() {