implementation of spotlight + spotlightIDs; output spotlight
This commit is contained in:
@@ -88,7 +88,7 @@ namespace OnePeek.Api
|
|||||||
/// <param name="store">The store where the app is published.</param>
|
/// <param name="store">The store where the app is published.</param>
|
||||||
/// <param name="storeCulture">Culture of the query (returns location specific metadata + ratings).</param>
|
/// <param name="storeCulture">Culture of the query (returns location specific metadata + ratings).</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<StoreSearchResults> GetSpotlight(StoreSpotlightType spotlightType, StoreType store, StoreCultureType storeCulture)
|
public async Task<StoreSpotlightResults> GetSpotlight(StoreSpotlightType spotlightType, StoreType store, StoreCultureType storeCulture)
|
||||||
{
|
{
|
||||||
if (storeCulture == StoreCultureType.Unknown || storeCulture == StoreCultureType.All)
|
if (storeCulture == StoreCultureType.Unknown || storeCulture == StoreCultureType.All)
|
||||||
{
|
{
|
||||||
@@ -101,11 +101,73 @@ namespace OnePeek.Api
|
|||||||
|
|
||||||
IEnumerable<XElement> xel = XDocument.Parse(xml).Elements().First().Descendants();
|
IEnumerable<XElement> 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<XElement> 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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get spotlight entries for the current day in the specified culture.
|
||||||
|
/// This only returns IDs for fast access.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="spotlightType">Can either be apps or games. Both return approx. 20 new results per day.</param>
|
||||||
|
/// <param name="store">The store where the app is published.</param>
|
||||||
|
/// <param name="storeCulture">Culture of the query (returns location specific metadata + ratings).</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<IEnumerable<string>> 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<string> ids = XDocument.Parse(xml).Elements().First().Descendants().Where(x => x.Name.LocalName == "application").Select(x => x.Descendants().Get("id").Split(':').Last());
|
||||||
|
return ids;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get app description, images, publisher, rating and more for an app in the specified culture.
|
/// Get app description, images, publisher, rating and more for an app in the specified culture.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -48,6 +48,7 @@
|
|||||||
<Compile Include="StoreImageType.cs" />
|
<Compile Include="StoreImageType.cs" />
|
||||||
<Compile Include="StoreReviewSorting.cs" />
|
<Compile Include="StoreReviewSorting.cs" />
|
||||||
<Compile Include="StoreSearchResults.cs" />
|
<Compile Include="StoreSearchResults.cs" />
|
||||||
|
<Compile Include="StoreSpotlightResults.cs" />
|
||||||
<Compile Include="StoreSpotlightType.cs" />
|
<Compile Include="StoreSpotlightType.cs" />
|
||||||
<Compile Include="StoreType.cs" />
|
<Compile Include="StoreType.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ namespace OnePeek.Entities
|
|||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// List of results.
|
/// 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.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public IEnumerable<AppMetadata> Results { get; set; }
|
public IEnumerable<AppMetadata> Results { get; set; }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Xml.Serialization;
|
||||||
|
|
||||||
|
namespace OnePeek.Entities
|
||||||
|
{
|
||||||
|
public partial class StoreSpotlightResults
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Count the results.
|
||||||
|
/// </summary>
|
||||||
|
public int Count { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The type of the store (WP or Windows 8/10)
|
||||||
|
/// </summary>
|
||||||
|
public StoreType StoreType { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The culture is relevant for the review results,
|
||||||
|
/// as they are unique per country
|
||||||
|
/// </summary>
|
||||||
|
public StoreCultureType StoreCultureType { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Spotlight type. Either apps or games.
|
||||||
|
/// </summary>
|
||||||
|
public StoreSpotlightType StoreSpotlightType { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 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.
|
||||||
|
/// </summary>
|
||||||
|
public IEnumerable<AppMetadata> Results { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -16,8 +16,11 @@ namespace OnePeek.WebConsole.Modules
|
|||||||
|
|
||||||
Get["/", true] = async (ctx, token) =>
|
Get["/", true] = async (ctx, token) =>
|
||||||
{
|
{
|
||||||
StoreSearchResults result = await api.GetSpotlight(StoreSpotlightType.Apps, StoreType.WindowsPhone8, StoreCultureType.EN_US);
|
StoreSpotlightResults result = await api.GetSpotlight(StoreSpotlightType.Apps, StoreType.WindowsPhone8, StoreCultureType.EN_US);
|
||||||
return View["Index", result];
|
return View["Index", new
|
||||||
|
{
|
||||||
|
Spotlight = result
|
||||||
|
}];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -3,10 +3,6 @@
|
|||||||
Layout = "_Layout.cshtml";
|
Layout = "_Layout.cshtml";
|
||||||
}
|
}
|
||||||
|
|
||||||
<div class="spotlight">
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<form id="apiquery" action="/meta" method="get">
|
<form id="apiquery" action="/meta" method="get">
|
||||||
<div class="large-12 columns">
|
<div class="large-12 columns">
|
||||||
<h3>API QUERY</h3>
|
<h3>API QUERY</h3>
|
||||||
@@ -37,6 +33,44 @@
|
|||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
<div style="clear:both;"></div>
|
||||||
|
<br /><br />
|
||||||
|
|
||||||
|
<div class="large-12 columns">
|
||||||
|
<h3>SPOTLIGHT</h3>
|
||||||
|
<div class="spotlight">
|
||||||
|
@{ var i = 0; }
|
||||||
|
@foreach (var result in Model.Spotlight.Results)
|
||||||
|
{
|
||||||
|
<a href="/meta/?id=@result.Id" class="spotlight-item">
|
||||||
|
<img src="/api/image/@(result.Images.Logo.Id).jpg" alt="@result.Name" class="spotlight-image" />
|
||||||
|
<b>@result.Name</b>
|
||||||
|
</a>
|
||||||
|
@if (++i % 5 == 0 && i > 1)
|
||||||
|
{
|
||||||
|
<div style="clear:both;float:none;"></div>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.spotlight-item
|
||||||
|
{
|
||||||
|
display: inline-block;
|
||||||
|
width: 20%;
|
||||||
|
float: left;
|
||||||
|
padding: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.spotlight-image
|
||||||
|
{
|
||||||
|
display: block;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
$('#apiquery').on('submit', function (e)
|
$('#apiquery').on('submit', function (e)
|
||||||
|
|||||||
Reference in New Issue
Block a user