diff --git a/SteamStorefrontAPI/Classes/Converters.cs b/SteamStorefrontAPI/Classes/Converters.cs index 15589a4..8a742e6 100644 --- a/SteamStorefrontAPI/Classes/Converters.cs +++ b/SteamStorefrontAPI/Classes/Converters.cs @@ -22,7 +22,14 @@ namespace SteamStorefrontAPI.Classes public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { + if (reader.TokenType == JsonToken.Null) return null; var value = reader.Value.ToString(); + + if(value.Length < 2) + { + return double.Parse($".{value}"); + } + return double.Parse(value.Insert(value.Length - 2, ".")); } diff --git a/SteamStorefrontAPI/Classes/featured/SteamFeatured.cs b/SteamStorefrontAPI/Classes/featured/SteamFeatured.cs index 1547b01..dcb015d 100644 --- a/SteamStorefrontAPI/Classes/featured/SteamFeatured.cs +++ b/SteamStorefrontAPI/Classes/featured/SteamFeatured.cs @@ -12,7 +12,7 @@ namespace SteamStorefrontAPI.Classes public class SteamFeatured { [JsonProperty("large_capsules")] - public List LargeCapsules { get; set; } + public List LargeCapsules { get; set; } [JsonProperty("featured_win")] public List FeaturedWin { get; set; } @@ -26,30 +26,23 @@ namespace SteamStorefrontAPI.Classes [JsonProperty("layout")] public string Layout { get; set; } - [JsonProperty("status")] - public int Status { get; set; } + //[JsonProperty("status")] + //public int Status { get; set; } - public static SteamFeatured FromJson(string json) => JsonConvert.DeserializeObject(json, Converter.Settings); - } - - - - 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 + public static SteamFeatured FromJson(string json) { - MetadataPropertyHandling = MetadataPropertyHandling.Ignore, - DateParseHandling = DateParseHandling.None, - Converters = { + + var serializerSettings = new JsonSerializerSettings + { + MetadataPropertyHandling = MetadataPropertyHandling.Ignore, + DateParseHandling = DateParseHandling.None, + Converters = { new ControllerSupportConverter(), new IsoDateTimeConverter { DateTimeStyles = DateTimeStyles.AssumeUniversal } - }, - }; - } + }, + }; + return JsonConvert.DeserializeObject(json, serializerSettings); + } + } } diff --git a/SteamStorefrontAPI/Endpoints/Featured.cs b/SteamStorefrontAPI/Endpoints/Featured.cs new file mode 100644 index 0000000..745a7c3 --- /dev/null +++ b/SteamStorefrontAPI/Endpoints/Featured.cs @@ -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 Featured + { + private static HttpClient client = new HttpClient(); + private const string steamBaseUri = "https://store.steampowered.com/api/featured"; + + + public static async Task GetAsync() + { + return await GetAsync(null, null); + } + + public static async Task GetAsync(string CountryCode) + { + return await GetAsync(CountryCode, null); + } + + public static async Task GetAsync(string CountryCode, string Language) + { + string steamUri = steamBaseUri; + 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(); + + var jsonData = JToken.Parse(result); + if (jsonData["status"].ToString() != "1") { return null; } + + return SteamFeatured.FromJson(result); + } + } +} diff --git a/SteamStorefrontAPI/SteamStorefrontAPI.csproj b/SteamStorefrontAPI/SteamStorefrontAPI.csproj index dbe7eeb..fd02cd7 100644 --- a/SteamStorefrontAPI/SteamStorefrontAPI.csproj +++ b/SteamStorefrontAPI/SteamStorefrontAPI.csproj @@ -44,6 +44,7 @@ + diff --git a/SteamStorefrontConsole/Program.cs b/SteamStorefrontConsole/Program.cs index 7ba6c60..d80bcf4 100644 --- a/SteamStorefrontConsole/Program.cs +++ b/SteamStorefrontConsole/Program.cs @@ -19,11 +19,13 @@ namespace SteamStorefrontConsole static async Task GetGame() { - var steamApp = Task.Run(async () => await AppDetails.GetAsync(637670)).Result; - //var steamApp = Task.Run(async () => await AppDetails.GetAsync(443790)).Result; + //var steamApp = await AppDetails.GetAsync(637670); + //var steamApp = await AppDetails.GetAsync(443790); //var steamApp = await AppDetails.GetAsync(460810, "JP"); - Console.WriteLine(steamApp); + //var featured = await Featured.GetAsync(); + + //Console.WriteLine(featured); } } }