diff --git a/src/OnePeek.Api/OnePeekApi.cs b/src/OnePeek.Api/OnePeekApi.cs index c64a112..9ec98f8 100644 --- a/src/OnePeek.Api/OnePeekApi.cs +++ b/src/OnePeek.Api/OnePeekApi.cs @@ -88,7 +88,7 @@ namespace OnePeek.Api /// The store where the app is published. /// Culture of the query (returns location specific metadata + ratings). /// - public async Task GetSpotlight(StoreSpotlightType spotlightType, StoreType store, StoreCultureType storeCulture) + public async Task GetSpotlight(StoreSpotlightType spotlightType, StoreType store, StoreCultureType storeCulture) { if (storeCulture == StoreCultureType.Unknown || storeCulture == StoreCultureType.All) { @@ -101,11 +101,73 @@ namespace OnePeek.Api IEnumerable xel = XDocument.Parse(xml).Elements().First().Descendants(); - StoreSearchResults result = new StoreSearchResults(); + StoreSpotlightResults result = new StoreSpotlightResults(); + result.StoreCultureType = storeCulture; + result.StoreSpotlightType = spotlightType; + result.StoreType = store; + result.Results = xel.Where(x => x.Name.LocalName == "application").Select(x => + { + IEnumerable childs = x.Descendants(); + + float rating = childs.GetFloat("averageUserRating"); + + if (Configuration.UseFiveStarSystem) + { + rating = rating * 0.5f; + } + + AppMetadata data = new AppMetadata() + { + Id = childs.Get("id").Split(':').Last(), + Urn = childs.Get("id"), + Name = childs.Get("title"), + Rating = new AppRating() + { + AverageRating = rating, + RatingCount = Convert.ToInt32(childs.Get("userRatingCount")) + }, + Images = new AppMetadataImages() + { + Logo = new AppImage() + { + Rotation = 0, + Urn = childs.Get("image") + } + } + }; + + return data; + }); + result.Count = result.Results.Count(); + return result; } + /// + /// Get spotlight entries for the current day in the specified culture. + /// This only returns IDs for fast access. + /// + /// Can either be apps or games. Both return approx. 20 new results per day. + /// The store where the app is published. + /// Culture of the query (returns location specific metadata + ratings). + /// + public async Task> GetSpotlightIds(StoreSpotlightType spotlightType, StoreType store, StoreCultureType storeCulture) + { + if (storeCulture == StoreCultureType.Unknown || storeCulture == StoreCultureType.All) + { + throw new ArgumentException("Please provide a valid store culture"); + } + + Uri uri = EndpointUris.GetWindowsPhoneSpotlightUri(storeCulture.ToString(), spotlightType.GetEnumDisplayName()); + + string xml = await ApiHttpClient.Instance.Get(uri); + + IEnumerable ids = XDocument.Parse(xml).Elements().First().Descendants().Where(x => x.Name.LocalName == "application").Select(x => x.Descendants().Get("id").Split(':').Last()); + return ids; + } + + /// /// Get app description, images, publisher, rating and more for an app in the specified culture. /// diff --git a/src/OnePeek.Entities/OnePeek.Entities.csproj b/src/OnePeek.Entities/OnePeek.Entities.csproj index face56f..2bc1f19 100644 --- a/src/OnePeek.Entities/OnePeek.Entities.csproj +++ b/src/OnePeek.Entities/OnePeek.Entities.csproj @@ -48,6 +48,7 @@ + diff --git a/src/OnePeek.Entities/StoreSearchResults.cs b/src/OnePeek.Entities/StoreSearchResults.cs index 83f5957..2b00738 100644 --- a/src/OnePeek.Entities/StoreSearchResults.cs +++ b/src/OnePeek.Entities/StoreSearchResults.cs @@ -31,7 +31,7 @@ namespace OnePeek.Entities /// /// List of results. - /// Note that the AppMetadata POCO does not contain all data in this case, only necessary data build a search results list. + /// Note that the AppMetadata POCO does not contain all data in this case, only necessary data to build a search results list. /// public IEnumerable Results { get; set; } } diff --git a/src/OnePeek.Entities/StoreSpotlightResults.cs b/src/OnePeek.Entities/StoreSpotlightResults.cs new file mode 100644 index 0000000..4fa2b6f --- /dev/null +++ b/src/OnePeek.Entities/StoreSpotlightResults.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.Xml.Serialization; + +namespace OnePeek.Entities +{ + public partial class StoreSpotlightResults + { + /// + /// Count the results. + /// + public int Count { get; set; } + + /// + /// The type of the store (WP or Windows 8/10) + /// + public StoreType StoreType { get; set; } + + /// + /// The culture is relevant for the review results, + /// as they are unique per country + /// + public StoreCultureType StoreCultureType { get; set; } + + /// + /// Spotlight type. Either apps or games. + /// + public StoreSpotlightType StoreSpotlightType { get; set; } + + /// + /// List of results. + /// Note that the AppMetadata POCO does not contain all data in this case, only necessary data to build a spotlight results list. + /// + public IEnumerable Results { get; set; } + } +} diff --git a/src/OnePeek.WebConsole/Modules/HomeModule.cs b/src/OnePeek.WebConsole/Modules/HomeModule.cs index 8ac8c82..56688ce 100644 --- a/src/OnePeek.WebConsole/Modules/HomeModule.cs +++ b/src/OnePeek.WebConsole/Modules/HomeModule.cs @@ -16,8 +16,11 @@ namespace OnePeek.WebConsole.Modules Get["/", true] = async (ctx, token) => { - StoreSearchResults result = await api.GetSpotlight(StoreSpotlightType.Apps, StoreType.WindowsPhone8, StoreCultureType.EN_US); - return View["Index", result]; + StoreSpotlightResults result = await api.GetSpotlight(StoreSpotlightType.Apps, StoreType.WindowsPhone8, StoreCultureType.EN_US); + return View["Index", new + { + Spotlight = result + }]; }; diff --git a/src/OnePeek.WebConsole/Views/Index.cshtml b/src/OnePeek.WebConsole/Views/Index.cshtml index 6fe6047..7d68e90 100644 --- a/src/OnePeek.WebConsole/Views/Index.cshtml +++ b/src/OnePeek.WebConsole/Views/Index.cshtml @@ -3,10 +3,6 @@ Layout = "_Layout.cshtml"; } -
- -
-

API QUERY

@@ -37,6 +33,44 @@
+
+

+ +
+

SPOTLIGHT

+
+ @{ var i = 0; } + @foreach (var result in Model.Spotlight.Results) + { + + @result.Name + @result.Name + + @if (++i % 5 == 0 && i > 1) + { +
+ } + } +
+
+ + + +