Skip to content

Commit

Permalink
Merge pull request #73 from babelshift/chore/refactor-http-client
Browse files Browse the repository at this point in the history
Refactored to allow injecting custom HttpClient. Also some cleanup.
  • Loading branch information
babelshift authored Aug 12, 2019
2 parents 400843c + 75466d8 commit db48211
Show file tree
Hide file tree
Showing 28 changed files with 145 additions and 108 deletions.
2 changes: 0 additions & 2 deletions src/SteamWebAPI2/AutoMapperConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
using SteamWebAPI2.Utilities;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;

namespace SteamWebAPI2
Expand Down Expand Up @@ -88,7 +87,6 @@ public static void Initialize()
CreateSteamWebResponseMap<MatchHistoryBySequenceNumberResultContainer, IReadOnlyCollection<MatchHistoryMatchModel>>(x);
CreateSteamWebResponseMap<TeamInfoResultContainer, IReadOnlyCollection<TeamInfoModel>>(x);
CreateSteamWebResponseMap<EconItemResultContainer, EconItemResultModel>(x);
//CreateSteamWebResponseMap<SchemaResultContainer, Steam.Models.DOTA2.SchemaModel>(x);
CreateSteamWebResponseMap<SchemaResultContainer, Steam.Models.TF2.SchemaModel>(x);
CreateSteamWebResponseMap<SchemaUrlResultContainer, string>(x);
CreateSteamWebResponseMap<StoreMetaDataResultContainer, StoreMetaDataModel>(x);
Expand Down
4 changes: 2 additions & 2 deletions src/SteamWebAPI2/Interfaces/CSGOServers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ public class CSGOServers : ICSGOServers
/// Default constructor established the Steam Web API key and initializes for subsequent method calls
/// </summary>
/// <param name="steamWebApiKey"></param>
public CSGOServers(string steamWebApiKey, ISteamWebInterface steamWebInterface = null)
public CSGOServers(ISteamWebRequest steamWebRequest, ISteamWebInterface steamWebInterface = null)
{
this.steamWebInterface = steamWebInterface == null
? new SteamWebInterface(steamWebApiKey, "ICSGOServers_730")
? new SteamWebInterface("ICSGOServers_730", steamWebRequest)
: steamWebInterface;
}

Expand Down
4 changes: 2 additions & 2 deletions src/SteamWebAPI2/Interfaces/DOTA2Econ.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ public class DOTA2Econ : IDOTA2Econ
/// Default constructor established the Steam Web API key and initializes for subsequent method calls
/// </summary>
/// <param name="steamWebApiKey"></param>
public DOTA2Econ(string steamWebApiKey, ISteamWebInterface steamWebInterface = null)
public DOTA2Econ(ISteamWebRequest steamWebRequest, ISteamWebInterface steamWebInterface = null)
{
this.steamWebInterface = steamWebInterface == null
? new SteamWebInterface(steamWebApiKey, "IEconDOTA2_570")
? new SteamWebInterface("IEconDOTA2_570", steamWebRequest)
: steamWebInterface;
}

Expand Down
4 changes: 2 additions & 2 deletions src/SteamWebAPI2/Interfaces/DOTA2Fantasy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ public class DOTA2Fantasy : IDOTA2Fantasy
/// Default constructor established the Steam Web API key and initializes for subsequent method calls
/// </summary>
/// <param name="steamWebApiKey"></param>
public DOTA2Fantasy(string steamWebApiKey, ISteamWebInterface steamWebInterface = null)
public DOTA2Fantasy(ISteamWebRequest steamWebRequest, ISteamWebInterface steamWebInterface = null)
{
this.steamWebInterface = steamWebInterface == null
? new SteamWebInterface(steamWebApiKey, "IDOTA2Fantasy_570")
? new SteamWebInterface("IDOTA2Fantasy_570", steamWebRequest)
: steamWebInterface;
}

Expand Down
4 changes: 2 additions & 2 deletions src/SteamWebAPI2/Interfaces/DOTA2Match.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ public class DOTA2Match : IDOTA2Match
/// Default constructor established the Steam Web API key and initializes for subsequent method calls
/// </summary>
/// <param name="steamWebApiKey"></param>
public DOTA2Match(string steamWebApiKey, ISteamWebInterface steamWebInterface = null)
public DOTA2Match(ISteamWebRequest steamWebRequest, ISteamWebInterface steamWebInterface = null)
{
this.steamWebInterface = steamWebInterface == null
? new SteamWebInterface(steamWebApiKey, "IDOTA2Match_570")
? new SteamWebInterface("IDOTA2Match_570", steamWebRequest)
: steamWebInterface;
}

Expand Down
6 changes: 3 additions & 3 deletions src/SteamWebAPI2/Interfaces/DOTA2Ticket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ public class DOTA2Ticket : IDOTA2Ticket
/// <summary>
/// Default constructor established the Steam Web API key and initializes for subsequent method calls
/// </summary>
/// <param name="steamWebApiKey"></param>
public DOTA2Ticket(string steamWebApiKey, ISteamWebInterface steamWebInterface = null)
/// <param name="steamWebRequest"></param>
public DOTA2Ticket(ISteamWebRequest steamWebRequest, ISteamWebInterface steamWebInterface = null)
{
this.steamWebInterface = steamWebInterface == null
? new SteamWebInterface(steamWebApiKey, "IDOTA2Ticket_570")
? new SteamWebInterface("IDOTA2Ticket_570", steamWebRequest)
: steamWebInterface;
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/SteamWebAPI2/Interfaces/EconItems.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,16 @@ public class EconItems : IEconItems
/// <summary>
/// Default constructor established the Steam Web API key and initializes for subsequent method calls
/// </summary>
/// <param name="steamWebApiKey"></param>
public EconItems(string steamWebApiKey, EconItemsAppId appId, ISteamWebInterface steamWebInterface = null)
/// <param name="steamWebRequest"></param>
public EconItems(ISteamWebRequest steamWebRequest, EconItemsAppId appId, ISteamWebInterface steamWebInterface = null)
{
if (appId <= 0)
{
throw new ArgumentOutOfRangeException("appId");
}

this.steamWebInterface = steamWebInterface == null
? new SteamWebInterface(steamWebApiKey, "IEconItems_" + (uint)appId)
? new SteamWebInterface("IEconItems_" + (uint)appId, steamWebRequest)
: steamWebInterface;

this.appId = (uint)appId;
Expand Down
6 changes: 3 additions & 3 deletions src/SteamWebAPI2/Interfaces/EconService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ public class EconService : IEconService
/// <summary>
/// Default constructor established the Steam Web API key and initializes for subsequent method calls
/// </summary>
/// <param name="steamWebApiKey"></param>
public EconService(string steamWebApiKey, ISteamWebInterface steamWebInterface = null)
/// <param name="steamWebRequest"></param>
public EconService(ISteamWebRequest steamWebRequest, ISteamWebInterface steamWebInterface = null)
{
this.steamWebInterface = steamWebInterface == null
? new SteamWebInterface(steamWebApiKey, "IEconService")
? new SteamWebInterface("IEconService", steamWebRequest)
: steamWebInterface;
}

Expand Down
6 changes: 3 additions & 3 deletions src/SteamWebAPI2/Interfaces/GCVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ public class GCVersion : IGCVersion
/// <summary>
/// Default constructor established the Steam Web API key and initializes for subsequent method calls
/// </summary>
/// <param name="steamWebApiKey"></param>
public GCVersion(string steamWebApiKey, GCVersionAppId appId, ISteamWebInterface steamWebInterface = null)
/// <param name="steamWebRequest"></param>
public GCVersion(ISteamWebRequest steamWebRequest, GCVersionAppId appId, ISteamWebInterface steamWebInterface = null)
{
this.steamWebInterface = steamWebInterface == null
? new SteamWebInterface(steamWebApiKey, "IGCVersion_" + (uint)appId)
? new SteamWebInterface("IGCVersion_" + (uint)appId, steamWebRequest)
: steamWebInterface;

if (appId <= 0)
Expand Down
6 changes: 3 additions & 3 deletions src/SteamWebAPI2/Interfaces/GameServersService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ public class GameServersService : IGameServersService
/// <summary>
/// Default constructor established the Steam Web API key and initializes for subsequent method calls
/// </summary>
/// <param name="steamWebApiKey"></param>
public GameServersService(string steamWebApiKey, ISteamWebInterface steamWebInterface = null)
/// <param name="steamWebRequest"></param>
public GameServersService(ISteamWebRequest steamWebRequest, ISteamWebInterface steamWebInterface = null)
{
this.steamWebInterface = steamWebInterface == null
? new SteamWebInterface(steamWebApiKey, "IGameServersService")
? new SteamWebInterface("IGameServersService", steamWebRequest)
: steamWebInterface;
}

Expand Down
6 changes: 3 additions & 3 deletions src/SteamWebAPI2/Interfaces/PlayerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ public class PlayerService : IPlayerService
/// <summary>
/// Default constructor established the Steam Web API key and initializes for subsequent method calls
/// </summary>
/// <param name="steamWebApiKey"></param>
public PlayerService(string steamWebApiKey, ISteamWebInterface steamWebInterface = null)
/// <param name="steamWebRequest"></param>
public PlayerService(ISteamWebRequest steamWebRequest, ISteamWebInterface steamWebInterface = null)
{
this.steamWebInterface = steamWebInterface == null
? new SteamWebInterface(steamWebApiKey, "IPlayerService")
? new SteamWebInterface("IPlayerService", steamWebRequest)
: steamWebInterface;
}

Expand Down
6 changes: 3 additions & 3 deletions src/SteamWebAPI2/Interfaces/SteamApps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ public class SteamApps : ISteamApps
/// <summary>
/// Default constructor established the Steam Web API key and initializes for subsequent method calls
/// </summary>
/// <param name="steamWebApiKey"></param>
public SteamApps(string steamWebApiKey, ISteamWebInterface steamWebInterface = null)
/// <param name="steamWebRequest"></param>
public SteamApps(ISteamWebRequest steamWebRequest, ISteamWebInterface steamWebInterface = null)
{
this.steamWebInterface = steamWebInterface == null
? new SteamWebInterface(steamWebApiKey, "ISteamApps")
? new SteamWebInterface("ISteamApps", steamWebRequest)
: steamWebInterface;
}

Expand Down
4 changes: 2 additions & 2 deletions src/SteamWebAPI2/Interfaces/SteamEconomy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ public class SteamEconomy : ISteamEconomy
/// Default constructor established the Steam Web API key and initializes for subsequent method calls
/// </summary>
/// <param name="steamWebApiKey"></param>
public SteamEconomy(string steamWebApiKey, ISteamWebInterface steamWebInterface = null)
public SteamEconomy(ISteamWebRequest steamWebRequest, ISteamWebInterface steamWebInterface = null)
{
this.steamWebInterface = steamWebInterface == null
? new SteamWebInterface(steamWebApiKey, "ISteamEconomy")
? new SteamWebInterface("ISteamEconomy", steamWebRequest)
: steamWebInterface;
}

Expand Down
6 changes: 3 additions & 3 deletions src/SteamWebAPI2/Interfaces/SteamNews.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ public class SteamNews : ISteamNews
/// <summary>
/// Default constructor established the Steam Web API key and initializes for subsequent method calls
/// </summary>
/// <param name="steamWebApiKey"></param>
public SteamNews(string steamWebApiKey, ISteamWebInterface steamWebInterface = null)
/// <param name="steamWebRequest"></param>
public SteamNews(ISteamWebRequest steamWebRequest, ISteamWebInterface steamWebInterface = null)
{
this.steamWebInterface = steamWebInterface == null
? new SteamWebInterface(steamWebApiKey, "ISteamNews")
? new SteamWebInterface("ISteamNews", steamWebRequest)
: steamWebInterface;
}

Expand Down
6 changes: 3 additions & 3 deletions src/SteamWebAPI2/Interfaces/SteamRemoteStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ public class SteamRemoteStorage : ISteamRemoteStorage
/// <summary>
/// Default constructor established the Steam Web API key and initializes for subsequent method calls
/// </summary>
/// <param name="steamWebApiKey"></param>
public SteamRemoteStorage(string steamWebApiKey, ISteamWebInterface steamWebInterface = null)
/// <param name="steamWebRequest"></param>
public SteamRemoteStorage(ISteamWebRequest steamWebRequest, ISteamWebInterface steamWebInterface = null)
{
this.steamWebInterface = steamWebInterface == null
? new SteamWebInterface(steamWebApiKey, "ISteamRemoteStorage")
? new SteamWebInterface("ISteamRemoteStorage", steamWebRequest)
: steamWebInterface;
}

Expand Down
6 changes: 3 additions & 3 deletions src/SteamWebAPI2/Interfaces/SteamUser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ public class SteamUser : ISteamUser
/// <summary>
/// Default constructor established the Steam Web API key and initializes for subsequent method calls
/// </summary>
/// <param name="steamWebApiKey"></param>
public SteamUser(string steamWebApiKey, ISteamWebInterface steamWebInterface = null)
/// <param name="steamWebRequest"></param>
public SteamUser(ISteamWebRequest steamWebRequest, ISteamWebInterface steamWebInterface = null)
{
this.steamWebInterface = steamWebInterface == null
? new SteamWebInterface(steamWebApiKey, "ISteamUser")
? new SteamWebInterface("ISteamUser", steamWebRequest)
: steamWebInterface;
}

Expand Down
6 changes: 3 additions & 3 deletions src/SteamWebAPI2/Interfaces/SteamUserAuth.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ public class SteamUserAuth : ISteamUserAuth
/// <summary>
/// Default constructor established the Steam Web API key and initializes for subsequent method calls
/// </summary>
/// <param name="steamWebApiKey"></param>
public SteamUserAuth(string steamWebApiKey, ISteamWebInterface steamWebInterface = null)
/// <param name="steamWebRequest"></param>
public SteamUserAuth(ISteamWebRequest steamWebRequest, ISteamWebInterface steamWebInterface = null)
{
this.steamWebInterface = steamWebInterface == null
? new SteamWebInterface(steamWebApiKey, "ISteamUserAuth")
? new SteamWebInterface("ISteamUserAuth", steamWebRequest)
: steamWebInterface;
}

Expand Down
6 changes: 3 additions & 3 deletions src/SteamWebAPI2/Interfaces/SteamUserStats.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ public class SteamUserStats : ISteamUserStats
/// <summary>
/// Default constructor established the Steam Web API key and initializes for subsequent method calls
/// </summary>
/// <param name="steamWebApiKey"></param>
public SteamUserStats(string steamWebApiKey, ISteamWebInterface steamWebInterface = null)
/// <param name="steamWebRequest"></param>
public SteamUserStats(ISteamWebRequest steamWebRequest, ISteamWebInterface steamWebInterface = null)
{
this.steamWebInterface = steamWebInterface == null
? new SteamWebInterface(steamWebApiKey, "ISteamUserStats")
? new SteamWebInterface("ISteamUserStats", steamWebRequest)
: steamWebInterface;
}

Expand Down
6 changes: 3 additions & 3 deletions src/SteamWebAPI2/Interfaces/SteamWebAPIUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ public class SteamWebAPIUtil : ISteamWebAPIUtil
/// <summary>
/// Default constructor established the Steam Web API key and initializes for subsequent method calls
/// </summary>
/// <param name="steamWebApiKey"></param>
public SteamWebAPIUtil(string steamWebApiKey, ISteamWebInterface steamWebInterface = null)
/// <param name="steamWebRequest"></param>
public SteamWebAPIUtil(ISteamWebRequest steamWebRequest, ISteamWebInterface steamWebInterface = null)
{
this.steamWebInterface = steamWebInterface == null
? new SteamWebInterface(steamWebApiKey, "ISteamWebAPIUtil")
? new SteamWebInterface("ISteamWebAPIUtil", steamWebRequest)
: steamWebInterface;
}

Expand Down
6 changes: 3 additions & 3 deletions src/SteamWebAPI2/Interfaces/TFItems.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ public class TFItems : ITFItems
/// <summary>
/// Default constructor established the Steam Web API key and initializes for subsequent method calls
/// </summary>
/// <param name="steamWebApiKey"></param>
public TFItems(string steamWebApiKey, ISteamWebInterface steamWebInterface = null)
/// <param name="steamWebRequest"></param>
public TFItems(ISteamWebRequest steamWebRequest, ISteamWebInterface steamWebInterface = null)
{
this.steamWebInterface = steamWebInterface == null
? new SteamWebInterface(steamWebApiKey, "ITFItems_440")
? new SteamWebInterface("ITFItems_440", steamWebRequest)
: steamWebInterface;
}

Expand Down
17 changes: 4 additions & 13 deletions src/SteamWebAPI2/Models/SteamId.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using SteamWebAPI2.Exceptions;
using SteamWebAPI2.Interfaces;
using SteamWebAPI2.Utilities;
using System;
using System.Runtime.ExceptionServices;
using System.Text.RegularExpressions;
Expand Down Expand Up @@ -187,8 +188,8 @@ public SteamId(ulong steamId64)
/// to receive a return value from this method in the event that the Steam Web API is required.
/// </summary>
/// <param name="value">Value to parse, can be a 64-bit Steam ID, a full Steam Community Profile URL, or the user's Steam Community Profile Name.</param>
/// <param name="steamWebApiKey">Required in the event that the Steam Web API is needed to resolve a Profile URL to a 64-bit Steam ID.</param>
public SteamId(string value, string steamWebApiKey = "")
/// <param name="steamWebRequest">Required in the event that the Steam Web API is needed to resolve a Profile URL to a 64-bit Steam ID.</param>
public SteamId(string value, ISteamWebRequest steamWebRequest)
{
if (String.IsNullOrEmpty(value))
{
Expand Down Expand Up @@ -241,7 +242,7 @@ public SteamId(string value, string steamWebApiKey = "")
bool isUri = Uri.TryCreate(value, UriKind.Absolute, out uriResult)
&& (uriResult.Scheme == "http" || uriResult.Scheme == "https");

SteamUser steamUser = new SteamUser(steamWebApiKey);
SteamUser steamUser = new SteamUser(steamWebRequest);

try
{
Expand All @@ -261,11 +262,6 @@ public SteamId(string value, string steamWebApiKey = "")
// the third segment isn't a 64-bit Steam ID, check if it's a profile name which resolves to a 64-bit Steam ID
if (!isSteamId64)
{
if (String.IsNullOrEmpty(steamWebApiKey))
{
throw new InvalidOperationException(ErrorMessages.SteamWebApiKeyNotProvided);
}

steamId = await ResolveSteamIdFromValueAsync(steamUser, profileId);
}

Expand All @@ -280,11 +276,6 @@ public SteamId(string value, string steamWebApiKey = "")
}
else
{
if (String.IsNullOrEmpty(steamWebApiKey))
{
throw new InvalidOperationException(ErrorMessages.SteamWebApiKeyNotProvided);
}

// not a 64-bit Steam ID and not a uri, try to just resolve it as if it was a Steam Community Profile Name
steamId = await ResolveSteamIdFromValueAsync(steamUser, value);

Expand Down
3 changes: 1 addition & 2 deletions src/SteamWebAPI2/SteamStoreInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ public abstract class SteamStoreInterface
{
private const string steamStoreApiBaseUrl = "http://store.steampowered.com/api/";
private readonly SteamStoreRequest steamStoreRequest;
private readonly string endpointName;


/// <summary>
/// Constructs and maps the default objects for Steam Store Web API use
/// </summary>
Expand Down
2 changes: 0 additions & 2 deletions src/SteamWebAPI2/SteamStoreRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;

namespace SteamWebAPI2
Expand Down
2 changes: 1 addition & 1 deletion src/SteamWebAPI2/SteamWebAPI2.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<Description>This is a .NET library that makes it easy to use the Steam Web API. It conveniently wraps around all of the JSON data and ugly API details with clean methods, structures and classes.</Description>
<VersionPrefix>4.0.8</VersionPrefix>
<VersionPrefix>4.0.9</VersionPrefix>
<Authors>Justin Skiles</Authors>
<AssemblyName>SteamWebAPI2</AssemblyName>
<PackageId>SteamWebAPI2</PackageId>
Expand Down
Loading

0 comments on commit db48211

Please sign in to comment.