Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added instanceToken and forceHttps to PlexAccountClient.GetAccountSer… #107

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions Source/Plex.Library/ApiModels/Accounts/PlexAccount.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,18 +152,24 @@ public async Task<OAuthPin> 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.
/// </summary>
/// <param name="forceHttps">Forces URI scheme to https</param>
/// <param name="overrideHost">Accepts dictionary that overwrites the HOST part of the servers URI.
/// key = serverName, value = custom host string </param>
/// <returns>AccountServerContainer</returns>
public async Task<AccountServerContainer> ServerSummaries() =>
await this.plexAccountClient.GetAccountServersAsync(this.AuthToken);
public async Task<AccountServerContainer> ServerSummaries(bool forceHttps = false, Dictionary<string, string> overrideHost = null) =>
await this.plexAccountClient.GetAccountServersAsync(this.AuthToken, forceHttps, overrideHost);

/// <summary>
/// Get Active Servers tied to this Account
/// </summary>
/// <param name="forceHttps">Forces URI scheme to https</param>
/// <param name="overrideHost">Accepts dictionary that overwrites the HOST part of the servers URI.
/// key = serverName, value = custom host string </param>
/// <returns>List of Server objects</returns>
public async Task<List<Server>> Servers()
public async Task<List<Server>> Servers(bool forceHttps = false, Dictionary<string, string> overrideHost = null)
{
var servers = new List<Server>();
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,11 @@ public interface IPlexAccountClient
/// Retrieves a list of servers tied to your Plex Account.
/// </summary>
/// <param name="authToken">Authentication Token.</param>
/// <param name="forceHttps">Forces URI scheme to https</param>
/// <param name="overrideHost">Accepts dictionary that overwrites the HOST part of the servers URI.
/// key = serverName, value = custom host string </param>
/// <returns>AccountServerContainer.</returns>
Task<AccountServerContainer> GetAccountServersAsync(string authToken);
Task<AccountServerContainer> GetAccountServersAsync(string authToken, bool forceHttps = false, Dictionary<string, string> overrideHost = null);

/// <summary>
/// Get Plex Announcements
Expand Down
15 changes: 14 additions & 1 deletion Source/Plex.ServerApi/Clients/PlexAccountClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public async Task<User> SignInAsync(string username, string password)
}

/// <inheritdoc/>
public async Task<AccountServerContainer> GetAccountServersAsync(string authToken)
public async Task<AccountServerContainer> GetAccountServersAsync(string authToken, bool forceHttps = false, Dictionary<string, string> overrideHost = null)
{
var apiRequest = new ApiRequestBuilder("https://plex.tv/pms/servers.xml", string.Empty, HttpMethod.Get)
.AddPlexToken(authToken)
Expand All @@ -152,6 +152,19 @@ public async Task<AccountServerContainer> GetAccountServersAsync(string authToke

var serverContainer = await this.apiService.InvokeApiAsync<AccountServerContainer>(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;
}

Expand Down
19 changes: 19 additions & 0 deletions Tests/Plex.ServerApi.Test/Tests/AccountTest.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace Plex.ServerApi.Test.Tests
{
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Clients.Interfaces;
Expand Down Expand Up @@ -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<string, string>();

// overrideHosts.Add("serverName", "customHost");

var container = await this.fixture.PlexAccount.ServerSummaries(true, overrideHosts);
Assert.NotNull(container);
}

[Fact]
public async void Test_Opt_Out()
{
Expand Down