Skip to content

Commit

Permalink
Merge pull request #23 from aspriddell/framework-bump
Browse files Browse the repository at this point in the history
bump data framework
  • Loading branch information
aspriddell authored Aug 7, 2020
2 parents df95d01 + a5f617d commit 3c55cbe
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 56 deletions.
8 changes: 4 additions & 4 deletions DragonFruit.Link.Tests/DragonFruit.Link.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
<PackageReference Include="MSTest.TestAdapter" Version="2.1.1" />
<PackageReference Include="MSTest.TestFramework" Version="2.1.1" />
<PackageReference Include="coverlet.collector" Version="1.2.1">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.1.2" />
<PackageReference Include="MSTest.TestFramework" Version="2.1.2" />
<PackageReference Include="coverlet.collector" Version="1.3.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
2 changes: 1 addition & 1 deletion DragonFruit.Link/DragonFruit.Link.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="DragonFruit.Common.Data" Version="2020.519.27-beta" />
<PackageReference Include="DragonFruit.Common.Data" Version="2020.807.11" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ namespace DragonFruit.Link.Economy.Requests
{
public class SteamUserTradeCancelRequest : SteamApiRequest
{
public override Methods Method => Methods.Post;
public override DataTypes DataType => DataTypes.Encoded;
protected override Methods Method => Methods.Post;
protected override BodyType BodyType => BodyType.Encoded;

public override string Interface => "IEconService";
public override string InterfaceMethod => "CancelTradeOffer";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ namespace DragonFruit.Link.Economy.Requests
{
public class SteamUserTradeDeclineRequest : SteamApiRequest
{
public override Methods Method => Methods.Post;
public override DataTypes DataType => DataTypes.Encoded;
protected override Methods Method => Methods.Post;
protected override BodyType BodyType => BodyType.Encoded;

public override string Interface => "IEconService";
public override string InterfaceMethod => "DeclineTradeOffer";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ namespace DragonFruit.Link.Servers.Requests
{
public class SteamGameServerAccountCreationRequest : SteamApiRequest, IForSteamApp
{
public override Methods Method => Methods.Post;
public override DataTypes DataType => DataTypes.Encoded;
protected override Methods Method => Methods.Post;
protected override BodyType BodyType => BodyType.Encoded;

public override string Interface => "IGameServersService";
public override string InterfaceMethod => "CreateAccount";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ namespace DragonFruit.Link.Servers.Requests
{
public class SteamGameServerDeletionRequest : SteamApiRequest, IForSteamUser
{
public override Methods Method => Methods.Post;
public override DataTypes DataType => DataTypes.Encoded;
protected override Methods Method => Methods.Post;
protected override BodyType BodyType => BodyType.Encoded;

public override string Interface => "IGameServersService";
public override string InterfaceMethod => "DeleteAccount";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ namespace DragonFruit.Link.Servers.Requests
{
public class SteamGameServerLoginResetRequest : SteamApiRequest, IForSteamUser
{
public override Methods Method => Methods.Post;
public override DataTypes DataType => DataTypes.Encoded;
protected override Methods Method => Methods.Post;
protected override BodyType BodyType => BodyType.Encoded;

public override string Interface => "IGameServersService";
public override string InterfaceMethod => "ResetLoginToken";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ namespace DragonFruit.Link.Servers.Requests
{
public class SteamGameServerMemoChangeRequest : SteamApiRequest, IForSteamUser
{
public override Methods Method => Methods.Post;
public override DataTypes DataType => DataTypes.Encoded;
protected override Methods Method => Methods.Post;
protected override BodyType BodyType => BodyType.Encoded;

public override string Interface => "IGameServersService";
public override string InterfaceMethod => "SetMemo";
Expand Down
35 changes: 15 additions & 20 deletions DragonFruit.Link/SteamApiClient.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// DragonFruit Link API Copyright 2020 (C) DragonFruit Network <inbox@dragonfruit.network>
// Licensed under the GNU GPLv3 License. Refer to the license.md file at the root of the repo for more info

using System.Net.Http;
using System.Globalization;
using DragonFruit.Common.Data;
using DragonFruit.Link.Exceptions;

Expand All @@ -14,41 +14,36 @@ public class SteamApiClient : ApiClient

#region Constructors

public SteamApiClient(string apiKey, string userAgent)
: this(apiKey)
public SteamApiClient()
: base(CultureInfo.InvariantCulture) // creates a new ApiJsonSerializer
{
UserAgent = userAgent;
}

public SteamApiClient(string apiKey)
: this()
{
_apiKey = apiKey;
_apiKeySet = true;
}

public SteamApiClient()
public SteamApiClient(string apiKey, string userAgent)
: this(apiKey)
{
// this should only be for non-auth requiring things
_apiKeySet = false;
UserAgent = userAgent;
}

#endregion

public T Perform<T>(SteamApiRequest request) where T : class/*, ISteamApiResponse*/
protected override void ValidateRequest(ApiRequest requestData)
{
CheckAuthorization(request);
return base.Perform<T>(request);
}
base.ValidateRequest(requestData);

public HttpResponseMessage Perform(SteamApiRequest request)
{
CheckAuthorization(request);
return base.Perform(request);
}
if (!(requestData is SteamApiRequest steamRequest))
{
return;
}

private void CheckAuthorization(SteamApiRequest request)
{
if (!request.RequireApiKey)
if (!steamRequest.RequireApiKey)
{
return;
}
Expand All @@ -58,7 +53,7 @@ private void CheckAuthorization(SteamApiRequest request)
throw new SteamApiKeyMissingException();
}

request.ApiKey = _apiKey;
steamRequest.ApiKey = _apiKey;
}
}
}
27 changes: 8 additions & 19 deletions DragonFruit.Link/SteamApiRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,43 +9,32 @@

namespace DragonFruit.Link
{
[JsonObject(MemberSerialization.OptIn)]
public abstract class SteamApiRequest : ApiRequest
{
#region Overrides

public override Methods Method => Methods.Get;

public override string AcceptedContent => "application/json";

#endregion

#region Authentication

//we use the RequireApiKey instead, as keys need to be sent as a query
public override bool RequireAuth => false;
protected override Methods Method => Methods.Get;
protected override bool RequireAuth => false; //this only checks headers, ours is in the query

//replaces RequireAuth, see above
public abstract bool RequireApiKey { get; }

[QueryParameter("key"), JsonIgnore]
public string ApiKey { get; set; }

#endregion
#region Path

#region Path Constructors

public virtual string? PathOverride { get; }

public override string Path => PathOverride ?? $"https://api.steampowered.com/{Interface}/{InterfaceMethod}/v{MethodVersion}/";

public abstract int MethodVersion { get; }

public abstract string Interface { get; }

public abstract string InterfaceMethod { get; }

#endregion

[QueryParameter("key")]
public string ApiKey { get; set; } = null!;

[QueryParameter("format")]
protected string OutputFormat => "json";
}
Expand Down

0 comments on commit 3c55cbe

Please sign in to comment.