Skip to content

Commit 917af3b

Browse files
author
Justin Skiles
authored
Merge pull request #77 from peppage/master
add short description and price overview to app details data
2 parents 73eaa5a + 24af4e6 commit 917af3b

5 files changed

Lines changed: 80 additions & 9 deletions

File tree

src/SteamWebAPI2/AutoMapperConfiguration.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,7 @@ public static void Initialize()
579579
x.CreateMap<Metacritic, StoreMetacriticModel>();
580580
x.CreateMap<Platforms, StorePlatformsModel>();
581581
x.CreateMap<PackageGroup, StorePackageGroupModel>();
582+
x.CreateMap<Price, StorePriceOverview>();
582583
x.CreateMap<Sub, StoreSubModel>();
583584

584585
x.CreateMap<FeaturedCategoriesContainer, StoreFeaturedCategoriesModel>();
@@ -658,4 +659,4 @@ public static void Reset()
658659
mapper = null;
659660
}
660661
}
661-
}
662+
}

src/SteamWebAPI2/Interfaces/SteamStore.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,21 @@
22
using SteamWebAPI2.Models.SteamStore;
33
using SteamWebAPI2.Utilities;
44
using System.Collections.Generic;
5+
using System.Net.Http;
56
using System.Threading.Tasks;
67

78
namespace SteamWebAPI2.Interfaces
89
{
910
public class SteamStore : SteamStoreInterface, ISteamStore
1011
{
12+
public SteamStore() : base()
13+
{
14+
}
15+
16+
public SteamStore(HttpClient httpClient) : base(httpClient)
17+
{
18+
}
19+
1120
/// <summary>
1221
/// Maps to the steam store api endpoint: GET http://store.steampowered.com/api/appdetails/
1322
/// </summary>
@@ -52,4 +61,4 @@ public async Task<StoreFeaturedProductsModel> GetStoreFeaturedProductsAsync()
5261
return featuredProductsModel;
5362
}
5463
}
55-
}
64+
}

src/SteamWebAPI2/Models/SteamStore/AppDetailsContainer.cs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,27 @@ internal class SupportInfo
159159
public string Email { get; set; }
160160
}
161161

162+
internal class Price
163+
{
164+
[JsonProperty("currency")]
165+
public string Currency { get; set; }
166+
167+
[JsonProperty("initial")]
168+
public uint Initial { get; set; }
169+
170+
[JsonProperty("final")]
171+
public uint Final { get; set; }
172+
173+
[JsonProperty("discount_percent")]
174+
public uint DiscountPercent { get; set; }
175+
176+
[JsonProperty("initial_formatted")]
177+
public string InitialFormatted { get; set; }
178+
179+
[JsonProperty("final_formatted")]
180+
public string FinalFormatted { get; set; }
181+
}
182+
162183
internal class Data
163184
{
164185
[JsonProperty("type")]
@@ -185,6 +206,9 @@ internal class Data
185206
[JsonProperty("about_the_game")]
186207
public string AboutTheGame { get; set; }
187208

209+
[JsonProperty("short_description")]
210+
public string ShortDescription { get; set; }
211+
188212
[JsonProperty("supported_languages")]
189213
public string SupportedLanguages { get; set; }
190214

@@ -206,6 +230,9 @@ internal class Data
206230
[JsonProperty("developers")]
207231
public string[] Developers { get; set; }
208232

233+
[JsonProperty("price_overview")]
234+
public Price PriceOverview { get; set; }
235+
209236
[JsonProperty("publishers")]
210237
public string[] Publishers { get; set; }
211238

@@ -255,4 +282,4 @@ internal class AppDetailsContainer
255282
[JsonProperty("data")]
256283
public Data Data { get; set; }
257284
}
258-
}
285+
}

src/SteamWebAPI2/SteamStoreInterface.cs

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
using System;
33
using System.Collections.Generic;
44
using System.Diagnostics;
5-
using System.Linq;
6-
using System.Text;
5+
using System.Net.Http;
76
using System.Threading.Tasks;
87

98
namespace SteamWebAPI2
@@ -15,7 +14,7 @@ public abstract class SteamStoreInterface
1514
{
1615
private const string steamStoreApiBaseUrl = "http://store.steampowered.com/api/";
1716
private readonly SteamStoreRequest steamStoreRequest;
18-
17+
1918
/// <summary>
2019
/// Constructs and maps the default objects for Steam Store Web API use
2120
/// </summary>
@@ -26,6 +25,17 @@ public SteamStoreInterface()
2625
AutoMapperConfiguration.Initialize();
2726
}
2827

28+
/// <summary>
29+
/// Constructs and maps based on a custom http client
30+
/// </summary>
31+
/// <param name="httpClient">Client to make requests with</param>
32+
public SteamStoreInterface(HttpClient httpClient)
33+
{
34+
this.steamStoreRequest = new SteamStoreRequest(steamStoreApiBaseUrl, httpClient);
35+
36+
AutoMapperConfiguration.Initialize();
37+
}
38+
2939
/// <summary>
3040
/// Constructs and maps based on a custom Steam Store Web API URL
3141
/// </summary>
@@ -37,6 +47,18 @@ public SteamStoreInterface(string steamStoreApiBaseUrl)
3747
AutoMapperConfiguration.Initialize();
3848
}
3949

50+
/// <summary>
51+
/// Constructs and maps based on a custom http client and custom Steam Store Web API URL
52+
/// </summary>
53+
/// <param name="steamStoreApiBaseUrl">Steam Store Web API URL</param>
54+
/// <param name="httpClient">Client to make requests with</param>
55+
public SteamStoreInterface(string steamStoreApiBaseUrl, HttpClient httpClient)
56+
{
57+
this.steamStoreRequest = new SteamStoreRequest(steamStoreApiBaseUrl, httpClient);
58+
59+
AutoMapperConfiguration.Initialize();
60+
}
61+
4062
/// <summary>
4163
/// Calls a endpoint on the constructed Web API with parameters
4264
/// </summary>

src/SteamWebAPI2/SteamStoreRequest.cs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ namespace SteamWebAPI2
1414
internal class SteamStoreRequest
1515
{
1616
private string steamStoreApiBaseUrl;
17+
private readonly HttpClient httpClient;
1718

1819
/// <summary>
1920
/// Constructs a Steam Store Web API request
@@ -29,6 +30,17 @@ public SteamStoreRequest(string steamStoreApiBaseUrl)
2930
this.steamStoreApiBaseUrl = steamStoreApiBaseUrl;
3031
}
3132

33+
public SteamStoreRequest(string steamStoreApiBaseUrl, HttpClient httpClient)
34+
{
35+
if (String.IsNullOrEmpty(steamStoreApiBaseUrl))
36+
{
37+
throw new ArgumentNullException("steamStoreApiBaseUrl");
38+
}
39+
40+
this.steamStoreApiBaseUrl = steamStoreApiBaseUrl;
41+
this.httpClient = httpClient;
42+
}
43+
3244
/// <summary>
3345
/// Sends a request to a Steam Store Web API endpoint
3446
/// </summary>
@@ -71,10 +83,10 @@ public async Task<T> SendStoreRequestAsync<T>(string endpointName, IList<SteamWe
7183
/// </summary>
7284
/// <param name="command">Command (method endpoint) to send to an interface</param>
7385
/// <returns>HTTP response as a string without tabs and newlines</returns>
74-
private static async Task<string> GetHttpStringResponseAsync(string command)
86+
private async Task<string> GetHttpStringResponseAsync(string command)
7587
{
76-
HttpClient httpClient = new HttpClient();
77-
string response = await httpClient.GetStringAsync(command);
88+
HttpClient client = httpClient ?? new HttpClient();
89+
string response = await client.GetStringAsync(command);
7890
response = response.Replace("\n", "");
7991
response = response.Replace("\t", "");
8092
return response;

0 commit comments

Comments
 (0)