Skip to content

Commit 10ee94d

Browse files
Kevin JensenKevin Jensen
authored andcommitted
migrated to v2 api
1 parent 371b82a commit 10ee94d

7 files changed

Lines changed: 118 additions & 120 deletions

File tree

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -249,11 +249,9 @@ public async Task<AnnouncementContainer> Announcements() =>
249249
/// Returns a list of Home Users for Account
250250
/// </summary>
251251
/// <returns>UserContainer Object</returns>
252-
public async Task<UserContainer> HomeUsers() =>
252+
public async Task<HomeUserContainer> HomeUsers() =>
253253
await this.plexAccountClient.GetHomeUsersAsync(this.AuthToken);
254254

255-
256-
257255
/// <summary>
258256
/// Returns a list of all User objects connected to your account.
259257
/// This includes both friends and pending invites. You can reference the user.Friend to
@@ -288,9 +286,7 @@ public async Task OptOut(bool playback, bool library) =>
288286
/// <returns>List of Device objects</returns>
289287
public async Task<List<Device>> Devices() =>
290288
await this.plexAccountClient.GetDevicesAsync(this.AuthToken);
291-
292-
293-
289+
294290
// AddWebhook(string url);
295291
// DeleteWebhook(string url);
296292
// SetWebhooks(string[] urls);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public interface IPlexAccountClient
9494
/// </summary>
9595
/// <param name="authToken">Authentication Token.</param>
9696
/// <returns>List of Users</returns>
97-
Task<UserContainer> GetHomeUsersAsync(string authToken);
97+
Task<HomeUserContainer> GetHomeUsersAsync(string authToken);
9898

9999
/// <summary>
100100
/// Opt in or out of sharing stuff with plex.

Source/Plex.ServerApi/Clients/PlexAccountClient.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,22 +189,24 @@ public async Task<List<Friend>> GetFriendsAsync(string authToken)
189189
var apiRequest = new ApiRequestBuilder(BaseUri + "friends.json", string.Empty, HttpMethod.Get)
190190
.AddPlexToken(authToken)
191191
.AddRequestHeaders(ClientUtilities.GetClientIdentifierHeader(this.clientOptions.ClientId))
192+
.AcceptJson()
192193
.Build();
193194

194195
var friends = await this.apiService.InvokeApiAsync<List<Friend>>(apiRequest);
195196
return friends;
196197
}
197198

198199
/// <inheritdoc/>
199-
public async Task<UserContainer> GetHomeUsersAsync(string authToken)
200+
public async Task<HomeUserContainer> GetHomeUsersAsync(string authToken)
200201
{
201-
var apiRequest = new ApiRequestBuilder("https://plex.tv/home/users", string.Empty, HttpMethod.Get)
202+
var apiRequest = new ApiRequestBuilder(BaseUri + "home/users", string.Empty, HttpMethod.Get)
202203
.AddPlexToken(authToken)
203204
.AddRequestHeaders(ClientUtilities.GetClientIdentifierHeader(this.clientOptions.ClientId))
204205
.AddRequestHeaders(ClientUtilities.GetClientMetaHeaders(this.clientOptions))
206+
.AcceptJson()
205207
.Build();
206208

207-
var container = await this.apiService.InvokeApiAsync<UserContainer>(apiRequest);
209+
var container = await this.apiService.InvokeApiAsync<HomeUserContainer>(apiRequest);
208210
return container;
209211
}
210212

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
namespace Plex.ServerApi.PlexModels.Account.User;
2+
3+
using System.Text.Json.Serialization;
4+
5+
public class HomeUser
6+
{
7+
/// <summary>
8+
/// User's Plex account ID.
9+
/// </summary>
10+
public int Id { get; set; }
11+
12+
/// <summary>
13+
/// User's Plex account UUID.
14+
/// </summary>
15+
public string Uuid { get; set; }
16+
17+
/// <summary>
18+
/// Seems to be an alias for username.
19+
/// </summary>
20+
public string Title { get; set; }
21+
22+
/// <summary>
23+
/// User's username.
24+
/// </summary>
25+
public string Username { get; set; }
26+
27+
/// <summary>
28+
/// User's email address (user@gmail.com).
29+
/// </summary>
30+
public string Email { get; set; }
31+
32+
/// <summary>
33+
/// ???
34+
/// </summary>
35+
public string FriendlyName { get; set; }
36+
37+
/// <summary>
38+
/// Link to the users avatar.
39+
/// </summary>
40+
public string Thumb { get; set; }
41+
42+
/// <summary>
43+
/// Does the user have a password
44+
/// </summary>
45+
public bool HasPassword { get; set; }
46+
47+
/// <summary>
48+
/// Date user was last updated
49+
/// </summary>
50+
public long UpdatedAt { get; set; }
51+
52+
/// <summary>
53+
/// Is User Account Admin.
54+
/// </summary>
55+
[JsonPropertyName("admin")]
56+
public bool IsAdmin { get; set; }
57+
58+
/// <summary>
59+
/// Is User Account Guest.
60+
/// </summary>
61+
[JsonPropertyName("guest")]
62+
public bool IsGuest { get; set; }
63+
64+
/// <summary>
65+
/// Is User Account Restricted.
66+
/// </summary>
67+
[JsonPropertyName("restricted")]
68+
public bool IsRestricted { get; set; }
69+
70+
/// <summary>
71+
/// Profile if user is restricted
72+
/// </summary>
73+
public string RestrictionProfile { get; set; }
74+
75+
/// <summary>
76+
/// Unknown (possibly SSL enabled?).
77+
/// </summary>
78+
[JsonPropertyName("protected")]
79+
public bool IsProtected { get; set; }
80+
}

Source/Plex.ServerApi/PlexModels/Account/User/User.cs

Lines changed: 0 additions & 87 deletions
This file was deleted.
Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,21 @@
1-
namespace Plex.ServerApi.PlexModels.Account.User
2-
{
3-
using System.Collections.Generic;
4-
using System.Xml.Serialization;
5-
6-
[XmlRoot(ElementName="MediaContainer")]
7-
public class UserContainer
8-
{
9-
[XmlElement(ElementName="User")]
10-
public List<User> User { get; set; }
1+
namespace Plex.ServerApi.PlexModels.Account.User;
112

12-
[XmlAttribute(AttributeName="friendlyName")]
13-
public string FriendlyName { get; set; }
3+
using System.Collections.Generic;
4+
using System.Text.Json.Serialization;
145

15-
[XmlAttribute(AttributeName="identifier")]
16-
public string Identifier { get; set; }
6+
public class HomeUserContainer
7+
{
8+
public int Id { get; set; }
9+
public string Name { get; set; }
1710

18-
[XmlAttribute(AttributeName="machineIdentifier")]
19-
public string MachineIdentifier { get; set; }
11+
[JsonPropertyName(("guestUserID"))]
12+
public int GuestUserId { get; set; }
2013

21-
[XmlAttribute(AttributeName="totalSize")]
22-
public int TotalSize { get; set; }
14+
[JsonPropertyName(("guestUserUUID"))]
15+
public string GuestUserUuid { get; set; }
2316

24-
[XmlAttribute(AttributeName="size")]
25-
public int Size { get; set; }
17+
public bool GuestEnabled { get; set; }
18+
public bool Subscription { get; set; }
2619

27-
[XmlAttribute(AttributeName="guestUserID")]
28-
public int GuestUserId { get; set; }
29-
}
20+
public List<HomeUser> Users { get; set; }
3021
}

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,22 @@ public AccountTest(ITestOutputHelper output, PlexFixture fixture)
2424
this.plexAccountClient = fixture.ServiceProvider.GetService<IPlexAccountClient>();
2525
}
2626

27+
[Fact]
28+
public async void Test_GetAccountFriends()
29+
{
30+
var friends = await this.plexAccountClient.GetFriendsAsync(this.config.AuthenticationKey);
31+
32+
Assert.NotEmpty(friends);
33+
}
34+
35+
[Fact]
36+
public async void Test_GetHomeUsers()
37+
{
38+
var homeUserContainer = await this.plexAccountClient.GetHomeUsersAsync(this.config.AuthenticationKey);
39+
40+
Assert.NotNull(homeUserContainer);
41+
}
42+
2743
[Fact]
2844
public async void Test_GetWatchlist()
2945
{

0 commit comments

Comments
 (0)