From 57636c5fa947dfd0d2d304f50608d2722eda9ddb Mon Sep 17 00:00:00 2001 From: Albie Date: Thu, 2 Feb 2023 13:10:12 +0000 Subject: [PATCH 1/4] add const platform strings --- DragonFruit.Six.Api/UbisoftPlatforms.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 DragonFruit.Six.Api/UbisoftPlatforms.cs diff --git a/DragonFruit.Six.Api/UbisoftPlatforms.cs b/DragonFruit.Six.Api/UbisoftPlatforms.cs new file mode 100644 index 00000000..87f75be4 --- /dev/null +++ b/DragonFruit.Six.Api/UbisoftPlatforms.cs @@ -0,0 +1,16 @@ +// Dragon6 API Copyright 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"; + } +} From 9c228f711022f655d4d51940d8bf796e24bec4b8 Mon Sep 17 00:00:00 2001 From: Albie Date: Thu, 2 Feb 2023 13:10:21 +0000 Subject: [PATCH 2/4] allow crossplatform requests --- .../Accounts/Requests/UbisoftAccountRequest.cs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/DragonFruit.Six.Api/Accounts/Requests/UbisoftAccountRequest.cs b/DragonFruit.Six.Api/Accounts/Requests/UbisoftAccountRequest.cs index fbb1da9b..889fa68e 100644 --- a/DragonFruit.Six.Api/Accounts/Requests/UbisoftAccountRequest.cs +++ b/DragonFruit.Six.Api/Accounts/Requests/UbisoftAccountRequest.cs @@ -1,7 +1,6 @@ // Dragon6 API Copyright DragonFruit Network // Licensed under Apache-2. Refer to the LICENSE file for more info -using System; using System.Collections.Generic; using System.Reflection; using System.Runtime.Serialization; @@ -30,11 +29,6 @@ public UbisoftAccountRequest(string query, Platform platform, IdentifierType ide /// public UbisoftAccountRequest(IEnumerable queries, Platform platform, IdentifierType identifierType) { - if (Platform == Platform.CrossPlatform) - { - throw new ArgumentException($"Cannot lookup an account against {nameof(Platform.CrossPlatform)}", nameof(Platform)); - } - Platform = platform; IdentifierType = identifierType; @@ -70,7 +64,9 @@ public UbisoftAccountRequest(IEnumerable queries, Platform platform, Ide [UsedImplicitly] [QueryParameter("platformType")] - private string PlatformValue => typeof(Platform).GetField(Platform.ToString()).GetCustomAttribute().Value; + private string PlatformValue => Platform == Platform.CrossPlatform + ? null + : typeof(Platform).GetField(Platform.ToString()).GetCustomAttribute().Value; private IEnumerable LookupString(IdentifierType method) => IdentifierType == method ? Identifiers : null; } From ce26c59e61b53a50bccda7bc76a905e8d4cc4c8f Mon Sep 17 00:00:00 2001 From: Albie Date: Thu, 2 Feb 2023 13:10:32 +0000 Subject: [PATCH 3/4] update to use new platform names --- .../Dragon6TestAccounts.cs | 23 +++++++++---------- .../Accounts/Entities/UbisoftAccount.cs | 17 ++++++++++---- .../Accounts/Enums/Platform.cs | 8 +++---- 3 files changed, 28 insertions(+), 20 deletions(-) diff --git a/DragonFruit.Six.Api.Tests/Dragon6TestAccounts.cs b/DragonFruit.Six.Api.Tests/Dragon6TestAccounts.cs index facfe94d..85ddb7c1 100644 --- a/DragonFruit.Six.Api.Tests/Dragon6TestAccounts.cs +++ b/DragonFruit.Six.Api.Tests/Dragon6TestAccounts.cs @@ -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 { @@ -21,7 +20,7 @@ public class Dragon6TestAccounts : IEnumerable 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" @@ -29,7 +28,7 @@ public class Dragon6TestAccounts : IEnumerable 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" @@ -37,7 +36,7 @@ public class Dragon6TestAccounts : IEnumerable 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" @@ -45,7 +44,7 @@ public class Dragon6TestAccounts : IEnumerable new UbisoftAccount { Username = "TheOnePistolGuy-", - Platform = Platform.PSN, + PlatformName = UbisoftPlatforms.PLAYSTATION, ProfileId = "18255d23-8073-440e-9011-1b9b8faa15fe", UbisoftId = "5e992dc8-7d93-4f28-9690-08b4d6788cc8", PlatformId = "1678314272891637227" @@ -53,7 +52,7 @@ public class Dragon6TestAccounts : IEnumerable new UbisoftAccount { Username = "TheKoreanKoala", - Platform = Platform.PSN, + PlatformName = UbisoftPlatforms.PLAYSTATION, ProfileId = "be982999-2adb-4fbe-b2a5-3cbc4b7a79bf", UbisoftId = "a5e7c9c4-a225-4d8e-810f-0c529d829a34", PlatformId = "7729747787525340203" @@ -61,7 +60,7 @@ public class Dragon6TestAccounts : IEnumerable 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" @@ -69,7 +68,7 @@ public class Dragon6TestAccounts : IEnumerable new UbisoftAccount { Username = "Jancer", - Platform = Platform.XB1, + PlatformName = UbisoftPlatforms.XBOX, ProfileId = "6c5b5c77-a7db-4c5f-8802-de797ce529a8", UbisoftId = "b6c8e00a-00f9-44fb-b83e-eb9135933b91", PlatformId = "2535444832986122" @@ -77,7 +76,7 @@ public class Dragon6TestAccounts : IEnumerable 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" @@ -85,7 +84,7 @@ public class Dragon6TestAccounts : IEnumerable 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" @@ -93,7 +92,7 @@ public class Dragon6TestAccounts : IEnumerable 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" @@ -101,7 +100,7 @@ public class Dragon6TestAccounts : IEnumerable 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" diff --git a/DragonFruit.Six.Api/Accounts/Entities/UbisoftAccount.cs b/DragonFruit.Six.Api/Accounts/Entities/UbisoftAccount.cs index c443c5da..199d189f 100644 --- a/DragonFruit.Six.Api/Accounts/Entities/UbisoftAccount.cs +++ b/DragonFruit.Six.Api/Accounts/Entities/UbisoftAccount.cs @@ -14,17 +14,26 @@ public class UbisoftAccount : IEquatable [JsonProperty("nameOnPlatform")] public string Username { get; set; } - /// - /// Platform this user was looked up on - /// [JsonProperty("platformType")] - public Platform Platform { get; set; } + public string PlatformName { get; set; } /// /// 256x256px avatar image url /// public string Image => $"https://ubisoft-avatars.akamaized.net/{UbisoftId}/default_256_256.png"; + /// + /// Platform this user profile targets. If the platform is not available, will be returned + /// + public Platform Platform => PlatformName switch + { + UbisoftPlatforms.PC => Platform.PC, + UbisoftPlatforms.XBOX => Platform.XB1, + UbisoftPlatforms.PLAYSTATION => Platform.PSN, + + _ => Platform.CrossPlatform + }; + /// /// Unique identifier for the platform-specific account used to get stats. /// This may not match the if the user's first platform is not diff --git a/DragonFruit.Six.Api/Accounts/Enums/Platform.cs b/DragonFruit.Six.Api/Accounts/Enums/Platform.cs index a19419f8..3231ffb3 100644 --- a/DragonFruit.Six.Api/Accounts/Enums/Platform.cs +++ b/DragonFruit.Six.Api/Accounts/Enums/Platform.cs @@ -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 } } From d6341a1ed5aa4e7ddbe33bf2bf163dab856519a9 Mon Sep 17 00:00:00 2001 From: Albie Date: Thu, 2 Feb 2023 15:19:07 +0000 Subject: [PATCH 4/4] add exception to ensure userid lookup is used --- .../Accounts/Requests/UbisoftAccountRequest.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/DragonFruit.Six.Api/Accounts/Requests/UbisoftAccountRequest.cs b/DragonFruit.Six.Api/Accounts/Requests/UbisoftAccountRequest.cs index 889fa68e..827c5549 100644 --- a/DragonFruit.Six.Api/Accounts/Requests/UbisoftAccountRequest.cs +++ b/DragonFruit.Six.Api/Accounts/Requests/UbisoftAccountRequest.cs @@ -1,6 +1,7 @@ // Dragon6 API Copyright DragonFruit Network // Licensed under Apache-2. Refer to the LICENSE file for more info +using System; using System.Collections.Generic; using System.Reflection; using System.Runtime.Serialization; @@ -29,6 +30,11 @@ public UbisoftAccountRequest(string query, Platform platform, IdentifierType ide /// public UbisoftAccountRequest(IEnumerable queries, Platform platform, IdentifierType identifierType) { + if (Platform == Platform.CrossPlatform && IdentifierType != IdentifierType.UserId) + { + throw new ArgumentException($"Cannot perform a cross-platform search with {IdentifierType} lookup mode"); + } + Platform = platform; IdentifierType = identifierType;