Skip to content

Commit 1dae8fc

Browse files
author
babelshift
committed
Completed calls to store api endpoints.
1 parent aacda44 commit 1dae8fc

10 files changed

Lines changed: 105 additions & 3 deletions

File tree

SteamWebAPI2.Net451/SteamWebAPI2.Net451.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,9 @@
347347
<Compile Include="..\SteamWebAPI2\Utilities\JsonConverters\GlobalStatJsonConverter.cs">
348348
<Link>Utilities\JsonConverters\GlobalStatJsonConverter.cs</Link>
349349
</Compile>
350+
<Compile Include="..\SteamWebAPI2\Utilities\JsonConverters\StoreAppDetailsContainerJsonConverter.cs">
351+
<Link>Utilities\JsonConverters\StoreAppDetailsContainerJsonConverter.cs</Link>
352+
</Compile>
350353
<Compile Include="..\SteamWebAPI2\Utilities\JsonConverters\TeamInfoJsonConverter.cs">
351354
<Link>Utilities\JsonConverters\TeamInfoJsonConverter.cs</Link>
352355
</Compile>

SteamWebAPI2.Net452/SteamWebAPI2.Net452.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,9 @@
348348
<Compile Include="..\SteamWebAPI2\Utilities\JsonConverters\GlobalStatJsonConverter.cs">
349349
<Link>Utilities\JsonConverters\GlobalStatJsonConverter.cs</Link>
350350
</Compile>
351+
<Compile Include="..\SteamWebAPI2\Utilities\JsonConverters\StoreAppDetailsContainerJsonConverter.cs">
352+
<Link>Utilities\JsonConverters\StoreAppDetailsContainerJsonConverter.cs</Link>
353+
</Compile>
351354
<Compile Include="..\SteamWebAPI2\Utilities\JsonConverters\TeamInfoJsonConverter.cs">
352355
<Link>Utilities\JsonConverters\TeamInfoJsonConverter.cs</Link>
353356
</Compile>

SteamWebAPI2.Portable/SteamWebAPI2.Portable.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,9 @@
339339
<Compile Include="..\SteamWebAPI2\Utilities\JsonConverters\GlobalStatJsonConverter.cs">
340340
<Link>Utilities\JsonConverters\GlobalStatJsonConverter.cs</Link>
341341
</Compile>
342+
<Compile Include="..\SteamWebAPI2\Utilities\JsonConverters\StoreAppDetailsContainerJsonConverter.cs">
343+
<Link>Utilities\JsonConverters\StoreAppDetailsContainerJsonConverter.cs</Link>
344+
</Compile>
342345
<Compile Include="..\SteamWebAPI2\Utilities\JsonConverters\TeamInfoJsonConverter.cs">
343346
<Link>Utilities\JsonConverters\TeamInfoJsonConverter.cs</Link>
344347
</Compile>

SteamWebAPI2/AutoMapperConfiguration.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,36 @@ public static void Initialize()
182182
x.CreateMap<LiveLeagueGamePlayerDetail, LiveLeagueGamePlayerDetailModel>();
183183

184184
x.CreateMap<Data, StoreAppDetailsDataModel>();
185+
x.CreateMap<SupportInfo, StoreSupportInfoModel>();
186+
x.CreateMap<ReleaseDate, StoreReleaseDateModel>();
187+
x.CreateMap<Recommendations, StoreRecommendationsModel>();
188+
x.CreateMap<Movie, StoreMovieModel>();
189+
x.CreateMap<Webm, StoreWebmModel>();
190+
x.CreateMap<Screenshot, StoreScreenshotModel>();
191+
x.CreateMap<Genre, StoreGenreModel>();
192+
x.CreateMap<Category, StoreCategoryModel>();
193+
x.CreateMap<Metacritic, StoreMetacriticModel>();
194+
x.CreateMap<Platforms, StorePlatformsModel>();
195+
x.CreateMap<PackageGroup, StorePackageGroupModel>();
196+
x.CreateMap<Sub, StoreSubModel>();
197+
x.CreateMap<LinuxRequirements, StoreLinuxRequirementsModel>();
198+
x.CreateMap<MacRequirements, StoreMacRequirementsModel>();
199+
x.CreateMap<PcRequirements, StorePcRequirementsModel>();
200+
185201
x.CreateMap<FeaturedCategoriesContainer, StoreFeaturedCategoriesModel>();
202+
x.CreateMap<TrailerSlideshow, StoreTrailerSlideshowModel>();
203+
x.CreateMap<Genres, StoreFeaturedCategoryGenreModel>();
204+
x.CreateMap<NewReleases, StoreNewReleasesModel>();
205+
x.CreateMap<TopSellers, StoreTopSellersModel>();
206+
x.CreateMap<ComingSoon, StoreComingSoonModel>();
207+
x.CreateMap<Specials, StoreSpecialsModel>();
208+
x.CreateMap<Item, StoreItemModel>();
209+
186210
x.CreateMap<FeaturedProductsContainer, StoreFeaturedProductsModel>();
211+
x.CreateMap<FeaturedLinux, StoreFeaturedLinuxModel>();
212+
x.CreateMap<FeaturedMac, StoreFeaturedMacModel>();
213+
x.CreateMap<FeaturedWin, StoreFeaturedWinModel>();
214+
x.CreateMap<LargeCapsule, StoreLargeCapsuleModel>();
187215
});
188216
}
189217

SteamWebAPI2/Interfaces/ISteamStore.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Steam.Models.SteamStore;
2+
using System.Collections.Generic;
23
using System.Threading.Tasks;
34

45
namespace SteamWebAPI2.Interfaces

SteamWebAPI2/Interfaces/SteamStore.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,16 @@ namespace SteamWebAPI2.Interfaces
1111
{
1212
public class SteamStore : SteamStoreInterface, ISteamStore
1313
{
14+
/// <summary>
15+
/// Maps to the steam store api endpoint: GET http://store.steampowered.com/api/appdetails/
16+
/// </summary>
17+
/// <param name="appId"></param>
18+
/// <returns></returns>
1419
public async Task<StoreAppDetailsDataModel> GetStoreAppDetailsAsync(int appId)
1520
{
1621
List<SteamWebRequestParameter> parameters = new List<SteamWebRequestParameter>();
1722

18-
parameters.AddIfHasValue(appId, "appId");
23+
parameters.AddIfHasValue(appId, "appids");
1924

2025
var appDetails = await CallMethodAsync<AppDetailsContainer>("appdetails", parameters);
2126

@@ -24,6 +29,10 @@ public async Task<StoreAppDetailsDataModel> GetStoreAppDetailsAsync(int appId)
2429
return appDetailsModel;
2530
}
2631

32+
/// <summary>
33+
/// Maps to the steam store api endpoint: GET http://store.steampowered.com/api/featuredcategories/
34+
/// </summary>
35+
/// <returns></returns>
2736
public async Task<StoreFeaturedCategoriesModel> GetStoreFeaturedCategoriesAsync()
2837
{
2938
var featuredCategories = await CallMethodAsync<FeaturedCategoriesContainer>("featuredcategories");
@@ -33,9 +42,13 @@ public async Task<StoreFeaturedCategoriesModel> GetStoreFeaturedCategoriesAsync(
3342
return featuredCategoriesModel;
3443
}
3544

45+
/// <summary>
46+
/// Maps to the steam store api endpoint: GET http://store.steampowered.com/api/featured/
47+
/// </summary>
48+
/// <returns></returns>
3649
public async Task<StoreFeaturedProductsModel> GetStoreFeaturedProductsAsync()
3750
{
38-
var featuredProducts = await CallMethodAsync<FeaturedProductsContainer>("featuredcategories");
51+
var featuredProducts = await CallMethodAsync<FeaturedProductsContainer>("featured");
3952

4053
var featuredProductsModel = AutoMapperConfiguration.Mapper.Map<FeaturedProductsContainer, StoreFeaturedProductsModel>(featuredProducts);
4154

SteamWebAPI2/Models/SteamStore/AppDetailsContainer.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Newtonsoft.Json;
2+
using SteamWebAPI2.Utilities.JsonConverters;
23

34
namespace SteamWebAPI2.Models.SteamStore
45
{
@@ -263,6 +264,7 @@ internal class Data
263264
public string Background { get; set; }
264265
}
265266

267+
[JsonConverter(typeof(StoreAppDetailsContainerJsonConverter))]
266268
internal class AppDetailsContainer
267269
{
268270
[JsonProperty("success")]

SteamWebAPI2/Models/SteamStore/FeaturedProductsContainer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ internal class LargeCapsule
2020
public int DiscountPercent { get; set; }
2121

2222
[JsonProperty("original_price")]
23-
public int OriginalPrice { get; set; }
23+
public int? OriginalPrice { get; set; }
2424

2525
[JsonProperty("final_price")]
2626
public int FinalPrice { get; set; }

SteamWebAPI2/SteamWebAPI2.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@
156156
<Compile Include="Utilities\JsonConverters\AssetClassInfoJsonConverter.cs" />
157157
<Compile Include="Utilities\JsonConverters\CSGODataCenterJsonConverter.cs" />
158158
<Compile Include="Utilities\JsonConverters\GlobalStatJsonConverter.cs" />
159+
<Compile Include="Utilities\JsonConverters\StoreAppDetailsContainerJsonConverter.cs" />
159160
<Compile Include="Utilities\JsonConverters\TeamInfoJsonConverter.cs" />
160161
<Compile Include="Utilities\JsonConverters\UnixTimeJsonConverter.cs" />
161162
<Compile Include="Utilities\SteamWebRequestParameterExtensions.cs" />
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using Newtonsoft.Json;
2+
using Newtonsoft.Json.Linq;
3+
using SteamWebAPI2.Models.SteamStore;
4+
using System;
5+
using System.Reflection;
6+
7+
namespace SteamWebAPI2.Utilities.JsonConverters
8+
{
9+
/// <summary>
10+
/// Take some special steps when deserializing the AppDetails response since the response has a dynamic property based on the app id which is passed as a parameter.
11+
/// For example, passing app id "570" to the AppDetails endpoint will give a response like so:
12+
/// "570": {
13+
/// "success": true
14+
/// }
15+
/// </summary>
16+
internal class StoreAppDetailsContainerJsonConverter : JsonConverter
17+
{
18+
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
19+
{
20+
throw new NotImplementedException();
21+
}
22+
23+
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
24+
{
25+
if (reader.TokenType == JsonToken.Null)
26+
{
27+
return null;
28+
}
29+
30+
JObject o = JObject.Load(reader);
31+
32+
foreach (var x in o)
33+
{
34+
var data = x.Value["data"].ToObject<Data>();
35+
return data;
36+
}
37+
38+
return null;
39+
}
40+
41+
public override bool CanWrite { get { return false; } }
42+
43+
public override bool CanConvert(Type objectType)
44+
{
45+
return typeof(AppDetailsContainer).GetTypeInfo().IsAssignableFrom(objectType.GetTypeInfo());
46+
}
47+
}
48+
}

0 commit comments

Comments
 (0)