Skip to content
This repository has been archived by the owner on Apr 8, 2024. It is now read-only.

Commit

Permalink
Merge pull request #368 from dragonfruitnetwork/crossplatform-account…
Browse files Browse the repository at this point in the history
…-lookup

Enable cross-platform lookup
  • Loading branch information
aspriddell authored Feb 2, 2023
2 parents 5420704 + 93bf9fe commit 3c5cb81
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 23 deletions.
23 changes: 11 additions & 12 deletions DragonFruit.Six.Api.Tests/Dragon6TestAccounts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.Collections.Generic;
using System.Linq;
using DragonFruit.Six.Api.Accounts.Entities;
using DragonFruit.Six.Api.Accounts.Enums;

namespace DragonFruit.Six.Api.Tests
{
Expand All @@ -21,87 +20,87 @@ public class Dragon6TestAccounts : IEnumerable<UbisoftAccount>
new UbisoftAccount
{
Username = "PaPa.Curry",
Platform = Platform.PC,
PlatformName = UbisoftPlatforms.PC,
ProfileId = "14c01250-ef26-4a32-92ba-e04aa557d619",
PlatformId = "14c01250-ef26-4a32-92ba-e04aa557d619",
UbisoftId = "14c01250-ef26-4a32-92ba-e04aa557d619"
},
new UbisoftAccount
{
Username = "ITFC_max",
Platform = Platform.PC,
PlatformName = UbisoftPlatforms.PC,
ProfileId = "45c0cccb-a1a8-4433-b3d8-52aaa40d16d2",
UbisoftId = "45c0cccb-a1a8-4433-b3d8-52aaa40d16d2",
PlatformId = "45c0cccb-a1a8-4433-b3d8-52aaa40d16d2"
},
new UbisoftAccount
{
Username = "P9-",
Platform = Platform.PC,
PlatformName = UbisoftPlatforms.PC,
ProfileId = "d0cc86e3-f3b8-493c-bb36-c9416183477a",
UbisoftId = "d0cc86e3-f3b8-493c-bb36-c9416183477a",
PlatformId = "d0cc86e3-f3b8-493c-bb36-c9416183477a"
},
new UbisoftAccount
{
Username = "TheOnePistolGuy-",
Platform = Platform.PSN,
PlatformName = UbisoftPlatforms.PLAYSTATION,
ProfileId = "18255d23-8073-440e-9011-1b9b8faa15fe",
UbisoftId = "5e992dc8-7d93-4f28-9690-08b4d6788cc8",
PlatformId = "1678314272891637227"
},
new UbisoftAccount
{
Username = "TheKoreanKoala",
Platform = Platform.PSN,
PlatformName = UbisoftPlatforms.PLAYSTATION,
ProfileId = "be982999-2adb-4fbe-b2a5-3cbc4b7a79bf",
UbisoftId = "a5e7c9c4-a225-4d8e-810f-0c529d829a34",
PlatformId = "7729747787525340203"
},
new UbisoftAccount
{
Username = "Charr._",
Platform = Platform.PC,
PlatformName = UbisoftPlatforms.PC,
ProfileId = "a5e7c9c4-a225-4d8e-810f-0c529d829a34",
UbisoftId = "a5e7c9c4-a225-4d8e-810f-0c529d829a34",
PlatformId = "a5e7c9c4-a225-4d8e-810f-0c529d829a34"
},
new UbisoftAccount
{
Username = "Jancer",
Platform = Platform.XB1,
PlatformName = UbisoftPlatforms.XBOX,
ProfileId = "6c5b5c77-a7db-4c5f-8802-de797ce529a8",
UbisoftId = "b6c8e00a-00f9-44fb-b83e-eb9135933b91",
PlatformId = "2535444832986122"
},
new UbisoftAccount
{
Username = "MeatyMarley",
Platform = Platform.PC,
PlatformName = UbisoftPlatforms.PC,
ProfileId = "603fc6ba-db16-4aba-81b2-e9f9601d7d24",
UbisoftId = "603fc6ba-db16-4aba-81b2-e9f9601d7d24",
PlatformId = "603FC6BA-DB16-4ABA-81B2-E9F9601D7D24"
},
new UbisoftAccount
{
Username = "Revilo_333",
Platform = Platform.PC,
PlatformName = UbisoftPlatforms.PC,
ProfileId = "e76672be-1269-4afd-a1f5-d2ec6f5a2c7f",
UbisoftId = "e76672be-1269-4afd-a1f5-d2ec6f5a2c7f",
PlatformId = "e76672be-1269-4afd-a1f5-d2ec6f5a2c7f"
},
new UbisoftAccount
{
Username = string.Empty,
Platform = Platform.PC,
PlatformName = UbisoftPlatforms.PC,
ProfileId = "9b1918ce-a45b-4140-b1d8-7e00965fbf92",
UbisoftId = "9b1918ce-a45b-4140-b1d8-7e00965fbf92",
PlatformId = "9b1918ce-a45b-4140-b1d8-7e00965fbf92"
},
new UbisoftAccount
{
Username = "Unique.Enough",
Platform = Platform.PC,
PlatformName = UbisoftPlatforms.PC,
ProfileId = "3dc3cd27-8eb7-4fe0-8774-1006a8f509a2",
UbisoftId = "3dc3cd27-8eb7-4fe0-8774-1006a8f509a2",
PlatformId = "3DC3CD27-8EB7-4FE0-8774-1006A8F509A2"
Expand Down
17 changes: 13 additions & 4 deletions DragonFruit.Six.Api/Accounts/Entities/UbisoftAccount.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,26 @@ public class UbisoftAccount : IEquatable<UbisoftAccount>
[JsonProperty("nameOnPlatform")]
public string Username { get; set; }

/// <summary>
/// Platform this user was looked up on
/// </summary>
[JsonProperty("platformType")]
public Platform Platform { get; set; }
public string PlatformName { get; set; }

/// <summary>
/// 256x256px avatar image url
/// </summary>
public string Image => $"https://ubisoft-avatars.akamaized.net/{UbisoftId}/default_256_256.png";

/// <summary>
/// Platform this user profile targets. If the platform is not available, <see cref="Platform.CrossPlatform"/> will be returned
/// </summary>
public Platform Platform => PlatformName switch
{
UbisoftPlatforms.PC => Platform.PC,
UbisoftPlatforms.XBOX => Platform.XB1,
UbisoftPlatforms.PLAYSTATION => Platform.PSN,

_ => Platform.CrossPlatform
};

/// <summary>
/// Unique identifier for the platform-specific account used to get stats.
/// This may not match the <see cref="UbisoftId"/> if the user's first platform is not <see cref="Platform.PC"/>
Expand Down
8 changes: 4 additions & 4 deletions DragonFruit.Six.Api/Accounts/Enums/Platform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ namespace DragonFruit.Six.Api.Accounts.Enums
[JsonConverter(typeof(StringEnumConverter))]
public enum Platform
{
[EnumMember(Value = "uplay")]
[EnumMember(Value = UbisoftPlatforms.PC)]
PC = 1,

[EnumMember(Value = "psn")]
[EnumMember(Value = UbisoftPlatforms.PLAYSTATION)]
PSN = 2,

[EnumMember(Value = "xbl")]
[EnumMember(Value = UbisoftPlatforms.XBOX)]
XB1 = 3,

[EnumMember(Value = "xplay")]
[EnumMember(Value = UbisoftPlatforms.CROSSPLAY)]
CrossPlatform = 4
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ public UbisoftAccountRequest(string query, Platform platform, IdentifierType ide
/// </summary>
public UbisoftAccountRequest(IEnumerable<string> queries, Platform platform, IdentifierType identifierType)
{
if (Platform == Platform.CrossPlatform)
if (Platform == Platform.CrossPlatform && IdentifierType != IdentifierType.UserId)
{
throw new ArgumentException($"Cannot lookup an account against {nameof(Platform.CrossPlatform)}", nameof(Platform));
throw new ArgumentException($"Cannot perform a cross-platform search with {IdentifierType} lookup mode");
}

Platform = platform;
Expand Down Expand Up @@ -70,7 +70,9 @@ public UbisoftAccountRequest(IEnumerable<string> queries, Platform platform, Ide

[UsedImplicitly]
[QueryParameter("platformType")]
private string PlatformValue => typeof(Platform).GetField(Platform.ToString()).GetCustomAttribute<EnumMemberAttribute>().Value;
private string PlatformValue => Platform == Platform.CrossPlatform
? null
: typeof(Platform).GetField(Platform.ToString()).GetCustomAttribute<EnumMemberAttribute>().Value;

private IEnumerable<string> LookupString(IdentifierType method) => IdentifierType == method ? Identifiers : null;
}
Expand Down
16 changes: 16 additions & 0 deletions DragonFruit.Six.Api/UbisoftPlatforms.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Dragon6 API Copyright DragonFruit Network <inbox@dragonfruit.network>
// Licensed under Apache-2. Refer to the LICENSE file for more info

// ReSharper disable InconsistentNaming

namespace DragonFruit.Six.Api
{
public static class UbisoftPlatforms
{
public const string PC = "uplay";
public const string XBOX = "xbl";
public const string PLAYSTATION = "psn";

public const string CROSSPLAY = "xplay";
}
}

0 comments on commit 3c5cb81

Please sign in to comment.