Added FeaturedCategories endpoint.

This commit is contained in:
mmuffins 2018-05-24 20:13:39 +02:00
parent 8adfcf9b99
commit 975b6991fa
6 changed files with 112 additions and 2 deletions

View File

@ -67,5 +67,11 @@ namespace SteamStorefrontAPI.Classes
[JsonProperty("controller_support", NullValueHandling = NullValueHandling.Ignore)] [JsonProperty("controller_support", NullValueHandling = NullValueHandling.Ignore)]
[JsonConverter(typeof(ControllerSupportConverter))] [JsonConverter(typeof(ControllerSupportConverter))]
public ControllerSupport? ControllerSupport { get; set; } public ControllerSupport? ControllerSupport { get; set; }
[JsonProperty("headline", NullValueHandling = NullValueHandling.Ignore)]
public string Headline { get; set; }
[JsonProperty("purchase_package", NullValueHandling = NullValueHandling.Ignore)]
public string PurchasePackage { get; set; }
} }
} }

View File

@ -0,0 +1,48 @@
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 FeaturedCategory
{
[JsonProperty("id")]
public string Id { get; set; }
[JsonProperty("name")]
public string Name { get; set; }
[JsonProperty("items")]
public List<AppInfo> Items { get; set; }
[JsonProperty("header_image")]
public string HeaderImage { get; set; }
[JsonProperty("body")]
public string Body { get; set; }
[JsonProperty("url")]
public string Url { get; set; }
public static FeaturedCategory FromJson(string json)
{
var serializerSettings = new JsonSerializerSettings
{
MetadataPropertyHandling = MetadataPropertyHandling.Ignore,
DateParseHandling = DateParseHandling.None,
Converters = {
new IsoDateTimeConverter { DateTimeStyles = DateTimeStyles.AssumeUniversal }
},
};
return JsonConvert.DeserializeObject<FeaturedCategory>(json, serializerSettings);
}
}
}

View File

@ -0,0 +1,53 @@
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 FeaturedCategories
{
private static HttpClient client = new HttpClient();
private const string steamBaseUri = "https://store.steampowered.com/api/featuredcategories";
public static async Task<List<FeaturedCategory>> GetAsync()
{
return await GetAsync(null, null);
}
public static async Task<List<FeaturedCategory>> GetAsync(string CountryCode)
{
return await GetAsync(CountryCode, null);
}
public static async Task<List<FeaturedCategory>> 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 = JObject.Parse(result);
if (jsonData["status"].ToString() != "1") { return null; }
var featuredCatList = new List<FeaturedCategory>();
jsonData.Remove("status");
foreach (var item in jsonData.Children())
{
featuredCatList.Add(item.First.ToObject<FeaturedCategory>());
}
return featuredCatList;
}
}
}

View File

@ -43,7 +43,9 @@
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Classes\featuredcategories\FeaturedCategory.cs" />
<Compile Include="Classes\Converters.cs" /> <Compile Include="Classes\Converters.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\appdetails\LinuxRequirements.cs" />
@ -55,7 +57,7 @@
<Compile Include="Classes\appdetails\PcRequirements.cs" /> <Compile Include="Classes\appdetails\PcRequirements.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\appdetails\Genre.cs" /> <Compile Include="Classes\common\Genre.cs" />
<Compile Include="Classes\appdetails\Category.cs" /> <Compile Include="Classes\appdetails\Category.cs" />
<Compile Include="Classes\appdetails\Highlighted.cs" /> <Compile Include="Classes\appdetails\Highlighted.cs" />
<Compile Include="Classes\appdetails\Achievements.cs" /> <Compile Include="Classes\appdetails\Achievements.cs" />

View File

@ -23,7 +23,8 @@ namespace SteamStorefrontConsole
//var steamApp = await AppDetails.GetAsync(443790); //var steamApp = await AppDetails.GetAsync(443790);
//var steamApp = await AppDetails.GetAsync(460810, "JP"); //var steamApp = await AppDetails.GetAsync(460810, "JP");
var featured = await Featured.GetAsync(); //var featured = await Featured.GetAsync();
var featuredCategories = await FeaturedCategories.GetAsync();
//Console.WriteLine(featured); //Console.WriteLine(featured);
} }