Skip to content

Commit

Permalink
Fixed small bug and added example project
Browse files Browse the repository at this point in the history
  • Loading branch information
rist0 committed Oct 12, 2019
1 parent e49800e commit d764b16
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 0 deletions.
12 changes: 12 additions & 0 deletions OpenDota.NET.Examples/OpenDota.NET.Examples.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\OpenDota.NET\OpenDota.NET.csproj" />
</ItemGroup>

</Project>
75 changes: 75 additions & 0 deletions OpenDota.NET.Examples/Program.cs
Original file line number Diff line number Diff line change
@@ -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();
}
}
}
9 changes: 9 additions & 0 deletions OpenDota.NET.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions OpenDota.NET/Endpoints/PlayerEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,8 @@ private List<string> CreateArgumentListForPlayerEndpointRequest(PlayerEndpointPa
{
var addedArguments = new List<string>();

if (parameters == null) return addedArguments;

if (parameters.Limit != null)
{
addedArguments.Add($@"limit={parameters.Limit}");
Expand Down

0 comments on commit d764b16

Please sign in to comment.