Added Packageinfo endpoint.
This commit is contained in:
parent
975b6991fa
commit
884027869b
@ -9,12 +9,12 @@ using Newtonsoft.Json.Converters;
|
|||||||
|
|
||||||
namespace SteamStorefrontAPI.Classes
|
namespace SteamStorefrontAPI.Classes
|
||||||
{
|
{
|
||||||
public class LinuxRequirements
|
public class Requirements
|
||||||
{
|
{
|
||||||
[JsonProperty("minimum")]
|
[JsonProperty("minimum", NullValueHandling = NullValueHandling.Ignore)]
|
||||||
public string Minimum { get; set; }
|
public string Minimum { get; set; }
|
||||||
|
|
||||||
[JsonProperty("recommended")]
|
[JsonProperty("recommended", NullValueHandling = NullValueHandling.Ignore)]
|
||||||
public string Recommended { get; set; }
|
public string Recommended { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -45,14 +45,17 @@ namespace SteamStorefrontAPI.Classes
|
|||||||
[JsonProperty("website")]
|
[JsonProperty("website")]
|
||||||
public string Website { get; set; }
|
public string Website { get; set; }
|
||||||
|
|
||||||
[JsonProperty("pc_requirements")]
|
[JsonProperty("pc_requirements", NullValueHandling = NullValueHandling.Ignore)]
|
||||||
public PcRequirements PcRequirements { get; set; }
|
[JsonConverter(typeof(RequirementsConverter))]
|
||||||
|
public Requirements PcRequirements { get; set; }
|
||||||
|
|
||||||
[JsonProperty("mac_requirements")]
|
[JsonProperty("mac_requirements", NullValueHandling = NullValueHandling.Ignore)]
|
||||||
public List<MacRequirements> MacRequirements { get; set; }
|
[JsonConverter(typeof(RequirementsConverter))]
|
||||||
|
public Requirements MacRequirements { get; set; }
|
||||||
|
|
||||||
[JsonProperty("linux_requirements")]
|
[JsonProperty("linux_requirements", NullValueHandling = NullValueHandling.Ignore)]
|
||||||
public List<LinuxRequirements> LinuxRequirements { get; set; }
|
[JsonConverter(typeof(RequirementsConverter))]
|
||||||
|
public Requirements LinuxRequirements { get; set; }
|
||||||
|
|
||||||
[JsonProperty("legal_notice")]
|
[JsonProperty("legal_notice")]
|
||||||
public string LegalNotice { get; set; }
|
public string LegalNotice { get; set; }
|
||||||
|
@ -65,6 +65,7 @@ namespace SteamStorefrontAPI.Classes
|
|||||||
return convertedValue;
|
return convertedValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO: fix the controller converter
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,6 +94,7 @@ namespace SteamStorefrontAPI.Classes
|
|||||||
return new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(parsedValue);
|
return new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(parsedValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO: fix the epoch converter
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,4 +109,38 @@ namespace SteamStorefrontAPI.Classes
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Returns a Requirements object if the provided data is valid, otherwise returns null
|
||||||
|
public class RequirementsConverter : JsonConverter
|
||||||
|
{
|
||||||
|
public override bool CanRead
|
||||||
|
{
|
||||||
|
get => true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool CanWrite
|
||||||
|
{
|
||||||
|
get => false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
|
||||||
|
{
|
||||||
|
if(reader.TokenType != JsonToken.StartObject) return null;
|
||||||
|
|
||||||
|
var value = serializer.Deserialize<Requirements>(reader);
|
||||||
|
|
||||||
|
//TODO: Fix the requirements converter
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool CanConvert(Type objectType)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -24,5 +24,9 @@ namespace SteamStorefrontAPI.Classes
|
|||||||
|
|
||||||
[JsonProperty("discount_percent")]
|
[JsonProperty("discount_percent")]
|
||||||
public int DiscountPercent { get; set; }
|
public int DiscountPercent { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("individual", NullValueHandling = NullValueHandling.Ignore)]
|
||||||
|
[JsonConverter(typeof(SteamPriceStringConverter))]
|
||||||
|
public double Individual { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -9,12 +9,9 @@ using Newtonsoft.Json.Converters;
|
|||||||
|
|
||||||
namespace SteamStorefrontAPI.Classes
|
namespace SteamStorefrontAPI.Classes
|
||||||
{
|
{
|
||||||
public class MacRequirements
|
public class FullGamepadSupport
|
||||||
{
|
{
|
||||||
[JsonProperty("minimum")]
|
[JsonProperty("full_gamepad")]
|
||||||
public string Minimum { get; set; }
|
public bool FullGamepad { get; set; }
|
||||||
|
|
||||||
[JsonProperty("recommended")]
|
|
||||||
public string Recommended { get; set; }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -9,12 +9,12 @@ using Newtonsoft.Json.Converters;
|
|||||||
|
|
||||||
namespace SteamStorefrontAPI.Classes
|
namespace SteamStorefrontAPI.Classes
|
||||||
{
|
{
|
||||||
public class PcRequirements
|
public partial class PackageApp
|
||||||
{
|
{
|
||||||
[JsonProperty("minimum")]
|
[JsonProperty("id")]
|
||||||
public string Minimum { get; set; }
|
public int Id { get; set; }
|
||||||
|
|
||||||
[JsonProperty("recommended")]
|
[JsonProperty("name")]
|
||||||
public string Recommended { get; set; }
|
public string Name { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
56
SteamStorefrontAPI/Classes/packagedetails/PackageInfo.cs
Normal file
56
SteamStorefrontAPI/Classes/packagedetails/PackageInfo.cs
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Globalization;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Newtonsoft.Json.Converters;
|
||||||
|
|
||||||
|
namespace SteamStorefrontAPI.Classes
|
||||||
|
{
|
||||||
|
public class PackageInfo
|
||||||
|
{
|
||||||
|
[JsonProperty("name")]
|
||||||
|
public string Name { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("purchase_text")]
|
||||||
|
public string PurchaseText { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("page_image")]
|
||||||
|
public string PageImage { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("small_logo")]
|
||||||
|
public string SmallLogo { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("apps")]
|
||||||
|
public List<PackageApp> Apps { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("price")]
|
||||||
|
public PriceOverview Price { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("platforms")]
|
||||||
|
public Platforms Platforms { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("controller")]
|
||||||
|
public FullGamepadSupport Controller { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("release_date")]
|
||||||
|
public ReleaseDate ReleaseDate { get; set; }
|
||||||
|
|
||||||
|
public static SteamApp FromJson(string json)
|
||||||
|
{
|
||||||
|
|
||||||
|
var serializerSettings = new JsonSerializerSettings
|
||||||
|
{
|
||||||
|
MetadataPropertyHandling = MetadataPropertyHandling.Ignore,
|
||||||
|
DateParseHandling = DateParseHandling.None,
|
||||||
|
Converters = {
|
||||||
|
new IsoDateTimeConverter { DateTimeStyles = DateTimeStyles.AssumeUniversal }
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
return JsonConvert.DeserializeObject<SteamApp>(json, serializerSettings);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
45
SteamStorefrontAPI/Endpoints/PackageDetails.cs
Normal file
45
SteamStorefrontAPI/Endpoints/PackageDetails.cs
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
using SteamStorefrontAPI.Classes;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Net.Http;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace SteamStorefrontAPI
|
||||||
|
{
|
||||||
|
public static class PackageDetails
|
||||||
|
{
|
||||||
|
private static HttpClient client = new HttpClient();
|
||||||
|
private const string steamBaseUri = "http://store.steampowered.com/api/packagedetails";
|
||||||
|
|
||||||
|
public static async Task<PackageInfo> GetAsync(int PackageId)
|
||||||
|
{
|
||||||
|
return await GetAsync(PackageId, null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async Task<PackageInfo> GetAsync(int PackageId, string CountryCode)
|
||||||
|
{
|
||||||
|
return await GetAsync(PackageId, CountryCode, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async Task<PackageInfo> GetAsync(int PackageId, string CountryCode, string Language)
|
||||||
|
{
|
||||||
|
string steamUri = $"{steamBaseUri}?packageids={PackageId}";
|
||||||
|
steamUri = CountryCode is null ? steamUri : $"{steamUri}&cc={CountryCode}";
|
||||||
|
steamUri = Language is null ? steamUri : $"{steamUri}&l={Language}";
|
||||||
|
|
||||||
|
var response = await client.GetAsync(steamUri);
|
||||||
|
if (!response.IsSuccessStatusCode) { return null; }
|
||||||
|
|
||||||
|
var result = await response.Content.ReadAsStringAsync();
|
||||||
|
|
||||||
|
// The actual payload is wrapped, drill down to the third level to get to it
|
||||||
|
var jsonData = JToken.Parse(result).First.First;
|
||||||
|
if (!bool.Parse(jsonData["success"].ToString())) { return null; }
|
||||||
|
|
||||||
|
return jsonData["data"].ToObject<PackageInfo>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -44,17 +44,19 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Classes\featuredcategories\FeaturedCategory.cs" />
|
<Compile Include="Classes\featuredcategories\FeaturedCategory.cs" />
|
||||||
<Compile Include="Classes\Converters.cs" />
|
<Compile Include="Classes\common\Converters.cs" />
|
||||||
|
<Compile Include="Classes\packagedetails\FullGamepadSupport.cs" />
|
||||||
|
<Compile Include="Classes\packagedetails\PackageApp.cs" />
|
||||||
|
<Compile Include="Classes\packagedetails\PackageInfo.cs" />
|
||||||
|
<Compile Include="Endpoints\PackageDetails.cs" />
|
||||||
<Compile Include="Endpoints\FeaturedCategories.cs" />
|
<Compile Include="Endpoints\FeaturedCategories.cs" />
|
||||||
<Compile Include="Endpoints\Featured.cs" />
|
<Compile Include="Endpoints\Featured.cs" />
|
||||||
<Compile Include="Endpoints\AppDetails.cs" />
|
<Compile Include="Endpoints\AppDetails.cs" />
|
||||||
<Compile Include="Classes\appdetails\LinuxRequirements.cs" />
|
<Compile Include="Classes\common\ReleaseDate.cs" />
|
||||||
<Compile Include="Classes\appdetails\MacRequirements.cs" />
|
|
||||||
<Compile Include="Classes\appdetails\ReleaseDate.cs" />
|
|
||||||
<Compile Include="Classes\appdetails\Recommendations.cs" />
|
<Compile Include="Classes\appdetails\Recommendations.cs" />
|
||||||
<Compile Include="Classes\appdetails\PriceOverview.cs" />
|
<Compile Include="Classes\common\PriceOverview.cs" />
|
||||||
<Compile Include="Classes\appdetails\Platforms.cs" />
|
<Compile Include="Classes\common\Platforms.cs" />
|
||||||
<Compile Include="Classes\appdetails\PcRequirements.cs" />
|
<Compile Include="Classes\appdetails\Requirements.cs" />
|
||||||
<Compile Include="Classes\appdetails\PackageGroup.cs" />
|
<Compile Include="Classes\appdetails\PackageGroup.cs" />
|
||||||
<Compile Include="Classes\appdetails\Movie.cs" />
|
<Compile Include="Classes\appdetails\Movie.cs" />
|
||||||
<Compile Include="Classes\common\Genre.cs" />
|
<Compile Include="Classes\common\Genre.cs" />
|
||||||
|
@ -19,12 +19,18 @@ namespace SteamStorefrontConsole
|
|||||||
|
|
||||||
static async Task GetGame()
|
static async Task GetGame()
|
||||||
{
|
{
|
||||||
//var steamApp = await AppDetails.GetAsync(637670);
|
//var steamApp1 = await AppDetails.GetAsync(637670);
|
||||||
//var steamApp = await AppDetails.GetAsync(443790);
|
//var steamApp2 = await AppDetails.GetAsync(443790);
|
||||||
//var steamApp = await AppDetails.GetAsync(460810, "JP");
|
//var steamApp3 = await AppDetails.GetAsync(460810, "JP");
|
||||||
|
//var steamApp4 = await AppDetails.GetAsync(322330);
|
||||||
|
|
||||||
|
var package1 = await PackageDetails.GetAsync(68179);
|
||||||
|
var package2 = await PackageDetails.GetAsync(68179, "JP");
|
||||||
|
var package3 = await PackageDetails.GetAsync(235158);
|
||||||
|
var package4 = await PackageDetails.GetAsync(235158, "US");
|
||||||
|
|
||||||
//var featured = await Featured.GetAsync();
|
//var featured = await Featured.GetAsync();
|
||||||
var featuredCategories = await FeaturedCategories.GetAsync();
|
//var featuredCategories = await FeaturedCategories.GetAsync();
|
||||||
|
|
||||||
//Console.WriteLine(featured);
|
//Console.WriteLine(featured);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user