Skip to content

Commit 1924a3b

Browse files
author
babelshift
committed
Added wrappers for GetMatchHistoryBySequenceNum.
Added methods to help with adding parameters if they have a value.
1 parent a9fe274 commit 1924a3b

5 files changed

Lines changed: 90 additions & 12 deletions

File tree

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace SteamWebAPI2.Models.DOTA2
8+
{
9+
public class MatchHistoryBySequenceNumberResult
10+
{
11+
public int Status { get; set; }
12+
public List<MatchHistoryMatch> Matches { get; set; }
13+
}
14+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace SteamWebAPI2.Models.DOTA2
8+
{
9+
public class MatchHistoryBySequenceNumberResultContainer
10+
{
11+
public MatchHistoryBySequenceNumberResult Result { get; set; }
12+
}
13+
}

SteamWebAPI2.Models/SteamWebAPI2.Models.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,11 @@
7272
<Compile Include="DOTA2\LiveLeagueGameTeamDireInfo.cs" />
7373
<Compile Include="DOTA2\LiveLeagueGameTeamRadiantDetail.cs" />
7474
<Compile Include="DOTA2\LiveLeagueGameTeamRadiantInfo.cs" />
75+
<Compile Include="DOTA2\MatchHistoryBySequenceNumberResult.cs" />
7576
<Compile Include="DOTA2\MatchHistoryMatch.cs" />
7677
<Compile Include="DOTA2\MatchHistoryPlayer.cs" />
7778
<Compile Include="DOTA2\MatchHistoryResult.cs" />
79+
<Compile Include="DOTA2\MatchHistoryBySequenceNumberResultContainer.cs" />
7880
<Compile Include="DOTA2\MatchHistoryResultContainer.cs" />
7981
<Compile Include="DOTA2\MatchPlayerAbilityUpgrade.cs" />
8082
<Compile Include="DOTA2\MatchDetailResult.cs" />

SteamWebAPI2/DOTA2Match.cs

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using SteamWebAPI2.Models.DOTA2;
2+
using System;
23
using System.Collections.Generic;
34
using System.Collections.ObjectModel;
45
using System.Threading.Tasks;
@@ -22,15 +23,8 @@ public async Task<IReadOnlyCollection<LiveLeagueGame>> GetLiveLeagueGames(int? l
2223
{
2324
List<SteamWebRequestParameter> parameters = new List<SteamWebRequestParameter>();
2425

25-
if(leagueId.HasValue)
26-
{
27-
parameters.Add(new SteamWebRequestParameter("league_id", leagueId.Value.ToString()));
28-
}
29-
30-
if (matchId.HasValue)
31-
{
32-
parameters.Add(new SteamWebRequestParameter("match_id", matchId.Value.ToString()));
33-
}
26+
AddToParametersIfHasValue("league_id", leagueId, parameters);
27+
AddToParametersIfHasValue("match_id", matchId, parameters);
3428

3529
var liveLeagueGames = await CallMethodAsync<LiveLeagueGameResultContainer>("GetLiveLeagueGames", 1, parameters);
3630
return new ReadOnlyCollection<LiveLeagueGame>(liveLeagueGames.Result.Games);
@@ -39,15 +33,42 @@ public async Task<IReadOnlyCollection<LiveLeagueGame>> GetLiveLeagueGames(int? l
3933
public async Task<MatchDetailResult> GetMatchDetails(int matchId)
4034
{
4135
List<SteamWebRequestParameter> parameters = new List<SteamWebRequestParameter>();
42-
parameters.Add(new SteamWebRequestParameter("match_id", matchId.ToString()));
36+
37+
AddToParametersIfHasValue("match_id", matchId, parameters);
38+
4339
var matchDetail = await CallMethodAsync<MatchDetailResultContainer>("GetMatchDetails", 1, parameters);
4440
return matchDetail.Result;
4541
}
4642

47-
public async Task<MatchHistoryResult> GetMatchHistory()
43+
public async Task<MatchHistoryResult> GetMatchHistory(int? heroId = null, int? gameMode = null, int? skill = null,
44+
string minPlayers = "", string accountId = "", string leagueId = "", long? startAtMatchId = null,
45+
string matchesRequested = "", string tournamentGamesOnly = "")
4846
{
47+
List<SteamWebRequestParameter> parameters = new List<SteamWebRequestParameter>();
48+
49+
AddToParametersIfHasValue("hero_id", heroId, parameters);
50+
AddToParametersIfHasValue("game_mode", gameMode, parameters);
51+
AddToParametersIfHasValue("skill", skill, parameters);
52+
AddToParametersIfHasValue("min_players", minPlayers, parameters);
53+
AddToParametersIfHasValue("account_id", accountId, parameters);
54+
AddToParametersIfHasValue("league_id", leagueId, parameters);
55+
AddToParametersIfHasValue("start_at_match_id", startAtMatchId, parameters);
56+
AddToParametersIfHasValue("matches_requested", matchesRequested, parameters);
57+
AddToParametersIfHasValue("tournament_games_only", tournamentGamesOnly, parameters);
58+
4959
var matchHistory = await CallMethodAsync<MatchHistoryResultContainer>("GetMatchHistory", 1);
5060
return matchHistory.Result;
5161
}
62+
63+
public async Task<MatchHistoryBySequenceNumberResult> GetMatchHistoryBySequenceNumber(long? startAtMatchSequenceNumber = null, int? matchesRequested = null)
64+
{
65+
List<SteamWebRequestParameter> parameters = new List<SteamWebRequestParameter>();
66+
67+
AddToParametersIfHasValue("start_at_match_seq_num", startAtMatchSequenceNumber, parameters);
68+
AddToParametersIfHasValue("matches_requested", matchesRequested, parameters);
69+
70+
var matchHistory = await CallMethodAsync<MatchHistoryBySequenceNumberResultContainer>("GetMatchHistoryBySequenceNum", 1);
71+
return matchHistory.Result;
72+
}
5273
}
5374
}

SteamWebAPI2/SteamWebInterface.cs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
namespace SteamWebAPI2
99
{
10-
public class SteamWebInterface
10+
public abstract class SteamWebInterface
1111
{
1212
private readonly SteamWebRequest steamWebRequest;
1313
private readonly string interfaceName;
@@ -27,5 +27,33 @@ internal async Task<T> CallMethodAsync<T>(string methodName, int version, IList<
2727

2828
return await steamWebRequest.GetJsonAsync<T>(interfaceName, methodName, version, parameters);
2929
}
30+
31+
#region Helpers
32+
33+
internal void AddToParametersIfHasValue<T>(string name, T? value, IList<SteamWebRequestParameter> parameters) where T : struct
34+
{
35+
if (value.HasValue)
36+
{
37+
parameters.Add(new SteamWebRequestParameter(name, value.Value.ToString()));
38+
}
39+
}
40+
41+
internal void AddToParametersIfHasValue<T>(string name, T value, IList<SteamWebRequestParameter> parameters)
42+
{
43+
if (value != null)
44+
{
45+
parameters.Add(new SteamWebRequestParameter(name, value.ToString()));
46+
}
47+
}
48+
49+
internal void AddToParametersIfHasValue(string name, string value, IList<SteamWebRequestParameter> parameters)
50+
{
51+
if (!String.IsNullOrEmpty(value))
52+
{
53+
parameters.Add(new SteamWebRequestParameter(name, value));
54+
}
55+
}
56+
57+
#endregion Helpers
3058
}
3159
}

0 commit comments

Comments
 (0)