mirror of
https://github.com/Facepunch/Facepunch.Steamworks.git
synced 2025-01-12 06:38:01 +03:00
IWorkshopService.GetItemDailyRevenue
This commit is contained in:
parent
9fe91b48b6
commit
ef2fb26911
@ -100,6 +100,7 @@
|
||||
<Compile Include="Server\Inventory.cs" />
|
||||
<Compile Include="Server\Server.cs" />
|
||||
<Compile Include="Server\Stats.cs" />
|
||||
<Compile Include="Web\IWorkshopService.cs" />
|
||||
<Compile Include="Web\ISteamEconomy.cs" />
|
||||
<Compile Include="Web\ISteamApps.cs" />
|
||||
</ItemGroup>
|
||||
|
40
Facepunch.Steamworks.Test/Web/IWorkshopService.cs
Normal file
40
Facepunch.Steamworks.Test/Web/IWorkshopService.cs
Normal file
@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
namespace Facepunch.Steamworks.Test
|
||||
{
|
||||
[TestClass]
|
||||
public partial class IWorkshopService
|
||||
{
|
||||
[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 GetItemDailyRevenue()
|
||||
{
|
||||
var response = Facepunch.SteamApi.IWorkshopService.GetItemDailyRevenue( 252490, 20006, DateTime.UtcNow.Subtract( TimeSpan.FromDays( 30 ) ), DateTime.UtcNow.AddDays( 30 ) );
|
||||
|
||||
Console.WriteLine( "Item Sold " + response.TotalUnitsSold + " worldwide" );
|
||||
Console.WriteLine( "Item Generated $" + response.TotalRevenue + " worldwide" );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Xml;
|
||||
using System.Xml.Serialization;
|
||||
@ -82,4 +83,37 @@ namespace Facepunch.SteamApi
|
||||
}
|
||||
|
||||
|
||||
public partial class IWorkshopService
|
||||
{
|
||||
public class GetItemDailyRevenueResponse
|
||||
{
|
||||
public class Country
|
||||
{
|
||||
public string country_code;
|
||||
public uint date;
|
||||
|
||||
/// <summary>
|
||||
/// Appears to be the dollar amount multiplied by 10000
|
||||
/// Use Revenue to get the real value as a double
|
||||
/// </summary>
|
||||
public double revenue_usd;
|
||||
|
||||
/// <summary>
|
||||
/// Total dollar revenue, normalised
|
||||
/// </summary>
|
||||
public double Revenue { get { return revenue_usd / 10000.0; } }
|
||||
|
||||
/// <summary>
|
||||
/// Number of units sold
|
||||
/// </summary>
|
||||
public long Units;
|
||||
}
|
||||
|
||||
public Country[] country_revenue;
|
||||
|
||||
public long TotalUnitsSold { get { return country_revenue.Sum( x => x.Units ); } }
|
||||
public double TotalRevenue { get { return country_revenue.Sum( x => x.Revenue ); } }
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Xml;
|
||||
using System.Xml.Serialization;
|
||||
@ -27,6 +28,38 @@ namespace Facepunch.SteamApi
|
||||
return response.Response;
|
||||
}
|
||||
|
||||
public static T WebPost<T>( string url, System.Collections.Generic.Dictionary<string, object> variables )
|
||||
{
|
||||
var www = new System.Net.WebClient();
|
||||
|
||||
var nvc = new NameValueCollection();
|
||||
|
||||
if ( Config.Key != null )
|
||||
variables.Add( "key", Config.Key );
|
||||
|
||||
foreach ( var v in variables )
|
||||
{
|
||||
nvc.Add( v.Key, v.Value.ToString() );
|
||||
}
|
||||
|
||||
var bytes = www.UploadValues( url, "POST", nvc );
|
||||
var data = System.Text.Encoding.UTF8.GetString( bytes );
|
||||
|
||||
www.Dispose();
|
||||
|
||||
if ( typeof( T ) == typeof( string ) )
|
||||
return (T)(object)data;
|
||||
|
||||
var response = DeserializeJson<ApiResponse<T>>( data );
|
||||
|
||||
if ( response.Response == null )
|
||||
return response.Result;
|
||||
|
||||
return response.Response;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private static T DeserializeJson<T>( string data )
|
||||
{
|
||||
return (T)Facepunch.SteamApi.Config.DeserializeJson( data, typeof( T ) );
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -38,6 +38,14 @@ namespace Facepunch.Steamworks
|
||||
return epoch.AddSeconds( (long)unixTime );
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Convert a DateTime to a unix time
|
||||
/// </summary>
|
||||
public static uint FromDateTime( DateTime dt )
|
||||
{
|
||||
return (uint)( dt.Subtract( epoch ).TotalSeconds );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user