From a5dde84207bc78c67f51f17521ad75cd6202b1fa Mon Sep 17 00:00:00 2001 From: Tobias Klika Date: Sat, 18 Apr 2015 19:56:40 +0200 Subject: [PATCH] start search implementation --- src/OnePeek.Api/AppMetadataEndpoint.cs | 37 +++++++++++++++++++ src/OnePeek.Api/AppSpotlightEndpoint.cs | 3 +- src/OnePeek.Api/EndpointUris.cs | 12 +++++++ src/OnePeek.Entities/OnePeek.Entities.csproj | 1 + src/OnePeek.Entities/StoreSearchResults.cs | 38 ++++++++++++++++++++ 5 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 src/OnePeek.Entities/StoreSearchResults.cs diff --git a/src/OnePeek.Api/AppMetadataEndpoint.cs b/src/OnePeek.Api/AppMetadataEndpoint.cs index c838108..717434e 100644 --- a/src/OnePeek.Api/AppMetadataEndpoint.cs +++ b/src/OnePeek.Api/AppMetadataEndpoint.cs @@ -14,6 +14,43 @@ namespace OnePeek.Api { public class AppMetadataEndpoint : ApiBase { + /// + /// Searches for apps based on a term (app name, keywords, ..) + /// + /// Search termn, is typically an app name or keyword (as used in the store interface). + /// The store where the app is published. + /// Culture of the query (returns location specific metadata + ratings). + /// + public async Task 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 xel = XDocument.Parse(xml).Elements().First().Descendants(); + + // create metadatas + StoreSearchResults result = Deserialize.Xml(xml); + result.StoreType = store; + result.StoreCultureType = storeCulture; + + // create results + // TODO + + return result; + } + + /// /// Get app description, images, publisher, rating and more for an app in the specified culture. /// diff --git a/src/OnePeek.Api/AppSpotlightEndpoint.cs b/src/OnePeek.Api/AppSpotlightEndpoint.cs index 4fa6812..fbee3cc 100644 --- a/src/OnePeek.Api/AppSpotlightEndpoint.cs +++ b/src/OnePeek.Api/AppSpotlightEndpoint.cs @@ -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 } } diff --git a/src/OnePeek.Api/EndpointUris.cs b/src/OnePeek.Api/EndpointUris.cs index 2907289..f589ef5 100644 --- a/src/OnePeek.Api/EndpointUris.cs +++ b/src/OnePeek.Api/EndpointUris.cs @@ -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); diff --git a/src/OnePeek.Entities/OnePeek.Entities.csproj b/src/OnePeek.Entities/OnePeek.Entities.csproj index e6a2ccc..6dec3a1 100644 --- a/src/OnePeek.Entities/OnePeek.Entities.csproj +++ b/src/OnePeek.Entities/OnePeek.Entities.csproj @@ -47,6 +47,7 @@ + diff --git a/src/OnePeek.Entities/StoreSearchResults.cs b/src/OnePeek.Entities/StoreSearchResults.cs new file mode 100644 index 0000000..83f5957 --- /dev/null +++ b/src/OnePeek.Entities/StoreSearchResults.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.Xml.Serialization; + +namespace OnePeek.Entities +{ + public partial class StoreSearchResults + { + /// + /// Count the results. + /// + [XmlElement("itemsperpage")] + public int Count { get; set; } + + /// + /// Last modified date of the resource (by Microsoft). + /// + [XmlElement("updated")] + public DateTime? StoreDataModifiedDate { 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; } + + /// + /// List of results. + /// Note that the AppMetadata POCO does not contain all data in this case, only necessary data build a search results list. + /// + public IEnumerable Results { get; set; } + } +}