Added featured endpoint.

This commit is contained in:
mmuffins 2018-05-23 22:58:09 +02:00
parent b2a28190dc
commit bd85216992
5 changed files with 73 additions and 25 deletions

View File

@ -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, "."));
}

View File

@ -12,7 +12,7 @@ namespace SteamStorefrontAPI.Classes
public class SteamFeatured
{
[JsonProperty("large_capsules")]
public List<object> LargeCapsules { get; set; }
public List<FeaturedApp> LargeCapsules { get; set; }
[JsonProperty("featured_win")]
public List<FeaturedApp> FeaturedWin { get; set; }
@ -26,22 +26,13 @@ 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<SteamFeatured>(json, Converter.Settings);
}
public static class Serialize
public static SteamFeatured FromJson(string json)
{
public static string ToJson(this SteamFeatured self) => JsonConvert.SerializeObject(self, Converter.Settings);
}
static class Converter
{
public static readonly JsonSerializerSettings Settings = new JsonSerializerSettings
var serializerSettings = new JsonSerializerSettings
{
MetadataPropertyHandling = MetadataPropertyHandling.Ignore,
DateParseHandling = DateParseHandling.None,
@ -50,6 +41,8 @@ namespace SteamStorefrontAPI.Classes
new IsoDateTimeConverter { DateTimeStyles = DateTimeStyles.AssumeUniversal }
},
};
}
return JsonConvert.DeserializeObject<SteamFeatured>(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 Featured
{
private static HttpClient client = new HttpClient();
private const string steamBaseUri = "https://store.steampowered.com/api/featured";
public static async Task<SteamFeatured> GetAsync()
{
return await GetAsync(null, null);
}
public static async Task<SteamFeatured> GetAsync(string CountryCode)
{
return await GetAsync(CountryCode, null);
}
public static async Task<SteamFeatured> 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);
}
}
}

View File

@ -44,6 +44,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Classes\Converters.cs" />
<Compile Include="Endpoints\Featured.cs" />
<Compile Include="Endpoints\AppDetails.cs" />
<Compile Include="Classes\appdetails\LinuxRequirements.cs" />
<Compile Include="Classes\appdetails\MacRequirements.cs" />

View File

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