Reorganized file structure, added featured endpoint.

This commit is contained in:
mmuffins 2018-05-23 22:03:38 +02:00
parent dd39c19c84
commit 0b8ec19632
22 changed files with 213 additions and 36 deletions

View File

@ -7,7 +7,7 @@ using System.Globalization;
using Newtonsoft.Json; using Newtonsoft.Json;
using Newtonsoft.Json.Converters; using Newtonsoft.Json.Converters;
namespace SteamStorefrontAPI namespace SteamStorefrontAPI.Classes
{ {
public class Achievements public class Achievements
{ {

View File

@ -7,7 +7,7 @@ using System.Globalization;
using Newtonsoft.Json; using Newtonsoft.Json;
using Newtonsoft.Json.Converters; using Newtonsoft.Json.Converters;
namespace SteamStorefrontAPI namespace SteamStorefrontAPI.Classes
{ {
public class Category public class Category
{ {

View File

@ -7,7 +7,7 @@ using System.Globalization;
using Newtonsoft.Json; using Newtonsoft.Json;
using Newtonsoft.Json.Converters; using Newtonsoft.Json.Converters;
namespace SteamStorefrontAPI namespace SteamStorefrontAPI.Classes
{ {
public class Genre public class Genre
{ {

View File

@ -7,7 +7,7 @@ using System.Globalization;
using Newtonsoft.Json; using Newtonsoft.Json;
using Newtonsoft.Json.Converters; using Newtonsoft.Json.Converters;
namespace SteamStorefrontAPI namespace SteamStorefrontAPI.Classes
{ {
public class Highlighted public class Highlighted
{ {

View File

@ -7,7 +7,7 @@ using System.Globalization;
using Newtonsoft.Json; using Newtonsoft.Json;
using Newtonsoft.Json.Converters; using Newtonsoft.Json.Converters;
namespace SteamStorefrontAPI namespace SteamStorefrontAPI.Classes
{ {
public class LinuxRequirements public class LinuxRequirements
{ {

View File

@ -7,7 +7,7 @@ using System.Globalization;
using Newtonsoft.Json; using Newtonsoft.Json;
using Newtonsoft.Json.Converters; using Newtonsoft.Json.Converters;
namespace SteamStorefrontAPI namespace SteamStorefrontAPI.Classes
{ {
public class MacRequirements public class MacRequirements
{ {

View File

@ -7,7 +7,7 @@ using System.Globalization;
using Newtonsoft.Json; using Newtonsoft.Json;
using Newtonsoft.Json.Converters; using Newtonsoft.Json.Converters;
namespace SteamStorefrontAPI namespace SteamStorefrontAPI.Classes
{ {
public class Movie public class Movie
{ {

View File

@ -7,7 +7,7 @@ using System.Globalization;
using Newtonsoft.Json; using Newtonsoft.Json;
using Newtonsoft.Json.Converters; using Newtonsoft.Json.Converters;
namespace SteamStorefrontAPI namespace SteamStorefrontAPI.Classes
{ {
public class PackageGroup public class PackageGroup

View File

@ -7,7 +7,7 @@ using System.Globalization;
using Newtonsoft.Json; using Newtonsoft.Json;
using Newtonsoft.Json.Converters; using Newtonsoft.Json.Converters;
namespace SteamStorefrontAPI namespace SteamStorefrontAPI.Classes
{ {
public class PcRequirements public class PcRequirements
{ {

View File

@ -7,7 +7,7 @@ using System.Globalization;
using Newtonsoft.Json; using Newtonsoft.Json;
using Newtonsoft.Json.Converters; using Newtonsoft.Json.Converters;
namespace SteamStorefrontAPI namespace SteamStorefrontAPI.Classes
{ {
public class Platforms public class Platforms
{ {

View File

@ -7,7 +7,7 @@ using System.Globalization;
using Newtonsoft.Json; using Newtonsoft.Json;
using Newtonsoft.Json.Converters; using Newtonsoft.Json.Converters;
namespace SteamStorefrontAPI namespace SteamStorefrontAPI.Classes
{ {
public class PriceOverview public class PriceOverview
{ {

View File

@ -7,7 +7,7 @@ using System.Globalization;
using Newtonsoft.Json; using Newtonsoft.Json;
using Newtonsoft.Json.Converters; using Newtonsoft.Json.Converters;
namespace SteamStorefrontAPI namespace SteamStorefrontAPI.Classes
{ {
public class Recommendations public class Recommendations
{ {

View File

@ -7,7 +7,7 @@ using System.Globalization;
using Newtonsoft.Json; using Newtonsoft.Json;
using Newtonsoft.Json.Converters; using Newtonsoft.Json.Converters;
namespace SteamStorefrontAPI namespace SteamStorefrontAPI.Classes
{ {
public class ReleaseDate public class ReleaseDate
{ {

View File

@ -7,7 +7,7 @@ using System.Globalization;
using Newtonsoft.Json; using Newtonsoft.Json;
using Newtonsoft.Json.Converters; using Newtonsoft.Json.Converters;
namespace SteamStorefrontAPI namespace SteamStorefrontAPI.Classes
{ {
public class Screenshot public class Screenshot

View File

@ -7,7 +7,7 @@ using System.Globalization;
using Newtonsoft.Json; using Newtonsoft.Json;
using Newtonsoft.Json.Converters; using Newtonsoft.Json.Converters;
namespace SteamStorefrontAPI namespace SteamStorefrontAPI.Classes
{ {
public class Sub public class Sub

View File

@ -7,7 +7,7 @@ using System.Globalization;
using Newtonsoft.Json; using Newtonsoft.Json;
using Newtonsoft.Json.Converters; using Newtonsoft.Json.Converters;
namespace SteamStorefrontAPI namespace SteamStorefrontAPI.Classes
{ {
public class SupportInfo public class SupportInfo
{ {

View File

@ -0,0 +1,65 @@
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 FeaturedApp
{
[JsonProperty("id")]
public long Id { get; set; }
[JsonProperty("type")]
public long Type { get; set; }
[JsonProperty("name")]
public string Name { get; set; }
[JsonProperty("discounted")]
public bool Discounted { get; set; }
[JsonProperty("discount_percent")]
public long DiscountPercent { get; set; }
[JsonProperty("original_price")]
public long? OriginalPrice { get; set; }
[JsonProperty("final_price")]
public long FinalPrice { get; set; }
[JsonProperty("currency")]
public Currency Currency { get; set; }
[JsonProperty("large_capsule_image")]
public string LargeCapsuleImage { get; set; }
[JsonProperty("small_capsule_image")]
public string SmallCapsuleImage { get; set; }
[JsonProperty("windows_available")]
public bool WindowsAvailable { get; set; }
[JsonProperty("mac_available")]
public bool MacAvailable { get; set; }
[JsonProperty("linux_available")]
public bool LinuxAvailable { get; set; }
[JsonProperty("streamingvideo_available")]
public bool StreamingvideoAvailable { get; set; }
[JsonProperty("header_image")]
public string HeaderImage { get; set; }
[JsonProperty("discount_expiration", NullValueHandling = NullValueHandling.Ignore)]
public long? DiscountExpiration { get; set; }
[JsonProperty("controller_support", NullValueHandling = NullValueHandling.Ignore)]
public ControllerSupport? ControllerSupport { get; set; }
}
}

View File

@ -0,0 +1,110 @@
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 SteamFeatured
{
[JsonProperty("large_capsules")]
public List<object> LargeCapsules { get; set; }
[JsonProperty("featured_win")]
public List<FeaturedApp> FeaturedWin { get; set; }
[JsonProperty("featured_mac")]
public List<FeaturedApp> FeaturedMac { get; set; }
[JsonProperty("featured_linux")]
public List<FeaturedApp> FeaturedLinux { get; set; }
[JsonProperty("layout")]
public string Layout { get; set; }
[JsonProperty("status")]
public long Status { get; set; }
public static SteamFeatured FromJson(string json) => JsonConvert.DeserializeObject<SteamFeatured>(json, Converter.Settings);
}
public enum ControllerSupport { Full };
public enum Currency { Eur };
public static class Serialize
{
public static string ToJson(this SteamFeatured self) => JsonConvert.SerializeObject(self, Converter.Settings);
}
static class Converter
{
public static readonly JsonSerializerSettings Settings = new JsonSerializerSettings
{
MetadataPropertyHandling = MetadataPropertyHandling.Ignore,
DateParseHandling = DateParseHandling.None,
Converters = {
new ControllerSupportConverter(),
new CurrencyConverter(),
new IsoDateTimeConverter { DateTimeStyles = DateTimeStyles.AssumeUniversal }
},
};
}
internal class ControllerSupportConverter : JsonConverter
{
public override bool CanConvert(Type t) => t == typeof(ControllerSupport) || t == typeof(ControllerSupport?);
public override object ReadJson(JsonReader reader, Type t, object existingValue, JsonSerializer serializer)
{
if (reader.TokenType == JsonToken.Null) return null;
var value = serializer.Deserialize<string>(reader);
if (value == "full")
{
return ControllerSupport.Full;
}
throw new Exception("Cannot unmarshal type ControllerSupport");
}
public override void WriteJson(JsonWriter writer, object untypedValue, JsonSerializer serializer)
{
var value = (ControllerSupport)untypedValue;
if (value == ControllerSupport.Full)
{
serializer.Serialize(writer, "full"); return;
}
throw new Exception("Cannot marshal type ControllerSupport");
}
}
internal class CurrencyConverter : JsonConverter
{
public override bool CanConvert(Type t) => t == typeof(Currency) || t == typeof(Currency?);
public override object ReadJson(JsonReader reader, Type t, object existingValue, JsonSerializer serializer)
{
if (reader.TokenType == JsonToken.Null) return null;
var value = serializer.Deserialize<string>(reader);
if (value == "EUR")
{
return Currency.Eur;
}
throw new Exception("Cannot unmarshal type Currency");
}
public override void WriteJson(JsonWriter writer, object untypedValue, JsonSerializer serializer)
{
var value = (Currency)untypedValue;
if (value == Currency.Eur)
{
serializer.Serialize(writer, "EUR"); return;
}
throw new Exception("Cannot marshal type Currency");
}
}
}

View File

@ -43,25 +43,27 @@
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="appdetails\AppDetails.cs" /> <Compile Include="Endpoints\AppDetails.cs" />
<Compile Include="appdetails\Classes\LinuxRequirements.cs" /> <Compile Include="Classes\appdetails\LinuxRequirements.cs" />
<Compile Include="appdetails\Classes\MacRequirements.cs" /> <Compile Include="Classes\appdetails\MacRequirements.cs" />
<Compile Include="appdetails\Classes\ReleaseDate.cs" /> <Compile Include="Classes\appdetails\ReleaseDate.cs" />
<Compile Include="appdetails\Classes\Recommendations.cs" /> <Compile Include="Classes\appdetails\Recommendations.cs" />
<Compile Include="appdetails\Classes\PriceOverview.cs" /> <Compile Include="Classes\appdetails\PriceOverview.cs" />
<Compile Include="appdetails\Classes\Platforms.cs" /> <Compile Include="Classes\appdetails\Platforms.cs" />
<Compile Include="appdetails\Classes\PcRequirements.cs" /> <Compile Include="Classes\appdetails\PcRequirements.cs" />
<Compile Include="appdetails\Classes\PackageGroup.cs" /> <Compile Include="Classes\appdetails\PackageGroup.cs" />
<Compile Include="appdetails\Classes\Movie.cs" /> <Compile Include="Classes\appdetails\Movie.cs" />
<Compile Include="appdetails\Classes\Genre.cs" /> <Compile Include="Classes\appdetails\Genre.cs" />
<Compile Include="appdetails\Classes\Category.cs" /> <Compile Include="Classes\appdetails\Category.cs" />
<Compile Include="appdetails\Classes\Highlighted.cs" /> <Compile Include="Classes\appdetails\Highlighted.cs" />
<Compile Include="appdetails\Classes\Achievements.cs" /> <Compile Include="Classes\appdetails\Achievements.cs" />
<Compile Include="appdetails\Classes\Sub.cs" /> <Compile Include="Classes\featured\FeaturedApp.cs" />
<Compile Include="appdetails\Classes\SupportInfo.cs" /> <Compile Include="Classes\featured\SteamFeatured.cs" />
<Compile Include="appdetails\Classes\Screenshot.cs" /> <Compile Include="Classes\appdetails\Sub.cs" />
<Compile Include="Classes\appdetails\SupportInfo.cs" />
<Compile Include="Classes\appdetails\Screenshot.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="appdetails\Classes\SteamApp.cs" /> <Compile Include="Classes\appdetails\SteamApp.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="packages.config" /> <None Include="packages.config" />

View File

@ -19,9 +19,9 @@ namespace SteamStorefrontConsole
static async Task GetGame() static async Task GetGame()
{ {
//var steamApp = Task.Run(async () => await AppDetails.GetAsync(637670)).Result; var steamApp = Task.Run(async () => await AppDetails.GetAsync(637670)).Result;
//var steamApp = Task.Run(async () => await AppDetails.GetAsync(443790)).Result; //var steamApp = Task.Run(async () => await AppDetails.GetAsync(443790)).Result;
var steamApp = await AppDetails.GetAsync(213670); //var steamApp = await AppDetails.GetAsync(460810, "JP");
Console.WriteLine(steamApp); Console.WriteLine(steamApp);
} }