Added Packageinfo endpoint.

This commit is contained in:
mmuffins 2018-05-24 21:04:14 +02:00
parent 975b6991fa
commit 884027869b
12 changed files with 180 additions and 31 deletions

View File

@ -9,12 +9,12 @@ using Newtonsoft.Json.Converters;
namespace SteamStorefrontAPI.Classes
{
public class LinuxRequirements
public class Requirements
{
[JsonProperty("minimum")]
[JsonProperty("minimum", NullValueHandling = NullValueHandling.Ignore)]
public string Minimum { get; set; }
[JsonProperty("recommended")]
[JsonProperty("recommended", NullValueHandling = NullValueHandling.Ignore)]
public string Recommended { get; set; }
}
}

View File

@ -45,14 +45,17 @@ namespace SteamStorefrontAPI.Classes
[JsonProperty("website")]
public string Website { get; set; }
[JsonProperty("pc_requirements")]
public PcRequirements PcRequirements { get; set; }
[JsonProperty("pc_requirements", NullValueHandling = NullValueHandling.Ignore)]
[JsonConverter(typeof(RequirementsConverter))]
public Requirements PcRequirements { get; set; }
[JsonProperty("mac_requirements")]
public List<MacRequirements> MacRequirements { get; set; }
[JsonProperty("mac_requirements", NullValueHandling = NullValueHandling.Ignore)]
[JsonConverter(typeof(RequirementsConverter))]
public Requirements MacRequirements { get; set; }
[JsonProperty("linux_requirements")]
public List<LinuxRequirements> LinuxRequirements { get; set; }
[JsonProperty("linux_requirements", NullValueHandling = NullValueHandling.Ignore)]
[JsonConverter(typeof(RequirementsConverter))]
public Requirements LinuxRequirements { get; set; }
[JsonProperty("legal_notice")]
public string LegalNotice { get; set; }

View File

@ -65,6 +65,7 @@ namespace SteamStorefrontAPI.Classes
return convertedValue;
}
//TODO: fix the controller converter
return null;
}
@ -93,6 +94,7 @@ namespace SteamStorefrontAPI.Classes
return new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(parsedValue);
}
//TODO: fix the epoch converter
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();
}
}
}

View File

@ -24,5 +24,9 @@ namespace SteamStorefrontAPI.Classes
[JsonProperty("discount_percent")]
public int DiscountPercent { get; set; }
[JsonProperty("individual", NullValueHandling = NullValueHandling.Ignore)]
[JsonConverter(typeof(SteamPriceStringConverter))]
public double Individual { get; set; }
}
}

View File

@ -9,12 +9,9 @@ using Newtonsoft.Json.Converters;
namespace SteamStorefrontAPI.Classes
{
public class MacRequirements
public class FullGamepadSupport
{
[JsonProperty("minimum")]
public string Minimum { get; set; }
[JsonProperty("recommended")]
public string Recommended { get; set; }
[JsonProperty("full_gamepad")]
public bool FullGamepad { get; set; }
}
}

View File

@ -9,12 +9,12 @@ using Newtonsoft.Json.Converters;
namespace SteamStorefrontAPI.Classes
{
public class PcRequirements
public partial class PackageApp
{
[JsonProperty("minimum")]
public string Minimum { get; set; }
[JsonProperty("id")]
public int Id { get; set; }
[JsonProperty("recommended")]
public string Recommended { get; set; }
[JsonProperty("name")]
public string Name { get; set; }
}
}

View 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);
}
}
}

View 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>();
}
}
}

View File

@ -44,17 +44,19 @@
</ItemGroup>
<ItemGroup>
<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\Featured.cs" />
<Compile Include="Endpoints\AppDetails.cs" />
<Compile Include="Classes\appdetails\LinuxRequirements.cs" />
<Compile Include="Classes\appdetails\MacRequirements.cs" />
<Compile Include="Classes\appdetails\ReleaseDate.cs" />
<Compile Include="Classes\common\ReleaseDate.cs" />
<Compile Include="Classes\appdetails\Recommendations.cs" />
<Compile Include="Classes\appdetails\PriceOverview.cs" />
<Compile Include="Classes\appdetails\Platforms.cs" />
<Compile Include="Classes\appdetails\PcRequirements.cs" />
<Compile Include="Classes\common\PriceOverview.cs" />
<Compile Include="Classes\common\Platforms.cs" />
<Compile Include="Classes\appdetails\Requirements.cs" />
<Compile Include="Classes\appdetails\PackageGroup.cs" />
<Compile Include="Classes\appdetails\Movie.cs" />
<Compile Include="Classes\common\Genre.cs" />

View File

@ -19,12 +19,18 @@ namespace SteamStorefrontConsole
static async Task GetGame()
{
//var steamApp = await AppDetails.GetAsync(637670);
//var steamApp = await AppDetails.GetAsync(443790);
//var steamApp = await AppDetails.GetAsync(460810, "JP");
//var steamApp1 = await AppDetails.GetAsync(637670);
//var steamApp2 = await AppDetails.GetAsync(443790);
//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 featuredCategories = await FeaturedCategories.GetAsync();
//var featuredCategories = await FeaturedCategories.GetAsync();
//Console.WriteLine(featured);
}