diff --git a/dotnet/Global/Contracts/ServiceConfig.cs b/dotnet/Global/Contracts/ServiceConfig.cs new file mode 100644 index 00000000..b6256bcf --- /dev/null +++ b/dotnet/Global/Contracts/ServiceConfig.cs @@ -0,0 +1,9 @@ +namespace Branch.Global.Contracts +{ + public class ServiceConfig + { + public string Url { get; set; } + + public string Key { get; set; } + } +} diff --git a/dotnet/Global/Extensions/StringExtensions.cs b/dotnet/Global/Extensions/StringExtensions.cs new file mode 100644 index 00000000..de9d8fce --- /dev/null +++ b/dotnet/Global/Extensions/StringExtensions.cs @@ -0,0 +1,34 @@ +using System.Text; +using System.Text.RegularExpressions; + +namespace Branch.Global.Extensions +{ + public static class StringExtensions + { + public static string ToSlug(this string str) + { + // Lifted from: https://stackoverflow.com/questions/2920744/url-slugify-algorithm-in-c + + // First to lower case + var slug = str.ToLowerInvariant(); + + // Remove all accents + var bytes = Encoding.UTF8.GetBytes(slug); + slug = Encoding.ASCII.GetString(bytes); + + // Replace spaces + slug = Regex.Replace(slug, @"\s", "-", RegexOptions.Compiled); + + // Remove invalid chars + slug = Regex.Replace(slug, @"[^a-z0-9\s-_]", "",RegexOptions.Compiled); + + // Trim dashes from end + slug = slug.Trim('-', '_'); + + // Replace double occurrences of - or _ + slug = Regex.Replace(slug, @"([-_]){2,}", "$1", RegexOptions.Compiled); + + return slug; + } + } +} diff --git a/dotnet/Global/Libraries/JsonClient.cs b/dotnet/Global/Libraries/JsonClient.cs index 42ba17cf..f104a80a 100644 --- a/dotnet/Global/Libraries/JsonClient.cs +++ b/dotnet/Global/Libraries/JsonClient.cs @@ -5,6 +5,7 @@ using System.Threading.Tasks; using Crpc.Exceptions; using Newtonsoft.Json; +using Newtonsoft.Json.Serialization; namespace Branch.Global.Libraries { @@ -18,6 +19,8 @@ public class JsonClient /// public readonly string RequestFailedCode = "request_failed"; + private JsonSerializerSettings _jss { get; } + /// /// Initializes a new JsonClient. /// @@ -30,6 +33,14 @@ public JsonClient(string baseUrl, HttpClientOptions options = null) options.Headers.Add("Accept", "application/json"); Client = new HttpClient(baseUrl, options); + + _jss = new JsonSerializerSettings + { + ContractResolver = new DefaultContractResolver + { + NamingStrategy = new SnakeCaseNamingStrategy() + } + }; } public async Task Do(string verb, string path, HttpClientOptions newOpts = null) @@ -56,11 +67,13 @@ public async Task Do(string verb, string path, Dictionary Do(string verb, string path, Dictionary - { - { "url", response.RequestMessage.RequestUri.ToString() }, - { "verb", verb }, - { "status_code", response.StatusCode }, - }); + response.EnsureSuccessStatusCode(); + + // NOTE(afr): This shouldn't be possible to hit + throw new InvalidOperationException("Not poss"); } private TimeSpan getTimeout(HttpClientOptions options, HttpClientOptions domOpts) @@ -97,13 +108,10 @@ private TimeSpan getTimeout(HttpClientOptions options, HttpClientOptions domOpts private void throwIfCrpcException(string str) { - try - { - var err = JsonConvert.DeserializeObject(str); + var err = JsonConvert.DeserializeObject(str); - if (err.Message != null) - throw err; - } catch { /* */ } + if (err.Message != null) + throw err; } } } diff --git a/dotnet/Global/Libraries/XboxLiveAuthClient.cs b/dotnet/Global/Libraries/XboxLiveAuthClient.cs index 169da059..006f26a4 100644 --- a/dotnet/Global/Libraries/XboxLiveAuthClient.cs +++ b/dotnet/Global/Libraries/XboxLiveAuthClient.cs @@ -84,6 +84,20 @@ public class XboxLiveAuthToken [JsonProperty("Token")] public string Token { get; set; } + + [JsonProperty("DisplayClaims")] + public XboxLiveAuthDisplayClaims DisplayClaims { get; set; } + } + + public class XboxLiveAuthDisplayClaims + { + [JsonProperty("xui")] + public XboxLiveAuthDisplayClaim[] Xui { get; set; } } -} + public class XboxLiveAuthDisplayClaim + { + [JsonProperty("uhs")] + public string Uhs { get; set; } + } +}