GetMarketPrices

This commit is contained in:
Garry Newman 2016-11-11 15:13:47 +00:00
parent 270595a540
commit 54fe75b2bc
7 changed files with 100 additions and 18 deletions

View File

@ -100,7 +100,8 @@
<Compile Include="Server\Inventory.cs" />
<Compile Include="Server\Server.cs" />
<Compile Include="Server\Stats.cs" />
<Compile Include="Web\WebSteamApps.cs" />
<Compile Include="Web\ISteamEconomy.cs" />
<Compile Include="Web\ISteamApps.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Facepunch.Steamworks\Facepunch.Steamworks.csproj">

View File

@ -7,7 +7,7 @@
namespace Facepunch.Steamworks.Test
{
[TestClass]
public partial class WebSteamApps
public partial class ISteamApps
{
[TestInitialize]
public void Init()

View File

@ -0,0 +1,44 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Facepunch.Steamworks.Test
{
[TestClass]
public partial class ISteamEconomy
{
[TestInitialize]
public void Init()
{
//
// For the sake of tests, we store our Key in an environment variable
// (so we don't end up shipping it to github and exposing it to everyone)
//
Facepunch.SteamApi.Config.Key = Environment.GetEnvironmentVariable( "SteamWebApi", EnvironmentVariableTarget.User );
//
// We're going to be using Newtonsoft to deserialize our json
//
Facepunch.SteamApi.Config.DeserializeJson = ( str, type ) =>
{
return Newtonsoft.Json.JsonConvert.DeserializeObject( str, type );
};
}
[TestMethod]
public void GetMarketPrices()
{
var response = Facepunch.SteamApi.ISteamEconomy.GetMarketPrices( 252490 );
var items = response.groups.OrderByDescending( x => x.sell_listings );
foreach ( var i in items )
{
Console.WriteLine( i.sell_listings + " " + i.name );
}
}
}
}

View File

@ -8,7 +8,8 @@ namespace Facepunch.SteamApi
{
internal class ApiResponse<T>
{
public T Response { get; set; }
public T Response;
public T Result;
}
public partial class ISteamApps
@ -17,10 +18,10 @@ public class GetAppBetasResponse
{
public class Beta
{
public ulong BuildId { get; set; }
public string Description { get; set; }
public bool ReqPassword { get; set; }
public bool ReqLocalCS { get; set; }
public ulong BuildId;
public string Description;
public bool ReqPassword;
public bool ReqLocalCS;
}
public Dictionary<string, Beta> betas;
@ -30,17 +31,17 @@ public class GetAppBuildsResponse
{
public class Build
{
public ulong BuildId { get; set; }
public string Description { get; set; }
public uint CreationTime { get; set; }
public ulong AccountIDCreator { get; set; }
public ulong BuildId;
public string Description;
public uint CreationTime;
public ulong AccountIDCreator;
public class Depot
{
public ulong DepotId { get; set; }
public ulong DepotVersionGID { get; set; }
public ulong TotalOriginalBytes { get; set; }
public ulong TotalCompressedBytes { get; set; }
public ulong DepotId;
public ulong DepotVersionGID;
public ulong TotalOriginalBytes;
public ulong TotalCompressedBytes;
}
public Dictionary<string, Depot> depots;
@ -50,5 +51,35 @@ public class Depot
}
}
public partial class ISteamEconomy
{
public class GetMarketPricesResponse
{
public int total_count;
public int start;
public int count;
public class Group
{
public string name;
public string icon_url;
public ulong sell_listings;
public ulong buy_listings;
public ulong listed_property_def_index;
public class Currency
{
public int ECurrencyCode;
public string currency;
public double sell_price;
}
public Currency[] currencies;
}
public Group[] groups;
}
}
}

View File

@ -12,13 +12,17 @@ public static T WebGet<T>( string url )
{
var www = new System.Net.WebClient();
var data = www.DownloadString( url );
www.Dispose();
if ( typeof( T ) == typeof( string ) )
return (T)(object)data;
var response = DeserializeJson<ApiResponse<T>>( data );
www.Dispose();
if ( response.Response == null )
return response.Result;
return response.Response;
}

View File

@ -282,10 +282,10 @@ public static string GetExportedAssetsForUser(ulong steamid, uint appid, ulong c
}
/// <param name="appid">Must be a steam economy app.</param>
public static string GetMarketPrices(uint appid)
public static GetMarketPricesResponse GetMarketPrices(uint appid)
{
string url = $"{Url}GetMarketPrices/v0001/?key={Facepunch.SteamApi.Config.Key}&format=json&appid={appid}";
return Utility.WebGet<string>( url );
return Utility.WebGet<GetMarketPricesResponse>( url );
}
/// <param name="appid">The app ID the user is buying assets for</param>

View File

@ -12,6 +12,8 @@ public partial class CodeWriter
{
"ISteamApps.GetAppBetas",
"ISteamApps.GetAppBuilds",
"ISteamEconomy.GetMarketPrices"
};
private void WebApi()