Skip to content

Commit

Permalink
Merge pull request #8 from sominola/feature/update-package
Browse files Browse the repository at this point in the history
Update contracts, update packages
  • Loading branch information
sominola committed Sep 15, 2023
2 parents e817d37 + 18259d7 commit cb40eb0
Show file tree
Hide file tree
Showing 17 changed files with 40 additions and 26 deletions.
2 changes: 1 addition & 1 deletion OpenDotaApi.Test/ApiTests/ConstantsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class ConstantsTest: IClassFixture<OpenDotaTestsFixtures>
public async Task TestGetStatValuesByIdHeroAsync()
{
var data = await _openDota.Constants.GetGameConstantsAsync(EnumConstants.XpLevel);
Assert.Contains("230", data);
Assert.NotEmpty(data);
}
}
}
10 changes: 5 additions & 5 deletions OpenDotaApi.Test/OpenDotaApi.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.msbuild" Version="3.2.0">
<PackageReference Include="coverlet.msbuild" Version="6.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
<PackageReference Include="xunit" Version="2.5.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.2.0">
<PackageReference Include="coverlet.collector" Version="6.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
12 changes: 6 additions & 6 deletions OpenDotaApi/Api/Constants/ConstantsEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> GetGameConstantsAsync(EnumConstants constant, CancellationToken? token = default)
public async Task<long[]> 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<long[]>($"constants/{parameter}",
cancellationToken: token.GetValueOrDefault());
}
}
}
2 changes: 1 addition & 1 deletion OpenDotaApi/Api/Constants/IConstantsEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ namespace OpenDotaApi.Api.Constants
{
public interface IConstantsEndpoint
{
Task<string> GetGameConstantsAsync(EnumConstants constant, CancellationToken? token = default);
Task<long[]> GetGameConstantsAsync(EnumConstants constant, CancellationToken? token = default);
}
}
2 changes: 2 additions & 0 deletions OpenDotaApi/Api/Distributions/Model/CountryMmr.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.Text.Json.Serialization;
using OpenDotaApi.Utilities.JsonConverters;

namespace OpenDotaApi.Api.Distributions.Model
{
Expand Down Expand Up @@ -32,6 +33,7 @@ public class CountryMmrRow
[JsonPropertyName("count")]
public long? Count { get; set; }

[JsonConverter(typeof(Int32Converter))]
[JsonPropertyName("avg")]
public int? Avg { get; set; }

Expand Down
2 changes: 2 additions & 0 deletions OpenDotaApi/Api/Live/Model/Live.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Text.Json.Serialization;
using OpenDotaApi.Utilities.JsonConverters;

namespace OpenDotaApi.Api.Live.Model
{
Expand Down Expand Up @@ -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; }

Expand Down
2 changes: 1 addition & 1 deletion OpenDotaApi/Api/Matches/Model/MatchPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
2 changes: 2 additions & 0 deletions OpenDotaApi/Api/Players/Model/Pro/Pro.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Text.Json.Serialization;
using OpenDotaApi.Utilities.JsonConverters;

namespace OpenDotaApi.Api.Players.Model.Pro
{
Expand Down Expand Up @@ -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; }

Expand Down
4 changes: 2 additions & 2 deletions OpenDotaApi/Api/ProPlayers/Model/ProPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand All @@ -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; }
Expand Down
3 changes: 3 additions & 0 deletions OpenDotaApi/Api/Scenarios/Model/LaneRoles.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Text.Json.Serialization;
using OpenDotaApi.Utilities.JsonConverters;

namespace OpenDotaApi.Api.Scenarios.Model
{
Expand All @@ -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; }
}
Expand Down
3 changes: 3 additions & 0 deletions OpenDotaApi/Api/Scenarios/Model/TeamScenarios.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Text.Json.Serialization;
using OpenDotaApi.Utilities.JsonConverters;

namespace OpenDotaApi.Api.Scenarios.Model
{
Expand All @@ -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; }
}
Expand Down
2 changes: 2 additions & 0 deletions OpenDotaApi/Api/Status/Model/ApiPath.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Text.Json.Serialization;
using OpenDotaApi.Utilities.JsonConverters;

namespace OpenDotaApi.Api.Status.Model
{
Expand All @@ -7,6 +8,7 @@ public class ApiPath
[JsonPropertyName("hostname")]
public string Hostname { get; set; }

[JsonConverter(typeof(Int32Converter))]
[JsonPropertyName("count")]
public int? Count { get; set; }
}
Expand Down
3 changes: 2 additions & 1 deletion OpenDotaApi/Enums/HeroPrimaryAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public enum HeroPrimaryAttribute
{
Agi,
Int,
Str
Str,
All,
}
}
2 changes: 1 addition & 1 deletion OpenDotaApi/OpenDota.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions OpenDotaApi/OpenDotaApi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@
<PackageReference Include="System.Text.Json" Version="6.0.7" />
</ItemGroup>
<ItemGroup Condition="('$(TargetFramework)' == 'netstandard2.0')">
<PackageReference Include="System.Text.Json" Version="7.0.1" />
<PackageReference Include="System.Text.Json" Version="7.0.3" />
</ItemGroup>
<ItemGroup Condition="('$(TargetFramework)' == 'netstandard2.1')">
<PackageReference Include="System.Text.Json" Version="7.0.1" />
<PackageReference Include="System.Text.Json" Version="7.0.3" />
</ItemGroup>
<ItemGroup Condition="('$(TargetFramework)' == 'net6.0')">
<PackageReference Include="System.Text.Json" Version="7.0.1" />
<PackageReference Include="System.Text.Json" Version="7.0.3" />
</ItemGroup>
<ItemGroup Condition="('$(TargetFramework)' == 'net7.0')">
<PackageReference Include="System.Text.Json" Version="7.0.1" />
<PackageReference Include="System.Text.Json" Version="7.0.3" />
</ItemGroup>

</Project>
5 changes: 3 additions & 2 deletions OpenDotaApi/Utilities/JsonConverters/DateTimeConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 0 additions & 2 deletions OpenDotaApi/Utilities/JsonFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> DeserializeAsync<T>(string url, string parameters = null, CancellationToken? cancellationToken = null ) where T : class
Expand Down

0 comments on commit cb40eb0

Please sign in to comment.