diff --git a/OpenDota.NET.Examples/OpenDota.NET.Examples.csproj b/OpenDota.NET.Examples/OpenDota.NET.Examples.csproj new file mode 100644 index 0000000..0b01d5c --- /dev/null +++ b/OpenDota.NET.Examples/OpenDota.NET.Examples.csproj @@ -0,0 +1,12 @@ + + + + Exe + netcoreapp3.0 + + + + + + + diff --git a/OpenDota.NET.Examples/Program.cs b/OpenDota.NET.Examples/Program.cs new file mode 100644 index 0000000..d78b0f3 --- /dev/null +++ b/OpenDota.NET.Examples/Program.cs @@ -0,0 +1,75 @@ +using System; +using System.Linq; +using System.Threading.Tasks; +using OpenDotaDotNet; +using OpenDotaDotNet.Dtos; + +namespace OpenDota.NET.Examples +{ + class Program + { + private static readonly OpenDotaApi OpenDota = OpenDotaApi.GetInstance(); + + static async Task Main(string[] args) + { + const long playerId = 375507918; + const long matchId = 5063190379; + + var playerInfo = await OpenDota.Player.GetPlayerByIdAsync(playerId); + + Console.WriteLine($@"Basic details of player with id {playerId}."); + Console.WriteLine($@"Steam name: {playerInfo.Profile.Personaname}"); + Console.WriteLine($@"Steam ID: {playerInfo.Profile.Steamid}"); + Console.WriteLine($@"Steam profile direct link: {playerInfo.Profile.Profileurl}"); + + if (playerInfo.MmrEstimate.Estimate.HasValue) + { + Console.WriteLine($@"Estimated MMR: {playerInfo.MmrEstimate.Estimate}"); + } + + Console.WriteLine(); + + Console.WriteLine("Win loss ratio"); + var playerWinLoss = await OpenDota.Player.GetPlayerWinLossByIdAsync(playerId); + Console.WriteLine($@"Total games played: {playerWinLoss.Wins + playerWinLoss.Losses}."); + Console.WriteLine($@"Total wins: {playerWinLoss.Wins}."); + Console.WriteLine($@"Total losses: {playerWinLoss.Losses}."); + + Console.WriteLine(); + + Console.WriteLine("Player heroes"); + var playerQueryParameters = new PlayerEndpointParameters + { + Limit = 20 + }; + var playerHeroes = await OpenDota.Player.GetPlayerHeroesAsync(playerId, playerQueryParameters); + + var playerMostPlayedHeroLast20 = playerHeroes.FirstOrDefault(); + + if (playerMostPlayedHeroLast20 != null) + { + Console.WriteLine( + $@"Most played hero in the last 20 matches is hero ID: {playerMostPlayedHeroLast20.HeroId} with {playerMostPlayedHeroLast20.Win} wins."); + } + + Console.WriteLine(); + + Console.WriteLine("Player heroes"); + var matchDetails = await OpenDota.Matches.GetMatchByIdAsync(matchId); + + Console.WriteLine($@"Details about match id {matchId}."); + Console.WriteLine($@"Duration of game: {TimeSpan.FromSeconds(matchDetails.Duration):mm\:ss}."); + Console.WriteLine($@"Radiant Score: {matchDetails.RadiantScore}. Dire Score: {matchDetails.DireScore}."); + + Console.WriteLine($@"Nickname of players in the game:"); + foreach (var player in matchDetails.Players) + { + Console.WriteLine(string.IsNullOrEmpty(player.Personaname) ? "Anonymous" : $@"{player.Personaname}"); + } + + Console.WriteLine("Example finished. Press esc key to exit..."); + + Console.ReadKey(); + } + } +} diff --git a/OpenDota.NET.sln b/OpenDota.NET.sln index caaeede..b9c1e5d 100644 --- a/OpenDota.NET.sln +++ b/OpenDota.NET.sln @@ -5,6 +5,11 @@ VisualStudioVersion = 16.0.29230.47 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenDota.NET", "OpenDota.NET\OpenDota.NET.csproj", "{48D8F366-71E5-444A-ACAA-E1C146A185F5}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenDota.NET.Examples", "OpenDota.NET.Examples\OpenDota.NET.Examples.csproj", "{AF4B5DA3-DD0F-4337-B9F9-6B19988A4EC3}" + ProjectSection(ProjectDependencies) = postProject + {48D8F366-71E5-444A-ACAA-E1C146A185F5} = {48D8F366-71E5-444A-ACAA-E1C146A185F5} + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -15,6 +20,10 @@ Global {48D8F366-71E5-444A-ACAA-E1C146A185F5}.Debug|Any CPU.Build.0 = Debug|Any CPU {48D8F366-71E5-444A-ACAA-E1C146A185F5}.Release|Any CPU.ActiveCfg = Release|Any CPU {48D8F366-71E5-444A-ACAA-E1C146A185F5}.Release|Any CPU.Build.0 = Release|Any CPU + {AF4B5DA3-DD0F-4337-B9F9-6B19988A4EC3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AF4B5DA3-DD0F-4337-B9F9-6B19988A4EC3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AF4B5DA3-DD0F-4337-B9F9-6B19988A4EC3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AF4B5DA3-DD0F-4337-B9F9-6B19988A4EC3}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/OpenDota.NET/Endpoints/PlayerEndpoint.cs b/OpenDota.NET/Endpoints/PlayerEndpoint.cs index 866cdf7..165a760 100644 --- a/OpenDota.NET/Endpoints/PlayerEndpoint.cs +++ b/OpenDota.NET/Endpoints/PlayerEndpoint.cs @@ -305,6 +305,8 @@ private List CreateArgumentListForPlayerEndpointRequest(PlayerEndpointPa { var addedArguments = new List(); + if (parameters == null) return addedArguments; + if (parameters.Limit != null) { addedArguments.Add($@"limit={parameters.Limit}");