Added featured endpoint.
This commit is contained in:
parent
b2a28190dc
commit
bd85216992
@ -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, "."));
|
||||
}
|
||||
|
||||
|
@ -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,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<SteamFeatured>(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<SteamFeatured>(json, serializerSettings);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
45
SteamStorefrontAPI/Endpoints/Featured.cs
Normal file
45
SteamStorefrontAPI/Endpoints/Featured.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
@ -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" />
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user