From bfe83c9c784ba9b55fca6e113ddefe0db571d981 Mon Sep 17 00:00:00 2001 From: Tobias Klika Date: Mon, 27 Apr 2015 23:56:11 +0200 Subject: [PATCH] search api --- src/OnePeek.Api/OnePeekApi.cs | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/src/OnePeek.Api/OnePeekApi.cs b/src/OnePeek.Api/OnePeekApi.cs index 1b048e2..d3e77c9 100644 --- a/src/OnePeek.Api/OnePeekApi.cs +++ b/src/OnePeek.Api/OnePeekApi.cs @@ -32,9 +32,9 @@ namespace OnePeek.Api throw new ArgumentException("Search term has to contain at least a char."); } - string xml = await ApiHttpClient.Instance.Get( - EndpointUris.GetWindowsPhoneSearchUri(searchTerm.Trim(), storeCulture.ToString()) - ); + Uri uri = EndpointUris.GetWindowsPhoneSearchUri(searchTerm.Trim(), storeCulture.ToString()); + + string xml = await ApiHttpClient.Instance.Get(uri); IEnumerable xel = XDocument.Parse(xml).Elements().First().Descendants(); @@ -42,9 +42,30 @@ namespace OnePeek.Api StoreSearchResults result = Deserialize.Xml(xml); result.StoreType = store; result.StoreCultureType = storeCulture; + result.Results = xel.Where(x => x.Name.LocalName == "entry").Select(x => + { + IEnumerable childs = x.Descendants(); - // create results - // TODO + float rating = childs.GetFloat("averageUserRating"); + + if (Configuration.UseFiveStarSystem) + { + rating = rating * 0.5f; + } + + return 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")) + } + }; + }); + result.Count = result.Results.Count(); return result; }