Skip to content

Commit 15df87d

Browse files
author
Justin Skiles
authored
Cleanup (#92)
1 parent ca35de6 commit 15df87d

File tree

8 files changed

+117
-62
lines changed

8 files changed

+117
-62
lines changed

src/Steam.UnitTests/EconItemsTeamFortress2Tests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ public class EconItemsTeamFortress2Tests : BaseTest
1717
public EconItemsTeamFortress2Tests()
1818
{
1919
steamInterface = factory.CreateSteamWebInterface<EconItems>(
20-
new HttpClient(),
21-
EconItemsAppId.TeamFortress2
20+
EconItemsAppId.TeamFortress2,
21+
new HttpClient()
2222
);
2323
}
2424

src/Steam.UnitTests/GCVersionTests.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,28 +23,28 @@ public GCVersionTests()
2323
HttpClient httpClient = new HttpClient();
2424

2525
steamInterfaceTeamFortress2 = factory.CreateSteamWebInterface<GCVersion>(
26-
httpClient,
27-
GCVersionAppId.TeamFortress2
26+
GCVersionAppId.TeamFortress2,
27+
httpClient
2828
);
2929

3030
steamInterfaceCounterStrikeGO= factory.CreateSteamWebInterface<GCVersion>(
31-
httpClient,
32-
GCVersionAppId.CounterStrikeGO
31+
GCVersionAppId.CounterStrikeGO,
32+
httpClient
3333
);
3434

3535
steamInterfaceDota2 = factory.CreateSteamWebInterface<GCVersion>(
36-
httpClient,
37-
GCVersionAppId.Dota2
36+
GCVersionAppId.Dota2,
37+
httpClient
3838
);
3939

4040
steamInterfaceArtifact = factory.CreateSteamWebInterface<GCVersion>(
41-
httpClient,
42-
GCVersionAppId.Artifact
41+
GCVersionAppId.Artifact,
42+
httpClient
4343
);
4444

4545
steamInterfaceDotaUnderlords = factory.CreateSteamWebInterface<GCVersion>(
46-
httpClient,
47-
GCVersionAppId.DotaUnderlords
46+
GCVersionAppId.DotaUnderlords,
47+
httpClient
4848
);
4949
}
5050

src/Steam.UnitTests/SteamWebInterfaceFactoryTests.cs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -53,105 +53,105 @@ public void Create_DOTA2Econ_Interface_Should_Succeed()
5353
[Fact]
5454
public void Create_DOTA2Match_Interface_Should_Succeed()
5555
{
56-
var steamInterface = factory.CreateSteamWebInterface<DOTA2Match>(new HttpClient());
56+
var steamInterface = factory.CreateSteamWebInterface<DOTA2Match>();
5757
Assert.NotNull(steamInterface);
5858
}
5959

6060
[Fact]
6161
public void Create_DOTA2Ticket_Interface_Should_Succeed()
6262
{
63-
var steamInterface = factory.CreateSteamWebInterface<DOTA2Ticket>(new HttpClient());
63+
var steamInterface = factory.CreateSteamWebInterface<DOTA2Ticket>();
6464
Assert.NotNull(steamInterface);
6565
}
6666

6767
[Fact]
6868
public void Create_EconItems_Interface_Should_Succeed()
6969
{
70-
var steamInterface = factory.CreateSteamWebInterface<EconItems>(new HttpClient(), EconItemsAppId.TeamFortress2);
70+
var steamInterface = factory.CreateSteamWebInterface<EconItems>(EconItemsAppId.TeamFortress2);
7171
Assert.NotNull(steamInterface);
7272
}
7373

7474
[Fact]
7575
public void Create_EconService_Interface_Should_Succeed()
7676
{
77-
var steamInterface = factory.CreateSteamWebInterface<EconService>(new HttpClient());
77+
var steamInterface = factory.CreateSteamWebInterface<EconService>();
7878
Assert.NotNull(steamInterface);
7979
}
8080

8181
[Fact]
8282
public void Create_GameServersService_Interface_Should_Succeed()
8383
{
84-
var steamInterface = factory.CreateSteamWebInterface<GameServersService>(new HttpClient());
84+
var steamInterface = factory.CreateSteamWebInterface<GameServersService>();
8585
Assert.NotNull(steamInterface);
8686
}
8787

8888
[Fact]
8989
public void Create_GCVersion_Interface_Should_Succeed()
9090
{
91-
var steamInterface = factory.CreateSteamWebInterface<GCVersion>(new HttpClient(), GCVersionAppId.TeamFortress2);
91+
var steamInterface = factory.CreateSteamWebInterface<GCVersion>(GCVersionAppId.TeamFortress2);
9292
Assert.NotNull(steamInterface);
9393
}
9494

9595
[Fact]
9696
public void Create_PlayerService_Interface_Should_Succeed()
9797
{
98-
var steamInterface = factory.CreateSteamWebInterface<PlayerService>(new HttpClient());
98+
var steamInterface = factory.CreateSteamWebInterface<PlayerService>();
9999
Assert.NotNull(steamInterface);
100100
}
101101

102102
[Fact]
103103
public void Create_SteamApps_Interface_Should_Succeed()
104104
{
105-
var steamInterface = factory.CreateSteamWebInterface<SteamApps>(new HttpClient());
105+
var steamInterface = factory.CreateSteamWebInterface<SteamApps>();
106106
Assert.NotNull(steamInterface);
107107
}
108108

109109
[Fact]
110110
public void Create_SteamEconomy_Interface_Should_Succeed()
111111
{
112-
var steamInterface = factory.CreateSteamWebInterface<SteamEconomy>(new HttpClient());
112+
var steamInterface = factory.CreateSteamWebInterface<SteamEconomy>();
113113
Assert.NotNull(steamInterface);
114114
}
115115

116116
[Fact]
117117
public void Create_SteamNews_Interface_Should_Succeed()
118118
{
119-
var steamInterface = factory.CreateSteamWebInterface<SteamNews>(new HttpClient());
119+
var steamInterface = factory.CreateSteamWebInterface<SteamNews>();
120120
Assert.NotNull(steamInterface);
121121
}
122122

123123
[Fact]
124124
public void Create_SteamRemoteStorage_Interface_Should_Succeed()
125125
{
126-
var steamInterface = factory.CreateSteamWebInterface<SteamRemoteStorage>(new HttpClient());
126+
var steamInterface = factory.CreateSteamWebInterface<SteamRemoteStorage>();
127127
Assert.NotNull(steamInterface);
128128
}
129129

130130
[Fact]
131131
public void Create_SteamStore_Interface_Should_Succeed()
132132
{
133-
var steamInterface = new SteamStore(new HttpClient());
133+
var steamInterface = new SteamStore();
134134
Assert.NotNull(steamInterface);
135135
}
136136

137137
[Fact]
138138
public void Create_SteamUserAuth_Interface_Should_Succeed()
139139
{
140-
var steamInterface = factory.CreateSteamWebInterface<SteamUserAuth>(new HttpClient());
140+
var steamInterface = factory.CreateSteamWebInterface<SteamUserAuth>();
141141
Assert.NotNull(steamInterface);
142142
}
143143

144144
[Fact]
145145
public void Create_SteamUserStats_Interface_Should_Succeed()
146146
{
147-
var steamInterface = factory.CreateSteamWebInterface<SteamUserStats>(new HttpClient());
147+
var steamInterface = factory.CreateSteamWebInterface<SteamUserStats>();
148148
Assert.NotNull(steamInterface);
149149
}
150150

151151
[Fact]
152152
public void Create_SteamWebAPIUtil_Interface_Should_Succeed()
153153
{
154-
var steamInterface = factory.CreateSteamWebInterface<SteamWebAPIUtil>(new HttpClient());
154+
var steamInterface = factory.CreateSteamWebInterface<SteamWebAPIUtil>();
155155
Assert.NotNull(steamInterface);
156156
}
157157
}

src/SteamWebAPI2/Utilities/ISteamWebResponse.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,17 @@ namespace SteamWebAPI2.Utilities
44
{
55
public interface ISteamWebResponse<T>
66
{
7+
// Data returned from Steam Web API (this is probably what you care about)
78
T Data { get; set; }
9+
// Content length from the HTTP response
810
long? ContentLength { get; set; }
11+
// Content type of the HTTP response
912
string ContentType { get; set; }
13+
// Charset of the content type of the HTTP response
1014
string ContentTypeCharSet { get; set; }
15+
// Expires header from the HTTP response
1116
DateTimeOffset? Expires { get; set; }
17+
// Last modified header from the HTTP response
1218
DateTimeOffset? LastModified { get; set; }
1319
}
1420
}

src/SteamWebAPI2/Utilities/SteamWebInterface.cs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,15 @@ public SteamWebInterface(string steamWebApiBaseUrl, string interfaceName, ISteam
6767
/// <returns></returns>
6868
public async Task<ISteamWebResponse<T>> GetAsync<T>(string methodName, int version, IList<SteamWebRequestParameter> parameters = null)
6969
{
70-
Debug.Assert(!string.IsNullOrWhiteSpace(methodName));
71-
Debug.Assert(version > 0);
70+
if(string.IsNullOrWhiteSpace(methodName))
71+
{
72+
throw new ArgumentNullException(nameof(methodName));
73+
}
74+
75+
if(version <= 0)
76+
{
77+
throw new ArgumentOutOfRangeException(nameof(version));
78+
}
7279

7380
return await steamWebRequest.GetAsync<T>(interfaceName, methodName, version, parameters);
7481
}
@@ -83,8 +90,15 @@ public async Task<ISteamWebResponse<T>> GetAsync<T>(string methodName, int versi
8390
/// <returns></returns>
8491
public async Task<ISteamWebResponse<T>> PostAsync<T>(string methodName, int version, IList<SteamWebRequestParameter> parameters = null)
8592
{
86-
Debug.Assert(!string.IsNullOrWhiteSpace(methodName));
87-
Debug.Assert(version > 0);
93+
if(string.IsNullOrWhiteSpace(methodName))
94+
{
95+
throw new ArgumentNullException(nameof(methodName));
96+
}
97+
98+
if(version <= 0)
99+
{
100+
throw new ArgumentOutOfRangeException(nameof(version));
101+
}
88102

89103
return await steamWebRequest.PostAsync<T>(interfaceName, methodName, version, parameters);
90104
}

src/SteamWebAPI2/Utilities/SteamWebInterfaceFactory.cs

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace SteamWebAPI2.Utilities
77
public class SteamWebInterfaceFactory
88
{
99
private readonly string steamWebApiBaseUrl = "https://api.steampowered.com/";
10-
private string steamWebApiKey;
10+
private readonly string steamWebApiKey;
1111

1212
/// <summary>
1313
/// Factory to create web interface objects to communicate with Steam Web API
@@ -30,44 +30,49 @@ public SteamWebInterfaceFactory(string steamWebApiKey, string steamWebApiBaseUrl
3030
}
3131

3232
/// <summary>
33-
/// Creates a web interface object connected to a specific Steam Web API interfac endpoint
33+
/// Creates a web interface object connected to a specific Steam Web API interface endpoint
3434
/// </summary>
35-
/// <param name="httpClient">Custom http client injected with your customization (if necessary)</param>
35+
/// <param name="httpClient">Custom http client injected with your customization (if necessary).
36+
/// If null, new instance is created with all defaults.</param>
3637
/// <typeparam name="T">Type of the web interface to create</typeparam>
3738
/// <returns>Instance of the web interface</returns>
38-
public T CreateSteamWebInterface<T>(HttpClient httpClient)
39+
public T CreateSteamWebInterface<T>(HttpClient httpClient = null)
3940
{
4041
var steamWebRequest = CreateSteamWebRequest(httpClient);
4142
return (T)Activator.CreateInstance(typeof(T), steamWebRequest, null);
4243
}
4344

4445
/// <summary>
45-
/// Creates a web interface object connected to a specific Steam Web API interfac endpoint
46+
/// Creates a web interface object connected to a specific Steam Web API interface endpoint
4647
/// </summary>
47-
/// <param name="httpClient">Custom http client injected with your customization (if necessary)</param>
48+
/// <param name="appId">Indicates which app to use</param>
49+
/// <param name="httpClient">Custom http client injected with your customization (if necessary).
50+
/// If null, new instance is created with all defaults.</param>
4851
/// <typeparam name="T">Type of the web interface to create</typeparam>
4952
/// <returns>Instance of the web interface</returns>
50-
public T CreateSteamWebInterface<T>(HttpClient httpClient, EconItemsAppId appId)
53+
public T CreateSteamWebInterface<T>(EconItemsAppId appId, HttpClient httpClient = null)
5154
{
5255
var steamWebRequest = CreateSteamWebRequest(httpClient);
5356
return (T)Activator.CreateInstance(typeof(T), steamWebRequest, appId, null);
5457
}
5558

5659
/// <summary>
57-
/// Creates a web interface object connected to a specific Steam Web API interfac endpoint
60+
/// Creates a web interface object connected to a specific Steam Web API interface endpoint
5861
/// </summary>
59-
/// <param name="httpClient">Custom http client injected with your customization (if necessary)</param>
62+
/// <param name="appId">Indicates which app to use</param>
63+
/// <param name="httpClient">Custom http client injected with your customization (if necessary).
64+
/// If null, new instance is created with all defaults.</param>
6065
/// <typeparam name="T">Type of the web interface to create</typeparam>
6166
/// <returns>Instance of the web interface</returns>
62-
public T CreateSteamWebInterface<T>(HttpClient httpClient, GCVersionAppId appId)
67+
public T CreateSteamWebInterface<T>(GCVersionAppId appId, HttpClient httpClient = null)
6368
{
6469
var steamWebRequest = CreateSteamWebRequest(httpClient);
6570
return (T)Activator.CreateInstance(typeof(T), steamWebRequest, appId, null);
6671
}
6772

6873
private ISteamWebRequest CreateSteamWebRequest(HttpClient httpClient)
6974
{
70-
return new SteamWebRequest(steamWebApiBaseUrl, steamWebApiKey, httpClient);
75+
return new SteamWebRequest(steamWebApiBaseUrl, steamWebApiKey, httpClient ?? new HttpClient());
7176
}
7277
}
7378
}

0 commit comments

Comments
 (0)