Skip to content

Commit 9b02eb8

Browse files
author
Justin Skiles
authored
Issue/94 (#95)
* Added strongly typed models to GetAccountList endpoint. * Added strong types to CreateAccount interface * Strong typed responses on SetMemo and ResetLoginToken endpoints. * Strong types for DeleteAccount, AccountPublicInfo, and QueryLoginToken endpoints. * Adding some profiles * Adding more automapper profiles * Finished adding AutoMapper profiles * Added missing SteamNews mapper profile. Strongly typed QueryLoginToken endpoint.
1 parent 65d080b commit 9b02eb8

30 files changed

+1088
-588
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System;
2+
using System.Collections.Generic;
3+
4+
namespace Steam.Models.GameServers
5+
{
6+
public class AccountListModel
7+
{
8+
public IEnumerable<AccountServerModel> Servers { get; set; }
9+
10+
public bool IsBanned { get; set; }
11+
12+
/// <summary>Not sure if this should be a DateTime or bool. Can't find
13+
/// documentation on what this field indicates.
14+
/// </summary>
15+
public uint Expires { get; set; }
16+
17+
/// <summary>Steam ID of the account holder that created the game server account.
18+
/// </summary>
19+
public ulong Actor { get; set; }
20+
21+
/// <summary>Not sure what this indicates. After creating a game server account,
22+
/// I expected to see a time stamp here, but it returns 0 instead.
23+
/// </summary>
24+
public DateTime? LastActionTime { get; set; }
25+
}
26+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace Steam.Models.GameServers
2+
{
3+
public class AccountPublicInfoModel
4+
{
5+
public ulong SteamId { get; set; }
6+
7+
public uint AppId { get; set; }
8+
}
9+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System;
2+
3+
namespace Steam.Models.GameServers
4+
{
5+
public class AccountServerModel
6+
{
7+
/// <summary>Steam ID of the game server.
8+
/// </summary>
9+
public ulong SteamId { get; set; }
10+
11+
/// <summary>AppId that the game server is associated with such as TF2 or CS:GO
12+
/// </summary>
13+
public uint AppId { get; set; }
14+
15+
public string LoginToken { get; set; }
16+
17+
public string Memo { get; set; }
18+
19+
public bool IsDeleted { get; set; }
20+
21+
public bool IsExpired { get; set; }
22+
23+
public DateTime? RtLastLogon { get; set; }
24+
}
25+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace Steam.Models.GameServers
2+
{
3+
public class CreateAccountModel
4+
{
5+
public ulong SteamId { get; set; }
6+
7+
public string LoginToken { get; set; }
8+
}
9+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace Steam.Models.GameServers
2+
{
3+
public class QueryLoginTokenModel
4+
{
5+
public bool IsBanned { get; set; }
6+
7+
public uint Expires { get; set; }
8+
9+
public ulong SteamId { get; set; }
10+
}
11+
}

src/SteamWebAPI2/AutoMapperConfiguration.cs

Lines changed: 55 additions & 553 deletions
Large diffs are not rendered by default.

src/SteamWebAPI2/Interfaces/GameServersService.cs

Lines changed: 76 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
1-
using SteamWebAPI2.Utilities;
1+
using Steam.Models.GameServers;
2+
using SteamWebAPI2.Models.GameServers;
3+
using SteamWebAPI2.Utilities;
24
using System.Collections.Generic;
35
using System.Threading.Tasks;
46

57
namespace SteamWebAPI2.Interfaces
68
{
9+
public enum GameServersAppId
10+
{
11+
TeamFortress2 = 440,
12+
CounterStrikeGo = 730
13+
}
14+
715
public class GameServersService : IGameServersService
816
{
917
private ISteamWebInterface steamWebInterface;
@@ -19,71 +27,114 @@ public GameServersService(ISteamWebRequest steamWebRequest, ISteamWebInterface s
1927
: steamWebInterface;
2028
}
2129

22-
public async Task<ISteamWebResponse<dynamic>> GetAccountListAsync()
30+
/// <summary>Gets a list of game server accounts with their logon tokens.
31+
/// </summary>
32+
/// <returns>Collection of game server accounts attached to the account associated with the web API key.</returns>
33+
public async Task<ISteamWebResponse<AccountListModel>> GetAccountListAsync()
2334
{
24-
var steamWebResponse = await steamWebInterface.GetAsync<dynamic>("GetAccountList", 1);
25-
return steamWebResponse;
35+
var steamWebResponse = await steamWebInterface.GetAsync<AccountListContainer>("GetAccountList", 1);
36+
var steamWebResponseModel = AutoMapperConfiguration.Mapper.Map<
37+
ISteamWebResponse<AccountListContainer>,
38+
ISteamWebResponse<AccountListModel>>(steamWebResponse);
39+
return steamWebResponseModel;
2640
}
2741

28-
public async Task<ISteamWebResponse<dynamic>> CreateAccount(uint appId, string memo)
42+
/// <summary>Creates a persistent game server account.
43+
/// </summary>
44+
/// <param name="appId">Only supports TF2 and CSGO.</param>
45+
/// <param name="memo">Free text to attach to server. Does nothing but act as an identifier.</param>
46+
/// <returns>Steam ID and LoginToken for the new server.</returns>
47+
public async Task<ISteamWebResponse<CreateAccountModel>> CreateAccountAsync(GameServersAppId appId, string memo)
2948
{
3049
List<SteamWebRequestParameter> parameters = new List<SteamWebRequestParameter>();
31-
parameters.AddIfHasValue(appId, "appid");
50+
parameters.AddIfHasValue((int)appId, "appid");
3251
parameters.AddIfHasValue(memo, "memo");
33-
var steamWebResponse = await steamWebInterface.PostAsync<dynamic>("CreateAccount", 1, parameters);
34-
return steamWebResponse;
52+
53+
var steamWebResponse = await steamWebInterface.PostAsync<CreateAccountContainer>("CreateAccount", 1, parameters);
54+
55+
var steamWebResponseModel = AutoMapperConfiguration.Mapper.Map<
56+
ISteamWebResponse<CreateAccountContainer>,
57+
ISteamWebResponse<CreateAccountModel>>(steamWebResponse);
58+
59+
return steamWebResponseModel;
3560
}
3661

37-
public async Task<ISteamWebResponse<dynamic>> SetMemo(ulong steamId, string memo)
62+
/// <summary>This method changes the memo associated with the game server account.
63+
/// Memos do not affect the account in any way. The memo shows up in the GetAccountList
64+
/// response and serves only as a reminder of what the account is used for.
65+
/// </summary>
66+
/// <param name="steamId">Steam ID of the server to alter.</param>
67+
/// <param name="memo">Free text to attach to server. Does nothing but act as an identifier.</param>
68+
/// <returns>200 OK with no content indicates success from this endpoint.</returns>
69+
public async Task SetMemoAsync(ulong steamId, string memo)
3870
{
3971
List<SteamWebRequestParameter> parameters = new List<SteamWebRequestParameter>();
4072
parameters.AddIfHasValue(steamId, "steamid");
4173
parameters.AddIfHasValue(memo, "memo");
42-
var steamWebResponse = await steamWebInterface.PostAsync<dynamic>("SetMemo", 1, parameters);
43-
return steamWebResponse;
74+
await steamWebInterface.PostAsync<dynamic>("SetMemo", 1, parameters);
4475
}
4576

46-
public async Task<ISteamWebResponse<dynamic>> ResetLoginToken(ulong steamId)
77+
/// <summary>Generates a new login token for the specified game server
78+
/// </summary>
79+
/// <param name="steamId">The SteamID of the game server to reset the login token</param>
80+
/// <returns>New login token</returns>
81+
public async Task<ISteamWebResponse<string>> ResetLoginTokenAsync(ulong steamId)
4782
{
4883
List<SteamWebRequestParameter> parameters = new List<SteamWebRequestParameter>();
4984
parameters.AddIfHasValue(steamId, "steamid");
50-
var steamWebResponse = await steamWebInterface.PostAsync<dynamic>("ResetLoginToken", 1, parameters);
51-
return steamWebResponse;
85+
var steamWebResponse = await steamWebInterface.PostAsync<ResetLoginTokenContainer>("ResetLoginToken", 1, parameters);
86+
var steamWebResponseModel = AutoMapperConfiguration.Mapper.Map<
87+
ISteamWebResponse<ResetLoginTokenContainer>,
88+
ISteamWebResponse<string>>(steamWebResponse);
89+
return steamWebResponseModel;
5290
}
5391

54-
public async Task<ISteamWebResponse<dynamic>> DeleteAccount(ulong steamId)
92+
/// <summary>Deletes a persistent game server account
93+
/// </summary>
94+
/// <param name="steamId">The SteamID of the game server account to delete</param>
95+
/// <returns>200 OK with no content indicates success from this endpoint.</returns>
96+
public async Task DeleteAccountAsync(ulong steamId)
5597
{
5698
List<SteamWebRequestParameter> parameters = new List<SteamWebRequestParameter>();
5799
parameters.AddIfHasValue(steamId, "steamid");
58-
var steamWebResponse = await steamWebInterface.PostAsync<dynamic>("DeleteAccount", 1, parameters);
59-
return steamWebResponse;
100+
await steamWebInterface.PostAsync<dynamic>("DeleteAccount", 1, parameters);
60101
}
61102

62-
public async Task<ISteamWebResponse<dynamic>> GetAccountPublicInfo(ulong steamId)
103+
/// <summary>Gets public information about a given game server account
104+
/// </summary>
105+
/// <param name="steamId">The SteamID of the game server to get info</param>
106+
/// <returns>Steam ID and associated App ID of the game server</returns>
107+
public async Task<ISteamWebResponse<AccountPublicInfoModel>> GetAccountPublicInfoAsync(ulong steamId)
63108
{
64109
List<SteamWebRequestParameter> parameters = new List<SteamWebRequestParameter>();
65110
parameters.AddIfHasValue(steamId, "steamid");
66-
var steamWebResponse = await steamWebInterface.GetAsync<dynamic>("GetAccountPublicInfo", 1, parameters);
67-
return steamWebResponse;
111+
var steamWebResponse = await steamWebInterface.GetAsync<AccountPublicInfoContainer>("GetAccountPublicInfo", 1, parameters);
112+
var steamWebResponseModel = AutoMapperConfiguration.Mapper.Map<
113+
ISteamWebResponse<AccountPublicInfoContainer>,
114+
ISteamWebResponse<AccountPublicInfoModel>>(steamWebResponse);
115+
return steamWebResponseModel;
68116
}
69117

70-
public async Task<ISteamWebResponse<dynamic>> QueryLoginToken(string loginToken)
118+
public async Task<ISteamWebResponse<QueryLoginTokenModel>> QueryLoginTokenAsync(string loginToken)
71119
{
72120
List<SteamWebRequestParameter> parameters = new List<SteamWebRequestParameter>();
73121
parameters.AddIfHasValue(loginToken, "login_token");
74-
var steamWebResponse = await steamWebInterface.GetAsync<dynamic>("QueryLoginToken", 1, parameters);
75-
return steamWebResponse;
122+
var steamWebResponse = await steamWebInterface.GetAsync<QueryLoginTokenContainer>("QueryLoginToken", 1, parameters);
123+
var steamWebResponseModel = AutoMapperConfiguration.Mapper.Map<
124+
ISteamWebResponse<QueryLoginTokenContainer>,
125+
ISteamWebResponse<QueryLoginTokenModel>>(steamWebResponse);
126+
return steamWebResponseModel;
76127
}
77128

78-
public async Task<ISteamWebResponse<dynamic>> GetServerSteamIDsByIP(IReadOnlyCollection<string> serverIPs)
129+
public async Task<ISteamWebResponse<dynamic>> GetServerSteamIDsByIPAsync(IReadOnlyCollection<string> serverIPs)
79130
{
80131
List<SteamWebRequestParameter> parameters = new List<SteamWebRequestParameter>();
81132
parameters.AddIfHasValue(serverIPs, "server_ips");
82133
var steamWebResponse = await steamWebInterface.GetAsync<dynamic>("GetServerSteamIDsByIP", 1, parameters);
83134
return steamWebResponse;
84135
}
85136

86-
public async Task<ISteamWebResponse<dynamic>> GetServerIPsBySteamID(IReadOnlyCollection<ulong> steamIds)
137+
public async Task<ISteamWebResponse<dynamic>> GetServerIPsBySteamIDAsync(IReadOnlyCollection<ulong> steamIds)
87138
{
88139
List<SteamWebRequestParameter> parameters = new List<SteamWebRequestParameter>();
89140
parameters.AddIfHasValue(steamIds, "server_steamids");
Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
1-
using SteamWebAPI2.Utilities;
1+
using Steam.Models.GameServers;
2+
using SteamWebAPI2.Utilities;
23
using System.Collections.Generic;
34
using System.Threading.Tasks;
45

56
namespace SteamWebAPI2.Interfaces
67
{
78
public interface IGameServersService
89
{
9-
Task<ISteamWebResponse<dynamic>> GetAccountListAsync();
10+
Task<ISteamWebResponse<AccountListModel>> GetAccountListAsync();
1011

11-
Task<ISteamWebResponse<dynamic>> CreateAccount(uint appid, string memo);
12+
Task<ISteamWebResponse<CreateAccountModel>> CreateAccountAsync(GameServersAppId appId, string memo);
1213

13-
Task<ISteamWebResponse<dynamic>> SetMemo(ulong steamId, string memo);
14+
Task SetMemoAsync(ulong steamId, string memo);
1415

15-
Task<ISteamWebResponse<dynamic>> ResetLoginToken(ulong steamId);
16+
Task<ISteamWebResponse<string>> ResetLoginTokenAsync(ulong steamId);
1617

17-
Task<ISteamWebResponse<dynamic>> DeleteAccount(ulong steamId);
18+
Task DeleteAccountAsync(ulong steamId);
1819

19-
Task<ISteamWebResponse<dynamic>> GetAccountPublicInfo(ulong steamId);
20+
Task<ISteamWebResponse<AccountPublicInfoModel>> GetAccountPublicInfoAsync(ulong steamId);
2021

21-
Task<ISteamWebResponse<dynamic>> QueryLoginToken(string loginToken);
22+
Task<ISteamWebResponse<QueryLoginTokenModel>> QueryLoginTokenAsync(string loginToken);
2223

23-
Task<ISteamWebResponse<dynamic>> GetServerSteamIDsByIP(IReadOnlyCollection<string> serverIPs);
24+
Task<ISteamWebResponse<dynamic>> GetServerSteamIDsByIPAsync(IReadOnlyCollection<string> serverIPs);
2425

25-
Task<ISteamWebResponse<dynamic>> GetServerIPsBySteamID(IReadOnlyCollection<ulong> steamIds);
26+
Task<ISteamWebResponse<dynamic>> GetServerIPsBySteamIDAsync(IReadOnlyCollection<ulong> steamIds);
2627
}
2728
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
using System.Collections.Generic;
2+
using AutoMapper;
3+
using Steam.Models.DOTA2;
4+
using SteamWebAPI2.Models.DOTA2;
5+
using SteamWebAPI2.Models.GameEconomy;
6+
7+
namespace SteamWebAPI2.Mappings
8+
{
9+
public class DOTA2EconProfile : Profile
10+
{
11+
public DOTA2EconProfile()
12+
{
13+
CreateMap<Hero, HeroModel>();
14+
CreateMap<HeroResultContainer, IReadOnlyCollection<HeroModel>>().ConvertUsing((src, dest, context) =>
15+
context.Mapper.Map<IList<Hero>, IReadOnlyCollection<HeroModel>>(src.Result != null ? src.Result.Heroes : null)
16+
);
17+
18+
CreateMap<GameItem, GameItemModel>();
19+
CreateMap<GameItemResultContainer, IReadOnlyCollection<GameItemModel>>().ConvertUsing((src, dest, context) =>
20+
context.Mapper.Map<IList<GameItem>, IReadOnlyCollection<GameItemModel>>(src.Result != null ? src.Result.Items : null)
21+
);
22+
23+
CreateMap<ItemIconPathResultContainer, string>().ConvertUsing(src => src.Result != null ? src.Result.Path : null);
24+
25+
CreateMap<SchemaQualities, Steam.Models.TF2.SchemaQualitiesModel>();
26+
CreateMap<SchemaOriginName, Steam.Models.TF2.SchemaOriginNameModel>();
27+
CreateMap<SchemaItem, Steam.Models.TF2.SchemaItemModel>();
28+
CreateMap<SchemaCapabilities, Steam.Models.TF2.SchemaCapabilitiesModel>();
29+
CreateMap<SchemaStyle, Steam.Models.TF2.SchemaStyleModel>();
30+
CreateMap<SchemaAdditionalHiddenBodygroups, Steam.Models.TF2.SchemaAdditionalHiddenBodygroupsModel>();
31+
CreateMap<SchemaItemAttribute, Steam.Models.TF2.SchemaItemAttributeModel>();
32+
CreateMap<SchemaPerClassLoadoutSlots, Steam.Models.TF2.SchemaPerClassLoadoutSlotsModel>();
33+
CreateMap<SchemaTool, Steam.Models.TF2.SchemaToolModel>();
34+
CreateMap<SchemaUsageCapabilities, Steam.Models.TF2.SchemaUsageCapabilitiesModel>();
35+
CreateMap<SchemaAttribute, Steam.Models.TF2.SchemaAttributeModel>();
36+
CreateMap<SchemaItemSet, Steam.Models.TF2.SchemaItemSetModel>();
37+
CreateMap<SchemaItemSetAttribute, Steam.Models.TF2.SchemaItemSetAttributeModel>();
38+
CreateMap<SchemaAttributeControlledAttachedParticle, Steam.Models.TF2.SchemaAttributeControlledAttachedParticleModel>();
39+
CreateMap<SchemaItemLevel, Steam.Models.TF2.SchemaItemLevelModel>();
40+
CreateMap<SchemaLevel, Steam.Models.TF2.SchemaLevelModel>();
41+
CreateMap<SchemaKillEaterScoreType, Steam.Models.TF2.SchemaKillEaterScoreTypeModel>();
42+
CreateMap<SchemaStringLookup, Steam.Models.TF2.SchemaStringLookupModel>();
43+
CreateMap<SchemaString, Steam.Models.TF2.SchemaStringModel>();
44+
45+
// TODO: Rework the way Schema models are used for different games (TF2 / DOTA2)
46+
//CreateMap<SchemaQualities, Steam.Models.DOTA2.SchemaQualityModel>()
47+
// .ForMember(dest => dest.Name, opts => opts.Ignore())
48+
// .ForMember(dest => dest.Value, opts => opts.Ignore())
49+
// .ForMember(dest => dest.HexColor, opts => opts.Ignore());
50+
//CreateMap<SchemaResult, Steam.Models.DOTA2.SchemaModel>()
51+
// .ForMember(dest => dest.GameInfo, opts => opts.Ignore())
52+
// .ForMember(dest => dest.Rarities, opts => opts.Ignore())
53+
// .ForMember(dest => dest.Colors, opts => opts.Ignore())
54+
// .ForMember(dest => dest.Prefabs, opts => opts.Ignore())
55+
// .ForMember(dest => dest.ItemAutographs, opts => opts.Ignore());
56+
//CreateMap<SchemaResultContainer, Steam.Models.DOTA2.SchemaModel>().ConvertUsing(
57+
// src => Mapper.Map<SchemaResult, Steam.Models.DOTA2.SchemaModel>(src.Result)
58+
//);
59+
60+
CreateMap<Rarity, RarityModel>();
61+
CreateMap<RarityResultContainer, IReadOnlyCollection<RarityModel>>().ConvertUsing((src, dest, context) =>
62+
context.Mapper.Map<IList<Rarity>, IReadOnlyCollection<RarityModel>>(src.Result != null ? src.Result.Rarities : null)
63+
);
64+
65+
CreateMap<PrizePoolResultContainer, uint>().ConvertUsing(src => src.Result != null ? src.Result.PrizePool : default(uint));
66+
}
67+
}
68+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using AutoMapper;
2+
using Steam.Models.DOTA2;
3+
using SteamWebAPI2.Models.DOTA2;
4+
5+
namespace SteamWebAPI2.Mappings
6+
{
7+
public class DOTA2FantasyProfile : Profile
8+
{
9+
public DOTA2FantasyProfile()
10+
{
11+
CreateMap<PlayerOfficialInfoResult, PlayerOfficialInfoModel>();
12+
CreateMap<PlayerOfficialInfoResultContainer, PlayerOfficialInfoModel>().ConvertUsing((src, dest, context) =>
13+
context.Mapper.Map<PlayerOfficialInfoResult, PlayerOfficialInfoModel>(src.Result)
14+
);
15+
16+
CreateMap<ProPlayerInfo, ProPlayerInfoModel>();
17+
CreateMap<ProPlayerLeaderboard, ProPlayerLeaderboardModel>();
18+
CreateMap<ProPlayerListResult, ProPlayerDetailModel>();
19+
}
20+
}
21+
}

0 commit comments

Comments
 (0)