Skip to content

Commit a07729f

Browse files
author
babelshift
committed
Added wrappers for GetNumberOfCurrentPlayers method.
Added missing parameters to GetGlobalStatsForGame method.
1 parent 52ddd5a commit a07729f

3 files changed

Lines changed: 48 additions & 1 deletion

File tree

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Generated by Xamasoft JSON Class Generator
2+
// http://www.xamasoft.com/json-class-generator
3+
4+
using Newtonsoft.Json;
5+
6+
namespace SteamWebAPI2.Models
7+
{
8+
public class CurrentPlayersResult
9+
{
10+
[JsonProperty("player_count")]
11+
public int PlayerCount { get; set; }
12+
13+
[JsonProperty("result")]
14+
public int Result { get; set; }
15+
}
16+
17+
public class CurrentPlayersResultContainer
18+
{
19+
[JsonProperty("response")]
20+
public CurrentPlayersResult Result { get; set; }
21+
}
22+
}

SteamWebAPI2.Models/SteamWebAPI2.Models.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
<Compile Include="FriendListResultContainer.cs" />
5050
<Compile Include="GlobalAchievementPercentagesResultContainer.cs" />
5151
<Compile Include="GlobalStatsForGameResultContainer.cs" />
52+
<Compile Include="CurrentPlayersResultContainer.cs" />
5253
<Compile Include="PlayerBansContainer.cs" />
5354
<Compile Include="ResolveVanityUrlResultContainer.cs" />
5455
<Compile Include="SteamAppUpToDateCheckResultContainer.cs" />

SteamWebAPI2/SteamUserStats.cs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Linq;
66
using System.Text;
77
using System.Threading.Tasks;
8+
using SteamWebAPI2.Models.Utilities;
89

910
namespace SteamWebAPI2
1011
{
@@ -22,11 +23,26 @@ public async Task<IReadOnlyCollection<GlobalAchievementPercentage>> GetGlobalAch
2223
return new ReadOnlyCollection<GlobalAchievementPercentage>(achievementPercentagesResult.Result.AchievementPercentages);
2324
}
2425

25-
public async Task<GlobalStatsForGameResult> GetGlobalStatsForGameAsync(long appId, IReadOnlyList<string> statNames)
26+
public async Task<GlobalStatsForGameResult> GetGlobalStatsForGameAsync(long appId, IReadOnlyList<string> statNames, DateTime? startDate = null, DateTime? endDate = null)
2627
{
28+
long? startDateUnixTimeStamp = null;
29+
long? endDateUnixTimeStamp = null;
30+
31+
if (startDate.HasValue)
32+
{
33+
startDateUnixTimeStamp = startDate.Value.ToUnixTimeStamp();
34+
}
35+
36+
if (endDate.HasValue)
37+
{
38+
endDateUnixTimeStamp = endDate.Value.ToUnixTimeStamp();
39+
}
40+
2741
List<SteamWebRequestParameter> parameters = new List<SteamWebRequestParameter>();
2842
AddToParametersIfHasValue("appid", appId, parameters);
2943
AddToParametersIfHasValue("count", statNames.Count, parameters);
44+
AddToParametersIfHasValue("startdate", startDateUnixTimeStamp, parameters);
45+
AddToParametersIfHasValue("enddate", endDateUnixTimeStamp, parameters);
3046

3147
for (int i = 0; i < statNames.Count; i++)
3248
{
@@ -36,5 +52,13 @@ public async Task<GlobalStatsForGameResult> GetGlobalStatsForGameAsync(long appI
3652
var globalStatsResult = await CallMethodAsync<GlobalStatsForGameResultContainer>("GetGlobalStatsForGame", 1, parameters);
3753
return globalStatsResult.Result;
3854
}
55+
56+
public async Task<int> GetNumberOfCurrentPlayersForGameAsync(long appId)
57+
{
58+
List<SteamWebRequestParameter> parameters = new List<SteamWebRequestParameter>();
59+
AddToParametersIfHasValue("appid", appId, parameters);
60+
var globalStatsResult = await CallMethodAsync<CurrentPlayersResultContainer>("GetNumberOfCurrentPlayers", 1, parameters);
61+
return globalStatsResult.Result.PlayerCount;
62+
}
3963
}
4064
}

0 commit comments

Comments
 (0)