complete ratings/reviews
This commit is contained in:
@@ -7,6 +7,7 @@ using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace OnePeek.Api
|
||||
{
|
||||
@@ -23,23 +24,37 @@ namespace OnePeek.Api
|
||||
EndpointUris.GetWindowsPhoneReviewsUri(appId, storeCulture.ToString(), sorting.ToString())
|
||||
);
|
||||
|
||||
try
|
||||
{
|
||||
//string entryXml = XDocument.Parse(xml).Descendants().FirstOrDefault(x => x.Name.LocalName == "entry").ToString();
|
||||
IEnumerable<XElement> xel = XDocument.Parse(xml).Elements().First().Descendants();
|
||||
|
||||
AppReviews result = Deserialize.Xml<AppReviews>(xml);
|
||||
result.Id = appId;
|
||||
result.StoreType = store;
|
||||
result.StoreCultureType = storeCulture;
|
||||
result.Sorting = sorting;
|
||||
|
||||
// parse markers
|
||||
result.PrevPageMarkerId = Utils.GetQueryPart(xel.FirstOrDefault(x => x.Name.LocalName == "link" && x.Attribute("rel").Value == "prev"), "href", "beforeMarker");
|
||||
result.NextPageMarkerId = Utils.GetQueryPart(xel.FirstOrDefault(x => x.Name.LocalName == "link" && x.Attribute("rel").Value == "next"), "href", "afterMarker");
|
||||
|
||||
// create images
|
||||
result.Reviews = xel.Where(x => x.Name.LocalName == "entry").Select(x =>
|
||||
{
|
||||
IEnumerable<XElement> childs = x.Descendants();
|
||||
byte rating = (byte)childs.GetFloat("userRating");
|
||||
|
||||
return new AppReview()
|
||||
{
|
||||
Id = childs.Get("reviewId"),
|
||||
CreatedDate = DateTime.Parse(childs.Get("updated")),
|
||||
Author = childs.FirstOrDefault(c => c.Name.LocalName == "author").Descendants().Get("name"),
|
||||
Text = childs.Get("content"),
|
||||
Rating = Configuration.UseFiveStarSystem ? (byte)(rating * 0.5) : rating,
|
||||
Device = childs.Get("device"),
|
||||
AppVersion = childs.Get("productVersion")
|
||||
};
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Debug.WriteLine(exc.Message);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -50,6 +50,7 @@
|
||||
<Compile Include="Extensions\EnumExtensions.cs" />
|
||||
<Compile Include="Extensions\XmlExtensions.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Utils.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\OnePeek.Entities\OnePeek.Entities.csproj">
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace OnePeek.Api
|
||||
{
|
||||
internal static class Utils
|
||||
{
|
||||
public static string GetQueryPart(XElement element, string attribute, string queryKey)
|
||||
{
|
||||
if (element == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
XAttribute attr = element.Attribute(attribute);
|
||||
|
||||
if (attr == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
Match match = new Regex(queryKey + @"=([A-Za-z0-9\-=]+)").Match(attr.Value);
|
||||
return match.Success ? match.Groups[1].Value + "=" : null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
namespace OnePeek.Entities
|
||||
@@ -25,24 +22,32 @@ namespace OnePeek.Entities
|
||||
|
||||
public string NextPageMarkerId { get; set; }
|
||||
|
||||
public List<AppReview> Reviews { get; set; }
|
||||
public IEnumerable<AppReview> Reviews { get; set; }
|
||||
}
|
||||
|
||||
|
||||
[XmlRoot("entry")]
|
||||
public partial class AppReview
|
||||
{
|
||||
public DateTime CreatedDate { get; set; }
|
||||
|
||||
public string Author { get; set; }
|
||||
|
||||
public string Text { get; set; }
|
||||
|
||||
public float Rating { get; set; }
|
||||
|
||||
[XmlElement("reviewId")]
|
||||
public string Id { get; set; }
|
||||
|
||||
[XmlElement("updated")]
|
||||
public DateTime CreatedDate { get; set; }
|
||||
|
||||
[XmlElement("name")]
|
||||
public string Author { get; set; }
|
||||
|
||||
[XmlElement("content")]
|
||||
public string Text { get; set; }
|
||||
|
||||
[XmlElement("userRating")]
|
||||
public byte Rating { get; set; }
|
||||
|
||||
[XmlElement("device")]
|
||||
public string Device { get; set; }
|
||||
|
||||
[XmlElement("productVersion")]
|
||||
public string AppVersion { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Nancy;
|
||||
using Nancy.Responses;
|
||||
using OnePeek.Api;
|
||||
using OnePeek.Entities;
|
||||
using System.IO;
|
||||
@@ -17,6 +18,7 @@ namespace OnePeek.WebConsole
|
||||
{
|
||||
AppMetadata meta = await metaEndpoint.GetMetadata(ctx.id, StoreType.WindowsPhone8, StoreCultureType.EN_US);
|
||||
return Response.AsJson(meta);
|
||||
//return new JsonResponse(ctx)
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user