start search implementation

This commit is contained in:
2015-04-18 19:56:40 +02:00
parent 955ca6b51d
commit a5dde84207
5 changed files with 90 additions and 1 deletions
+37
View File
@@ -14,6 +14,43 @@ namespace OnePeek.Api
{
public class AppMetadataEndpoint : ApiBase
{
/// <summary>
/// Searches for apps based on a term (app name, keywords, ..)
/// </summary>
/// <param name="searchTerm">Search termn, is typically an app name or keyword (as used in the store interface).</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<StoreSearchResults> Search(string searchTerm, StoreType store, StoreCultureType storeCulture)
{
if (storeCulture == StoreCultureType.Unknown || storeCulture == StoreCultureType.All)
{
throw new ArgumentException("Please provide a valid store culture");
}
if (String.IsNullOrWhiteSpace(searchTerm))
{
throw new ArgumentException("Search term has to contain at least a char.");
}
string xml = await ApiHttpClient.Instance.Get(
EndpointUris.GetWindowsPhoneSearchUri(searchTerm.Trim(), storeCulture.ToString())
);
IEnumerable<XElement> xel = XDocument.Parse(xml).Elements().First().Descendants();
// create metadatas
StoreSearchResults result = Deserialize.Xml<StoreSearchResults>(xml);
result.StoreType = store;
result.StoreCultureType = storeCulture;
// create results
// TODO
return result;
}
/// <summary>
/// Get app description, images, publisher, rating and more for an app in the specified culture.
/// </summary>
+2 -1
View File
@@ -8,6 +8,7 @@ namespace OnePeek.Api
{
public class AppSpotlightEndpoint : ApiBase
{
// starting point
// http://cdn.marketplaceedgeservice.windowsphone.com/v9/catalog/hubs?os=8.10.14219.0&cc=AT&lang=en-US&hw=520293381&dm=RM-1045_1012&oemId=NOKIA&moId=HUT-AT&hub=apps&cf=99-1
}
}
+12
View File
@@ -1,4 +1,5 @@
using System;
using System.Net;
namespace OnePeek.Api
{
@@ -10,6 +11,8 @@ namespace OnePeek.Api
public const string WINDOWSPHONE_REVIEWS_URI = "http://marketplaceedgeservice.windowsphone.com/v9/ratings/product/{0}/reviews?os=8.10.14219.0&cc={1}&lang={2}&dm=RM-1045_1012&chunksize=20&skuId=c1424839-be1e-40eb-8bc3-b2730db30b62&orderBy={3}";
public const string WINDOWSPHONE_SEARCH_URI = "http://marketplaceedgeservice.windowsphone.com/v9/catalog/apps?os=8.10.14219.0&cc={0}&lang={1}&dm=Virtual&chunkSize=50&q={2}";
internal static Uri GetWindowsPhoneMetadataUri(string appId, string culture)
@@ -48,6 +51,15 @@ namespace OnePeek.Api
internal static Uri GetWindowsPhoneSearchUri(string query, string culture)
{
culture = culture.Replace('_', '-');
string country = culture.Split('-')[1];
return Uri(WINDOWSPHONE_SEARCH_URI, country, culture, WebUtility.HtmlEncode(query));
}
private static Uri Uri(string template, params string[] replacements)
{
string uriString = String.Format(template, replacements);
@@ -47,6 +47,7 @@
<Compile Include="StoreCultureType.cs" />
<Compile Include="StoreImageType.cs" />
<Compile Include="StoreReviewSorting.cs" />
<Compile Include="StoreSearchResults.cs" />
<Compile Include="StoreType.cs" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
@@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using System.Xml.Serialization;
namespace OnePeek.Entities
{
public partial class StoreSearchResults
{
/// <summary>
/// Count the results.
/// </summary>
[XmlElement("itemsperpage")]
public int Count { get; set; }
/// <summary>
/// Last modified date of the resource (by Microsoft).
/// </summary>
[XmlElement("updated")]
public DateTime? StoreDataModifiedDate { 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>
/// List of results.
/// Note that the AppMetadata POCO does not contain all data in this case, only necessary data build a search results list.
/// </summary>
public IEnumerable<AppMetadata> Results { get; set; }
}
}