Skip to content

Commit 386cb4f

Browse files
Kevin JensenKevin Jensen
authored andcommitted
uri cleanup
1 parent 10ee94d commit 386cb4f

9 files changed

Lines changed: 439 additions & 496 deletions

File tree

Source/Plex.Library/ApiModels/Accounts/PlexAccount.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ public async Task<List<Server>> Servers()
188188
/// Return list of Resources for Plex Account
189189
/// </summary>
190190
/// <returns>List of Resource Objects</returns>
191-
public async Task<ResourceContainer> Resources() =>
191+
public async Task<List<Resource>> Resources() =>
192192
await this.plexAccountClient.GetResourcesAsync(this.AuthToken);
193193

194194
/// <summary>
@@ -286,7 +286,7 @@ public async Task OptOut(bool playback, bool library) =>
286286
/// <returns>List of Device objects</returns>
287287
public async Task<List<Device>> Devices() =>
288288
await this.plexAccountClient.GetDevicesAsync(this.AuthToken);
289-
289+
290290
// AddWebhook(string url);
291291
// DeleteWebhook(string url);
292292
// SetWebhooks(string[] urls);

Source/Plex.ServerApi/Clients/Interfaces/IPlexAccountClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public interface IPlexAccountClient
6363
/// </summary>
6464
/// <param name="authToken">Authentication Token.</param>
6565
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
66-
Task<ResourceContainer> GetResourcesAsync(string authToken);
66+
Task<List<Resource>> GetResourcesAsync(string authToken);
6767

6868
/// <summary>
6969
/// http://[PMS_IP_Address]:32400/library/sections?X-Plex-Token=YourTokenGoesHere

Source/Plex.ServerApi/Clients/PlexAccountClient.cs

Lines changed: 373 additions & 370 deletions
Large diffs are not rendered by default.
Lines changed: 37 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,42 @@
1-
namespace Plex.ServerApi.PlexModels.Account.Resources
1+
namespace Plex.ServerApi.PlexModels.Account.Resources;
2+
3+
using System.Collections.Generic;
4+
using System.Xml.Serialization;
5+
6+
/// <summary>
7+
/// This object represents resources connected to your Plex server that can provide
8+
/// content such as Plex Media Servers, iPhone or Android clients, etc. The raw xml
9+
/// for the data presented here can be found at:
10+
/// https://plex.tv/api/resources?includeHttps=1&includeRelay=1
11+
/// </summary>
12+
public class Resource
213
{
3-
using System.Collections.Generic;
4-
using System.Xml.Serialization;
14+
public string Name { get; set; }
15+
public string Product { get; set; }
16+
public string ProductVersion { get; set; }
17+
public string Platform { get; set; }
18+
public string PlatformVersion { get; set; }
19+
public string Device { get; set; }
20+
public string ClientIdentifier { get; set; }
21+
public string CreatedAt { get; set; }
22+
public string LastSeenAt { get; set; }
23+
public string Provides { get; set; }
24+
public int? OwnerId { get; set; }
25+
public string SourceTitle { get; set; }
26+
public string PublicAddress { get; set; }
27+
public string AccessToken { get; set; }
28+
public bool Owned { get; set; }
29+
public bool Home { get; set; }
30+
public bool Synced { get; set; }
31+
public bool Relay { get; set; }
32+
public bool Presence { get; set; }
33+
public bool HttpsRequired { get; set; }
34+
public bool PublicAddressMatches { get; set; }
35+
public bool DnsRebindingProtection { get; set; }
36+
public bool NatLoopbackSupport { get; set; }
537

638
/// <summary>
7-
/// This object represents resources connected to your Plex server that can provide
8-
/// content such as Plex Media Servers, iPhone or Android clients, etc. The raw xml
9-
/// for the data presented here can be found at:
10-
/// https://plex.tv/api/resources?includeHttps=1&includeRelay=1
39+
/// Connections
1140
/// </summary>
12-
[XmlRoot(ElementName = "Device")]
13-
public class Resource
14-
{
15-
[XmlElement(ElementName = "Connection")]
16-
public List<ResourceConnection> Connections { get; set; }
17-
18-
[XmlAttribute(AttributeName = "name")]
19-
public string Name { get; set; }
20-
21-
[XmlAttribute(AttributeName = "product")]
22-
public string Product { get; set; }
23-
24-
[XmlAttribute(AttributeName = "productVersion")]
25-
public string ProductVersion { get; set; }
26-
27-
[XmlAttribute(AttributeName = "platform")]
28-
public string Platform { get; set; }
29-
30-
[XmlAttribute(AttributeName = "platformVersion")]
31-
public string PlatformVersion { get; set; }
32-
33-
[XmlAttribute(AttributeName = "device")]
34-
public string Device { get; set; }
35-
36-
[XmlAttribute(AttributeName = "clientIdentifier")]
37-
public string ClientIdentifier { get; set; }
38-
39-
[XmlAttribute(AttributeName = "createdAt")]
40-
public int CreatedAt { get; set; }
41-
42-
[XmlAttribute(AttributeName = "lastSeenAt")]
43-
public int LastSeenAt { get; set; }
44-
45-
[XmlAttribute(AttributeName = "provides")]
46-
public string Provides { get; set; }
47-
48-
[XmlAttribute(AttributeName = "owned")]
49-
public int Owned { get; set; }
50-
51-
[XmlAttribute(AttributeName = "accessToken")]
52-
public string AccessToken { get; set; }
53-
54-
[XmlAttribute(AttributeName = "publicAddress")]
55-
public string PublicAddress { get; set; }
56-
57-
[XmlAttribute(AttributeName = "httpsRequired")]
58-
public int HttpsRequired { get; set; }
59-
60-
[XmlAttribute(AttributeName = "synced")]
61-
public int Synced { get; set; }
62-
63-
[XmlAttribute(AttributeName = "relay")]
64-
public int Relay { get; set; }
65-
66-
[XmlAttribute(AttributeName = "dnsRebindingProtection")]
67-
public int DnsRebindingProtection { get; set; }
68-
69-
[XmlAttribute(AttributeName = "natLoopbackSupported")]
70-
public int NatLoopbackSupported { get; set; }
71-
72-
[XmlAttribute(AttributeName = "publicAddressMatches")]
73-
public int PublicAddressMatches { get; set; }
74-
75-
[XmlAttribute(AttributeName = "presence")]
76-
public int Presence { get; set; }
77-
78-
[XmlAttribute(AttributeName = "ownerId")]
79-
public int OwnerId { get; set; }
80-
81-
[XmlAttribute(AttributeName = "home")]
82-
public int Home { get; set; }
83-
84-
[XmlAttribute(AttributeName = "sourceTitle")]
85-
public string SourceTitle { get; set; }
86-
}
41+
public List<ResourceConnection> Connections { get; set; }
8742
}
Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,15 @@
1-
namespace Plex.ServerApi.PlexModels.Account.Resources
2-
{
3-
using System.Xml.Serialization;
1+
namespace Plex.ServerApi.PlexModels.Account.Resources;
42

5-
[XmlRoot(ElementName="Connection")]
6-
public class ResourceConnection {
3+
using System.Text.Json.Serialization;
74

8-
[XmlAttribute(AttributeName="protocol")]
9-
public string Protocol { get; set; }
5+
public class ResourceConnection {
106

11-
[XmlAttribute(AttributeName="address")]
12-
public string Address { get; set; }
13-
14-
[XmlAttribute(AttributeName="port")]
15-
public int Port { get; set; }
16-
17-
[XmlAttribute(AttributeName="uri")]
18-
public string Uri { get; set; }
19-
20-
[XmlAttribute(AttributeName="local")]
21-
public int Local { get; set; }
22-
}
7+
public string Protocol { get; set; }
8+
public string Address { get; set; }
9+
public int Port { get; set; }
10+
public string Uri { get; set; }
11+
public bool Local { get; set; }
12+
public bool Relay { get; set; }
13+
[JsonPropertyName("IPv6")]
14+
public bool IpV6 { get; set; }
2315
}

Source/Plex.ServerApi/PlexModels/Account/Resources/ResourceContainer.cs

Lines changed: 0 additions & 15 deletions
This file was deleted.

Tests/Plex.Library.Test/Tests/AccountTest.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ public async void Test_GetHomeUsers()
4040
Assert.NotNull(homeUserContainer);
4141
}
4242

43+
[Fact]
44+
public async void Test_GetAccountResources()
45+
{
46+
var resources = await this.plexAccountClient.GetResourcesAsync(this.config.AuthenticationKey);
47+
48+
Assert.NotNull(resources);
49+
}
50+
4351
[Fact]
4452
public async void Test_GetWatchlist()
4553
{

Tests/Plex.Library.Test/Tests/LibraryTest.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,18 +125,18 @@ await this.plexLibraryClient.CreatePlayQueue(this.config.AuthenticationKey,
125125
Assert.True(playQueueContainer.Size > 0);
126126

127127
// 1. Get All Active Resources tied to Plex Account
128-
var resourceContainer = await this.plexAccountClient.GetResourcesAsync(this.config.AuthenticationKey);
128+
var resources = await this.plexAccountClient.GetResourcesAsync(this.config.AuthenticationKey);
129129

130130
// 2. Get Server we want to use
131-
var plexServer = resourceContainer.Resources
132-
.First(c => c.Name == "Plex Media Server" && c.Provides.Contains("server"));
131+
var plexServer = resources.
132+
First(c => c.Name == "Plex Media Server" && c.Provides.Contains("server"));
133133

134134
// 3. Get Transient Token from Server
135135
var token = await this.plexServerClient.GetTransientToken(this.config.AuthenticationKey,
136136
this.config.Host);
137137

138138
// 4. Get List of players that support 'player'.
139-
var players = resourceContainer.Resources
139+
var players = resources
140140
.Where(c => c.Provides.Contains("player"));
141141

142142
// 5. Get Player by name

Tests/Plex.ServerApi.Test/Tests/AccountTest.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,8 @@ public async void Test_GetPlexAccountWatchlist_ShowsOnly()
157157
[Fact]
158158
public async void Test_Get_Resources()
159159
{
160-
var resourceContainer = await this.fixture.PlexAccount.Resources();
161-
foreach (var resource in resourceContainer.Resources)
160+
var resources = await this.fixture.PlexAccount.Resources();
161+
foreach (var resource in resources)
162162
{
163163
var name = string.IsNullOrEmpty(resource.Name) ? "Unkown" : resource.Name;
164164
if (resource.Connections.Any())
@@ -171,7 +171,7 @@ public async void Test_Get_Resources()
171171
this.output.WriteLine("No Connections");
172172
}
173173
}
174-
Assert.NotNull(resourceContainer);
174+
Assert.NotNull(resources);
175175
}
176176

177177
[Fact]

0 commit comments

Comments
 (0)