diff --git a/OpenDotaApi.Test/ApiTests/ConstantsTests.cs b/OpenDotaApi.Test/ApiTests/ConstantsTests.cs index 2546599..dd63b23 100644 --- a/OpenDotaApi.Test/ApiTests/ConstantsTests.cs +++ b/OpenDotaApi.Test/ApiTests/ConstantsTests.cs @@ -17,7 +17,7 @@ public class ConstantsTest: IClassFixture public async Task TestGetStatValuesByIdHeroAsync() { var data = await _openDota.Constants.GetGameConstantsAsync(EnumConstants.XpLevel); - Assert.Contains("230", data); + Assert.NotEmpty(data); } } } \ No newline at end of file diff --git a/OpenDotaApi.Test/OpenDotaApi.Test.csproj b/OpenDotaApi.Test/OpenDotaApi.Test.csproj index 532405a..446001d 100644 --- a/OpenDotaApi.Test/OpenDotaApi.Test.csproj +++ b/OpenDotaApi.Test/OpenDotaApi.Test.csproj @@ -9,17 +9,17 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - + + + runtime; build; native; contentfiles; analyzers; buildtransitive all - + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/OpenDotaApi/Api/Constants/ConstantsEndpoint.cs b/OpenDotaApi/Api/Constants/ConstantsEndpoint.cs index d016a31..c1740aa 100644 --- a/OpenDotaApi/Api/Constants/ConstantsEndpoint.cs +++ b/OpenDotaApi/Api/Constants/ConstantsEndpoint.cs @@ -8,18 +8,18 @@ namespace OpenDotaApi.Api.Constants { public class ConstantsEndpoint : IConstantsEndpoint { - private readonly RequestHandler _request; + private readonly JsonFormatter _formatter; - public ConstantsEndpoint(RequestHandler request) + public ConstantsEndpoint(JsonFormatter formatter) { - _request = request; + _formatter = formatter; } - public async Task GetGameConstantsAsync(EnumConstants constant, CancellationToken? token = default) + public async Task GetGameConstantsAsync(EnumConstants constant, CancellationToken? token = default) { var parameter = Regex.Replace(constant.ToString(), "([a-z])([A-Z])", "$1_$2").ToLower(); - var response = await _request.GetResponseAsync($"constants/{parameter}", cancellationToken: token.GetValueOrDefault()); - return await response.Content.ReadAsStringAsync(); + return await _formatter.DeserializeAsync($"constants/{parameter}", + cancellationToken: token.GetValueOrDefault()); } } } \ No newline at end of file diff --git a/OpenDotaApi/Api/Constants/IConstantsEndpoint.cs b/OpenDotaApi/Api/Constants/IConstantsEndpoint.cs index 3412ee3..08e8186 100644 --- a/OpenDotaApi/Api/Constants/IConstantsEndpoint.cs +++ b/OpenDotaApi/Api/Constants/IConstantsEndpoint.cs @@ -6,6 +6,6 @@ namespace OpenDotaApi.Api.Constants { public interface IConstantsEndpoint { - Task GetGameConstantsAsync(EnumConstants constant, CancellationToken? token = default); + Task GetGameConstantsAsync(EnumConstants constant, CancellationToken? token = default); } } \ No newline at end of file diff --git a/OpenDotaApi/Api/Distributions/Model/CountryMmr.cs b/OpenDotaApi/Api/Distributions/Model/CountryMmr.cs index 75fa0ed..b6aeb33 100644 --- a/OpenDotaApi/Api/Distributions/Model/CountryMmr.cs +++ b/OpenDotaApi/Api/Distributions/Model/CountryMmr.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using System.Text.Json.Serialization; +using OpenDotaApi.Utilities.JsonConverters; namespace OpenDotaApi.Api.Distributions.Model { @@ -32,6 +33,7 @@ public class CountryMmrRow [JsonPropertyName("count")] public long? Count { get; set; } + [JsonConverter(typeof(Int32Converter))] [JsonPropertyName("avg")] public int? Avg { get; set; } diff --git a/OpenDotaApi/Api/Live/Model/Live.cs b/OpenDotaApi/Api/Live/Model/Live.cs index dec2589..29eb1a8 100644 --- a/OpenDotaApi/Api/Live/Model/Live.cs +++ b/OpenDotaApi/Api/Live/Model/Live.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Text.Json.Serialization; +using OpenDotaApi.Utilities.JsonConverters; namespace OpenDotaApi.Api.Live.Model { @@ -39,6 +40,7 @@ public class Live [JsonPropertyName("average_mmr")] public int? AverageMmr { get; set; } + [JsonConverter(typeof(Int64Converter))] [JsonPropertyName("match_id")] public long? MatchId { get; set; } diff --git a/OpenDotaApi/Api/Matches/Model/MatchPlayer.cs b/OpenDotaApi/Api/Matches/Model/MatchPlayer.cs index bfad83c..5399e6e 100644 --- a/OpenDotaApi/Api/Matches/Model/MatchPlayer.cs +++ b/OpenDotaApi/Api/Matches/Model/MatchPlayer.cs @@ -310,7 +310,7 @@ public class MatchPlayer public double KillsPerMin { get; set; } [JsonPropertyName("kda")] - public long? Kda { get; set; } + public double? Kda { get; set; } [JsonPropertyName("abandons")] public int? Abandons { get; set; } diff --git a/OpenDotaApi/Api/Players/Model/Pro/Pro.cs b/OpenDotaApi/Api/Players/Model/Pro/Pro.cs index bd545a3..cd7948b 100644 --- a/OpenDotaApi/Api/Players/Model/Pro/Pro.cs +++ b/OpenDotaApi/Api/Players/Model/Pro/Pro.cs @@ -1,5 +1,6 @@ using System; using System.Text.Json.Serialization; +using OpenDotaApi.Utilities.JsonConverters; namespace OpenDotaApi.Api.Players.Model.Pro { @@ -35,6 +36,7 @@ public class Pro [JsonPropertyName("locked_until")] public long? LockedUntil { get; set; } + [JsonConverter(typeof(Int64Converter))] [JsonPropertyName("steamid")] public long? Steamid { get; set; } diff --git a/OpenDotaApi/Api/ProPlayers/Model/ProPlayer.cs b/OpenDotaApi/Api/ProPlayers/Model/ProPlayer.cs index 5147d96..49fc247 100644 --- a/OpenDotaApi/Api/ProPlayers/Model/ProPlayer.cs +++ b/OpenDotaApi/Api/ProPlayers/Model/ProPlayer.cs @@ -33,7 +33,7 @@ public class ProPlayer public DateTimeOffset? FullHistoryTime { get; set; } [JsonPropertyName("cheese")] - public int Cheese { get; set; } + public long? Cheese { get; set; } [JsonPropertyName("fh_unavailable")] public bool? FhUnavailable { get; set; } @@ -42,7 +42,7 @@ public class ProPlayer public string Loccountrycode { get; set; } [JsonPropertyName("last_match_time")] - public DateTimeOffset LastMatchTime { get; set; } + public DateTimeOffset? LastMatchTime { get; set; } [JsonPropertyName("plus")] public bool? Plus { get; set; } diff --git a/OpenDotaApi/Api/Scenarios/Model/LaneRoles.cs b/OpenDotaApi/Api/Scenarios/Model/LaneRoles.cs index 1b92a96..888de47 100644 --- a/OpenDotaApi/Api/Scenarios/Model/LaneRoles.cs +++ b/OpenDotaApi/Api/Scenarios/Model/LaneRoles.cs @@ -1,4 +1,5 @@ using System.Text.Json.Serialization; +using OpenDotaApi.Utilities.JsonConverters; namespace OpenDotaApi.Api.Scenarios.Model { @@ -13,9 +14,11 @@ public class LaneRoles [JsonPropertyName("time")] public int? Time { get; set; } + [JsonConverter(typeof(Int64Converter))] [JsonPropertyName("games")] public long? Games { get; set; } + [JsonConverter(typeof(Int64Converter))] [JsonPropertyName("wins")] public long? Wins { get; set; } } diff --git a/OpenDotaApi/Api/Scenarios/Model/TeamScenarios.cs b/OpenDotaApi/Api/Scenarios/Model/TeamScenarios.cs index 6b567c0..2965468 100644 --- a/OpenDotaApi/Api/Scenarios/Model/TeamScenarios.cs +++ b/OpenDotaApi/Api/Scenarios/Model/TeamScenarios.cs @@ -1,4 +1,5 @@ using System.Text.Json.Serialization; +using OpenDotaApi.Utilities.JsonConverters; namespace OpenDotaApi.Api.Scenarios.Model { @@ -13,9 +14,11 @@ public class TeamScenarios [JsonPropertyName("region")] public long? Region { get; set; } + [JsonConverter(typeof(Int64Converter))] [JsonPropertyName("games")] public long? Games { get; set; } + [JsonConverter(typeof(Int64Converter))] [JsonPropertyName("wins")] public long? Wins { get; set; } } diff --git a/OpenDotaApi/Api/Status/Model/ApiPath.cs b/OpenDotaApi/Api/Status/Model/ApiPath.cs index 9a70f25..f53199c 100644 --- a/OpenDotaApi/Api/Status/Model/ApiPath.cs +++ b/OpenDotaApi/Api/Status/Model/ApiPath.cs @@ -1,4 +1,5 @@ using System.Text.Json.Serialization; +using OpenDotaApi.Utilities.JsonConverters; namespace OpenDotaApi.Api.Status.Model { @@ -7,6 +8,7 @@ public class ApiPath [JsonPropertyName("hostname")] public string Hostname { get; set; } + [JsonConverter(typeof(Int32Converter))] [JsonPropertyName("count")] public int? Count { get; set; } } diff --git a/OpenDotaApi/Enums/HeroPrimaryAttribute.cs b/OpenDotaApi/Enums/HeroPrimaryAttribute.cs index 0b37467..43b950d 100644 --- a/OpenDotaApi/Enums/HeroPrimaryAttribute.cs +++ b/OpenDotaApi/Enums/HeroPrimaryAttribute.cs @@ -7,6 +7,7 @@ public enum HeroPrimaryAttribute { Agi, Int, - Str + Str, + All, } } \ No newline at end of file diff --git a/OpenDotaApi/OpenDota.cs b/OpenDotaApi/OpenDota.cs index 9ad605f..3aee9f5 100644 --- a/OpenDotaApi/OpenDota.cs +++ b/OpenDotaApi/OpenDota.cs @@ -63,7 +63,7 @@ public OpenDota(string apiKey = null, IWebProxy proxy = null) Live = new LiveEndpoint(_jsonFormatter); Scenarios = new ScenariosEndpoint(_jsonFormatter); Schema = new SchemaEndpoint(_jsonFormatter); - Constants = new ConstantsEndpoint(_request); + Constants = new ConstantsEndpoint(_jsonFormatter); } public string ApiKey diff --git a/OpenDotaApi/OpenDotaApi.csproj b/OpenDotaApi/OpenDotaApi.csproj index 4c0c4f5..8e915cd 100644 --- a/OpenDotaApi/OpenDotaApi.csproj +++ b/OpenDotaApi/OpenDotaApi.csproj @@ -28,16 +28,16 @@ - + - + - + - + diff --git a/OpenDotaApi/Utilities/JsonConverters/DateTimeConverter.cs b/OpenDotaApi/Utilities/JsonConverters/DateTimeConverter.cs index 44fcd53..a1d83bf 100644 --- a/OpenDotaApi/Utilities/JsonConverters/DateTimeConverter.cs +++ b/OpenDotaApi/Utilities/JsonConverters/DateTimeConverter.cs @@ -16,13 +16,14 @@ public override DateTime Read(ref Utf8JsonReader reader, Type typeToConvert, Jso { if (long.TryParse(reader.GetString(), out var value)) { - return new DateTime(Epoch.Ticks + value * TimeSpan.TicksPerSecond, DateTimeKind.Utc); + return DateTimeOffset.FromUnixTimeSeconds(value).DateTime; } break; } } - return new DateTime(Epoch.Ticks + reader.GetInt64() * TimeSpan.TicksPerSecond, DateTimeKind.Utc); + + return DateTimeOffset.FromUnixTimeSeconds(reader.GetInt64()).DateTime; } public override void Write(Utf8JsonWriter writer, DateTime value, JsonSerializerOptions options) diff --git a/OpenDotaApi/Utilities/JsonFormatter.cs b/OpenDotaApi/Utilities/JsonFormatter.cs index b339f52..eca7979 100644 --- a/OpenDotaApi/Utilities/JsonFormatter.cs +++ b/OpenDotaApi/Utilities/JsonFormatter.cs @@ -17,9 +17,7 @@ public JsonFormatter(RequestHandler request) _request = request; _options = new JsonSerializerOptions(); - _options.Converters.Add(new Int32Converter()); _options.Converters.Add(new DateTimeConverter()); - _options.Converters.Add(new Int64Converter()); } public async Task DeserializeAsync(string url, string parameters = null, CancellationToken? cancellationToken = null ) where T : class